public override void OnInspectorGUI()
    {
        if (isValid)
        {
            //Updates the object we are editing
            serializedObject.Update();

            //Quick reference to the script
            QCAnimationAddon q = target as QCAnimationAddon;
            q.cutsceneEventAmount = numberOfEvents;

            //Quick references for when we want to change the size of the array
            bool enlarge  = false;
            bool decrease = false;

            EditorGUILayout.BeginHorizontal();
            //Animators
            EditorGUILayout.LabelField("Animator variable actions:", EditorStyles.boldLabel);
            //Plus button
            if (GUILayout.Button("+"))
            {
                enlarge = true;
            }
            //If we press the plus button, increase the size of the array
            if (enlarge)
            {
                EnlargeMidAnimatorArray();
                serializedObject.ApplyModifiedProperties();
            }
            //Minus button
            if (GUILayout.Button("-"))
            {
                decrease = true;
            }
            //If we press the minus button, decrease array size
            if (decrease)
            {
                DecreaseMidAnimatorArray();
                serializedObject.ApplyModifiedProperties();
            }
            EditorGUILayout.EndHorizontal();

            for (int i = 0; i < animStartAtTransition.arraySize; i++)
            {
                GUIContent popoutContent = new GUIContent("Action # " + (i + 1).ToString());
                q.showEvent[i] = EditorGUILayout.Foldout(q.showEvent[i], popoutContent);

                if (q.showEvent[i] == true)
                {
                    q.animStartAtTransition[i] = EditorGUILayout.IntPopup(" Transition to start at", q.animStartAtTransition[i], names, events);


                    q.midCutsceneAnimators[i] = EditorGUILayout.ObjectField(" Animator", q.midCutsceneAnimators[i], typeof(Animator), true) as Animator;

                    //Show animator options
                    EditorGUILayout.BeginVertical();
                    //Display stuff
                    EditorGUILayout.BeginHorizontal();
                    if (q.midCutsceneAnimators[i] != null)
                    {
                        UnityEditor.Animations.AnimatorController animatorController = (UnityEditor.Animations.AnimatorController)GetEffectiveController(q.midCutsceneAnimators[i]) as UnityEditor.Animations.AnimatorController;
                        int currentHash = animatorController.GetHashCode();

                        string[] temp = null;

                        //If we dont have it, add it
                        if (midAniVars.TryGetValue(currentHash, out temp))
                        {
                            q.midCutsceneAnimatorVarChoices[i]      = EditorGUILayout.Popup(" Variables & target value", q.midCutsceneAnimatorVarChoices[i], temp);
                            q.midCutsceneAnimatorVariables[i]       = temp[q.midCutsceneAnimatorVarChoices[i]];
                            q.midCutsceneAnimatorVariableTargets[i] = EditorGUILayout.Toggle(q.midCutsceneAnimatorVariableTargets[i]);
                        }
                        else
                        {
                            List <string> animatorVars = new List <string>();
                            int           count        = 0;
                            for (int n = 0; n < animatorController.parameters.Length; n++)
                            {
                                if (animatorController.parameters[n].type == UnityEngine.AnimatorControllerParameterType.Bool)
                                {
                                    //animatorVars[count] = animatorController.GetParameter(n).ToString();
                                    UnityEngine.AnimatorControllerParameter acp = animatorController.parameters[n];
                                    animatorVars.Add(acp.name);
                                    count++;
                                }
                            }

                            temp = animatorVars.ToArray();
                            midAniVars.Add(currentHash, animatorVars.ToArray());

                            q.midCutsceneAnimatorVarChoices[i]      = EditorGUILayout.Popup(" Variables & value", q.midCutsceneAnimatorVarChoices[i], temp);
                            q.midCutsceneAnimatorVariables[i]       = temp[q.midCutsceneAnimatorVarChoices[i]];
                            q.midCutsceneAnimatorVariableTargets[i] = EditorGUILayout.Toggle(q.midCutsceneAnimatorVariableTargets[i]);
                        }
                    }
                    EditorGUILayout.EndHorizontal();

                    EditorGUILayout.EndVertical();

                    q.actionStartDelay[i] = EditorGUILayout.FloatField(" Delay (sec) ", q.actionStartDelay[i]);
                }
            }

            if (GUI.changed)
            {
                EditorUtility.SetDirty(target);
            }
        }
    }
Exemple #2
0
    public override void OnInspectorGUI()
    {
        if (isValid)
        {
            //Quick references for when we want to change the size of the animator array
            bool enlarge  = false;
            bool decrease = false;

            //Quick references for when we want to change the size of the scripts to disable array
            bool enlargeScripts  = false;
            bool decreaseScripts = false;

            //Quick reference for controlling the audio component arrays in the cutscene
            bool enlargeAudio  = false;
            bool decreaseAudio = false;

            //Updates the object we are editing
            serializedObject.Update();

            //Quick reference to the Quicktakecutscenecontroller script
            QuickCutsceneController q = target as QuickCutsceneController;

            EditorGUILayout.BeginHorizontal();
            //Button to manually call the StartCutscene function, only if the game is in play mode
            if (GUILayout.Button("Play"))
            {
                if (Application.isPlaying)
                {
                    q.ActivateCutscene();
                }

                if (!Application.isPlaying)
                {
                    Debug.Log("You can only play the cutscene when the game is running");
                }
            }
            //Button to manually call the StartCutscene function, only if the game is in play mode
            if (GUILayout.Button("Stop"))
            {
                if (Application.isPlaying)
                {
                    q.EndCutscene();
                }

                if (!Application.isPlaying)
                {
                    Debug.Log("You can only play/stop the cutscene when the game is running");
                }
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button("Toggle Path (" + q.showPathType.GetHashCode() + ")"))
            {
                q.ToggleShowPath();
            }

            if (GUILayout.Button("Add camera point"))
            {
                GameObject g = new GameObject();
                g.transform.position = (Selection.activeTransform.position + Random.insideUnitSphere * 5f);
                g.transform.rotation = Selection.activeTransform.rotation;
                g.transform.parent   = Selection.activeTransform;
                string n = ("CameraPoint_" + numberOfEvents.ToString());
                g.name = n;
                Undo.RegisterCreatedObjectUndo(g, n);
                this.OnEnable();
            }

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            //Camera selector
            EditorGUILayout.LabelField(cameraContent);
            q.mainCutsceneCam = EditorGUILayout.ObjectField(q.mainCutsceneCam, typeof(Camera), true) as Camera;
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(startAudioContent);
            //Plus button
            if (GUILayout.Button("+"))
            {
                enlargeAudio = true;
            }
            //If we press the plus button, increase the size of the array
            if (enlargeAudio)
            {
                EnlargeAudioArray();
                serializedObject.ApplyModifiedProperties();
            }
            //Minus button
            if (GUILayout.Button("-"))
            {
                decreaseAudio = true;
            }
            //If we press the minus button, decrease array size
            if (decreaseAudio)
            {
                DecreaseAudioArray();
                serializedObject.ApplyModifiedProperties();
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.BeginVertical();
            for (int i = 0; i < q.mainAudioPoints.Length; ++i)
            {
                q.mainAudioPoints[i] = EditorGUILayout.ObjectField(q.mainAudioPoints[i], typeof(AudioSource), true) as AudioSource;
            }
            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginVertical();
            for (int i = 0; i < q.cutsceneAudio.Length; ++i)
            {
                q.cutsceneAudio[i] = EditorGUILayout.ObjectField(q.cutsceneAudio[i], typeof(AudioClip), true) as AudioClip;
            }
            EditorGUILayout.EndVertical();

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(startDisabledScriptContent);
            //Plus button
            if (GUILayout.Button("+"))
            {
                enlargeScripts = true;
            }
            //If we press the plus button, increase the size of the array
            if (enlargeScripts)
            {
                EnlargeDisabledScriptArray();
                serializedObject.ApplyModifiedProperties();
            }
            //Minus button
            if (GUILayout.Button("-"))
            {
                decreaseScripts = true;
            }
            //If we press the minus button, decrease array size
            if (decreaseScripts)
            {
                DecreaseDisabledScriptArray();
                serializedObject.ApplyModifiedProperties();
            }
            EditorGUILayout.EndHorizontal();

            //Disabled scripts
            for (int i = 0; i < q.disableWhileInCutscene.Length; ++i)
            {
                q.disableWhileInCutscene[i] = EditorGUILayout.ObjectField(q.disableWhileInCutscene[i], typeof(MonoBehaviour), true) as MonoBehaviour;
            }
            EditorGUILayout.Space();

            EditorGUILayout.BeginHorizontal();
            //Animators
            EditorGUILayout.LabelField(animatorContent);
            //Plus button
            if (GUILayout.Button("+"))
            {
                enlarge = true;
            }
            //If we press the plus button, increase the size of the array
            if (enlarge)
            {
                EnlargeAnimatorArray();
                serializedObject.ApplyModifiedProperties();
            }
            //Minus button
            if (GUILayout.Button("-"))
            {
                decrease = true;
            }
            //If we press the minus button, decrease array size
            if (decrease)
            {
                DecreaseAnimatorArray();
                serializedObject.ApplyModifiedProperties();
            }
            EditorGUILayout.EndVertical();


            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.BeginVertical();
            for (int i = 0; i < q.cutsceneAnimators.Length; ++i)
            {
                q.cutsceneAnimators[i] = EditorGUILayout.ObjectField(q.cutsceneAnimators[i], typeof(Animator), true) as Animator;
            }
            EditorGUILayout.EndHorizontal();

            //Animators
            EditorGUILayout.BeginVertical();
            for (int i = 0; i < q.cutsceneAnimators.Length; ++i)
            {
                if (q.cutsceneAnimators[i] != null)
                {
                    UnityEditor.Animations.AnimatorController animatorController = (UnityEditor.Animations.AnimatorController)GetEffectiveController(q.cutsceneAnimators[i]) as UnityEditor.Animations.AnimatorController;
                    int currentHash = animatorController.GetHashCode();

                    string[] temp = null;

                    //If we dont have it, add it
                    if (aVars.TryGetValue(currentHash, out temp))
                    {
                        q.cutsceneAnimatorVarChoices[i] = EditorGUILayout.Popup(q.cutsceneAnimatorVarChoices[i], temp);
                        q.cutsceneAnimatorVariables[i]  = temp[q.cutsceneAnimatorVarChoices[i]];
                    }
                    else
                    {
                        List <string> animatorVars = new List <string>();
                        int           count        = 0;
                        for (int n = 0; n < animatorController.parameters.Length; n++)
                        {
                            if (animatorController.parameters[n].type == UnityEngine.AnimatorControllerParameterType.Bool)
                            {
                                //animatorVars[count] = animatorController.GetParameter(n).ToString();
                                UnityEngine.AnimatorControllerParameter acp = animatorController.parameters[n];
                                animatorVars.Add(acp.name);
                                count++;
                            }
                        }

                        temp = animatorVars.ToArray();
                        aVars.Add(currentHash, animatorVars.ToArray());

                        q.cutsceneAnimatorVarChoices[i] = EditorGUILayout.Popup(q.cutsceneAnimatorVarChoices[i], temp);
                        q.cutsceneAnimatorVariables[i]  = temp[q.cutsceneAnimatorVarChoices[i]];
                    }
                }
            }
            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginVertical();
            for (int i = 0; i < q.cutsceneAnimators.Length; i++)
            {
                q.cutsceneAnimatorVariableTargets[i] = EditorGUILayout.Toggle(q.cutsceneAnimatorVariableTargets[i]);
            }
            EditorGUILayout.EndVertical();

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();

            //Use delta time
            //EditorGUILayout.BeginHorizontal();
            //q.useDeltaTime = EditorGUILayout.Toggle(deltaTimeContent, q.useDeltaTime);
            //EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();

            //This for loop controls the display of each camera transition event, and the variables relating to it.
            for (int i = 0; i < (numberOfEvents - 2); i++)
            {
                //Handle error which occurs when we undo a deleted CP
                if (!points[i + 2])
                {
                    this.OnEnable();
                }
                else
                {
                    GUIContent popoutContent = new GUIContent("Camera transition " + (i + 1) + " --> " + (i + 2) + "     (" + points[i + 1].name + " -> " + points[i + 2].name + ")");
                    showEvent[i] = EditorGUILayout.Foldout(showEvent[i], popoutContent);                    //"Camera transition " + (i+1) + " --> " + (i+2));
                }

                if (showEvent[i] == true)
                {
                    if (i >= q.cutsceneEventKeyTime.Length)
                    {
                        //Debug.Log("Refreshing Editor GUI");
                        //EditorGUIUtility.ExitGUI();
                        this.OnEnable();
                    }
                    q.cutsceneEventKeyTime[i] = EditorGUILayout.FloatField(delayContent, q.cutsceneEventKeyTime[i]);

                    //EditorGUILayout.Space();

                    q.cutsceneCameraSpeedOptions[i] = (CameraSpeedOptions)EditorGUILayout.EnumPopup(moveContent, q.cutsceneCameraSpeedOptions[i]);

                    if (q.cutsceneCameraSpeedOptions[i] == CameraSpeedOptions.Curve || q.cutsceneCameraSpeedOptions[i] == CameraSpeedOptions.MobileCurve)
                    {
                        q.curveChoice[i] = true;

                        EditorGUILayout.BeginHorizontal();

                        q.lerpCurveChoice[i] = EditorGUILayout.Toggle(lerpCurveContent, q.lerpCurveChoice[i]);

                        EditorGUILayout.EndHorizontal();

                        if (q.lerpCurveChoice[i])
                        {
                            q.customCurveMovementSpeed[i] = EditorGUILayout.Slider("   >Time (sec)", q.customCurveMovementSpeed[i], 0.0001f, 120f);
                        }
                        else
                        {
                            moveContent = new GUIContent("Movement ", "Movement speed options. Mobile curves require 1 mid-point, normal curves require 2 mid-points.");
                            EditorGUILayout.BeginHorizontal();
                            q.curveNodeCount[i] = EditorGUILayout.IntSlider(nodesContent, q.curveNodeCount[i], 10, 1000);
                            EditorGUILayout.EndHorizontal();
                            q.customCurveMovementSpeed[i] = EditorGUILayout.Slider(curveSpeedContent, q.customCurveMovementSpeed[i], 0.0001f, 120f);
                        }

                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.LabelField(midPointContent);
                        EditorGUILayout.LabelField(midPoints[i + 1].name);
                        EditorGUILayout.EndHorizontal();
                        if (q.cutsceneCameraSpeedOptions[i] == CameraSpeedOptions.Curve)
                        {
                            EditorGUILayout.BeginHorizontal();
                            EditorGUILayout.LabelField(midPointTwoContent);
                            EditorGUILayout.LabelField(cubicPoints[i + 1].name);
                            EditorGUILayout.EndHorizontal();
                        }
                    }
                    else
                    {
                        q.curveChoice[i] = false;
                        moveContent      = new GUIContent("Movement ", "Camera positional movement speed during this event. (Units)");
                    }

                    //Custom movement speed
                    if (q.cutsceneCameraSpeedOptions[i] == CameraSpeedOptions.Custom)
                    {
                        q.customMovementSpeed[i] = EditorGUILayout.FloatField("   >Movement speed", q.customMovementSpeed[i]);
                    }

                    if (q.cutsceneCameraSpeedOptions[i] == CameraSpeedOptions.Lerp)
                    {
                        q.customMovementSpeed[i] = EditorGUILayout.FloatField("   >Movement time", q.customMovementSpeed[i]);
                    }

                    //EditorGUILayout.Space();

                    //Rotation speed
                    q.cutsceneCameraRotationSpeedOptions[i] = (CameraRotationSpeedOptions)EditorGUILayout.EnumPopup(rotationContent, q.cutsceneCameraRotationSpeedOptions[i]);
                    if (q.cutsceneCameraRotationSpeedOptions[i] == CameraRotationSpeedOptions.FollowTarget)
                    {
                        q.smoothFollowTarget[i] = (Transform)EditorGUILayout.ObjectField("   >Follow target", q.smoothFollowTarget[i], typeof(Transform), true) as Transform;
                    }

                    //Custom rotation speed
                    if (q.cutsceneCameraRotationSpeedOptions[i] == CameraRotationSpeedOptions.Custom)
                    {
                        q.customRotationSpeed[i] = EditorGUILayout.FloatField("   >Rotation speed", q.customRotationSpeed[i]);
                    }

                    //Custom rotation speed
                    if (q.cutsceneCameraRotationSpeedOptions[i] == CameraRotationSpeedOptions.Lerp)
                    {
                        q.customRotationSpeed[i] = EditorGUILayout.FloatField("   >Rotation time", q.customRotationSpeed[i]);
                    }

                    //EditorGUILayout.Space();

                    //Camera shake
                    q.doShake[i] = EditorGUILayout.Toggle("Shake camera ", q.doShake[i]);
                    if (q.doShake[i])
                    {
                        q.cameraShakeAmount[i] = EditorGUILayout.Slider("   >Shake intensity", q.cameraShakeAmount[i], 0.1f, 5f);
                    }

                    //EditorGUILayout.Space();

                    //time scale and broadcastmessage
                    q.cutsceneEventTimescale[i] = EditorGUILayout.Slider("Time scale", q.cutsceneEventTimescale[i], 0f, 2f);

                    //EditorGUILayout.Space();

                    q.broadcastMessageChoice[i] = EditorGUILayout.Toggle(broadcastContent, q.broadcastMessageChoice[i]);
                    if (q.broadcastMessageChoice[i] == true)
                    {
                        EditorGUILayout.BeginVertical();
                        q.broadcastMessageString[i] = EditorGUILayout.TextField("   >Method name", q.broadcastMessageString[i]);
                        q.broadcastMessageTarget[i] = EditorGUILayout.ObjectField("   >Target", q.broadcastMessageTarget[i], typeof(GameObject), true) as GameObject;
                        EditorGUILayout.EndVertical();
                    }

                    //EditorGUILayout.Space();

                    q.cutsceneEventZoom[i] = EditorGUILayout.Toggle(zoomContent, q.cutsceneEventZoom[i]);
                    if (q.cutsceneEventZoom[i] == true)
                    {
                        q.cutsceneEventZoomAmount[i] = EditorGUILayout.Slider("   >Field of View", q.cutsceneEventZoomAmount[i], 1f, 144f);
                        q.cutsceneEventZoomSpeed[i]  = EditorGUILayout.Slider("   >Zoom speed", q.cutsceneEventZoomSpeed[i], 0.001f, 40f);
                    }


                    //EditorGUILayout.EndVertical();
                }
            }

            if (GUI.changed)
            {
                EditorUtility.SetDirty(target);
            }

            //And apply
            serializedObject.ApplyModifiedProperties();
        }
    }