浏览代码

Fixes in Callable Property Drawer when null + Added spawn location to factory

/main
Thomas ICHÉ 6 年前
当前提交
68034388
共有 2 个文件被更改,包括 52 次插入7 次删除
  1. 19
      Editor/PropertyDrawers/CallablePropertyDrawer.cs
  2. 40
      Runtime/Factory/Factory.cs

19
Editor/PropertyDrawers/CallablePropertyDrawer.cs


if (GUI.changed)
property.objectReferenceValue = obj;
if (GUI.Button(gotoRect, ">"))
if(property.objectReferenceValue != null)
Selection.activeObject = property.objectReferenceValue;
if (GUI.Button(gotoRect, ">"))
{
Selection.activeObject = property.objectReferenceValue;
}
if (GUI.Button(pickRect, (property.objectReferenceValue as Callable).Name, EditorStyles.popup))
{
ShowMenu(property);
}
if (GUI.Button(pickRect, (property.objectReferenceValue as Callable).Name, EditorStyles.popup))
else
ShowMenu(property);
EditorGUI.BeginDisabledGroup(true);
GUI.Label(pickRect, "No Callable Selected", EditorStyles.popup);
EditorGUI.EndDisabledGroup();
}
}

40
Runtime/Factory/Factory.cs


All
}
public enum SpawnLocation
{
Default,
SameSceneAsTarget,
ChildOfTarget,
DontDestroyOnLoad
}
[ReorderableList, NonNullCheck]
public GameObject[] FactoryBlueprints;
[NonNullCheck]

public bool RespawnTarget = true;
public bool AttachToTarget = true;
public SpawnLocation spawnLocation = SpawnLocation.SameSceneAsTarget;
public bool ReapInstancesOnDestroy = true;
[Min(1), SerializeField]
private int MaxInstances = 1;

List<GameObject> m_Instances;
private void OnDestroy()
{
if(ReapInstancesOnDestroy)
{
foreach(var instance in m_Instances)
{
if (instance != null)
Destroy(instance);
}
}
}
public void Spawn()
{
if(SpawnTarget == null || FactoryBlueprints == null || FactoryBlueprints.Length == 0)

if (m_Instances.Count <= MaxInstances)
{
GameObject newInstance = Spawn(SelectBlueprint(), SpawnTarget);
if (AttachToTarget)
newInstance.transform.parent = SpawnTarget.transform;
switch(spawnLocation)
{
case SpawnLocation.Default:
break;
case SpawnLocation.SameSceneAsTarget:
UnityEngine.SceneManagement.SceneManager.MoveGameObjectToScene( newInstance, SpawnTarget.scene);
break;
case SpawnLocation.ChildOfTarget:
newInstance.transform.parent = SpawnTarget.transform;
break;
case SpawnLocation.DontDestroyOnLoad:
DontDestroyOnLoad(newInstance);
break;
}
m_Instances.Add(newInstance);

正在加载...
取消
保存