|
|
|
|
|
|
using UnityEngine.Graphing; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
public class UVRotatorNode : Function2Input, IGeneratesFunction |
|
|
|
public class UVRotatorNode : Function2Input, IGeneratesFunction, IMayRequireMeshUV |
|
|
|
{ |
|
|
|
private const string kUVSlotName = "UV"; |
|
|
|
private const string kRotationSlotName = "Rotation"; |
|
|
|
|
|
|
return new MaterialSlot(OutputSlotId, kUVSlotName, kUVSlotName, SlotType.Output, SlotValueType.Vector4, Vector4.zero); |
|
|
|
} |
|
|
|
|
|
|
|
protected override string GetFunctionCallBody(string input1Value, string input2Value) |
|
|
|
{ |
|
|
|
//get input UV slot
|
|
|
|
var uvName = string.Format("{0}", UVChannel.uv0.GetUVName()); |
|
|
|
bool isConnected = false; |
|
|
|
|
|
|
|
var uvSlot = FindInputSlot<MaterialSlot>(InputSlot1Id); |
|
|
|
if (uvSlot != null) |
|
|
|
{ |
|
|
|
var edges = owner.GetEdges(uvSlot.slotReference).ToList(); |
|
|
|
|
|
|
|
if (edges.Count > 0) |
|
|
|
{ |
|
|
|
var edge = edges[0]; |
|
|
|
var fromNode = owner.GetNodeFromGuid<AbstractMaterialNode>(edge.outputSlot.nodeGuid); |
|
|
|
uvName = ShaderGenerator.AdaptNodeOutput(fromNode, edge.outputSlot.slotId, ConcreteSlotValueType.Vector4, true); |
|
|
|
isConnected = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (isConnected) |
|
|
|
return GetFunctionName() + " (" + input1Value + ", " + input2Value + ")"; |
|
|
|
else |
|
|
|
return GetFunctionName() + " (" + uvName + ", " + input2Value + ")"; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
outputString.AddShaderChunk(GetFunctionPrototype("arg1", "arg2"), false); |
|
|
|
outputString.AddShaderChunk("{", false); |
|
|
|
outputString.Indent(); |
|
|
|
|
|
|
outputString.AddShaderChunk("}", false); |
|
|
|
|
|
|
|
visitor.AddShaderChunk(outputString.GetShaderString(0), true); |
|
|
|
} |
|
|
|
|
|
|
|
public bool RequiresMeshUV(UVChannel channel) |
|
|
|
{ |
|
|
|
if (channel != UVChannel.uv0) |
|
|
|
{ |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
var uvSlot = FindInputSlot<MaterialSlot>(InputSlot1Id); |
|
|
|
if (uvSlot == null) |
|
|
|
return true; |
|
|
|
|
|
|
|
var edges = owner.GetEdges(uvSlot.slotReference).ToList(); |
|
|
|
return edges.Count == 0; |
|
|
|
} |
|
|
|
} |
|
|
|
} |