浏览代码

Add object field attribute control

/main
Peter Bay Bastian 7 年前
当前提交
9bf884ab
共有 8 个文件被更改,包括 60 次插入106 次删除
  1. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/MasterRemapNode.cs
  2. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/SubGraphNode.cs
  3. 53
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ObjectControl.cs
  4. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ObjectControl.cs.meta
  5. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/RemapMasterNodePresenter.cs.meta
  6. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/SubgraphNodePresenter.cs.meta
  7. 41
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/SubgraphNodePresenter.cs
  8. 41
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/RemapMasterNodePresenter.cs

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/MasterRemapNode.cs


using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEditor.MaterialGraph.Drawing.Controls;
using UnityEngine.Graphing;
namespace UnityEngine.MaterialGraph

}
#if UNITY_EDITOR
[ObjectControl("Remap")]
public MasterRemapGraphAsset remapGraphAsset
{
get

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/SubGraphNode.cs


using System;
using System.Linq;
using UnityEditor.MaterialGraph.Drawing.Controls;
#if UNITY_EDITOR
using UnityEditor;
#endif

}
#if UNITY_EDITOR
[ObjectControl("Subgraph")]
public MaterialSubGraphAsset subGraphAsset
{
get

53
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ObjectControl.cs


using System;
using System.Reflection;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
using UnityEngine.MaterialGraph;
using Object = UnityEngine.Object;
namespace UnityEditor.MaterialGraph.Drawing.Controls
{
[AttributeUsage(AttributeTargets.Property)]
public class ObjectControlAttribute : Attribute, IControlAttribute
{
string m_Label;
public ObjectControlAttribute(string label = null)
{
m_Label = label;
}
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
{
return new ObjectControlView(m_Label, node, propertyInfo);
}
}
public class ObjectControlView : VisualElement
{
AbstractMaterialNode m_Node;
PropertyInfo m_PropertyInfo;
GUIContent m_Label;
public ObjectControlView(string label, AbstractMaterialNode node, PropertyInfo propertyInfo)
{
if (!typeof(Object).IsAssignableFrom(propertyInfo.PropertyType))
throw new ArgumentException("Property must be assignable to UnityEngine.Object.");
m_Node = node;
m_PropertyInfo = propertyInfo;
m_Label = new GUIContent(label ?? propertyInfo.Name);
Add(new IMGUIContainer(OnGUIHandler));
}
void OnGUIHandler()
{
var value = (Object) m_PropertyInfo.GetValue(m_Node, null);
using (var changeCheckScope = new EditorGUI.ChangeCheckScope())
{
value = EditorGUILayout.MiniThumbnailObjectField(m_Label, value, m_PropertyInfo.PropertyType);
if (changeCheckScope.changed)
m_PropertyInfo.SetValue(m_Node, value, null);
}
}
}
}

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ObjectControl.cs.meta


fileFormatVersion: 2
guid: 3f483132ae7b4689b20fd6b8c59633b5
timeCreated: 1507900115

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


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

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


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

41
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/SubgraphNodePresenter.cs


using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing
{
[Serializable]
class SubgraphContolPresenter : GraphControlPresenter
{
public override void OnGUIHandler()
{
base.OnGUIHandler();
var subGraphNode = node as SubGraphNode;
if (subGraphNode == null)
return;
subGraphNode.subGraphAsset = (MaterialSubGraphAsset)EditorGUILayout.MiniThumbnailObjectField(
new GUIContent("Subgraph"),
subGraphNode.subGraphAsset,
typeof(MaterialSubGraphAsset), null);
}
public override float GetHeight()
{
return EditorGUIUtility.singleLineHeight + 2 * EditorGUIUtility.standardVerticalSpacing;
}
}
[Serializable]
public class SubgraphNodePresenter : MaterialNodePresenter
{
protected override IEnumerable<GraphControlPresenter> GetControlData()
{
var instance = CreateInstance<SubgraphContolPresenter>();
instance.Initialize(node);
return new List<GraphControlPresenter> { instance };
}
}
}

41
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/Nodes/RemapMasterNodePresenter.cs


using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing
{
[Serializable]
class RemapContolPresenter : GraphControlPresenter
{
public override void OnGUIHandler()
{
base.OnGUIHandler();
var remapNode = node as MasterRemapNode;
if (remapNode == null)
return;
remapNode.remapGraphAsset = (MasterRemapGraphAsset)EditorGUILayout.MiniThumbnailObjectField(
new GUIContent("Remap"),
remapNode.remapGraphAsset,
typeof(MasterRemapGraphAsset), null);
}
public override float GetHeight()
{
return EditorGUIUtility.singleLineHeight + 2 * EditorGUIUtility.standardVerticalSpacing;
}
}
[Serializable]
public class MasterRemapNodePresenter : MaterialNodePresenter
{
protected override IEnumerable<GraphControlPresenter> GetControlData()
{
var instance = CreateInstance<RemapContolPresenter>();
instance.Initialize(node);
return new List<GraphControlPresenter> { instance };
}
}
}
正在加载...
取消
保存