浏览代码

Property attribute control

/main
Peter Bay Bastian 7 年前
当前提交
56967512
共有 4 个文件被更改,包括 49 次插入3 次删除
  1. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/PropertyNode.cs
  2. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs
  3. 44
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/PropertyControl.cs
  4. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/PropertyControl.cs.meta

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/PropertyNode.cs


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

return edges.Count == 0;
}
[PropertyControl]
public Guid propertyGuid
{
get { return m_PropertyGuid; }

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


// typeMapper[typeof(TextureLODNode)] = typeof(TextureLODNodePresenter);
// typeMapper[typeof(CubemapNode)] = typeof(CubeNodePresenter);
// typeMapper[typeof(ToggleNode)] = typeof(ToggleNodePresenter);
typeMapper[typeof(PropertyNode)] = typeof(PropertyNodePresenter);
/* typeMapper[typeof(ScaleOffsetNode)] = typeof(AnyNodePresenter); // anything derived from AnyNode should use the AnyNodePresenter
typeMapper[typeof(RadialShearNode)] = typeof(AnyNodePresenter); // anything derived from AnyNode should use the AnyNodePresenter
typeMapper[typeof(SphereWarpNode)] = typeof(AnyNodePresenter); // anything derived from AnyNode should use the AnyNodePresenter

44
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/PropertyControl.cs


using System;
using System.Linq;
using System.Reflection;
using UnityEngine.Experimental.UIElements;
using UnityEngine.MaterialGraph;
namespace UnityEditor.MaterialGraph.Drawing.Controls
{
[AttributeUsage(AttributeTargets.Property)]
public class PropertyControlAttribute : Attribute, IControlAttribute
{
public VisualElement InstantiateControl(AbstractMaterialNode node, PropertyInfo propertyInfo)
{
return new PropertyControlView(node);
}
}
public class PropertyControlView : VisualElement
{
PropertyNode m_Node;
public PropertyControlView(AbstractMaterialNode node)
{
m_Node = (PropertyNode) node;
Add(new IMGUIContainer(OnGUIHandler));
}
void OnGUIHandler()
{
var graph = m_Node.owner as AbstractMaterialGraph;
var currentGUID = m_Node.propertyGuid;
var properties = graph.properties.ToList();
var propertiesGUID = properties.Select(x => x.guid).ToList();
var currentSelectedIndex = propertiesGUID.IndexOf(currentGUID);
using (var changeCheckScope = new EditorGUI.ChangeCheckScope())
{
var value = EditorGUILayout.Popup("Property", currentSelectedIndex, properties.Select(x => x.displayName).ToArray());
if (changeCheckScope.changed)
m_Node.propertyGuid = propertiesGUID[value];
}
}
}
}

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


fileFormatVersion: 2
guid: bb1167be0ec94c0a849394d34df45a98
timeCreated: 1507819549
正在加载...
取消
保存