예제 #1
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();
        }
    }