浏览代码

Merge branch 'hackweek2017' of https://github.com/stramit/MaterialGraph into hackweek2017

/main
Eduardo Chaves 8 年前
当前提交
4adac24f
共有 1 个文件被更改,包括 46 次插入1 次删除
  1. 47
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/UV/UVRotatorNode.cs

47
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/UV/UVRotatorNode.cs


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;
}
}
}
正在加载...
取消
保存