浏览代码

TypeMapper now derives from BaseDataMapper

Signed-off-by: joce <joce@unity3d.com>
/main
joce 8 年前
当前提交
cfc167d9
共有 6 个文件被更改,包括 39 次插入81 次删除
  1. 19
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphInspector.cs
  2. 15
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphPresenter.cs
  3. 7
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/SerializedGraphPresenter.cs
  4. 37
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Util/TypeMapper.cs
  5. 10
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/AbstractMaterialGraphInspector.cs
  6. 32
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/Presenters/MaterialGraphPresenter.cs

19
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphInspector.cs


using System;
using UnityEngine;
using UnityEngine.Graphing;
namespace UnityEditor.Graphing.Drawing

private readonly TypeMapper m_DataMapper = new TypeMapper(typeof(BasicNodeInspector));
protected TypeMapper dataMapper { get; set; }
protected List<INode> m_SelectedNodes = new List<INode>();

get { return target as IGraphAsset; }
}
protected abstract void AddTypeMappings(Action<Type, Type> map);
protected AbstractGraphInspector()
{
dataMapper = new TypeMapper(typeof(BasicNodeInspector));
}
public override void OnInspectorGUI()
{

m_Inspectors.Clear();
foreach (var node in m_SelectedNodes.OfType<SerializableNode>())
{
var inspector = CreateInspector(node);
var inspector = (AbstractNodeInspector)dataMapper.Create(node);
private AbstractNodeInspector CreateInspector(INode node)
{
var type = m_DataMapper.MapType(node.GetType());
return CreateInstance(type) as AbstractNodeInspector;
}
m_DataMapper.Clear();
AddTypeMappings(m_DataMapper.AddMapping);
UpdateSelection();
}
}

15
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/AbstractGraphPresenter.cs


[Serializable]
public abstract class AbstractGraphPresenter : GraphViewPresenter
{
private readonly TypeMapper m_DataMapper = new TypeMapper(typeof(GraphNodePresenter));
protected TypeMapper dataMapper { get; set; }
public IGraphAsset graphAsset { get; private set; }

public TitleBarPresenter titleBar
{
get { return m_TitleBar; }
}
protected AbstractGraphPresenter()
{
dataMapper = new TypeMapper(typeof(GraphNodePresenter));
}
void OnNodeChanged(INode inNode, ModificationScope scope)

if (m_Elements.OfType<GraphNodePresenter>().Any(e => e.node == node))
continue;
var type = m_DataMapper.MapType(node.GetType());
var nodeData = (GraphNodePresenter)CreateInstance(type);
var nodeData = (GraphNodePresenter)dataMapper.Create(node);
node.onModified += OnNodeChanged;

m_Elements.AddRange(drawableEdges.OfType<GraphElementPresenter>());
}
protected abstract void AddTypeMappings(Action<Type, Type> map);
m_DataMapper.Clear();
AddTypeMappings(m_DataMapper.AddMapping);
this.graphAsset = graphAsset;
m_Container = container;

7
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Drawing/SerializedGraphPresenter.cs


using System;
using UnityEngine;
using UnityEngine.Graphing;
namespace UnityEditor.Graphing.Drawing

protected SerializedGraphPresenter()
{}
protected override void AddTypeMappings(Action<Type, Type> map)
map(typeof(SerializableNode), typeof(GraphNodePresenter));
dataMapper[typeof(SerializableNode)] = typeof(GraphNodePresenter);
}
}
}

37
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Editor/Util/TypeMapper.cs


using System;
using System.Collections.Generic;
using System;
using RMGUI.GraphView;
using UnityEngine;
using UnityEngine.Graphing;
public class TypeMapper
public class TypeMapper : BaseDataMapper<INode, ScriptableObject>
private readonly Dictionary<Type, Type> m_Mappings = new Dictionary<Type, Type>();
private readonly Type m_Default;
public TypeMapper() : this(null) {}
public TypeMapper(Type defaultType)
public TypeMapper(Type fallbackType) : base(fallbackType)
m_Default = defaultType;
public void Clear()
protected override ScriptableObject InternalCreate(Type valueType)
m_Mappings.Clear();
}
public void AddMapping(Type from, Type to)
{
m_Mappings[from] = to;
}
public Type MapType(Type type)
{
Type found = null;
while (type != null)
{
if (m_Mappings.TryGetValue(type, out found))
break;
type = type.BaseType;
}
return found ?? m_Default;
return ScriptableObject.CreateInstance(valueType);
}
}
}

10
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/AbstractMaterialGraphInspector.cs


using System;
using System.Collections.Generic;
using System.Text;
using UnityEditor.Graphing.Drawing;
using UnityEngine;
using UnityEngine.Graphing;

}
}
protected override void AddTypeMappings(Action<Type, Type> map)
protected AbstractMaterialGraphInspector()
map(typeof(AbstractSurfaceMasterNode), typeof(SurfaceMasterNodeInspector));
map(typeof(SubGraphInputNode), typeof(SubgraphInputNodeInspector));
map(typeof(SubGraphOutputNode), typeof(SubgraphOutputNodeInspector));
dataMapper[typeof(AbstractSurfaceMasterNode)] = typeof(SurfaceMasterNodeInspector);
dataMapper[typeof(SubGraphInputNode)] = typeof(SubgraphInputNodeInspector);
dataMapper[typeof(SubGraphOutputNode)] = typeof(SubgraphOutputNodeInspector);
}
private void OnPreviewNodeModified(INode node, ModificationScope scope)

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


using System;
using RMGUI.GraphView;
namespace UnityEditor.MaterialGraph.Drawing
{

{}
protected override void AddTypeMappings(Action<Type, Type> map)
map(typeof(AbstractMaterialNode), typeof(MaterialNodePresenter));
map(typeof(ColorNode), typeof(ColorNodePresenter));
map(typeof(TextureNode), typeof(TextureNodePresenter));
map(typeof(UVNode), typeof(UVNodePresenter));
map(typeof(Vector1Node), typeof(Vector1NodePresenter));
map(typeof(Vector2Node), typeof(Vector2NodePresenter));
map(typeof(Vector3Node), typeof(Vector3NodePresenter));
map(typeof(Vector4Node), typeof(Vector4NodePresenter));
map(typeof(SubGraphNode), typeof(SubgraphNodePresenter));
map(typeof(RemapMasterNode), typeof(RemapMasterNodePresenter));
map(typeof(MasterRemapInputNode), typeof(RemapInputNodePresenter));
map(typeof(AbstractSubGraphIONode), typeof(SubgraphIONodePresenter));
map(typeof(AbstractSurfaceMasterNode), typeof(SurfaceMasterPresenter));
map(typeof(GraphEdgePresenter), typeof(Edge));
dataMapper[typeof(AbstractMaterialNode)] = typeof(MaterialNodePresenter);
dataMapper[typeof(ColorNode)] = typeof(ColorNodePresenter);
dataMapper[typeof(TextureNode)] = typeof(TextureNodePresenter);
dataMapper[typeof(UVNode)] = typeof(UVNodePresenter);
dataMapper[typeof(Vector1Node)] = typeof(Vector1NodePresenter);
dataMapper[typeof(Vector2Node)] = typeof(Vector2NodePresenter);
dataMapper[typeof(Vector3Node)] = typeof(Vector3NodePresenter);
dataMapper[typeof(Vector4Node)] = typeof(Vector4NodePresenter);
dataMapper[typeof(SubGraphNode)] = typeof(SubgraphNodePresenter);
dataMapper[typeof(RemapMasterNode)] = typeof(RemapMasterNodePresenter);
dataMapper[typeof(MasterRemapInputNode)] = typeof(RemapInputNodePresenter);
dataMapper[typeof(AbstractSubGraphIONode)] = typeof(SubgraphIONodePresenter);
dataMapper[typeof(AbstractSurfaceMasterNode)] = typeof(SurfaceMasterPresenter);
}
}
}
正在加载...
取消
保存