devNotes 4-14-2017 BaseLine Teleport

populus

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using ArgosTweenSpacePuppy;

public class Argos_Teleport : MonoBehaviour
{
    public enum DESTINATION
    {
        TO_THE_VU,
        TO_THE_LAB,
    }

    private DESTINATION toDest = DESTINATION.TO_THE_VU;

    public float tweenDuration_TelePort = 1.618f;
    private float normS_TelePort = 0;
    private float tAccum_TelePort = 0;
    private float base_Scale_TelePort = 1f;

    private Vector3 start_Pos_TelePort = Vector3.zero;
    private Vector3 end_Pos_TelePort = Vector3.zero;
    private float start_Scale_TelePort = 75.0f;
    private float end_Scale_TelePort = 1f;
    private Quaternion start_ROTA_TelePort = Quaternion.identity;
    private Quaternion end_ROTA_TelePort = Quaternion.identity;

    public GameObject gArgos_Lobby;
    public Transform tLobby_Start_Transform;
    public Vector3 startPos;
    public Quaternion startRota;

    private VU_UI_MANAGER vu_UI_Manager;
    private HMD_Ctrl_Tracking hmd_Ctrl_Tracking;

    public Egg_Tutor egg_Tutor;

    public float currentScale;

    public bool bReDisplay_UI;

    public void Awake()
    {
        startPos = tLobby_Start_Transform.position;
        startRota = tLobby_Start_Transform.rotation;
    }

    void Start ()
    {
        vu_UI_Manager       = VU_UI_MANAGER.Instance;
        hmd_Ctrl_Tracking   = HMD_Ctrl_Tracking.Instance;
    }
	
	void Update ()
    {
		
	}

    public void onTelePort_to(Vector3 pos, bool bLAB, bool bDisplay_UI)
    {
        start_Pos_TelePort   = transform.position;
        start_Scale_TelePort = transform.localScale.x;
        start_ROTA_TelePort  = transform.rotation;

        bReDisplay_UI = bDisplay_UI;

        if (bLAB)
        {
            end_Pos_TelePort = pos;
            end_Scale_TelePort = 75f;
            end_ROTA_TelePort = transform.rotation;
            toDest = DESTINATION.TO_THE_LAB;

        }
        else
        {
            end_Pos_TelePort = pos;
            end_Scale_TelePort = 75f / UI_Ladder.Instance.Zoom_Scale;
            end_ROTA_TelePort = transform.rotation;
            toDest = DESTINATION.TO_THE_VU;
        }
        tAccum_TelePort = 0;
        vu_UI_Manager.Disable_Colliders();

        StopCoroutine("Tween_Teleport");
        StartCoroutine(Tween_Teleport(true));
    }

    private IEnumerator Tween_Teleport(bool show)
    {
        float dir = 1;

        if (!show)
        {
            dir = -1;
        }

        int i = 0; //Sanity check for infinite loops

        float linProg = tAccum_TelePort / tweenDuration_TelePort;

        while (i < 150 && ((show && linProg < 1) || (!show && linProg > 0)))
        {
            tAccum_TelePort += dir * Time.deltaTime;
            linProg = tAccum_TelePort / tweenDuration_TelePort;
            Mathf.Clamp(tAccum_TelePort, 0, tweenDuration_TelePort);

            normS_TelePort = EaseMethods.SineEaseInOut(tAccum_TelePort, 0, 1, tweenDuration_TelePort);
            Teleport_From_To(normS_TelePort);

            yield return true;
            i++;
        }

        if (show)
        {
            tAccum_TelePort = tweenDuration_TelePort;
            normS_TelePort = 1;
        }
        else
        {
            tAccum_TelePort = 0;
            normS_TelePort = 0;
        }
        Teleport_From_To(normS_TelePort);
        gArgos_Lobby.SetActive(false);

        if(toDest == DESTINATION.TO_THE_LAB)
        {
            hmd_Ctrl_Tracking.Set_Miniature_Mode(false);
        }
        else
        if(toDest == DESTINATION.TO_THE_VU)
        {
            hmd_Ctrl_Tracking.Set_Miniature_Mode(true);
        }

        if (bReDisplay_UI && toDest == DESTINATION.TO_THE_LAB)
        {
            vu_UI_Manager.Present_VU_UI();
        }
        vu_UI_Manager.Enable_Colliders();
        StopCoroutine("Tween_Teleport");
    }

    public void Teleport_From_To(float normS)
    {
        transform.position = Vector3.Lerp(start_Pos_TelePort, end_Pos_TelePort, normS);
        currentScale = Mathf.Lerp(start_Scale_TelePort, end_Scale_TelePort, normS);
        transform.localScale = Vector3.one * currentScale;
        transform.rotation = Quaternion.Slerp(start_ROTA_TelePort, end_ROTA_TelePort, normS);

        HMD_Ctrl_Tracking.Instance.attractors_Relative_Scale = 0.88f * (currentScale / 75) + 0.12f;
        HMD_Ctrl_Tracking.Instance.emit_collect_Relative_Scale = 0.4f * (currentScale / 75) + 0.1f;
        HMD_Ctrl_Tracking.Instance.Scale_Emitter_Collector(UI_Ladder.Instance.scale_Emit_Collect_val);

        if (toDest == DESTINATION.TO_THE_VU && bReDisplay_UI)
        {
            vu_UI_Manager.VU_UI_Tween_From_Teleport(transform.position, normS, currentScale);
        }
   }

    public void Teleport_to_WayPoint(int idx)
    {
        start_Pos_TelePort = transform.position;
        start_Scale_TelePort = transform.localScale.x;
        start_ROTA_TelePort = transform.rotation;

        end_Pos_TelePort = WayPoints.Instance.positions[idx];
        end_Scale_TelePort = 75f;
        end_ROTA_TelePort = Quaternion.Euler(WayPoints.Instance.euler_angles[idx]);
        
        tAccum_TelePort = 0;

        StopCoroutine("Tween_Teleport_Parented");
        StartCoroutine(Tween_Teleport_Parented(true));
    }

    public void Start_In_Lab()
    {
        transform.position = Vector3.zero;
        currentScale = 75f;
        transform.localScale = Vector3.one * currentScale;
        transform.rotation = startRota;
        gArgos_Lobby.SetActive(false);
    }

    public void Start_In_Lobby()
    {
        transform.position = startPos;
        currentScale = 75f; 
        transform.localScale = Vector3.one * currentScale;
        transform.rotation = startRota;
        gArgos_Lobby.SetActive(true);
    }

    public void onTelePort_to_Lobby()
    {
        start_Pos_TelePort = transform.position;
        start_Scale_TelePort = transform.localScale.x;
        start_ROTA_TelePort = transform.rotation;
        vu_UI_Manager.Disable_Colliders();

        end_Pos_TelePort = startPos;
        end_Scale_TelePort = 75f;
        end_ROTA_TelePort = startRota;
        tAccum_TelePort = 0;
        StartCoroutine(Tween_Teleport_From_The_VU(true));
        gArgos_Lobby.SetActive(true); 
    }

    private IEnumerator Tween_Teleport_Parented(bool show)
    {
        float dir = 1;

        if (!show)
        {
            dir = -1;
        }

        int i = 0; //Sanity check for infinite loops

        float linProg = tAccum_TelePort / tweenDuration_TelePort;

        while (i < 150 && ((show && linProg < 1) || (!show && linProg > 0)))
        {
            tAccum_TelePort += dir * Time.deltaTime;
            linProg = tAccum_TelePort / tweenDuration_TelePort;
            Mathf.Clamp(tAccum_TelePort, 0, tweenDuration_TelePort);

            normS_TelePort = EaseMethods.SineEaseInOut(tAccum_TelePort, 0, 1, tweenDuration_TelePort);
            Teleport_From_To(normS_TelePort);

            yield return true;
            i++;
        }

        if (show)
        {
            tAccum_TelePort = tweenDuration_TelePort;
            normS_TelePort = 1;
        }
        else
        {
            tAccum_TelePort = 0;
            normS_TelePort = 0;
        }
        Teleport_From_To(normS_TelePort);
        gArgos_Lobby.SetActive(false);
        vu_UI_Manager.transform.SetParent(HMD_Ctrl_Tracking.Instance.transform);
        WayPoints.Instance.transform.SetParent(HMD_Ctrl_Tracking.Instance.transform);
        StopCoroutine("Tween_Teleport_Parented");
    }

    private IEnumerator Tween_Teleport_To_The_VU(bool show)
    {
        float dir = 1;

        if (!show)
        {
            dir = -1;
        }

        int i = 0; //Sanity check for infinite loops

        float linProg = tAccum_TelePort / tweenDuration_TelePort;

        while (i < 150 && ((show && linProg < 1) || (!show && linProg > 0)))
        {
            tAccum_TelePort += dir * Time.deltaTime;
            linProg = tAccum_TelePort / tweenDuration_TelePort;
            Mathf.Clamp(tAccum_TelePort, 0, tweenDuration_TelePort);

            normS_TelePort = EaseMethods.SineEaseInOut(tAccum_TelePort, 0, 1, tweenDuration_TelePort);
            Teleport_From_To(normS_TelePort);

            yield return true;
            i++;
        }

        if (show)
        {
            tAccum_TelePort = tweenDuration_TelePort;
            normS_TelePort = 1;
        }
        else
        {
            tAccum_TelePort = 0;
            normS_TelePort = 0;
        }
        Teleport_From_To(normS_TelePort);
        vu_UI_Manager.Present_VU_UI();
        gArgos_Lobby.SetActive(false);
        StopCoroutine("Tween_Teleport");
    }

    private IEnumerator Tween_Teleport_From_The_VU(bool show)
    {
        float dir = 1;

        if (!show)
        {
            dir = -1;
        }

        int i = 0; //Sanity check for infinite loops

        float linProg = tAccum_TelePort / tweenDuration_TelePort;

        while (i < 150 && ((show && linProg < 1) || (!show && linProg > 0)))
        {
            tAccum_TelePort += dir * Time.deltaTime;
            linProg = tAccum_TelePort / tweenDuration_TelePort;
            Mathf.Clamp(tAccum_TelePort, 0, tweenDuration_TelePort);

            normS_TelePort = EaseMethods.SineEaseInOut(tAccum_TelePort, 0, 1, tweenDuration_TelePort);
            Teleport_From_To(normS_TelePort);

            yield return true;
            i++;
        }

        if (show)
        {
            tAccum_TelePort = tweenDuration_TelePort;
            normS_TelePort = 1;
        }
        else
        {
            tAccum_TelePort = 0;
            normS_TelePort = 0;
        }
        vu_UI_Manager.Present_VU_UI();
        Teleport_From_To(normS_TelePort);
        StopCoroutine("Tween_Teleport");
    }
}