예제 #1
0
        private T CreateSubObject <T>() where T : MonoBehaviour
        {
            if (PrefabUtility.IsPartOfPrefabAsset(this.trigger.gameObject))
            {
                return(CreatePrefabObject.AddGameObjectToPrefab <T>(
                           this.trigger.gameObject,
                           typeof(T).Name
                           ));
            }

            GameObject asset = CreateSceneObject.Create(typeof(T).Name, false);

            return(asset.AddComponent <T>());
        }
예제 #2
0
        private void DoLayoutListOptions(ReorderableList list, string itemType)
        {
            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button("Create " + itemType, CoreGUIStyles.GetButtonLeft()))
            {
                if (PrefabUtility.GetPrefabType(target) == PrefabType.Prefab)
                {
                    int itemIndex = list.count;
                    list.serializedProperty.InsertArrayElementAtIndex(itemIndex);
                    SerializedProperty spNewItem = list.serializedProperty.GetArrayElementAtIndex(itemIndex);
                    list.index = itemIndex;

                    if (itemType == "Event")
                    {
                        spNewItem.objectReferenceValue = CreatePrefabObject.AddGameObjectToPrefab <Event>(
                            PrefabUtility.FindPrefabRoot(this.trigger.gameObject),
                            itemType
                            );
                    }
                    else if (itemType == "Actions")
                    {
                        spNewItem.objectReferenceValue = CreatePrefabObject.AddGameObjectToPrefab <Actions>(
                            PrefabUtility.FindPrefabRoot(this.trigger.gameObject),
                            itemType
                            );
                    }

                    this.serializedObject.ApplyModifiedProperties();
                    this.serializedObject.Update();
                }
                else
                {
                    this.CreateTriggerOption(list, itemType);
                }
            }

            if (GUILayout.Button("+", CoreGUIStyles.GetButtonMid(), GUILayout.MaxWidth(30f)))
            {
                int insertIndex = list.count;
                list.serializedProperty.InsertArrayElementAtIndex(insertIndex);
                list.serializedProperty.GetArrayElementAtIndex(insertIndex).objectReferenceValue = null;
            }

            if (GUILayout.Button("-", CoreGUIStyles.GetButtonRight(), GUILayout.MaxWidth(30f)))
            {
                bool indexInRange = (list.index >= 0 && list.index < list.count);
                if (indexInRange)
                {
                    SerializedProperty spItem = list.serializedProperty.GetArrayElementAtIndex(list.index);
                    if (spItem.objectReferenceValue != null)
                    {
                        if (PrefabUtility.GetPrefabType(target) == PrefabType.Prefab)
                        {
                            CreatePrefabObject.RemoveGameObjectFromPrefab(
                                PrefabUtility.FindPrefabRoot(this.trigger.gameObject),
                                ((MonoBehaviour)spItem.objectReferenceValue).gameObject
                                );

                            AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(this.trigger.gameObject));
                        }
                        else
                        {
                            Undo.DestroyObjectImmediate(((MonoBehaviour)spItem.objectReferenceValue).gameObject);
                        }
                    }

                    list.serializedProperty.RemoveFromObjectArrayAt(list.index);
                }

                if (list.index < 0)
                {
                    list.index = 0;
                }
                if (list.index >= list.count)
                {
                    list.index = list.count - 1;
                }
            }

            EditorGUILayout.EndHorizontal();
        }