본문 바로가기
NOTE/SaveSource

[SaveSource] TutorialManager

by DevAthena 2017. 2. 8.


using UnityEngine;
using System.Collections.Generic;
using System.Collections;
using System;
 
public enum TutorialState
{
    // None은 제외 하고 Step(단계) 순서대로 정렬해야함
    None,
    StartTutorial,
    MinimapClose,
    GunGrab,
    GunShoot,
    GunReload,
    GunDrop,
    GatlingGrab,
    GatlingShoot,
    GatlingDrop,
    SpecialGrab,
    SpecialThrow,
    EndTutorial,
}
 
class TutorialManager : MonoSingleTon<TutorialManager>
{
    public class TutorialStep
    {
        private TutorialState m_stepName;
        private bool m_stepClear;
 
        public TutorialStep(TutorialState stepName, bool stepClear)
        {
            m_stepName = stepName;
            m_stepClear = stepClear;
        }
 
        public TutorialState StepName
        {
            get { return m_stepName; }
            set { m_stepName = value; }
        }
 
        public bool StepClear
        {
            get { return m_stepClear; }
            set { m_stepClear = value; }
        }
    }
 
    private TutorialStep[] tutorialStep = new TutorialStep[15];
    private int m_curState = 0;
    private UITutorialMission m_uiTutorialMission;
    private GameObject m_tutorialObject;
    [SerializeField] private Animator anim;
    [SerializeField] private List<string> animStep;
 
    /// <summary>
    /// 상태 순서대로 초기화 해 놓기
    /// </summary>
    private void InitTutorial()
    {
        for(int i = 0; i < tutorialStep.Length; i++)
        {
            tutorialStep[i] = new TutorialStep((TutorialState)i, false);
        }
 
        // SettingTutorialObject에서 무기들의 활성화되어있는 부모
        m_tutorialObject = GameObject.Find("TutorialObject");
        // UI 오픈 && 받아 놓아서 StepClear마다 바꿔 줄 수 있게
        UIManager.Instance.Open("UITutorialControll");
        m_uiTutorialMission = UIManager.Instance.Open("UITutorialMission"as UITutorialMission;
    }
 
    public void TutorialStart()
    {
        InitTutorial();
 
        tutorialStep[m_curState].StepClear = true;
        m_curState++;
        StepClear(TutorialState.StartTutorial);        
    }
 
    /// <summary>
    /// 각 단계가 클리어 됬을 때 마다 호출해주기
    /// </summary>
    /// <param name="stepState">클리어 한 단계</param>
    public void StepClear(TutorialState stepState)
    {
        // 이전 단계가 클리어 되어 있고, 현재 깨야하는 스텝을 깼다고 호출했을 때에만~!
        if (tutorialStep[m_curState - 1].StepClear == true && tutorialStep[m_curState].StepName == stepState)
        {
            tutorialStep[m_curState].StepClear = true;
            Debug.LogError("튜토리얼 " + tutorialStep[m_curState].StepName.ToString() + " 단계 클리어 완료");
            EffectSoundPlayer.Instance.Play("ClearTutorialStep");
            m_curState++;
                        
            // 다음단계의 상태로 유아이와 상태 변경 
            m_uiTutorialMission.SetMissionText(m_curState);
            StepAni(m_curState);
            SettingTutorialObject();
            
            if(tutorialStep[m_curState].StepName == TutorialState.EndTutorial)
            {
                StartCoroutine(WaitGoToLobby());
            }          
        }
    }
 
    private IEnumerator WaitGoToLobby()
    {
        yield return new WaitForSeconds(3f);
        GameManager.Instance.LoadScene("Lobby");
    }
 
    /// <summary>
    /// 각 단계별 애니 재생
    /// </summary>
    /// <param name="step"></param>
    private void StepAni(int step)
    {
        anim.Play(animStep[step], -1, 0f);
    }
 
 
    /// <summary>
    /// 각 단계에 맞는 총기 또는 특수무기 나타나게하기
    /// </summary>
    private void SettingTutorialObject()
    {
        //TO DO : 총을 들었다 놨을 때 부모가 사라져 버려 아직 초기화같은 장치가 없음...
        if (GameManager.Instance.GetSceneType == SceneType.Tutorial)
        {
            if(tutorialStep[m_curState].StepName == TutorialState.GunGrab)
            {
                GameObject.Find("TutorialObject").transform.FindChild("RifleGun").gameObject.SetActive(true);
            }
            else if(tutorialStep[m_curState].StepName == TutorialState.GatlingGrab)
            {
                if(GameObject.Find("RifleGun"!= null)
                    GameObject.Find("RifleGun").SetActive(false);
                GameObject.Find("TutorialObject").transform.FindChild("VisionGames_MinigunHQ").gameObject.SetActive(true);
            }
            else if(tutorialStep[m_curState].StepName == TutorialState.SpecialGrab)
            {
                if (GameObject.Find("VisionGames_MinigunHQ"!= null)
                    GameObject.Find("VisionGames_MinigunHQ").SetActive(false);
                GameObject.Find("TutorialObject").transform.FindChild("Special1").gameObject.SetActive(true);
            }
        }        
    }
}
 
cs


'NOTE > SaveSource' 카테고리의 다른 글

[Save Source] UIResult  (0) 2017.01.26
[SaveSource] StageRankManager  (0) 2017.01.20
[SaveSource] CameraOrbit  (0) 2017.01.12
[SaveSource] WaveMoveTrigger  (0) 2017.01.12
[SaveSource] SpeicalWeapon  (0) 2017.01.12