Beispiel #1
0
    public T DrawSelector <T>(T obj) where T : PolymorphicSchema
    {
        string[] names = GetSubclasses().Keys.ToArray();

        int index = 0;

        if (obj != null)
        {
            index = GetSubclasses().Values.ToList().IndexOf(obj.GetType());
        }
        int selectedIndex = EditorGUILayout.Popup(baseType.Name, index, names);

        if (selectedIndex != index)
        {
            if (obj != null)
            {
                AssetDatabase.DeleteAsset(PathForTarget(currentValue.key));
                return(null);
            }
            if (selectedIndex != 0)
            {
                Type type     = GetSubclasses().Values.ToArray()[selectedIndex];
                var  newKey   = GenerateNewKey(type);
                var  instance = ScriptableObject.CreateInstance(type);
                currentValue     = (PolymorphicSchema)instance;
                currentValue.key = newKey;
                AssetDatabase.CreateAsset(instance, PathForTarget(newKey));
                return((T)instance);
            }
        }
        return(obj);
    }
Beispiel #2
0
 public PolymorphicFieldUtility(Type baseType, Type parentType, PolymorphicSchema existingValue)
 {
     this.baseType   = baseType;
     this.parentType = parentType;
     currentValue    = existingValue;
 }