浏览代码

Comment out IfNode for now

/main
Peter Bay Bastian 7 年前
当前提交
152042bb
共有 4 个文件被更改,包括 131 次插入181 次删除
  1. 261
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Logic/IFNode.cs
  2. 1
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
  3. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/IfNodePresenter.cs.meta
  4. 38
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/IfNodePresenter.cs

261
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Logic/IFNode.cs


namespace UnityEngine.MaterialGraph
{
[Title("Logic/If")]
public class IfNode : CodeFunctionNode
{
public enum ComparisonOperationType
{
Equal = 0,
NotEqual,
GreaterThan,
GreaterThanOrEqual,
LessThan,
LessThanOrEqual
}
[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 MethodInfo GetFunctionToConvert()
{
switch (ComparisonOperation)
{
case ComparisonOperationType.Equal:
return GetType().GetMethod("Unity_IfEqual", BindingFlags.Static | BindingFlags.NonPublic);
case ComparisonOperationType.NotEqual:
return GetType().GetMethod("Unity_IfNotEqual", BindingFlags.Static | BindingFlags.NonPublic);
case ComparisonOperationType.GreaterThan:
return GetType().GetMethod("Unity_IfGreaterThan", BindingFlags.Static | BindingFlags.NonPublic);
case ComparisonOperationType.GreaterThanOrEqual:
return GetType().GetMethod("Unity_IfGreaterThanOrEqual", BindingFlags.Static | BindingFlags.NonPublic);
case ComparisonOperationType.LessThan:
return GetType().GetMethod("Unity_IfLessThan", BindingFlags.Static | BindingFlags.NonPublic);
case ComparisonOperationType.LessThanOrEqual:
return GetType().GetMethod("Unity_IfLessThanOrEqual", BindingFlags.Static | BindingFlags.NonPublic);
default:
throw new ArgumentOutOfRangeException();
}
}
const string functionTemplate = @"
{
if({comparitor})
{
result = trueValue;
}
else
{
result = falseValue;
}
}
";
static string Unity_IfEqual(
[Slot(0, Binding.None)] DynamicDimensionVector a,
[Slot(1, Binding.None)] DynamicDimensionVector b,
[Slot(2, Binding.None)] DynamicDimensionVector trueValue,
[Slot(3, Binding.None)] DynamicDimensionVector falseValue,
[Slot(4, Binding.None)] DynamicDimensionVector result)
{
return functionTemplate.Replace("{comparitor}", "a == b");
}
static string Unity_IfNotEqual(
[Slot(0, Binding.None)] DynamicDimensionVector a,
[Slot(1, Binding.None)] DynamicDimensionVector b,
[Slot(2, Binding.None)] DynamicDimensionVector trueValue,
[Slot(3, Binding.None)] DynamicDimensionVector falseValue,
[Slot(4, Binding.None)] DynamicDimensionVector result)
{
return functionTemplate.Replace("{comparitor}", "a != b");
}
static string Unity_IfGreaterThan(
[Slot(0, Binding.None)] DynamicDimensionVector a,
[Slot(1, Binding.None)] DynamicDimensionVector b,
[Slot(2, Binding.None)] DynamicDimensionVector trueValue,
[Slot(3, Binding.None)] DynamicDimensionVector falseValue,
[Slot(4, Binding.None)] DynamicDimensionVector result)
{
return functionTemplate.Replace("{comparitor}", "a > b");
}
static string Unity_IfGreaterThanOrEqual(
[Slot(0, Binding.None)] DynamicDimensionVector a,
[Slot(1, Binding.None)] DynamicDimensionVector b,
[Slot(2, Binding.None)] DynamicDimensionVector trueValue,
[Slot(3, Binding.None)] DynamicDimensionVector falseValue,
[Slot(4, Binding.None)] DynamicDimensionVector result)
{
return functionTemplate.Replace("{comparitor}", "a >= b");
}
static string Unity_IfLessThan(
[Slot(0, Binding.None)] DynamicDimensionVector a,
[Slot(1, Binding.None)] DynamicDimensionVector b,
[Slot(2, Binding.None)] DynamicDimensionVector trueValue,
[Slot(3, Binding.None)] DynamicDimensionVector falseValue,
[Slot(4, Binding.None)] DynamicDimensionVector result)
{
return functionTemplate.Replace("{comparitor}", "a < b");
}
static string Unity_IfLessThanOrEqual(
[Slot(0, Binding.None)] DynamicDimensionVector a,
[Slot(1, Binding.None)] DynamicDimensionVector b,
[Slot(2, Binding.None)] DynamicDimensionVector trueValue,
[Slot(3, Binding.None)] DynamicDimensionVector falseValue,
[Slot(4, Binding.None)] DynamicDimensionVector result)
{
return functionTemplate.Replace("{comparitor}", "a <= b");
}
}
// PROBABLY USEFUL, BUT BROKEN AT THE MOMENT
// [Title("Logic/If")]
// public class IfNode : CodeFunctionNode
// {
// public enum ComparisonOperationType
// {
// Equal = 0,
// NotEqual,
// GreaterThan,
// GreaterThanOrEqual,
// LessThan,
// LessThanOrEqual
// }
//
// [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 MethodInfo GetFunctionToConvert()
// {
// switch (ComparisonOperation)
// {
// case ComparisonOperationType.Equal:
// return GetType().GetMethod("Unity_IfEqual", BindingFlags.Static | BindingFlags.NonPublic);
// case ComparisonOperationType.NotEqual:
// return GetType().GetMethod("Unity_IfNotEqual", BindingFlags.Static | BindingFlags.NonPublic);
// case ComparisonOperationType.GreaterThan:
// return GetType().GetMethod("Unity_IfGreaterThan", BindingFlags.Static | BindingFlags.NonPublic);
// case ComparisonOperationType.GreaterThanOrEqual:
// return GetType().GetMethod("Unity_IfGreaterThanOrEqual", BindingFlags.Static | BindingFlags.NonPublic);
// case ComparisonOperationType.LessThan:
// return GetType().GetMethod("Unity_IfLessThan", BindingFlags.Static | BindingFlags.NonPublic);
// case ComparisonOperationType.LessThanOrEqual:
// return GetType().GetMethod("Unity_IfLessThanOrEqual", BindingFlags.Static | BindingFlags.NonPublic);
// default:
// throw new ArgumentOutOfRangeException();
// }
// }
//
// const string functionTemplate = @"
//{
// if({comparitor})
// {
// result = trueValue;
// }
// else
// {
// result = falseValue;
// }
//}
//";
// static string Unity_IfEqual(
// [Slot(0, Binding.None)] DynamicDimensionVector a,
// [Slot(1, Binding.None)] DynamicDimensionVector b,
// [Slot(2, Binding.None)] DynamicDimensionVector trueValue,
// [Slot(3, Binding.None)] DynamicDimensionVector falseValue,
// [Slot(4, Binding.None)] DynamicDimensionVector result)
// {
// return functionTemplate.Replace("{comparitor}", "a == b");
// }
//
// static string Unity_IfNotEqual(
// [Slot(0, Binding.None)] DynamicDimensionVector a,
// [Slot(1, Binding.None)] DynamicDimensionVector b,
// [Slot(2, Binding.None)] DynamicDimensionVector trueValue,
// [Slot(3, Binding.None)] DynamicDimensionVector falseValue,
// [Slot(4, Binding.None)] DynamicDimensionVector result)
// {
// return functionTemplate.Replace("{comparitor}", "a != b");
// }
//
// static string Unity_IfGreaterThan(
// [Slot(0, Binding.None)] DynamicDimensionVector a,
// [Slot(1, Binding.None)] DynamicDimensionVector b,
// [Slot(2, Binding.None)] DynamicDimensionVector trueValue,
// [Slot(3, Binding.None)] DynamicDimensionVector falseValue,
// [Slot(4, Binding.None)] DynamicDimensionVector result)
// {
// return functionTemplate.Replace("{comparitor}", "a > b");
// }
//
// static string Unity_IfGreaterThanOrEqual(
// [Slot(0, Binding.None)] DynamicDimensionVector a,
// [Slot(1, Binding.None)] DynamicDimensionVector b,
// [Slot(2, Binding.None)] DynamicDimensionVector trueValue,
// [Slot(3, Binding.None)] DynamicDimensionVector falseValue,
// [Slot(4, Binding.None)] DynamicDimensionVector result)
// {
// return functionTemplate.Replace("{comparitor}", "a >= b");
// }
//
// static string Unity_IfLessThan(
// [Slot(0, Binding.None)] DynamicDimensionVector a,
// [Slot(1, Binding.None)] DynamicDimensionVector b,
// [Slot(2, Binding.None)] DynamicDimensionVector trueValue,
// [Slot(3, Binding.None)] DynamicDimensionVector falseValue,
// [Slot(4, Binding.None)] DynamicDimensionVector result)
// {
// return functionTemplate.Replace("{comparitor}", "a < b");
// }
//
// static string Unity_IfLessThanOrEqual(
// [Slot(0, Binding.None)] DynamicDimensionVector a,
// [Slot(1, Binding.None)] DynamicDimensionVector b,
// [Slot(2, Binding.None)] DynamicDimensionVector trueValue,
// [Slot(3, Binding.None)] DynamicDimensionVector falseValue,
// [Slot(4, Binding.None)] DynamicDimensionVector result)
// {
// return functionTemplate.Replace("{comparitor}", "a <= b");
// }
// }
}

1
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs


typeMapper[typeof(BlendModeNode)] = typeof(BlendModeNodePresenter);
// typeMapper[typeof(AddManyNode)] = typeof(AddManyNodePresenter);
typeMapper[typeof(IfNode)] = typeof(IfNodePresenter);
//typeMapper[typeof(CustomCodeNode)] = typeof(CustomCodePresenter);
typeMapper[typeof(Matrix2Node)] = typeof(Matrix2NodePresenter);

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


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

38
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/IfNodePresenter.cs


using System;
using System.Collections.Generic;
using UnityEditor.Experimental.UIElements.GraphView;
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<GraphControlPresenter> GetControlData()
{
var instance = CreateInstance<IfControlPresenter>();
instance.Initialize(node);
return new List<GraphControlPresenter>(base.GetControlData()) { instance };
}
}
}
正在加载...
取消
保存