示例#1
0
    private void CreateChild(InAudioEventNode node, EventNodeType type)
    {
        UndoHelper.DoInGroup(() =>
        {
            UndoHelper.RegisterUndo(node, "Event Creation");
            AudioEventWorker.CreateNode(node, type);
        });

        node.FoldedOut = true;
    }
示例#2
0
    private void CreateChildBus(object userData)
    {
        InAudioBus bus = userData as InAudioBus;

        UndoHelper.DoInGroup(() =>
        {
            UndoHelper.RecordObjectFull(bus, "Bus Creation");
            AudioBusWorker.CreateChild(bus);
        });
    }
示例#3
0
    private void DrawList(SerializedProperty arrayProp, SerializedProperty arrayPropSize,
                          Action <int> deleteAction = null)
    {
        if (arrayProp.isExpanded)
        {
            if (!arrayPropSize.hasMultipleDifferentValues)
            {
                for (int i = 0; i < arrayProp.arraySize; i++)
                {
                    EditorGUILayout.BeginHorizontal();
                    GUI.enabled = false;
                    EditorGUILayout.PropertyField(arrayProp.GetArrayElementAtIndex(i));
                    GUI.enabled = true;

                    if (deleteAction != null)
                    {
                        if (GUILayout.Button("X", GUILayout.Width(20)))
                        {
                            int index = i;
                            UndoHelper.DoInGroup(() =>
                            {
                                    #if UNITY_4_1 || UNITY_4_2
                                Undo.RegisterSceneUndo("Delete element in spline");
                                    #else
                                UndoAll("Delete element in spline");
                                    #endif
                                deleteAction(index);
                            });
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                }
            }
            else
            {
                EditorGUILayout.HelpBox("Cannot show lists of different lengths.", MessageType.None);
            }
        }
    }
示例#4
0
    public override void OnInspectorGUI()
    {
        if (!InAudioInstanceFinder.IsValid)
        {
            EditorGUILayout.HelpBox("Please add the InAudio Manager to the scene", MessageType.Info);
            if (GUILayout.Button("Add manager to scene"))
            {
                ErrorDrawer.AddManagerToScene();
            }
        }

        serializedObject.Update();
        EditorGUI.BeginChangeCheck();
        EditorGUILayout.PropertyField(serializedObject.FindProperty("SplineAudioEvent"));
        EditorGUILayout.Separator();

        bool add       = GUILayout.Button("Add Node");
        bool selectNew = false;

        if (GUILayout.Button("Add and Select"))
        {
            add       = true;
            selectNew = true;
        }

        var nodeArray     = serializedObject.FindProperty("Nodes");
        var nodeArraySize = nodeArray.FindPropertyRelative("Array.size");

        var connectionArray     = serializedObject.FindProperty("Connections");
        var connectionArraySize = connectionArray.FindPropertyRelative("Array.size");

        nodeArray.isExpanded = EditorGUILayout.Foldout(nodeArray.isExpanded, "Nodes");
        DrawList(nodeArray, nodeArraySize, i =>
        {
            var node = nodeArray.GetArrayElementAtIndex(i).objectReferenceValue as InSplineNode;

            nodeArray.DeleteArrayElementAtIndex(i);
            nodeArray.DeleteArrayElementAtIndex(i);

            for (int j = 0; j < connectionArray.arraySize; j++)
            {
                var prop = connectionArray.GetArrayElementAtIndex(j);
                if (prop.FindPropertyRelative("NodeA").objectReferenceValue == node ||
                    prop.FindPropertyRelative("NodeB").objectReferenceValue == node)
                {
                    connectionArray.DeleteArrayElementAtIndex(j);
                    --j;
                }
            }

            if (node != null)
            {
                UndoHelper.Destroy(node.gameObject);
            }
        });

        connectionArray.isExpanded = EditorGUILayout.Foldout(connectionArray.isExpanded, "Connections");
        DrawList(connectionArray, connectionArraySize, connectionArray.DeleteArrayElementAtIndex);

        if (add)
        {
            UndoHelper.DoInGroup(() =>
            {
                    #if UNITY_4_1 || UNITY_4_2
                Undo.RegisterSceneUndo("Delete element in spline");
                    #else
                UndoAll("Add new spline node");
                    #endif

                GameObject newNodeGO         = UndoHelper.CreateGO(SplineController.gameObject.name + " Node");
                var newNode                  = newNodeGO.AddComponent <InSplineNode>();
                newNodeGO.transform.position = SplineController.transform.position;
                newNode.SplineController     = SplineController;

                newNodeGO.transform.parent = SplineController.transform;

                newNodeGO.transform.position = SplineController.transform.position +
                                               SplineController.transform.forward;

                int count = SplineController.Nodes.Count;
                if (count > 0)
                {
                    SplineController.Nodes[0].ConnectTo(newNode);
                }

                SplineController.Nodes.Add(newNode);

                if (selectNew)
                {
                    Selection.activeGameObject = newNodeGO;
                }
            });
        }

        if (EditorGUI.EndChangeCheck())
        {
            serializedObject.ApplyModifiedProperties();
        }
    }