//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Monday, November 27, 2017
|
//--------------------------------------------------------
|
using UnityEngine;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine.UI;
|
|
namespace vnxbqy.UI
|
{
|
|
public class FunctionalGuideTrigger : MonoBehaviour
|
{
|
[SerializeField] int[] guides;
|
|
RectTransform container;
|
Dictionary<int, FunctionalGuideBehaviour> behaviours = new Dictionary<int, FunctionalGuideBehaviour>();
|
|
TreasureModel treasureModel { get { return ModelCenter.Instance.GetModel<TreasureModel>(); } }
|
AchievementModel achievementModel { get { return ModelCenter.Instance.GetModel<AchievementModel>(); } }
|
TaskModel taskModel { get { return ModelCenter.Instance.GetModel<TaskModel>(); } }
|
|
Window m_Parent;
|
Window parent { get { return m_Parent ?? (m_Parent = this.transform.GetComponentInParent<Window>()); } }
|
|
private void Awake()
|
{
|
WindowCenter.Instance.windowAfterOpenEvent += OnWindowOpen;
|
WindowCenter.Instance.windowBeforeCloseEvent += OnWindowPreClose;
|
|
var instance = new GameObject("FunctionalGuideContainer");
|
container = instance.AddMissingComponent<RectTransform>();
|
container.MatchWhith(parent.transform as RectTransform);
|
}
|
|
private void OnDestroy()
|
{
|
WindowCenter.Instance.windowAfterOpenEvent -= OnWindowOpen;
|
WindowCenter.Instance.windowBeforeCloseEvent -= OnWindowPreClose;
|
}
|
|
private void OnWindowOpen(Window _window)
|
{
|
if (parent != _window)
|
{
|
return;
|
}
|
|
container.SetActive(true);
|
CheckGuide();
|
|
var underwayGuides = FunctionalGuideCenter.Instance.GetUnderwayGuides();
|
for (int i = 0; i < underwayGuides.Count; i++)
|
{
|
var guideId = underwayGuides[i];
|
if (GuideBelongtoThisTrigger(guideId))
|
{
|
BeginFunctionalGuide(guideId);
|
}
|
}
|
|
FuncOpen.Instance.OnFuncStateChangeEvent += OnFunctionOpen;
|
PlayerDatas.Instance.playerDataRefreshEvent += OnLevelChange;
|
TaskModel.Event_MainlineTask += OnMainLineTaskUpdate;
|
TaskModel.CardLevelChange += OnMainLineTaskLimitStateChange;
|
FunctionUnlockFlyObject.functionUnLockShowEndEvent += OnFunctionUnLockShowEnd;
|
|
FunctionalGuideCenter.Instance.beginGuideEvent += BeginFunctionalGuide;
|
FunctionalGuideCenter.Instance.removeGuideEvent += OnGuideRemove;
|
|
taskModel.taskDescriptionRefresh += OnMainLineTaskDescriptionIndexUpdate;
|
treasureModel.treasureCollectProgressRefresh += OnTreasureCollectingStateChange;
|
treasureModel.treasureStageUpEvent += OnTreasureStageChange;
|
achievementModel.achievementAwardableEvent += OnAchievementAwardAble;
|
}
|
|
private void OnWindowPreClose(Window _window)
|
{
|
if (parent != _window)
|
{
|
return;
|
}
|
|
foreach (var behaviour in behaviours.Values)
|
{
|
if (behaviour != null)
|
{
|
FunctionalGuideBehaviourPool.Recycle(behaviour.gameObject);
|
}
|
}
|
|
behaviours.Clear();
|
container.SetActive(false);
|
FuncOpen.Instance.OnFuncStateChangeEvent -= OnFunctionOpen;
|
PlayerDatas.Instance.playerDataRefreshEvent -= OnLevelChange;
|
TaskModel.Event_MainlineTask -= OnMainLineTaskUpdate;
|
TaskModel.CardLevelChange -= OnMainLineTaskLimitStateChange;
|
FunctionUnlockFlyObject.functionUnLockShowEndEvent -= OnFunctionUnLockShowEnd;
|
|
FunctionalGuideCenter.Instance.beginGuideEvent -= BeginFunctionalGuide;
|
FunctionalGuideCenter.Instance.removeGuideEvent -= OnGuideRemove;
|
|
taskModel.taskDescriptionRefresh -= OnMainLineTaskDescriptionIndexUpdate;
|
treasureModel.treasureCollectProgressRefresh -= OnTreasureCollectingStateChange;
|
treasureModel.treasureStageUpEvent -= OnTreasureStageChange;
|
achievementModel.achievementAwardableEvent -= OnAchievementAwardAble;
|
}
|
|
private void OnFunctionOpen(int _functionId)
|
{
|
CheckGuide();
|
}
|
|
private void OnLevelChange(PlayerDataType refreshType)
|
{
|
switch (refreshType)
|
{
|
case PlayerDataType.LV:
|
CheckGuide();
|
break;
|
}
|
}
|
|
private void OnMainLineTaskUpdate(int _taskId, int _state)
|
{
|
CheckGuide();
|
}
|
|
private void OnMainLineTaskDescriptionIndexUpdate(int _taskId)
|
{
|
CheckGuide();
|
}
|
|
private void OnMainLineTaskLimitStateChange(int _taskId)
|
{
|
CheckGuide();
|
}
|
|
private void OnFunctionUnLockShowEnd(FunctionUnlockType _type)
|
{
|
CheckGuide();
|
}
|
|
private void OnTreasureCollectingStateChange(int _treasureId)
|
{
|
CheckGuide();
|
}
|
|
private void OnTreasureStageChange(int _treasureId)
|
{
|
CheckGuide();
|
}
|
|
private void OnAchievementAwardAble(int _achievementId)
|
{
|
CheckGuide();
|
}
|
|
private void CheckGuide()
|
{
|
FunctionalGuideCenter.Instance.CheckGuides(guides);
|
}
|
|
private void OnGuideRemove(int _guide)
|
{
|
if (behaviours.ContainsKey(_guide))
|
{
|
FunctionalGuideBehaviourPool.Recycle(behaviours[_guide].gameObject);
|
behaviours.Remove(_guide);
|
}
|
}
|
|
private void BeginFunctionalGuide(int _guide)
|
{
|
if (!GuideBelongtoThisTrigger(_guide))
|
{
|
return;
|
}
|
|
var behaviour = FunctionalGuideBehaviourPool.Require();
|
var behaviourRectTransform = (RectTransform)behaviour.transform;
|
behaviourRectTransform.MatchWhith(container);
|
behaviour.SetActive(true);
|
behaviour.BeginGuide(_guide);
|
|
behaviours[_guide] = behaviour;
|
}
|
|
private bool GuideBelongtoThisTrigger(int _guide)
|
{
|
for (int i = 0; i < guides.Length; i++)
|
{
|
if (guides[i] == _guide)
|
{
|
return true;
|
}
|
}
|
|
return false;
|
}
|
|
|
}
|
|
}
|
|
|
|