89 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			89 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			C#
		
	
	
	
| using System;
 | |
| using System.Collections;
 | |
| using System.Collections.Generic;
 | |
| using UnityEngine;
 | |
| 
 | |
| public class GuideManager : D_MonoSingleton<GuideManager>
 | |
| {
 | |
|     public int GuideCount = 3;
 | |
|     public bool EnableGuide = true;
 | |
| 
 | |
|     public int CurGuideIndex => mCurGuideIndex;
 | |
| 
 | |
|     private Dictionary<int, Action> mStepDoneDic = new Dictionary<int, Action>();
 | |
| 
 | |
|     private int mCurGuideIndex = -1;
 | |
|     private Vector3 mStartPos;
 | |
| 
 | |
|     private PanelGuide mUIGuide;
 | |
| 
 | |
|     public void StartGuide(int pGuideIndex, Dictionary<int, Action> pStepDoneDic = null, Vector3 pStartPos = default)
 | |
|     {
 | |
|         if (!EnableGuide)
 | |
|             return;
 | |
| 
 | |
|         if (mCurGuideIndex < 0)
 | |
|         {
 | |
|             if (pGuideIndex < GuideCount && !PlayerData.Instance.CheckGuide(pGuideIndex))
 | |
|             {
 | |
|                 if (pStepDoneDic != null)
 | |
|                 {
 | |
|                     mStepDoneDic = pStepDoneDic;
 | |
|                 }
 | |
|                 mCurGuideIndex = pGuideIndex;
 | |
|                 mStartPos = pStartPos;
 | |
| 
 | |
|                 mUIGuide = UIManager.Instance.OpenUI<PanelGuide>();
 | |
|                 mUIGuide.InitGuide(pGuideIndex);
 | |
|                 mUIGuide.DelStepDone = OnGuideStepDone;
 | |
|                 mUIGuide.DelGuideFinish = OnGuideFinished;
 | |
|                 mUIGuide.NextStep(mStartPos);
 | |
|             }
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     public void DoStep(Vector3 pScreenPos = default)
 | |
|     {
 | |
|         if (mCurGuideIndex < 0)
 | |
|             return;
 | |
| 
 | |
|         mUIGuide.NextStep(pScreenPos);
 | |
|     }
 | |
| 
 | |
|     public void FinishGuide(int pGuideIndex)
 | |
|     {
 | |
|         //Debug.Log("Finish guide!!!!!!");
 | |
|         PlayerData.Instance.FinishGuide(pGuideIndex);
 | |
| 
 | |
|         mUIGuide.Close();
 | |
|         mUIGuide = null;
 | |
| 
 | |
|         mCurGuideIndex = -1;
 | |
|         mStepDoneDic.Clear();
 | |
|     }
 | |
| 
 | |
|     public void FinishCurrentStep()
 | |
|     {
 | |
|         if (mUIGuide != null)
 | |
|         {
 | |
|             mUIGuide.FinishCurrentStep();
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     private void OnGuideStepDone(int pIndex)
 | |
|     {
 | |
|         //Debug.Log(string.Format("step {0} done!!!", pIndex));
 | |
| 
 | |
|         if (mStepDoneDic.ContainsKey(pIndex))
 | |
|         {
 | |
|             mStepDoneDic[pIndex]?.Invoke();
 | |
|         }
 | |
| 
 | |
|         TKGSDKManager.Instance.LogEvent(Const.AdsEvent.Guide, Const.AdsKey.GuideStep, string.Format("{0}_{1}", mCurGuideIndex, pIndex));
 | |
|     }
 | |
| 
 | |
|     private void OnGuideFinished()
 | |
|     {
 | |
|         FinishGuide(mCurGuideIndex);
 | |
|     }
 | |
| } |