da

da
mail@pastecode.io avatar
unknown
csharp
3 years ago
6.6 kB
5
Indexable
Never
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Tabtale.TTPlugins;

public class GameManagers : MonoBehaviour
{
    public List<Stage> stageAll;
    [HideInInspector] public int CurrentID;
    [HideInInspector] public GameObject CameraObje;
    [HideInInspector] public GameObject KnifeObje, Stick, AreaCut, PencilPivot, WoodShapeKeySkin,WoodShapeKey, CutLines,HandPivot;
    public List<PencilInList> listPencilIn;
    public GameObject UI_SWERVEANIM, UI_SLOTBARSPRAY;
    public GameObject Spray_Obje;
    public GameObject fakeObjePencil;
    private void Awake()
    {
        TTPCore.Setup();
    }

    private void Start()
    {
        FindAllObject();
        StartCoroutine(callNextStage(1.5f));
    }

    public void FindAllObject()
    {
        CameraObje = FindObject("Main Camera", true);
        KnifeObje = FindObject("Knife", true);
        Stick = FindObject("Stick", true);
        AreaCut = FindObject("AreaCut", false);
        UI_SLOTBARSPRAY = FindObject("SlotBarUISpray", false);
        PencilPivot = FindObject("PencilPivot", true);
        WoodShapeKeySkin = FindObject("WoodShapeKeySkin", true);
        WoodShapeKey = FindObject("WoodShapeKey", true);
        CutLines = FindObject("CutLines", false);
        HandPivot = FindObject("StickOld", true);
        UI_SWERVEANIM = FindObject("Swerve", false);
        Spray_Obje = FindObject("SprayCan (Red)", false);
    }

    public int CountHealt;
   
    public void ComplateCounter()
    {
        CountHealt++;
        if (CountHealt >= 15)
        {
            StartCoroutine(callNextStage(1f));
        }
    }

    public GameObject FindObject(string ObjectName, bool Status)
    {
        GameObject findObje = GameObject.Find(ObjectName);
        findObje.SetActive(Status);
        return findObje;
    }

    public GameObject sprayGreen;
    public GameObject NowChose, OldChose;
    public GameObject redText, greenText;
    public void ChooseGreen()
    {
        sprayGreen.SetActive(true);
        sprayGreen.transform.position = Spray_Obje.transform.position;
        sprayGreen.transform.rotation = Spray_Obje.transform.rotation;
        Spray_Obje.SetActive(false);
        NowChose.SetActive(true);
        OldChose.SetActive(false);
    }

    public float GetSliderValue()
    {
        
        return Mathf.Clamp(
            ( -0.266f - Stick.transform.Find("aa").transform.position.x).Remap(
                ( -0.266f - (-0.45f)),
                0, 
                0, 100),
            0,
            100);
    }

    
    public void NextStage()
    {
        switch (stageAll[CurrentID].StageNameCol)
        {
            case StageName.FirstZoom:
                LeanTween.move(CameraObje, new Vector3(-0.2438994f,6.807f,1.67f), 1);
                LeanTween.rotate(CameraObje, new Vector3(58.962f,180f,0f), 1).setOnComplete(() =>
                {
                    StartCoroutine(callNextStage(1.2f));

                });
                break;
                case StageName.TwoZoomLooKPencil:
                    LeanTween.move(CameraObje, new Vector3(-0.2438994f,5.181f,0.52f), 1);
                    LeanTween.rotate(CameraObje, new Vector3(90f,180f,0f), 1).setOnComplete(() =>
                    {
                        StartCoroutine(callNextStage(0.25f));
                    });
                    break;;
                    
            case StageName.ZoomAfterGetKnife:
                LeanTween.moveLocal(Stick, new Vector3(-0.2594472f, 4.623f, 1.686023f), 0.5f);
                LeanTween.rotateLocal(Stick, new Vector3(0,180,-90), 0.5f).setOnComplete(() =>
                {
                    AreaCut.SetActive(true);
                    StartCoroutine(DeleteMolp());
                    PencilPivot.GetComponent<Rotater>().enabled = true;
                });
                UI_SWERVEANIM.SetActive(true);
                break; 
            case StageName.FinishBlendGoText:
                PencilPivot.GetComponent<Rotater>().speed = 0;
                fakeObjePencil.SetActive(true);
                PencilPivot.transform.Find("Pencil").gameObject.SetActive(false);
                fakeObjePencil.GetComponent<BrokePencilCS>().StartBroker();
                //HandPivot.SetActive(true);
                break;
            case StageName.PaintText:
                Stick.SetActive(false);
                LeanTween.moveX(HandPivot, -4.7f, 0.25f).setOnComplete(() =>
                {
                    
                    HandPivot.SetActive(false);

                });
                UI_SWERVEANIM.SetActive(false);
                Spray_Obje.SetActive(true);
                UI_SLOTBARSPRAY.SetActive(true);
                LeanTween.move(Spray_Obje, new Vector3(-0.265f, 6.513f, 0.643f), 1f);
                break;
            case StageName.End:
                UI_SWERVEANIM.SetActive(false);
                Spray_Obje.SetActive(false);
                sprayGreen.SetActive(false);
                UI_SLOTBARSPRAY.SetActive(false);
                LeanTween.move(CameraObje, new Vector3(-0.2445171f, 6.521f, 3.831f), 1f);
                LeanTween.rotate(CameraObje, new Vector3(0,180,0), 1f); 
                
                LeanTween.move(PencilPivot, new Vector3(-0.2445171f, 6.521f, 0.4969f), 1f);
                LeanTween.rotate(PencilPivot, new Vector3(0,0,90), 1f);
                break;
        }

        CurrentID++;
    }

    IEnumerator DeleteMolp()
    {
        yield return new WaitForSeconds(5f);
        WoodShapeKeySkin.SetActive(false);
    }
    IEnumerator callNextStage(float time)
    {
        yield return new WaitForSeconds(time);
        NextStage();
    }

    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            fallObje();
        } 
        if (Input.GetKeyDown(KeyCode.A))
        {
            redText.SetActive(false);
            greenText.SetActive(true);
        }
        
    }

    [HideInInspector] public int FallID;
    public void fallObje()
    {
        
        listPencilIn[FallID].FallObje.AddComponent<Rigidbody>();
        Destroy(listPencilIn[FallID].LineObje);
        FallID++;
        if (FallID == 8)
        {
            NextStage();
        }
    }
}
[System.Serializable]
public class PencilInList
{
    public GameObject FallObje;
    public GameObject LineObje;
}