Ingen beskrivning
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PropertyConnectionStateMaterialSlot.cs 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System;
  2. using UnityEditor.Graphing;
  3. using UnityEditor.ShaderGraph.Drawing.Slots;
  4. using UnityEditor.ShaderGraph.Internal;
  5. using UnityEngine.UIElements;
  6. namespace UnityEditor.ShaderGraph
  7. {
  8. [Serializable]
  9. class PropertyConnectionStateMaterialSlot : MaterialSlot, IMaterialSlotHasValue<bool>
  10. {
  11. public PropertyConnectionStateMaterialSlot()
  12. { }
  13. public PropertyConnectionStateMaterialSlot(
  14. int slotId,
  15. string displayName,
  16. string shaderOutputName,
  17. SlotType slotType,
  18. ShaderStageCapability stageCapability = ShaderStageCapability.All,
  19. bool hidden = false)
  20. : base(slotId, displayName, shaderOutputName, slotType, stageCapability, hidden)
  21. {
  22. }
  23. public override VisualElement InstantiateControl()
  24. {
  25. return new PropertyConnectionStateSlotControlView(this);
  26. }
  27. protected override string ConcreteSlotValueAsVariable()
  28. {
  29. // This is a funky slot, that doesn't directly hold a value.
  30. return "false";
  31. }
  32. public bool defaultValue
  33. {
  34. // This is a funky slot, that doesn't directly hold a value.
  35. get { return false; }
  36. }
  37. public bool value
  38. {
  39. // This is a funky slot, that doesn't directly hold a value.
  40. get { return false; }
  41. }
  42. public override bool isDefaultValue => true;
  43. public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)
  44. {
  45. if (!generationMode.IsPreview())
  46. return;
  47. if (owner == null)
  48. throw new Exception(string.Format("Slot {0} either has no owner, or the owner is not a {1}", this, typeof(AbstractMaterialNode)));
  49. var property = new BooleanShaderProperty()
  50. {
  51. overrideReferenceName = owner.GetVariableNameForSlot(id),
  52. generatePropertyBlock = false,
  53. value = isConnected
  54. };
  55. properties.AddShaderProperty(property);
  56. }
  57. public override SlotValueType valueType { get { return SlotValueType.PropertyConnectionState; } }
  58. public override ConcreteSlotValueType concreteValueType { get { return ConcreteSlotValueType.PropertyConnectionState; } }
  59. public override void CopyValuesFrom(MaterialSlot foundSlot)
  60. {
  61. // This is a funky slot, that doesn't directly hold a value.
  62. }
  63. }
  64. }