176 lines
5.1 KiB
C#
176 lines
5.1 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using AibisDream.Framework;
|
|
using DG.Tweening;
|
|
using UnityEngine;
|
|
|
|
namespace AibisDream.FixSystem
|
|
{
|
|
public enum FixState
|
|
{
|
|
Clinic,
|
|
CoolingMachine,
|
|
BodyModule,
|
|
Memory,
|
|
VisualSense,
|
|
Engine,
|
|
Gear
|
|
}
|
|
|
|
public interface ITransitionCommand
|
|
{
|
|
IEnumerator Execute();
|
|
}
|
|
|
|
public struct BodyModuleToEngineCommand : ITransitionCommand
|
|
{
|
|
// 引擎相机设置
|
|
private static readonly Vector3 CameraPos = new(-2.5f, 2.13f, -10);
|
|
private const float OrthographicSize = 2.5f;
|
|
private const float Duration = 2f;
|
|
|
|
public IEnumerator Execute()
|
|
{
|
|
var bodyModuleSystem = FixSystemCenter.SystemDic.Get<BodyModuleSystem>();
|
|
var engineSystem = FixSystemCenter.SystemDic.Get<EngineSystem>();
|
|
|
|
// 插头回到初始插孔
|
|
bodyModuleSystem.ResetPlug();
|
|
// 相机聚焦到目标位
|
|
var cameraSq = CameraKit.Instance.TransCamera(CameraPos, OrthographicSize, Duration);
|
|
while (cameraSq.active && !cameraSq.IsComplete())
|
|
{
|
|
yield return null;
|
|
}
|
|
|
|
// 打开引擎盖子
|
|
var coverSq = engineSystem.OpenCover();
|
|
while (coverSq.active && !coverSq.IsComplete())
|
|
{
|
|
yield return null;
|
|
}
|
|
}
|
|
}
|
|
|
|
public struct EngineToBodyModuleCommand : ITransitionCommand
|
|
{
|
|
private const float Duration = 2f;
|
|
|
|
public IEnumerator Execute()
|
|
{
|
|
var engineSystem = FixSystemCenter.SystemDic.Get<EngineSystem>();
|
|
|
|
// 关闭引擎盖
|
|
var coverSq = engineSystem.CloseCover();
|
|
while (coverSq.active && !coverSq.IsComplete())
|
|
{
|
|
yield return null;
|
|
}
|
|
|
|
// 相机还原
|
|
var cameraSq = CameraKit.Instance.ReturnInitCamera(Duration);
|
|
while (cameraSq.active && !cameraSq.IsComplete())
|
|
{
|
|
yield return null;
|
|
}
|
|
}
|
|
}
|
|
|
|
public struct EngineToGearCommand : ITransitionCommand
|
|
{
|
|
private const float Duration = 2f;
|
|
private static readonly Vector3 CameraPos = new(-2.5f, 2.13f, -10);
|
|
|
|
public IEnumerator Execute()
|
|
{
|
|
var engineSystem = FixSystemCenter.SystemDic.Get<EngineSystem>();
|
|
var gearSystem = FixSystemCenter.SystemDic.Get<GearSystem>();
|
|
// 关闭一下引擎盖
|
|
var coverSq = engineSystem.CloseCover();
|
|
while (coverSq.active && !coverSq.IsComplete())
|
|
{
|
|
yield return null;
|
|
}
|
|
|
|
// 只需要移动一下相机就好了
|
|
var tween = CameraKit.Instance.TransCamera(CameraPos, Duration);
|
|
while (tween.active && !tween.IsComplete())
|
|
{
|
|
yield return null;
|
|
}
|
|
|
|
// 然后可以开启引擎盖
|
|
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 以两个Key为索引的Dic
|
|
/// </summary>
|
|
/// <typeparam name="T">Value类型</typeparam>
|
|
public class StateDictionary<T>
|
|
{
|
|
private readonly Dictionary<StateTransKey, T> _stateDic = new();
|
|
|
|
public T Get(FixState source, FixState target)
|
|
{
|
|
var key = new StateTransKey(source, target);
|
|
return _stateDic[key];
|
|
}
|
|
|
|
public void Add(FixState source, FixState target, T value)
|
|
{
|
|
var key = new StateTransKey(source, target);
|
|
_stateDic[key] = value;
|
|
}
|
|
|
|
public void Clear()
|
|
{
|
|
_stateDic.Clear();
|
|
}
|
|
|
|
public bool ContainsKey(FixState source, FixState target)
|
|
{
|
|
var key = new StateTransKey(source, target);
|
|
return _stateDic.ContainsKey(key);
|
|
}
|
|
|
|
public bool TryGetValue(FixState source, FixState target, out T value)
|
|
{
|
|
var key = new StateTransKey(source, target);
|
|
return _stateDic.TryGetValue(key, out value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 用于实现两个Key的Dictionary
|
|
/// </summary>
|
|
private class StateTransKey
|
|
{
|
|
private readonly FixState _sourceState;
|
|
private readonly FixState _targetState;
|
|
|
|
public StateTransKey(FixState sourceState, FixState targetState)
|
|
{
|
|
_sourceState = sourceState;
|
|
_targetState = targetState;
|
|
}
|
|
|
|
public override bool Equals(object obj)
|
|
{
|
|
// 类型不同肯定不相等
|
|
if (obj is not StateTransKey other) return false;
|
|
// 判断两个key相等
|
|
return _sourceState == other._sourceState && _targetState == other._targetState;
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
return HashCode.Combine(_sourceState, _targetState);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|