165 lines
3.2 KiB
C#
Raw Normal View History

2025-05-18 01:04:31 +08:00
// ***********************************************************************
// Assembly : Unity
// Author : Kimch
// Created : 2019-06-28
// Description :
// Last Modified By :
// Last Modified On :
// ***********************************************************************
// <copyright file= "StoryGroup" company="Kunpo"></copyright>
// <summary></summary>
// ***********************************************************************
namespace G
{
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 剧情
/// </summary>
public class StoryGroup
{
public enum GroupState
{
None,
Start,
Running,
Completed,
}
/// <summary>
///
/// </summary>
private ItemStoryGroup _groupItem;
/// <summary>
///
/// </summary>
private readonly List<StoryStage> _selfStages = new List<StoryStage>();
private StoryStage _currStage;
private GroupState _currState;
private int _currStep;
private int _maxStep;
private Callback _callback;
/// <summary>
///
/// </summary>
public int type => _groupItem.type;
/// <summary>
///
/// </summary>
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));
}
}
}
/// <summary>
///
/// </summary>
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;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public bool IsCompleted()
{
return _currState == GroupState.Completed;
}
/// <summary>
///
/// </summary>
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;
}
}
/// <summary>
///
/// </summary>
public void JumpToEnd()
{
_currStage = _selfStages[_selfStages.Count - 1];
_currStep = _currStage.step;
_currStage.Start();
}
/// <summary>
/// 指定步数
/// </summary>
/// <param name="step"></param>
public void JumpToStep(int step)
{
_currStage = _selfStages[step - 1];
_currStep = _currStage.step;
_currStage.Start();
}
}
}