// ***********************************************************************
// Assembly : Unity
// Author : Kimch
// Created : 2019-06-28
// Description :
// Last Modified By :
// Last Modified On :
// ***********************************************************************
//
//
// ***********************************************************************
namespace G
{
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
///
/// 剧情
///
public class StoryGroup
{
public enum GroupState
{
None,
Start,
Running,
Completed,
}
///
///
///
private ItemStoryGroup _groupItem;
///
///
///
private readonly List _selfStages = new List();
private StoryStage _currStage;
private GroupState _currState;
private int _currStep;
private int _maxStep;
private Callback _callback;
///
///
///
public int type => _groupItem.type;
///
///
///
public StoryStage currStage
{
get { return _currStage; }
}
public StoryGroup(ItemStoryGroup groupItem)
{
_groupItem = groupItem;
var stages = _groupItem.stages;
if (stages != null && stages.Length > 0)
{
for (int i = 0; i < stages.Length; i++)
{
_selfStages.Add(new StoryStage(this, stages[i], i + 1));
}
}
}
///
///
///
public void Start(Callback callback)
{
_callback = callback;
if (_selfStages.Count > 0)
{
_currStep = 1;
_maxStep = _selfStages.Count + 1;
_currState = GroupState.Start;
_currStage = _selfStages[0];
GlobalNotifier.PostNotification(GlobalDefine.EVENT_STORY_START, _currStage, this.type.ToString());
if (type == 0)
{
UI.StoryWindow.ShowStory(_currStage.action);
}
//else if (type == 1)
//{
// UI.TravelWindow.ShowStory(_currStage.action);
//}
_currStage.Start();
}
}
public bool CanTrigger()
{
return _groupItem.type == 1 || _currState != GroupState.Completed;
}
///
///
///
///
public bool IsCompleted()
{
return _currState == GroupState.Completed;
}
///
///
///
public bool JumpToNext()
{
if (_currStage.nextStep > 0)
{
_currStep = _currStage.nextStep;
}
else
{
_currStep++;
}
if (_currStep < _maxStep)
{
_currStage = _selfStages[_currStep - 1];
_currStage.Start();
return true;
}
else
{
_currState = GroupState.Completed;
GlobalNotifier.PostNotification(GlobalDefine.EVENT_STORY_FINISH, null, this.type.ToString());
_callback?.Invoke();
_callback = null;
return false;
}
}
///
///
///
public void JumpToEnd()
{
_currStage = _selfStages[_selfStages.Count - 1];
_currStep = _currStage.step;
_currStage.Start();
}
///
/// 指定步数
///
///
public void JumpToStep(int step)
{
_currStage = _selfStages[step - 1];
_currStep = _currStage.step;
_currStage.Start();
}
}
}