Exemplo n.º 1
0
        private static void HandleDragging(AudioEventAction currentAction, Rect dragArea)
        {
            if (currentAction != null)
            {
                if (currentAction is InEventAudioAction)
                {
                    InAudioNode dragged = OnDragging.DraggingObject <InAudioNode>(dragArea, node => node.IsPlayable);
                    if (dragged != null)
                    {
                        InUndoHelper.RecordObject(currentAction, "Change Action Type");
                        currentAction.Target = dragged;
                    }
                }
                else if (currentAction is InEventBankLoadingAction)
                {
                    InAudioBankLink dragged = OnDragging.DraggingObject <InAudioBankLink>(dragArea,
                                                                                          bank => bank._type == AudioBankTypes.Bank);

                    if (dragged != null)
                    {
                        InUndoHelper.RecordObject(currentAction, "Change Action Type");
                        currentAction.Target = dragged;
                    }
                }
                else if (currentAction is InEventMixerValueAction)
                {
                    AudioMixer dragged = OnDragging.DraggingObject <AudioMixer>(dragArea);
                    if (dragged != null)
                    {
                        InUndoHelper.RecordObject(currentAction, "Change Action Type");
                        currentAction.Target = dragged;
                    }
                }
                else if (currentAction is InEventMusicControl || currentAction is InEventMusicFade || currentAction is InEventSoloMuteMusic)
                {
                    InMusicGroup dragged = OnDragging.DraggingObject <InMusicGroup>(dragArea);
                    if (dragged != null)
                    {
                        InUndoHelper.RecordObject(currentAction, "Change Action Type");
                        currentAction.Target = dragged;
                    }
                }
            }
        }
Exemplo n.º 2
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();
            if (serializedObject.FindProperty("SplineController").hasMultipleDifferentValues)
            {
                EditorGUILayout.HelpBox("Different spline controllers", MessageType.Warning);
                return;
            }
            if (SplineNode.SplineController == null)
            {
                EditorGUILayout.HelpBox("Missing spline controller, please assign one", MessageType.Warning);
            }

            if (InAudioInstanceFinder.IsValid)
            {
                InAudioInstanceFinder.InAudioGuiUserPrefs.SelectedSplineController = SplineNode.SplineController;
            }

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

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


            var objectField = EditorGUILayout.ObjectField("Controlling Spline", serializedObject.FindProperty("SplineController").objectReferenceValue, typeof(InSpline), true);

            if (serializedObject.FindProperty("SplineController").objectReferenceValue == null)
            {
                serializedObject.FindProperty("SplineController").objectReferenceValue = objectField;
            }

            if (Selection.objects.Length == 1)
            {
                GUILayout.Button("Drag node here to connect");
                OnDragging.DraggingObject <Object>(GUILayoutUtility.GetLastRect(), o =>
                {
                    GameObject go = o as GameObject;
                    if (go != null)
                    {
                        var node = go.GetComponent <InSplineNode>();
                        if (node != SplineNode && !SplineNode.SplineController.ContainsConnection(SplineNode, node))
                        {
                            return(true);
                        }
                    }
                    return(false);
                }, o =>
                {
                    InUndoHelper.RecordObject(SplineNode.SplineController, "Connect nodes");
                    (o as GameObject).GetComponent <InSplineNode>().ConnectTo(SplineNode);
                });

                //var a = new SerializedObject(SplineNode.SplineController)
                if (SplineNode.SplineController != null)
                {
                    expandedConnections = EditorGUILayout.Foldout(expandedConnections, "Connected to");

                    for (int i = 0; i < SplineNode.SplineController.Connections.Count; i++)
                    {
                        EditorGUILayout.BeginHorizontal();
                        GUI.enabled = false;
                        var conc = SplineNode.SplineController.Connections[i];
                        if (conc.NodeA == SplineNode)
                        {
                            EditorGUILayout.ObjectField(conc.NodeB, typeof(InSplineNode), true);
                            GUI.enabled = true;
                            if (GUILayout.Button("X", GUILayout.Width(20)))
                            {
                                InUndoHelper.RecordObject(SplineNode.SplineController, "Remove spline connection");
                                SplineNode.SplineController.RemoveConnections(conc);
                            }
                            EditorUtility.SetDirty(SplineNode.SplineController);
                        }
                        else if (conc.NodeB == SplineNode)
                        {
                            EditorGUILayout.ObjectField(conc.NodeA, typeof(InSplineNode), true);
                            GUI.enabled = true;
                            if (GUILayout.Button("X", GUILayout.Width(20)))
                            {
                                InUndoHelper.RecordObject(SplineNode.SplineController, "Remove spline connection");
                                SplineNode.SplineController.RemoveConnections(conc);
                            }
                            EditorUtility.SetDirty(SplineNode.SplineController);
                        }


                        EditorGUILayout.EndHorizontal();
                    }
                }
            }



            EditorGUILayout.Separator();
            bool delete = true;

            if (GUILayout.Button("Delete"))
            {
                InUndoHelper.DoInGroup(() =>
                {
            #if UNITY_4_1 || UNITY_4_2
                    Undo.RegisterSceneUndo("Combine nodes");
            #else
                    UndoAll("Delete node");
            #endif
                    foreach (var gameObject in Selection.gameObjects)
                    {
                        InUndoHelper.Destroy(gameObject);
                    }

                    delete = true;
                });
            }


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

                    GameObject go         = InUndoHelper.CreateGO(SplineNode.SplineController.gameObject.name + " Node");
                    go.transform.parent   = SplineNode.SplineController.transform;
                    go.transform.position = SplineNode.transform.position + SplineNode.transform.forward;
                    go.transform.position = SplineNode.transform.position;

                    var newNode = go.AddComponent <InSplineNode>();
                    newNode.SplineController = SplineNode.SplineController;
                    newNode.ConnectTo(SplineNode);
                    SplineNode.SplineController.Nodes.Add(newNode);

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

            if (EditorGUI.EndChangeCheck() && delete == false)
            {
                serializedObject.ApplyModifiedProperties();
            }
        }