浏览代码

Added an IF node

/main
bfogerty 8 年前
当前提交
c80b6a3a
共有 6 个文件被更改,包括 212 次插入0 次删除
  1. 39
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/IfNodePresenter.cs
  2. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/IfNodePresenter.cs.meta
  3. 9
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Logic.meta
  4. 140
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Logic/IFNode.cs
  5. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Logic/IFNode.cs.meta

39
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/IfNodePresenter.cs


using System;
using System.Collections.Generic;
using RMGUI.GraphView;
using UnityEditor.Graphing.Drawing;
using UnityEngine;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing
{
class IfControlPresenter : GraphControlPresenter
{
public override void OnGUIHandler()
{
base.OnGUIHandler();
var tNode = node as UnityEngine.MaterialGraph.IfNode;
if (tNode == null)
return;
tNode.ComparisonOperation = (IfNode.ComparisonOperationType)EditorGUILayout.EnumPopup(tNode.ComparisonOperation);
}
public override float GetHeight()
{
return (EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing) + EditorGUIUtility.standardVerticalSpacing;
}
}
[Serializable]
public class IfNodePresenter : PropertyNodePresenter
{
protected override IEnumerable<GraphElementPresenter> GetControlData()
{
var instance = CreateInstance<IfControlPresenter>();
instance.Initialize(node);
return new List<GraphElementPresenter>(base.GetControlData()) { instance };
}
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/IfNodePresenter.cs.meta


fileFormatVersion: 2
guid: cdcac458dbe6b9d4c8425beecc36b37d
timeCreated: 1495614828
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

9
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Logic.meta


fileFormatVersion: 2
guid: ccd4e915255073341a538223ae6838f8
folderAsset: yes
timeCreated: 1495614357
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

140
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Logic/IFNode.cs


using UnityEngine.MaterialGraph;
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph
{
[Title("Logic/If")]
public class IfNode : Function4Input, IGeneratesFunction
{
public enum ComparisonOperationType
{
Equal = 0,
NotEqual,
GreaterThan,
GreaterThanOfEqual,
LessThan,
LessThanOfEqual
}
[SerializeField]
private ComparisonOperationType m_comparisonOperation = ComparisonOperationType.Equal;
public ComparisonOperationType ComparisonOperation
{
get { return m_comparisonOperation; }
set
{
if (m_comparisonOperation == value)
return;
m_comparisonOperation = value;
if (onModified != null)
{
onModified(this, ModificationScope.Graph);
}
}
}
public IfNode()
{
name = "If";
}
protected override string GetFunctionName()
{
return "unity_if_" + precision;
}
protected override string GetInputSlot1Name()
{
return "A";
}
protected override string GetInputSlot2Name()
{
return "B";
}
protected override string GetInputSlot3Name()
{
return "True Value";
}
protected override string GetInputSlot4Name()
{
return "False Value";
}
protected override MaterialSlot GetInputSlot1()
{
return new MaterialSlot(InputSlot1Id, GetInputSlot1Name(), kInputSlot1ShaderName, UnityEngine.Graphing.SlotType.Input, SlotValueType.Dynamic, Vector4.zero);
}
protected override MaterialSlot GetInputSlot2()
{
return new MaterialSlot(InputSlot2Id, GetInputSlot2Name(), kInputSlot2ShaderName, UnityEngine.Graphing.SlotType.Input, SlotValueType.Dynamic, Vector4.zero);
}
protected override MaterialSlot GetInputSlot3()
{
return new MaterialSlot(InputSlot3Id, GetInputSlot3Name(), kInputSlot3ShaderName, UnityEngine.Graphing.SlotType.Input, SlotValueType.Dynamic, Vector4.zero);
}
protected override MaterialSlot GetOutputSlot()
{
return new MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotShaderName, UnityEngine.Graphing.SlotType.Output, SlotValueType.Dynamic, Vector4.zero);
}
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)
{
var outputString = new ShaderGenerator();
outputString.AddShaderChunk(GetFunctionPrototype("a", "b", "trueOutputValue", "falseOutputValue"), false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
if (m_comparisonOperation == ComparisonOperationType.Equal)
{
outputString.AddShaderChunk("if (a == b)", false);
}
else if (m_comparisonOperation == ComparisonOperationType.NotEqual)
{
outputString.AddShaderChunk("if (a != b)", false);
}
else if (m_comparisonOperation == ComparisonOperationType.GreaterThan)
{
outputString.AddShaderChunk("if (a > b)", false);
}
else if (m_comparisonOperation == ComparisonOperationType.GreaterThanOfEqual)
{
outputString.AddShaderChunk("if (a >= b)", false);
}
else if (m_comparisonOperation == ComparisonOperationType.LessThan)
{
outputString.AddShaderChunk("if (a < b)", false);
}
else if (m_comparisonOperation == ComparisonOperationType.LessThanOfEqual)
{
outputString.AddShaderChunk("if (a <= b)", false);
}
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("return trueOutputValue;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
outputString.AddShaderChunk("else", false);
outputString.AddShaderChunk("{", false);
outputString.Indent();
outputString.AddShaderChunk("return falseOutputValue;", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
}
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/Logic/IFNode.cs.meta


fileFormatVersion: 2
guid: 53320a9c47f832e48a46514afeed9049
timeCreated: 1495614367
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存