浏览代码

Remove usage of EditorGUILayout.MiniThumbnailObjectField, so that we don't have to make it public

/main
Peter Bay Bastian 7 年前
当前提交
a00f148d
共有 9 个文件被更改,包括 78 次插入122 次删除
  1. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SubGraph/SubGraphNode.cs
  2. 25
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Controls/ObjectControl.cs
  3. 79
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/ShaderPropertyView.cs
  4. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MaterialGraph.uss
  5. 2
      MaterialGraphProject/ProjectSettings/ProjectVersion.txt
  6. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/IMGUISlotEditorView.cs.meta
  7. 72
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/IMGUISlotEditorView.cs
  8. 9
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeInspectors.meta

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


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

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


using System;
using System.Reflection;
using UnityEditor.Experimental.UIElements;
using UnityEngine;
using UnityEngine.Experimental.UIElements;
using Object = UnityEngine.Object;

{
AbstractMaterialNode m_Node;
PropertyInfo m_PropertyInfo;
GUIContent m_Label;
public ObjectControlView(string label, AbstractMaterialNode node, PropertyInfo propertyInfo)
{

m_PropertyInfo = propertyInfo;
m_Label = new GUIContent(label ?? propertyInfo.Name);
Add(new IMGUIContainer(OnGUIHandler));
label = label ?? propertyInfo.Name;
if (!string.IsNullOrEmpty(label))
Add(new Label{text = label});
var value = (Object) m_PropertyInfo.GetValue(m_Node, null);
var objectField = new ObjectField { objectType = propertyInfo.PropertyType, value = value };
objectField.OnValueChanged(OnValueChanged);
Add(objectField);
void OnGUIHandler()
void OnValueChanged(ChangeEvent<Object> evt)
using (var changeCheckScope = new EditorGUI.ChangeCheckScope())
if (evt.newValue != value)
//value = EditorGUILayout.MiniThumbnailObjectField(m_Label, value, m_PropertyInfo.PropertyType);
if (changeCheckScope.changed)
{
m_Node.owner.owner.RegisterCompleteObjectUndo("Change " + m_Node.name);
m_PropertyInfo.SetValue(m_Node, value, null);
}
m_Node.owner.owner.RegisterCompleteObjectUndo("Change + " + m_Node.name);
m_PropertyInfo.SetValue(m_Node, evt.newValue, null);
}
}
}

79
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/ShaderPropertyView.cs


using System;
using UnityEditor.Experimental.UIElements;
using Object = UnityEngine.Object;
namespace UnityEditor.ShaderGraph.Drawing.Inspector
{

this.graph = graph;
this.property = property;
var displayNameField = new TextField { name = "displayName", value = property.displayName };
displayNameField.OnValueChanged(OnDisplayNameChanged);
Add(displayNameField);
m_ValueAction = null;
if (property is FloatShaderProperty)
m_ValueAction = FloatField;

m_ValueAction = Vector3Field;
else if (property is Vector4ShaderProperty)
m_ValueAction = Vector4Field;
if (m_ValueAction != null)
{
Add(new IMGUIContainer(ValueField) { name = "value" });
}
m_ValueAction = ColorField;
{
var fProp = (ColorShaderProperty) property;
var colorField = new ColorField { name = "value", value = fProp.value };
colorField.OnValueChanged(OnColorChanged);
Add(colorField);
}
m_ValueAction = TextureField;
Assert.IsNotNull(m_ValueAction);
{
var fProp = (TextureShaderProperty) property;
var objectField = new ObjectField { name = "value", objectType = typeof(Texture), value = fProp.value.texture };
objectField.OnValueChanged(OnTextureChanged);
Add(objectField);
}
Add(new IMGUIContainer(DisplayNameField) { name = "displayName" });
Add(new IMGUIContainer(ValueField) { name = "value" });
void OnColorChanged(ChangeEvent<Color> evt)
{
var fProp = (ColorShaderProperty) property;
if (evt.newValue != fProp.value)
{
fProp.value = evt.newValue;
NotifyNodes();
}
}
void OnTextureChanged(ChangeEvent<Object> evt)
{
var fProp = (TextureShaderProperty) property;
var newValue = (Texture)evt.newValue;
if (newValue != fProp.value.texture)
{
fProp.value.texture = newValue;
NotifyNodes();
}
}
void OnDisplayNameChanged(ChangeEvent<string> evt)
{
if (evt.newValue != property.displayName)
{
property.displayName = evt.newValue;
NotifyNodes();
}
}
}
void DisplayNameField()
{
EditorGUI.BeginChangeCheck();
property.displayName = EditorGUILayout.DelayedTextField(property.displayName);
if (EditorGUI.EndChangeCheck())
NotifyNodes();
}
void ValueField()

{
var fProp = (Vector4ShaderProperty) property;
fProp.value = EditorGUILayout.Vector4Field("", fProp.value);
}
void ColorField()
{
var fProp = (ColorShaderProperty) property;
fProp.value = EditorGUILayout.ColorField("", fProp.value);
}
void TextureField()
{
//var fProp = (TextureShaderProperty) property;
//fProp.value.texture = EditorGUILayout.MiniThumbnailObjectField(new GUIContent("Texture"), fProp.value.texture, typeof(Texture), null) as Texture;
}
}
}

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MaterialGraph.uss


margin-left: 0;
margin-right: 0;
}
ObjectControlView {
flex-direction: row;
}
ObjectControlView > ObjectField {
flex: 1;
}

2
MaterialGraphProject/ProjectSettings/ProjectVersion.txt


m_EditorVersion: 2018.1.0a3
m_EditorVersion: 2018.1.0a4

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/IMGUISlotEditorView.cs.meta


fileFormatVersion: 2
guid: 1c0c3a78bde740fba369b4d5a58d5354
timeCreated: 1503663627

72
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/IMGUISlotEditorView.cs


using UnityEngine.Experimental.UIElements;
using UnityEditor.Graphing;
using UnityEngine;
namespace UnityEditor.ShaderGraph.Drawing.Inspector
{
public class IMGUISlotEditorView : VisualElement
{
MaterialSlot m_Slot;
int m_SlotsHash;
public IMGUISlotEditorView(MaterialSlot slot)
{
m_Slot = slot;
Add(new IMGUIContainer(OnGUIHandler));
}
void OnGUIHandler()
{
if (m_Slot == null)
return;
var previousWideMode = EditorGUIUtility.wideMode;
EditorGUIUtility.wideMode = true;
var modified = SlotField(m_Slot);
EditorGUIUtility.wideMode = previousWideMode;
if (modified)
m_Slot.owner.onModified(m_Slot.owner, ModificationScope.Node);
}
public static bool SlotField(MaterialSlot slot)
{
EditorGUI.BeginChangeCheck();
if (slot is DynamicVectorMaterialSlot)
{
var dynSlot = slot as DynamicVectorMaterialSlot;
dynSlot.value = EditorGUILayout.Vector4Field(slot.displayName, dynSlot.value);
}
if (slot is Vector1MaterialSlot)
{
var dynSlot = slot as Vector1MaterialSlot;
dynSlot.value = EditorGUILayout.FloatField(slot.displayName, dynSlot.value);
}
if (slot is Vector2MaterialSlot)
{
var dynSlot = slot as Vector2MaterialSlot;
dynSlot.value = EditorGUILayout.Vector2Field(slot.displayName, dynSlot.value);
}
if (slot is Vector3MaterialSlot)
{
var dynSlot = slot as Vector3MaterialSlot;
dynSlot.value = EditorGUILayout.Vector3Field(slot.displayName, dynSlot.value);
}
if (slot is Vector4MaterialSlot)
{
var dynSlot = slot as Vector4MaterialSlot;
dynSlot.value = EditorGUILayout.Vector4Field(slot.displayName, dynSlot.value);
}
if (slot is Texture2DInputMaterialSlot)
{
//var dynslot = slot as Texture2DInputMaterialSlot;
//dynslot.texture = EditorGUILayout.MiniThumbnailObjectField(new GUIContent("Texture"), dynslot.texture, typeof(Texture), null) as Texture;
}
return EditorGUI.EndChangeCheck();
}
}
}

9
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeInspectors.meta


fileFormatVersion: 2
guid: eb549fa7bbf654674b93a8ea187f48ea
folderAsset: yes
timeCreated: 1482418252
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存