예제 #1
0
    // Use this for initialization
    void Start()
    {
        nbPlayers = PlayerPrefs.GetInt("nbPlayers", 4);
        timeOfGame = PlayerPrefs.GetFloat("timeOfGame", -1);
        lifeAllowed = PlayerPrefs.GetInt("lifeAllowed", 3);
        playerID = PlayerPrefs.GetInt("playerID", 0);
        timeElapsed = 0;

        gameOver = false;
        canvas = GameObject.Find("Canvas");
        timeTxt = GameObject.Find("TimeText").GetComponent<Text>();

        level = GameObject.FindGameObjectWithTag("Arena").GetComponent<ArenaManager>().level;

        colors = new List<Color>();
        colors.Add(Color.red);
        colors.Add(Color.blue);
        colors.Add(Color.green);
        colors.Add(Color.yellow);
        names = new List<string>();

        /*intro anim*/
        introStep = 0;
        introStepCount = 4;
        introIsPlaying = true;
        nacelle = GameObject.Find("nacelle");
        nacelleFloor = GameObject.Find("nacellefloor");
        initPosOnnacelle = new List<Vector3>();
        initPosOnnacelle.Add(new Vector3(2.5f, 30.8f, 2.5f));
        initPosOnnacelle.Add(new Vector3(2.5f, 30.8f, -2.5f));
        initPosOnnacelle.Add(new Vector3(-2.5f, 30.8f, 2.5f));
        initPosOnnacelle.Add(new Vector3(-2.5f, 30.8f, -2.5f));
        moles = new List<GameObject>();
        QCSController = GameObject.Find("BaseCutscene").GetComponent<QuickCutsceneController>();
        cutScenePlayed = false;
        getReadyImg = GameObject.Find("GetReadyImage");
        goImg = GameObject.Find("GoImage");
        getReadyImg.SetActive(false);
        goImg.SetActive(false);

        /*create moles */
        for (int i = 0; i < nbPlayers; i++)
        {
            GameObject go = Instantiate(Resources.Load("Prefabs/Mole")) as GameObject;
            if (i == playerID)
            {
                go.AddComponent<MoleController>();
            }

            go.GetComponent<MoleManager>().SetInitPosition(initPosOnnacelle[i]);

            go.GetComponent<Rigidbody>().Sleep();
            //go.GetComponent<MoleManager>().SetInitPosition(level.GetInitalPosition(nbPlayers, i));
            go.GetComponent<MoleManager>().SetLife(lifeAllowed);
            go.GetComponent<MoleManager>().PlayerID = i;
            go.GetComponent<MoleManager>().Name = "Mole " + i;
            go.GetComponent<MeshRenderer>().material = Resources.Load("Materials/Mole" + i) as Material;

            moles.Add(go);
            names.Add(go.GetComponent<MoleManager>().Name);
        }

        updateTimetext();
    }
예제 #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();
        }
    }
예제 #3
0
    // Use this for initialization
    void Start()
    {
        nbPlayers   = PlayerPrefs.GetInt("nbPlayers", 4);
        timeOfGame  = PlayerPrefs.GetFloat("timeOfGame", -1);
        lifeAllowed = PlayerPrefs.GetInt("lifeAllowed", 3);
        playerID    = PlayerPrefs.GetInt("playerID", 0);
        timeElapsed = 0;

        gameOver = false;
        canvas   = GameObject.Find("Canvas");
        timeTxt  = GameObject.Find("TimeText").GetComponent <Text>();

        level = GameObject.FindGameObjectWithTag("Arena").GetComponent <ArenaManager>().level;

        colors = new List <Color>();
        colors.Add(Color.red);
        colors.Add(Color.blue);
        colors.Add(Color.green);
        colors.Add(Color.yellow);
        names = new List <string>();

        /*intro anim*/
        introStep        = 0;
        introStepCount   = 4;
        introIsPlaying   = true;
        nacelle          = GameObject.Find("nacelle");
        nacelleFloor     = GameObject.Find("nacellefloor");
        initPosOnnacelle = new List <Vector3>();
        initPosOnnacelle.Add(new Vector3(2.5f, 30.8f, 2.5f));
        initPosOnnacelle.Add(new Vector3(2.5f, 30.8f, -2.5f));
        initPosOnnacelle.Add(new Vector3(-2.5f, 30.8f, 2.5f));
        initPosOnnacelle.Add(new Vector3(-2.5f, 30.8f, -2.5f));
        moles          = new List <GameObject>();
        QCSController  = GameObject.Find("BaseCutscene").GetComponent <QuickCutsceneController>();
        cutScenePlayed = false;
        getReadyImg    = GameObject.Find("GetReadyImage");
        goImg          = GameObject.Find("GoImage");
        getReadyImg.SetActive(false);
        goImg.SetActive(false);

        /*create moles */
        for (int i = 0; i < nbPlayers; i++)
        {
            GameObject go = Instantiate(Resources.Load("Prefabs/Mole")) as GameObject;
            if (i == playerID)
            {
                go.AddComponent <MoleController>();
            }

            go.GetComponent <MoleManager>().SetInitPosition(initPosOnnacelle[i]);

            go.GetComponent <Rigidbody>().Sleep();
            //go.GetComponent<MoleManager>().SetInitPosition(level.GetInitalPosition(nbPlayers, i));
            go.GetComponent <MoleManager>().SetLife(lifeAllowed);
            go.GetComponent <MoleManager>().PlayerID  = i;
            go.GetComponent <MoleManager>().Name      = "Mole " + i;
            go.GetComponent <MeshRenderer>().material = Resources.Load("Materials/Mole" + i) as Material;

            moles.Add(go);
            names.Add(go.GetComponent <MoleManager>().Name);
        }

        updateTimetext();
    }
예제 #4
0
    void OnSceneGUI()
    {
        if (isValid)
        {
            //Quick reference to the Quicktakecutscenecontroller script
            QuickCutsceneController q = target as QuickCutsceneController;

            q.SetCameraPointReferences();

            //The size of the gizmos to draw for each camera point
            float gizmoSize = 0.4f;

            EditorGUI.BeginChangeCheck();

            //Only draw gizmos if we want to
            if (q.showPathType == PathType.PathOnly || q.showPathType == PathType.PathAndFrustum)
            {
                //Draw circles for each main cam point
                for (int i = 1; i < q.cutsceneCameraPoints.Length; i++)
                {
                    Handles.color = Color.green;
                    Undo.RecordObject(q.cutsceneCameraPoints[i], "Move");

                    q.cutsceneCameraPoints[i].position = Handles.FreeMoveHandle(q.cutsceneCameraPoints[i].position, Quaternion.identity,
                                                                                gizmoSize,
                                                                                Vector3.zero,
                                                                                Handles.SphereCap);
                }

                //Draw for each mid point
                for (int i = 0; i < q.cutsceneCameraPoints.Length - 2; i++)
                {
                    Handles.color = Color.yellow;

                    if (q.curveChoice[i] == true)
                    {
                        Undo.RecordObject(q.cutsceneMidPoints[i + 1], "Move");
                        q.cutsceneMidPoints[i + 1].position = Handles.FreeMoveHandle(q.cutsceneMidPoints[i + 1].position, Quaternion.identity,
                                                                                     gizmoSize * 0.9f,
                                                                                     Vector3.zero,
                                                                                     Handles.SphereCap);
                    }
                }

                //And draw for each cubic mid point, and a path
                for (int i = 0; i < q.cutsceneCameraPoints.Length - 2; i++)
                {
                    Handles.color = Color.magenta;

                    if (q.curveChoice[i] == true && q.cutsceneCameraSpeedOptions[i] == CameraSpeedOptions.Curve)                   //Only draw this midpoint if it is a cubic curve
                    {
                        Undo.RecordObject(q.cutsceneCubicMidPoints[i + 1], "Move");
                        q.cutsceneCubicMidPoints[i + 1].position = Handles.FreeMoveHandle(q.cutsceneCubicMidPoints[i + 1].position, Quaternion.identity,
                                                                                          gizmoSize * 0.8f,
                                                                                          Vector3.zero,
                                                                                          Handles.SphereCap);
                    }

                    Handles.color = Color.green;
                }
            }
        }

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(target, "Changes");

            EditorUtility.SetDirty(target);
        }
    }