Peter Bay Bastian
7 年前
当前提交
64c9a49b
共有 18 个文件被更改,包括 205 次插入 和 350 次删除
-
44MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/AbstractMaterialGraphEditWindow.cs
-
76MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Presenters/GraphInspectorPresenter.cs
-
31MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Views/AbstractNodeEditorView.cs
-
70MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Views/GraphInspectorView.cs
-
107MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Views/IMGUISlotEditorView.cs
-
53MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Views/StandardNodeEditorView.cs
-
35MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Views/SurfaceMasterNodeEditorView.cs
-
4MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/GraphEditorPresenter.cs
-
10MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Views/GraphEditorView.cs
-
7MaterialGraphProject/Assets/UnityShaderEditor/Editor/Util/UIUtilities.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Presenters/AbstractNodeEditorPresenter.cs.meta
-
30MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Presenters/IMGUISlotEditorPresenter.cs
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Presenters/IMGUISlotEditorPresenter.cs.meta
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Presenters/StandardNodeEditorPresenter.cs.meta
-
3MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Presenters/SurfaceMasterNodeEditorPresenter.cs.meta
-
10MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Presenters/AbstractNodeEditorPresenter.cs
-
43MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Presenters/StandardNodeEditorPresenter.cs
-
23MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Inspector/Presenters/SurfaceMasterNodeEditorPresenter.cs
|
|||
using System; |
|||
using System.Linq; |
|||
using UnityEditor.Graphing.Util; |
|||
using UnityEditor.MaterialGraph.Drawing.Inspector; |
|||
using UnityEngine.MaterialGraph; |
|||
[SerializeField] |
|||
AbstractNodeEditorPresenter m_Editor; |
|||
public IGraph graph { get; set; } |
|||
[SerializeField] |
|||
string m_Title; |
|||
public string assetName { get; set; } |
|||
[SerializeField] |
|||
int m_SelectionCount; |
|||
public List<INode> selectedNodes { get; set; } |
|||
TypeMapper m_TypeMapper; |
|||
|
|||
public AbstractNodeEditorPresenter editor |
|||
[Flags] |
|||
public enum ChangeType |
|||
get { return m_Editor; } |
|||
Graph = 1 << 0, |
|||
SelectedNodes = 1 << 1, |
|||
AssetName = 1 << 2, |
|||
All = -1 |
|||
public string title |
|||
{ |
|||
get { return m_Title; } |
|||
set { m_Title = value; } |
|||
} |
|||
public delegate void OnChange(ChangeType changeType); |
|||
public int selectionCount |
|||
{ |
|||
get { return m_SelectionCount; } |
|||
set { m_SelectionCount = value; } |
|||
} |
|||
public OnChange onChange; |
|||
public void Initialize(string graphName) |
|||
public void Initialize(string assetName, IGraph graph) |
|||
m_Title = graphName; |
|||
m_TypeMapper = new TypeMapper(typeof(INode), typeof(AbstractNodeEditorPresenter), typeof(StandardNodeEditorPresenter)) |
|||
{ |
|||
{typeof(AbstractSurfaceMasterNode), typeof(SurfaceMasterNodeEditorPresenter)} |
|||
}; |
|||
// Nodes missing custom editors:
|
|||
// - PropertyNode
|
|||
// - SubGraphInputNode
|
|||
// - SubGraphOutputNode
|
|||
this.graph = graph; |
|||
this.assetName = assetName; |
|||
selectedNodes = new List<INode>(); |
|||
|
|||
if (onChange != null) |
|||
onChange(ChangeType.Graph | ChangeType.SelectedNodes | ChangeType.AssetName); |
|||
using (var nodesList = ListPool<INode>.GetDisposable()) |
|||
{ |
|||
nodesList.value.AddRange(nodes); |
|||
|
|||
m_SelectionCount = nodesList.value.Count; |
|||
selectedNodes.Clear(); |
|||
selectedNodes.AddRange(nodes); |
|||
if (m_SelectionCount == 1) |
|||
{ |
|||
var node = nodesList.value.First(); |
|||
if (m_Editor == null || node != m_Editor.node) |
|||
{ |
|||
m_Editor = (AbstractNodeEditorPresenter) CreateInstance(m_TypeMapper.MapType(node.GetType())); |
|||
m_Editor.node = node; |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
m_Editor = null; |
|||
} |
|||
} |
|||
if (onChange != null) |
|||
onChange(ChangeType.SelectedNodes); |
|||
} |
|||
} |
|||
} |
|
|||
using UnityEditor.Experimental.UIElements.GraphView; |
|||
using System; |
|||
using UnityEngine.Experimental.UIElements; |
|||
using UnityEngine.Graphing; |
|||
public class AbstractNodeEditorView : DataWatchContainer |
|||
public abstract class AbstractNodeEditorView : VisualElement, IDisposable |
|||
[SerializeField] |
|||
AbstractNodeEditorPresenter m_Presenter; |
|||
public abstract INode node { get; set; } |
|||
public AbstractNodeEditorPresenter presenter |
|||
{ |
|||
get { return m_Presenter; } |
|||
set |
|||
{ |
|||
if (value == m_Presenter) |
|||
return; |
|||
RemoveWatch(); |
|||
m_Presenter = value; |
|||
m_ToWatch[0] = m_Presenter; |
|||
OnDataChanged(); |
|||
AddWatch(); |
|||
} |
|||
} |
|||
|
|||
Object[] m_ToWatch = { null }; |
|||
|
|||
protected override Object[] toWatch |
|||
{ |
|||
get { return m_ToWatch; } |
|||
} |
|||
public abstract void Dispose(); |
|||
} |
|||
} |
|
|||
using System; |
|||
using UnityEditor.Experimental.UIElements.GraphView; |
|||
using UnityEngine.Graphing; |
|||
using Object = UnityEngine.Object; |
|||
public class IMGUISlotEditorView : DataWatchContainer |
|||
public class IMGUISlotEditorView : VisualElement |
|||
[SerializeField] |
|||
IMGUISlotEditorPresenter m_Presenter; |
|||
MaterialSlot m_Slot; |
|||
int m_SlotsHash; |
|||
ConcreteSlotValueType m_CurrentValueType = ConcreteSlotValueType.Error; |
|||
|
|||
public override void OnDataChanged() |
|||
public IMGUISlotEditorView(MaterialSlot slot) |
|||
if (presenter == null) |
|||
{ |
|||
Clear(); |
|||
return; |
|||
} |
|||
|
|||
if (presenter.slot.concreteValueType == m_CurrentValueType) |
|||
return; |
|||
|
|||
Clear(); |
|||
m_CurrentValueType = presenter.slot.concreteValueType; |
|||
|
|||
Action onGUIHandler; |
|||
if (presenter.slot.concreteValueType == ConcreteSlotValueType.Vector4) |
|||
onGUIHandler = Vector4OnGUIHandler; |
|||
else if (presenter.slot.concreteValueType == ConcreteSlotValueType.Vector3) |
|||
onGUIHandler = Vector3OnGUIHandler; |
|||
else if (presenter.slot.concreteValueType == ConcreteSlotValueType.Vector2) |
|||
onGUIHandler = Vector2OnGUIHandler; |
|||
else if (presenter.slot.concreteValueType == ConcreteSlotValueType.Vector1) |
|||
onGUIHandler = Vector1OnGUIHandler; |
|||
else |
|||
return; |
|||
|
|||
Add(new IMGUIContainer(onGUIHandler)); |
|||
m_Slot = slot; |
|||
Add(new IMGUIContainer(OnGUIHandler)); |
|||
void Vector4OnGUIHandler() |
|||
void OnGUIHandler() |
|||
if (presenter.slot == null) |
|||
if (m_Slot == null) |
|||
presenter.value = EditorGUILayout.Vector4Field(presenter.slot.displayName, presenter.value); |
|||
var newValue = SlotField(m_Slot); |
|||
if (newValue != m_Slot.currentValue) |
|||
{ |
|||
m_Slot.currentValue = newValue; |
|||
m_Slot.owner.onModified(m_Slot.owner, ModificationScope.Node); |
|||
} |
|||
void Vector3OnGUIHandler() |
|||
static Vector4 SlotField(MaterialSlot slot) |
|||
if (presenter.slot == null) |
|||
return; |
|||
var previousWideMode = EditorGUIUtility.wideMode; |
|||
EditorGUIUtility.wideMode = true; |
|||
presenter.value = EditorGUILayout.Vector3Field(presenter.slot.displayName, presenter.value); |
|||
EditorGUIUtility.wideMode = previousWideMode; |
|||
} |
|||
|
|||
void Vector2OnGUIHandler() |
|||
{ |
|||
if (presenter.slot == null) |
|||
return; |
|||
var previousWideMode = EditorGUIUtility.wideMode; |
|||
EditorGUIUtility.wideMode = true; |
|||
presenter.value = EditorGUILayout.Vector2Field(presenter.slot.displayName, presenter.value); |
|||
EditorGUIUtility.wideMode = previousWideMode; |
|||
} |
|||
|
|||
void Vector1OnGUIHandler() |
|||
{ |
|||
if (presenter.slot == null) |
|||
return; |
|||
var previousWideMode = EditorGUIUtility.wideMode; |
|||
EditorGUIUtility.wideMode = true; |
|||
presenter.value = new Vector4(EditorGUILayout.FloatField(presenter.slot.displayName, presenter.value.x), 0, 0, 0); |
|||
EditorGUIUtility.wideMode = previousWideMode; |
|||
} |
|||
|
|||
protected override Object[] toWatch |
|||
{ |
|||
get { return new Object[] { presenter }; } |
|||
} |
|||
|
|||
public IMGUISlotEditorPresenter presenter |
|||
{ |
|||
get { return m_Presenter; } |
|||
set |
|||
{ |
|||
if (value == m_Presenter) |
|||
return; |
|||
RemoveWatch(); |
|||
m_Presenter = value; |
|||
OnDataChanged(); |
|||
AddWatch(); |
|||
} |
|||
if (slot.concreteValueType == ConcreteSlotValueType.Vector1) |
|||
return new Vector4(EditorGUILayout.FloatField(slot.displayName, slot.currentValue.x), 0, 0, 0); |
|||
if (slot.concreteValueType == ConcreteSlotValueType.Vector2) |
|||
return EditorGUILayout.Vector2Field(slot.displayName, slot.currentValue); |
|||
if (slot.concreteValueType == ConcreteSlotValueType.Vector3) |
|||
return EditorGUILayout.Vector3Field(slot.displayName, slot.currentValue); |
|||
if (slot.concreteValueType == ConcreteSlotValueType.Vector4) |
|||
return EditorGUILayout.Vector4Field(slot.displayName, slot.currentValue); |
|||
return Vector4.zero; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 97d910cfa5d2452e9ac7500b6cee25ab |
|||
timeCreated: 1503661223 |
|
|||
using UnityEngine; |
|||
using UnityEngine.Graphing; |
|||
using UnityEngine.MaterialGraph; |
|||
|
|||
namespace UnityEditor.MaterialGraph.Drawing.Inspector |
|||
{ |
|||
public class IMGUISlotEditorPresenter : ScriptableObject |
|||
{ |
|||
[SerializeField] |
|||
MaterialSlot m_Slot; |
|||
|
|||
public MaterialSlot slot |
|||
{ |
|||
get { return m_Slot; } |
|||
set { m_Slot = value; } |
|||
} |
|||
|
|||
public Vector4 value |
|||
{ |
|||
get { return m_Slot.currentValue; } |
|||
set |
|||
{ |
|||
if (value == slot.currentValue) |
|||
return; |
|||
slot.currentValue = value; |
|||
m_Slot.owner.onModified(m_Slot.owner, ModificationScope.Node); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 7be91f540ac243ec9bf12002b0fb8c1d |
|||
timeCreated: 1504002750 |
|
|||
fileFormatVersion: 2 |
|||
guid: a0786fdde6014aa6b3222772757dbbb5 |
|||
timeCreated: 1503661346 |
|
|||
fileFormatVersion: 2 |
|||
guid: 99655571e90540559a9c31cfc126bb8d |
|||
timeCreated: 1504786938 |
|
|||
using UnityEngine; |
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEditor.MaterialGraph.Drawing.Inspector |
|||
{ |
|||
public abstract class AbstractNodeEditorPresenter : ScriptableObject |
|||
{ |
|||
public abstract INode node { get; set; } |
|||
} |
|||
} |
|
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEngine.Graphing; |
|||
using UnityEngine.MaterialGraph; |
|||
|
|||
namespace UnityEditor.MaterialGraph.Drawing.Inspector |
|||
{ |
|||
public sealed class StandardNodeEditorPresenter : AbstractNodeEditorPresenter |
|||
{ |
|||
[SerializeField] |
|||
AbstractMaterialNode m_Node; |
|||
|
|||
[SerializeField] |
|||
List<IMGUISlotEditorPresenter> m_SlotEditorPresenters; |
|||
|
|||
public override INode node |
|||
{ |
|||
get { return m_Node; } |
|||
set |
|||
{ |
|||
m_Node = (AbstractMaterialNode)value; |
|||
m_SlotEditorPresenters = new List<IMGUISlotEditorPresenter>(); |
|||
foreach (var slot in node.GetInputSlots<MaterialSlot>()) |
|||
{ |
|||
if (slot.concreteValueType == ConcreteSlotValueType.Vector1 |
|||
|| slot.concreteValueType == ConcreteSlotValueType.Vector2 |
|||
|| slot.concreteValueType == ConcreteSlotValueType.Vector3 |
|||
|| slot.concreteValueType == ConcreteSlotValueType.Vector4) |
|||
{ |
|||
var slotEditorPresenter = CreateInstance<IMGUISlotEditorPresenter>(); |
|||
slotEditorPresenter.slot = slot; |
|||
m_SlotEditorPresenters.Add(slotEditorPresenter); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
public IEnumerable<IMGUISlotEditorPresenter> slotEditorPresenters |
|||
{ |
|||
get { return m_SlotEditorPresenters; } |
|||
} |
|||
} |
|||
} |
|
|||
using UnityEngine; |
|||
using UnityEngine.Graphing; |
|||
using UnityEngine.MaterialGraph; |
|||
|
|||
namespace UnityEditor.MaterialGraph.Drawing.Inspector |
|||
{ |
|||
public class SurfaceMasterNodeEditorPresenter : AbstractNodeEditorPresenter |
|||
{ |
|||
[SerializeField] |
|||
AbstractSurfaceMasterNode m_Node; |
|||
|
|||
public override INode node |
|||
{ |
|||
get { return m_Node; } |
|||
set { m_Node = (AbstractSurfaceMasterNode)value; } |
|||
} |
|||
|
|||
public AbstractSurfaceMasterNode materialNode |
|||
{ |
|||
get { return m_Node; } |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue