Inheritance: MonoBehaviour
Esempio n. 1
0
    public void Start()
    {
        tutorialCamera = FindObjectOfType <TutorialCamera>();
        MainGUI        = GameObject.Find("MainGUI").GetComponent <Animator>();
        if (TutorialCamera.Enabled())
        {
            enabled = false;
            return;
        }
        else
        {
            enabled = true;

            initialCameraPosition = transform.position;
            initialCameraRotation = transform.rotation;

            AmbientNoise.Play();

            PauseButton.paused = false;

            player          = GameObject.Find("Player");
            grapplingHook   = player.GetComponent <GrapplingHook>();
            playerMovements = player.GetComponent <PlayerMovements>();

            //ControlManager.Disabled = true;
            if (!GameRecorder.playingBack)
            {
                GameRecorder.StopPlayback();

                if (LevelSelectGUI.currentLevel != null)
                {
                    GUIController.ShowText("LevelName", LevelSelectGUI.currentLevel.name);
                }

#if UNITY_ANDROID || UNITY_IPHONE
                GUIController.ShowText("Text", "Tap to begin");
#else
                //GUIController.ShowText("Text", "Click to begin");
                //tutorialCamera.ShowTutorialText("Click to begin", false);
                StartCoroutine(ShowStartText());
#endif

                GUIController.GUILevelPause();
                GUIController.HideText("Paused");
            }

            EnableCameraController();
        }
    }
Esempio n. 2
0
    void Update()
    {
        Quaternion targetRot = transform.rotation;

        // Don't run if we're running the tutorial
        if (TutorialCamera.Enabled())
        {
            return;
        }

        // Stop if we have no target.
        if (target == null)
        {
            return;
        }

        // If we aren't pointing
        if (!PauseButton.paused)
        {
            dontPointTimer -= Time.deltaTime;
            if (dontPointTimer < 0)
            {
                // Set the rotation.
                Quaternion desired = CalculateDesiredRotation();
                targetRot = Quaternion.Slerp(transform.rotation, desired, CamTarget.sRate * Time.deltaTime);
            }
        }

        if (avoidOcclusion)
        {
            // Calculate nearest point of occlusion
            Plane nearPlane         = CalculateNearPlane(transform.position);
            float occlusionDistance = FindMinimumOcclusionDistance(target.transform.position, nearPlane);

            // Move camera to point of occlusion
            if (occlusionDistance > 0)
            {
                realDistance = Mathf.SmoothDamp(realDistance, occlusionDistance, ref velf, forwardOcclusionSmoothing);
            }
        }

        Vector3 targetPos = target.transform.position + offset - transform.forward * distanceFromCamera;// + (transform.forward * -1 * realDistance);

        // Move back a bit.
        //transform.position = Vector3.Lerp(transform.position, targetPos, Time.deltaTime * 10.0f);
        transform.position = targetPos;
        transform.rotation = targetRot;
    }
    public void Start()
    {
        if (SaveManager.save == null)
        {
            return;
        }

        TutorialCamera.ResetShownTutorials();

        foreach (var tile in created)
        {
            Destroy(tile);
        }
        created.Clear();

        var worlds = FindObjectsOfType <Levels>().ToList();

        foreach (var world in worlds.OrderBy(w => w.levels[0].world))
        {
            foreach (var level in world.levels)
            {
                if (level.world > SaveManager.save.worldUnlocked)
                {
                    continue;
                }
                if (level.world == SaveManager.save.worldUnlocked && level.number > SaveManager.save.levelUnlocked)
                {
                    continue;
                }

                Debug.Log("Loading level " + level.name);

                var newTile = GameObject.Instantiate(LevelTemplate, transform);
                newTile.SetActive(true);

                string displayName = (level.name == $"World {level.world} Level {level.number}" ? $"{level.world}-{level.number}" : level.name);

                newTile.name = level.name;
                newTile.GetComponentInChildren <Text>().text = displayName;

                newTile.GetComponent <Button>().onClick.AddListener(() => { LevelSelectGUI.currentLevel = level; SceneManager.LoadScene(level.name); });

                created.Add(newTile);
            }
        }
    }
Esempio n. 4
0
    void OnCollisionEnter(Collision collision)
    {
        if (TutorialCamera.Enabled())
        {
            return;
        }

        Collider collider = collision.collider;

        if (collider.gameObject.tag == "Player" && !LevelState.Dead && !LevelState.HasFinished)
        {
            GUIController.HideText("Tutorial");

            // Set flag so this doesn't run more than once
            LevelState.HasFinished = true;

            // Freeze score values
            ScoreCalculator.End();

            //freeze the player
            LevelState.Dead = true;
            collider.GetComponent <Rigidbody>().velocity    = Vector3.zero;
            collider.GetComponent <Rigidbody>().isKinematic = true;

            //make the player face the thing it hit
            collider.transform.LookAt(collider.transform.position + collision.contacts[0].normal, collider.transform.up);

            // Send a message to the player to start the mining particles.
            player.SendMessage("StartMining");

            // Switch to a camera that looks at the end thingy.
            ZoomOuterizer zout = Camera.main.GetComponent <ZoomOuterizer>();
            if (zout != null)
            {
                zout.ZoomOut(ZoomOut, ZoomOutTimer);
            }

            // Do level finish routine (scores, stars and audio)
            StartCoroutine("FinishLevel");
        }
    }
Esempio n. 5
0
    void Update()
    {
        if (!TutorialCamera.Enabled() && !LevelState.Dead)
        {
            if (!grapplingHook.enabled)
            {
                grapplingHook.Update();
            }

            // Handle back button
            if (Input.GetKeyDown(KeyCode.Escape) || Input.GetButtonDown("SkipTutorial"))
            {
                GameObject pauseButton = GameObject.Find("Pause");
                if (pauseButton != null)
                {
                    pauseButton.SendMessage("ButtonPressed", SendMessageOptions.DontRequireReceiver);
                }
            }

            if (!started && !GameRecorder.playingBack)
            {
                //			if (enablePreviews && useStaticPreviews && !GameRecorder.playingBack)
                //			{
                //				// Handle previews
                //				timePassed += Time.deltaTime;
                //				if (timePassed >= previewTime)
                //				{
                //					timePassed = 0.0f;
                //					NextPreview();
                //				}
                //			}

                // Start level if player tapped last frame or if reload is disabled
                if (start ||
                    (!reload && !started && (InputManager.pressed || InputManager.released) && !ControlManager.MouseOnGUI && !GameRecorder.playingBack))
                {
                    if (!reload)
                    {
                        Debug.Log("Reloading");
                        foreach (GameObject gameObject in GameObject.FindObjectsOfType(typeof(GameObject)))
                        {
                            Debug.Log(gameObject.name);
                            gameObject.BroadcastMessage("Reload", SendMessageOptions.DontRequireReceiver);
                        }

                        //persistClick = true;
                        //clickpos = InputManager.currentPosition;
                    }

                    playerMovements.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeRotation;

                    // Apply initial velocity
                    playerMovements.Go();

                    // Set state
                    start   = false;
                    started = true;

                    // Reset camera
                    transform.position = initialCameraPosition;
                    transform.rotation = initialCameraRotation;

                    // Enable camera controller
                    EnableCameraController();

                    // Initialise systems
                    GameRecorder.playingBack = false;
                    GameRecorder.StartRecording();
                    GUIController.HideText("Text");
                    tutorialCamera.HideTutorial();
                    GUIController.GUILevelPlay();
                    GUIController.LevelStarted = true;
                    ControlManager.Disabled    = false;
                    ScoreCalculator.Reset();
                    Debug.Log("Playing start level");
                    MainGUI.Play("StartLevel");

                    // Try to grapple
                    if (persistClick)
                    {
                        persistClick = false;
                        InputManager.currentPosition = clickpos;

                        grapplingHook.TryGrapple(InputManager.currentPosition);
                    }
                }
                else if (!LevelState.Dead)
                {
                    playerMovements.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;
                }

                // Reload and start level if reload is enabled
                if (reload && !started && InputManager.pressed && !ControlManager.MouseOnGUI && !GameRecorder.playingBack)
                {
                    start              = true;
                    persistClick       = true;
                    clickpos           = InputManager.currentPosition;
                    PauseButton.paused = false;
                    Application.LoadLevel(Application.loadedLevelName);
                    InputManager.pressed  = true;
                    InputManager.released = true;
                }
            }
        }
    }
 void Awake()
 {
     player = GameObject.Find("Player");
     tutorialCam = GameObject.FindObjectOfType<TutorialCamera>();
 }
Esempio n. 7
0
    void LateUpdate()
    {
        if (!recording || GameObject.Find("Player").GetComponent <Renderer>().enabled == false)
        {
            lineRenderer.enabled = false;
        }
        else
        {
            lineRenderer.enabled = true;
        }

        // Automatically dequeue old points
        int pointsToKeep = (int)(maxLineTime * fps);

        while (linePoints.Count > pointsToKeep)
        {
            linePoints.Dequeue();
        }

        // Add all vertices to line renderer
        int i = 0;

        lineRenderer.SetColors(Color.clear, lineColour);
        lineRenderer.SetVertexCount(linePoints.Count + 1);
        foreach (Vector3 point in linePoints)
        {
            lineRenderer.SetPosition(i, point);
            i++;
        }

        if (enableLine && linePoints.Count > 0)
        {
            lineRenderer.SetPosition(i, transform.position + offset);
        }

        if (playback && current != null)
        {
            if (!TutorialCamera.Enabled())
            {
                GUIController.GUIPlaybackRecording();

                ControlManager.Disabled = true;

                GUIController.ShowText("Replay", "Replay Mode");
            }

            time += Time.deltaTime;

            if (time < current.score.time)
            {
                transform.position = current.GetPosition(time);
                if (!GetComponent <Rigidbody>().isKinematic)
                {
                    GetComponent <Rigidbody>().velocity = current.GetVelocity(time);
                }

                transform.LookAt(transform.position + GetComponent <Rigidbody>().velocity);

                if (current.IsGrappling(time) && current.GetGrapplePos(lastTime) != current.GetGrapplePos(time))
                {
                    if (!current.IsGrappling(lastTime))
                    {
                        SoundManager.Play("attach");
                    }

                    RaycastHit hit = new RaycastHit();
                    hit.point = current.GetGrapplePos(time);

                    grappleScript.Attach(hit, -1, true);
                }
                else if (!current.IsGrappling(time) && current.IsGrappling(lastTime))
                {
                    grappleScript.Detach();
                }
            }

            lastTime = time;
        }
    }
Esempio n. 8
0
 void Awake()
 {
     tutorialCamera = FindObjectOfType <TutorialCamera>();
 }
Esempio n. 9
0
    void KillPlayer(GameObject player)
    {
        if (TutorialCamera.Enabled())
        {
            GameRecorder.StopPlayback();
            if (explode)
            {
                player.SendMessage("Explode");
                SoundManager.Play("crash");

                player.SendMessage("Reload");
                IncrementCrashCount(true);
            }

            return;
        }

        if (!LevelState.Dead)
        {
            MainGUI.Play("RestartLevel");

            // Disable text
            GUIController.DisableTexts();

            // Update drone count
            if (SaveManager.save != null)
            {
                if (explode)
                {
                    IncrementCrashCount(false);
                }
                SaveManager.save.droneCount++;
                SaveManager.Write();

                // Display drone coun
                if (false)
                {
                    GameObject thingy = Tutorial.ShowText("DroneText", "Drones lost: " + SaveManager.save.droneCount, 0, TextAlignment.Center, TextAnchor.MiddleCenter, 0.5f, 0.5f);
                    Mover      mover  = thingy.AddComponent <Mover>();
                    mover.direction = Vector3.up;
                    mover.speed     = 0.2f;
                    TextFader fader = thingy.AddComponent <TextFader>();
                    fader.fadeRate = 1.0f;
                    fader.FadeOut();
                }
            }

            // Update level state
            GUIController.LevelStarted = false;
            LevelStart.started         = false;
            LevelState.Dead            = true;

            if (explode)
            {
                // Create explosion effect
                player.SendMessage("Explode");

                // Crash sound
                SoundManager.Play("crash");

                // Disable renderers if exploding
                player.GetComponent <Renderer>().enabled = false;
                player.transform.Find("Shield").GetComponent <Renderer>().enabled = false;
            }

            // Disable default camera controller until level restarts
            ThirdPersonCamera cameraController = Camera.main.GetComponent <ThirdPersonCamera>();
            if (cameraController != null)
            {
                cameraController.enabled = false;
            }

            // Detach grappling hook so we don't keep swinging
            grapplingHook.Detach();

            // I don't really remember why
            ControlManager.DisabledFrame = true;

            // Pause and then restart the level
            StartCoroutine(PauseBeforeReset());
        }
    }
Esempio n. 10
0
    public void Update()
    {
        GameObject targetedObjectPrev = targetedObject;

        if (IsGrappled)
        {
            hangTime += Time.deltaTime;
            if (hangTime > 30 && !triedHangUnlock)
            {
                hangUnlocker = AchievementUnlocker.MakeUnlocker("hanginout");
                hangUnlocker.UnlockAchievement();
                triedHangUnlock = true;
            }
        }
        else
        {
            hangTime = 0;
        }

        // Do gamepad input
        // Detarget
        if (!Input.GetButton("Target"))
        {
            targetedObject = null;
        }

        // Target
        if (Input.GetButton("Target"))
        {
            Vector3 position = new Vector3(Input.GetAxis("Horizontal2"),
                                           Input.GetAxis("Vertical2"),
                                           0);

            // Confirm axis to viewport space (-1..1 to 0..1)
            position += new Vector3(1.0f, 1.0f, 0);
            position /= 2.0f;

            // Find nearest object
            float      distance  = float.MaxValue;
            GameObject nearest   = null;
            Vector3    viewPoint = Vector3.zero;

            foreach (GameObject gameObject in grappleable)
            {
                Vector3 inputViewportPoint = position;
                inputViewportPoint.z = 0;

                Vector3 objectViewportPoint = theCamera.WorldToViewportPoint(gameObject.transform.position);
                objectViewportPoint.z = 0;

                float gObjDistance = (inputViewportPoint - objectViewportPoint).magnitude;

                if (gObjDistance < distance)
                {
                    distance  = gObjDistance;
                    nearest   = gameObject;
                    viewPoint = objectViewportPoint;
                }
            }

            if (nearest != null)
            {
                targetedObject = nearest;

                GrappleGuide grappleGuide = targetedObject.GetComponent <GrappleGuide>();
                if (grappleGuide != null)
                {
                    targetedObject = grappleGuide.grappleTo.gameObject;
                }
            }
        }

        // Update targeted object
        if (targetedObject != targetedObjectPrev)
        {
            string targetName = (targetedObject == null ?
                                 "null" : targetedObject.name);
            string oldTargetName = (targetedObjectPrev == null ?
                                    "null" : targetedObjectPrev.name);

            Debug.Log("New target: " + targetName +
                      ", Old target: " + oldTargetName);

            if (targetedObject != null)
            {
                GameObject realObject = targetedObject;

                realObject.GetComponent <Renderer>().material.SetColor("_OutlineColor", Color.red);
            }

            if (targetedObjectPrev != null)
            {
                GameObject realObject = targetedObjectPrev;

                realObject.GetComponent <Renderer>().material.SetColor("_OutlineColor", Color.white);
            }
        }

        if (!enabled)
        {
            return;
        }

        // Detatch
        if (LevelStart.started &&
            Input.GetButtonUp("Grapple"))
        {
            Detach();
        }

        // Attach
        if (LevelStart.started &&
            Input.GetButtonDown("Grapple") &&
            targetedObject != null)
        {
            Vector3 viewPoint = theCamera.WorldToViewportPoint(targetedObject.transform.position);

            Ray        ray = theCamera.ViewportPointToRay(viewPoint);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))            // && (enableRegrapple || rope.enabled == false))
            {
                if (hit.collider.gameObject != gameObject && hit.collider.gameObject.tag != "Ungrappleable")
                {
                    if (rope.enabled == true)
                    {
                        Detach();
                    }

                    Attach(hit, (transform.position - hit.point).magnitude, true);
                    SoundManager.Play("attach");
                }
            }
        }

        // Point the shield at the grapple point.
        if (rope.enabled)
        {
            // Point.
            shield.GetComponent <Renderer>().enabled = true;

            // Get the last point on the grapple.
            shield.transform.LookAt(grapples[grapples.Count - 1].gameObject.transform.position);
            shield.transform.Rotate(Vector3.right, 90);

//			// Widen the grapple the closer we are to our target.
//
//			// Get the distance between the .
//			float actualDistance = (transform.position - grapples[grapples.Count - 1].gameObject.transform.position).magnitude;
//			float distanceFration = actualDistance / grapples[grapples.Count - 1].maxDistance;
//
//			if(distanceFration < TRANSPARENCY_THRESHOLD)
//			{
//				ropeWidth = Mathf.Lerp(ropeWidth, ENABLED_THICKNESS, TRANSITION_RATE * Time.deltaTime);
//			}
//			else
//			{
//				ropeWidth = Mathf.Lerp(ropeWidth, DISABLED_THICKNESS, TRANSITION_RATE * Time.deltaTime);
//			}
//
//			rope.SetWidth(ropeWidth, ropeWidth);
        }
        else
        {
            shield.GetComponent <Renderer>().enabled = false;
        }

        if (!ControlManager.MouseOnGUI)
        {
            if (!TutorialCamera.Enabled() && !EndFlagScript.hasFinished && !PauseButton.paused)
            {
#if UNITY_ANDROID || UNITY_IPHONE
                Vector3 pos;

                foreach (Touch touch in Input.touches)
                {
                    if (touch.phase == TouchPhase.Began)
                    {
                        // Register touch
                        TouchData touchData = new TouchData();
                        touchData.fingerId  = touch.fingerId;
                        touchData.startTime = Time.time;

                        localTouches.Add(touchData);
                    }

                    if (touch.phase == TouchPhase.Ended)
                    {
                        TouchData touchData = null;
                        foreach (TouchData td in localTouches)
                        {
                            if (td.fingerId == touch.fingerId)
                            {
                                touchData = td;
                                break;
                            }
                        }

                        if (touchData != null)
                        {
                            pos = touch.position;

                            localTouches.Remove(touchData);

                            float startTime = touchData.startTime;
                            float endTime   = Time.time;

                            float touchTime = endTime - startTime;

                            // If the drag was less than the minimum time for grapple/ungrapple
                            if (touchTime < CLICK_TIMER)
                            {
                                if (!IsGrappling())
                                {
                                    TryGrapple(pos);
                                }
                                else
                                {
                                    Detach();
                                }
                            }
                        }
                    }
                }
#else
                if (InputManager.pressed)
                {
                    pressTime = Time.time;
                }

                if (InputManager.released)
                {
                    float touchTime = Time.time - pressTime;

                    if (touchTime < CLICK_TIMER)
                    {
                        if (!IsGrappling())
                        {
                            TryGrapple(Input.mousePosition);
                        }
                        else
                        {
                            Detach();
                        }
                    }
                }
#endif
            }
        }

        if (IsGrappling())
        {
            // Shrink rope for "easy mode"
            float dist = (grapple.transform.position - transform.position).magnitude;
            if (dist < springJoint.maxDistance)
            {
                springJoint.maxDistance = dist;
            }
        }
    }
Esempio n. 11
0
 void Start()
 {
     tutCamera    = (TutorialCamera)FindObjectOfType(typeof(TutorialCamera));
     creationTime = Time.time;
 }
 void Start()
 {
     tutCamera = (TutorialCamera)FindObjectOfType(typeof(TutorialCamera));
     creationTime = Time.time;
 }
Esempio n. 13
0
 void Awake()
 {
     player      = GameObject.Find("Player");
     tutorialCam = GameObject.FindObjectOfType <TutorialCamera>();
 }