FunctionMultiInput.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. namespace UnityEditor.ShaderGraph
  2. {
  3. /*abstract class FunctionMultiInput : BaseMaterialNode, IGeneratesBodyCode
  4. {
  5. private const string kOutputSlotName = "Output";
  6. private const string kBaseInputSlotName = "Input";
  7. public override bool hasPreview { get { return true; } }
  8. public override void OnCreate()
  9. {
  10. base.OnCreate();
  11. AddSlot(new Slot(SlotType.OutputSlot, kOutputSlotName));
  12. AddSlot(new Slot(SlotType.InputSlot, GetInputSlotName(0)));
  13. AddSlot(new Slot(SlotType.InputSlot, GetInputSlotName(1)));
  14. }
  15. protected bool IsInputSlotConnected(int index)
  16. {
  17. var inputSlot = GetValidInputSlots().FirstOrDefault(x => x.name == GetInputSlotName(index));
  18. if (inputSlot == null)
  19. {
  20. Debug.LogError("Invalid slot configuration on node: " + name);
  21. return false;
  22. }
  23. return inputSlot.edges.Count > 0;
  24. }
  25. private static string GetInputSlotName(int index) { return kBaseInputSlotName + (index); }
  26. public override void InputEdgeChanged(Edge e)
  27. {
  28. base.InputEdgeChanged(e);
  29. int inputSlotCount = GetValidInputSlots().Count();
  30. if (IsInputSlotConnected(inputSlotCount - 1))
  31. AddSlot(new Slot(SlotType.InputSlot, GetInputSlotName(inputSlotCount)));
  32. else if (inputSlotCount > 2)
  33. {
  34. var lastSlot = inputSlots.FirstOrDefault(x => x.name == GetInputSlotName(inputSlotCount - 1));
  35. if (lastSlot != null)
  36. RemoveSlot(lastSlot);
  37. }
  38. }
  39. protected abstract string GetFunctionName();
  40. public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
  41. {
  42. var outputSlot = outputSlots.FirstOrDefault(x => x.name == kOutputSlotName);
  43. if (outputSlot == null)
  44. {
  45. Debug.LogError("Invalid slot configuration on node: " + name);
  46. return;
  47. }
  48. var inputSlots = GetValidInputSlots();
  49. int inputSlotCount = inputSlots.Count();
  50. // build up a list of the valid input connections
  51. var inputValues = new List<string>(inputSlotCount);
  52. MaterialWindow.DebugMaterialGraph("Generating On Node: " + GetOutputVariableNameForNode() + " - Preview is: " + generationMode);
  53. inputValues.AddRange(inputSlots.Select(inputSlot => GetSlotValue(inputSlot, generationMode)));
  54. visitor.AddShaderChunk(precision + "4 " + GetVariableNameForSlot(outputSlot, generationMode) + " = " + GetFunctionCallBody(inputValues) + ";", true);
  55. }
  56. protected virtual string GetFunctionCallBody(List<string> inputValues)
  57. {
  58. string functionCall = inputValues[0];
  59. for (int q = 1; q < inputValues.Count; ++q)
  60. functionCall = GetFunctionName() + " (" + functionCall + ", " + inputValues[q] + ")";
  61. return functionCall;
  62. }
  63. }*/
  64. }