joce
8 年前
当前提交
134a3007
共有 4 个文件被更改,包括 145 次插入 和 93 次删除
-
106MaterialGraphProject/Assets/NewUI/Editor/DataWatchTests/DataWatchTests.cs
-
50MaterialGraphProject/Assets/NewUI/Editor/GraphViewDataMapper.cs
-
70MaterialGraphProject/Assets/NewUI/Editor/BaseDataMapper.cs
-
12MaterialGraphProject/Assets/NewUI/Editor/BaseDataMapper.cs.meta
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
|
|||
public class GraphViewDataMapper |
|||
public class GraphViewDataMapper : BaseDataMapper<GraphElementPresenter, GraphElement> |
|||
private readonly Dictionary<Type, Type> m_DataToViewDict = new Dictionary<Type, Type>(); |
|||
|
|||
public Type this[Type t] |
|||
public GraphViewDataMapper() : base(typeof(FallbackGraphElement)) |
|||
get |
|||
{ |
|||
return m_DataToViewDict[t]; |
|||
} |
|||
set |
|||
{ |
|||
if (!t.IsSubclassOf(typeof(GraphElementPresenter))) |
|||
{ |
|||
throw new ArgumentException("The type passed as key does not derive from UnityEngine.Object."); |
|||
} |
|||
|
|||
if (!value.IsSubclassOf(typeof(GraphElement))) |
|||
{ |
|||
throw new ArgumentException("The type passed as value does not derive from DataContainer."); |
|||
} |
|||
|
|||
m_DataToViewDict[t] = value; |
|||
} |
|||
public GraphElement Create(GraphElementPresenter presenter) |
|||
public override GraphElement Create(GraphElementPresenter key) |
|||
Type viewType = null; |
|||
Type dataType = presenter.GetType(); |
|||
|
|||
while (viewType == null && dataType != typeof(GraphElementPresenter)) |
|||
GraphElement elem = base.Create(key); |
|||
if (elem != null) |
|||
if (!m_DataToViewDict.TryGetValue(dataType, out viewType)) |
|||
{ |
|||
dataType = dataType.BaseType; |
|||
} |
|||
elem.presenter = key; |
|||
|
|||
if (viewType == null) |
|||
{ |
|||
viewType = typeof(FallbackGraphElement); |
|||
} |
|||
|
|||
var dataContainer = (GraphElement)Activator.CreateInstance(viewType); |
|||
dataContainer.presenter = presenter; |
|||
return dataContainer; |
|||
return elem; |
|||
} |
|||
} |
|||
} |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
|
|||
namespace RMGUI.GraphView |
|||
{ |
|||
public abstract class BaseDataMapper<TKey, TValue> |
|||
{ |
|||
private readonly Dictionary<Type, Type> m_Mappings = new Dictionary<Type, Type>(); |
|||
private readonly Type m_FallbackType; |
|||
private static readonly Type k_KeyType; |
|||
private static readonly Type k_ValueType; |
|||
|
|||
static BaseDataMapper() |
|||
{ |
|||
k_KeyType = typeof(TKey); |
|||
k_ValueType = typeof(TValue); |
|||
} |
|||
|
|||
public Type this[Type t] |
|||
{ |
|||
get { return m_Mappings[t]; } |
|||
set |
|||
{ |
|||
if (!t.IsSubclassOf(k_KeyType) && !t.GetInterfaces().Contains(k_KeyType)) |
|||
{ |
|||
throw new ArgumentException("The type passed as key (" + t.Name + ") does not implement or derive from " + k_KeyType.Name + "."); |
|||
} |
|||
|
|||
if (!value.IsSubclassOf(k_ValueType)) |
|||
{ |
|||
throw new ArgumentException("The type passed as value ("+ value.Name + ") does not derive from " + k_ValueType.Name + "."); |
|||
} |
|||
|
|||
m_Mappings[t] = value; |
|||
} |
|||
} |
|||
|
|||
public virtual TValue Create(TKey key) |
|||
{ |
|||
Type valueType = null; |
|||
Type keyType = key.GetType(); |
|||
|
|||
while (valueType == null && keyType != null && keyType != typeof(TKey)) |
|||
{ |
|||
if (!m_Mappings.TryGetValue(keyType, out valueType)) |
|||
{ |
|||
keyType = keyType.BaseType; |
|||
} |
|||
} |
|||
|
|||
if (valueType == null) |
|||
{ |
|||
valueType = m_FallbackType; |
|||
} |
|||
|
|||
return InternalCreate(valueType); |
|||
} |
|||
|
|||
protected BaseDataMapper(Type fallbackType) |
|||
{ |
|||
m_FallbackType = fallbackType; |
|||
} |
|||
|
|||
protected virtual TValue InternalCreate(Type valueType) |
|||
{ |
|||
return (TValue) Activator.CreateInstance(valueType); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 1fa55599f19fa274d9bc2d296fb12861 |
|||
timeCreated: 1484682630 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue