Ejemplo n.º 1
0
 //Create and control the button
 void OnGUI()
 {
     if (demoCutscene.playingCutscene)
     {
         if (GUI.Button(new Rect(0, 0, 100, 20), "Stop cutscene"))
         {
             demoCutscene.EndCutscene();
         }
     }
 }
Ejemplo n.º 2
0
    /*
     * //collider way:
     * void OnTriggerEnter(Collider other)
     * {
     *
     *  if (other.tag == "Player")
     *  {
     *      myplayer = other.gameObject;
     *      player_old_position = other.transform.position;
     *      camera_old_position = myCamera.transform.localPosition;
     *      player_old_rotation = other.transform.rotation;
     *      camera_old_rotation = myCamera.transform.localRotation;
     *
     *      if (mycutscene.playingCutscene == false)
     *      {
     *          mycutscene.ActivateCutscene();
     *          Debug.Log("start camera!");
     *          //Start event:
     *          StartCoroutine("fish_event");
     *
     *          StartCoroutine("Finish");
     *          myplayer.gameObject.GetComponent<Camera_Track_Mouse>().enabled = false;
     *          myplayer.gameObject.GetComponent<Movement>().enabled = false;
     *
     *
     *      }
     *
     *  }
     * }
     */
    IEnumerator Finish(float time)
    {
        //Debug.Log("Finishing!!");
        yield return(new WaitForSeconds(time));

        myplayer.gameObject.GetComponent <Camera_Track_Mouse>().enabled = true;
        myplayer.gameObject.GetComponent <Movement>().enabled           = true;

        myCamera.transform.localPosition = camera_old_position;
        myCamera.transform.localRotation = camera_old_rotation;

        myplayer.transform.position = player_old_position;
        myplayer.transform.rotation = player_old_rotation;

        mycutscene.EndCutscene();
    }
Ejemplo n.º 3
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();
        }
    }