石头
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 97a19921a1af4dd291a2e5fd307c02df
|
||||
timeCreated: 1733904654
|
||||
+8
-1
@@ -17,7 +17,6 @@ namespace AibisDream.FixSystem
|
||||
public GameObject bodyModulePrefab;
|
||||
public Transform bodyModuleGroup;
|
||||
public OscilloscopeSystem oscilloscopeSystem;
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -119,6 +118,14 @@ namespace AibisDream.FixSystem
|
||||
curBodyModule?.ShowWave();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 插头重新插入初始插孔
|
||||
/// </summary>
|
||||
public void ResetPlug()
|
||||
{
|
||||
CableSystem.ResetPlug();
|
||||
}
|
||||
|
||||
#region 数据加载与保存
|
||||
|
||||
public override string[] GetDataKeyOptions()
|
||||
+9
@@ -64,6 +64,15 @@ namespace AibisDream.FixSystem
|
||||
PlugRef.InitPlug(InitSocket);
|
||||
}
|
||||
|
||||
public void ResetPlug()
|
||||
{
|
||||
// 已经在初始插孔里了,不用动
|
||||
if (curSocket == InitSocket) return;
|
||||
// 不在初始插孔里,就从当前插孔拔出来,插回初始插孔
|
||||
PlugRef.PullUpSocket();
|
||||
PlugRef.InsertSocket(InitSocket);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 寻找最接近的Module
|
||||
/// </summary>
|
||||
+3
-1
@@ -9,6 +9,8 @@ namespace AibisDream.FixSystem
|
||||
{
|
||||
#region 组件索引
|
||||
|
||||
private BodyModuleSystem _bodyModuleSystem;
|
||||
|
||||
private TMP_Text _screenText;
|
||||
private WaveformLine _waveformLine;
|
||||
private ScanLine _scanLine;
|
||||
@@ -114,7 +116,7 @@ namespace AibisDream.FixSystem
|
||||
/// </summary>
|
||||
public void OnScanSuccess()
|
||||
{
|
||||
FixSystemCenter.SystemDic.Get<BodyModuleSystem>().HandleDeepIn();
|
||||
_bodyModuleSystem.HandleDeepIn();
|
||||
_ = CommonUtil.Delay(2000, StopWave);
|
||||
}
|
||||
|
||||
+2
-3
@@ -47,7 +47,7 @@ namespace AibisDream.FixSystem
|
||||
/// 插入某个socket
|
||||
/// </summary>
|
||||
/// <param name="targetSocket">目标socket</param>
|
||||
private void InsertSocket(ISocket targetSocket)
|
||||
public void InsertSocket(ISocket targetSocket)
|
||||
{
|
||||
// 修改插头位置
|
||||
transform.position = targetSocket.GetSocketPos();
|
||||
@@ -71,7 +71,7 @@ namespace AibisDream.FixSystem
|
||||
/// <summary>
|
||||
/// 从某个Socket拔出来
|
||||
/// </summary>
|
||||
private void PullUpSocket()
|
||||
public void PullUpSocket()
|
||||
{
|
||||
// 修改线头位置
|
||||
_cableSystem.CableRef.SetEndPos(_plugRootPos);
|
||||
@@ -82,7 +82,6 @@ namespace AibisDream.FixSystem
|
||||
// 触发事件
|
||||
_cableSystem.BodyModuleSystem.plugOutEvent?.Invoke(_cableSystem.curSocket);
|
||||
|
||||
|
||||
_cableSystem.curBodyModule = null;
|
||||
_cableSystem.curSocket = null;
|
||||
}
|
||||
+5
-2
@@ -9,6 +9,7 @@ namespace AibisDream.FixSystem
|
||||
#region 组件索引
|
||||
|
||||
private LineRenderer _line;
|
||||
private OscilloscopeSystem _oscilloscopeSystem;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -33,6 +34,8 @@ namespace AibisDream.FixSystem
|
||||
|
||||
private void InitComponentRefs()
|
||||
{
|
||||
_oscilloscopeSystem = GetComponentInParent<OscilloscopeSystem>();
|
||||
|
||||
_line = GetComponent<LineRenderer>();
|
||||
_line.enabled = false;
|
||||
_line.positionCount = 2;
|
||||
@@ -41,7 +44,7 @@ namespace AibisDream.FixSystem
|
||||
public IEnumerator ScanForError(float spikeX)
|
||||
{
|
||||
_line.enabled = true;
|
||||
FixSystemCenter.SystemDic.Get<OscilloscopeSystem>().isScanning = true;
|
||||
_oscilloscopeSystem.isScanning = true;
|
||||
// 初始化扫描线
|
||||
InitStartLine();
|
||||
// 扫描线右移
|
||||
@@ -68,7 +71,7 @@ namespace AibisDream.FixSystem
|
||||
yield return null;
|
||||
}
|
||||
|
||||
FixSystemCenter.SystemDic.Get<OscilloscopeSystem>().isScanning = false;
|
||||
_oscilloscopeSystem.isScanning = false;
|
||||
}
|
||||
|
||||
private void InitStartLine()
|
||||
@@ -0,0 +1,44 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
public class BottleSlot : MonoBehaviour
|
||||
{
|
||||
private CoolingMachineViewer _coolingMachine;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
InitComponentRefs();
|
||||
}
|
||||
|
||||
private void InitComponentRefs()
|
||||
{
|
||||
_coolingMachine = GetComponentInParent<CoolingMachineViewer>();
|
||||
}
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D other)
|
||||
{
|
||||
if (_coolingMachine.isLocked) return;
|
||||
|
||||
if (other.gameObject.TryGetComponent<CoolingBottle>(out var bottle))
|
||||
{
|
||||
// 进入时只给吸附标记,松手才吸附
|
||||
bottle.isSnapped = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerExit2D(Collider2D other)
|
||||
{
|
||||
if (_coolingMachine.isLocked) return;
|
||||
|
||||
if (other.gameObject.TryGetComponent<CoolingBottle>(out var bottle))
|
||||
{
|
||||
// 离开时直接触发拔出逻辑,不等松手
|
||||
bottle.isSnapped = false;
|
||||
// 拔出
|
||||
_coolingMachine.MoveOutBottle();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7c928711dc2b0dc4c995288fdb23d1c7
|
||||
guid: bdcb57f53aa757b45a44803a2441d888
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using AibisDream.Framework;
|
||||
using AibisDream.Framework;
|
||||
using DG.Tweening;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -7,41 +6,97 @@ namespace AibisDream
|
||||
{
|
||||
public class CoolingBottle : MonoBehaviour, IMoveable
|
||||
{
|
||||
private GameObject _mask;
|
||||
public CoolingMachineViewer coolingMachine;
|
||||
private Transform _mask;
|
||||
private Rigidbody2D _rb;
|
||||
|
||||
private static readonly Vector3 UpPos = new(0, 1.56f, 0);
|
||||
private static readonly Vector3 UpPos = new(0, 1.86f, 0);
|
||||
private static readonly Vector3 DownPos = Vector3.zero;
|
||||
|
||||
public bool isSnapped;
|
||||
public bool isInMachine;
|
||||
public bool isLocked;
|
||||
|
||||
public bool isEmpty;
|
||||
public bool IsBlock { get; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
InitComponentRefs();
|
||||
}
|
||||
|
||||
private void InitComponentRefs()
|
||||
{
|
||||
_rb = GetComponent<Rigidbody2D>();
|
||||
_mask = transform.Find("Mask");
|
||||
coolingMachine = FindObjectOfType<CoolingMachineViewer>();
|
||||
|
||||
_mask.localPosition = isEmpty ? DownPos : UpPos;
|
||||
}
|
||||
|
||||
public void LiquidDown(float duration)
|
||||
{
|
||||
_mask.transform.DOMove(DownPos, duration).OnComplete(() => isEmpty = true);
|
||||
var targetPos = transform.parent.TransformPoint(DownPos);
|
||||
_mask.transform.DOMove(targetPos, duration).OnComplete(() => isEmpty = true);
|
||||
}
|
||||
|
||||
public void LiquidUp(float duration)
|
||||
{
|
||||
_mask.transform.DOMove(UpPos, duration).OnComplete(() => isEmpty = false);
|
||||
var targetPos = transform.parent.TransformPoint(UpPos);
|
||||
_mask.transform.DOMove(targetPos, duration).OnComplete(() => isEmpty = false);
|
||||
}
|
||||
|
||||
public void StartMove()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Move(Vector2 mousePos)
|
||||
{
|
||||
// 锁定后无法移动
|
||||
if (isLocked) return;
|
||||
|
||||
_rb.MovePosition(mousePos);
|
||||
}
|
||||
|
||||
public void StopMove()
|
||||
{
|
||||
// 松手时若是已吸附,就触发插入逻辑
|
||||
if (isSnapped) coolingMachine.InsertBottle(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 松手后吸附至某个位置
|
||||
/// </summary>
|
||||
/// <param name="snapPos">吸附点位</param>
|
||||
public void Snap(Vector3 snapPos)
|
||||
{
|
||||
// 吸附至指定位置
|
||||
transform.position = snapPos;
|
||||
// 停用重力
|
||||
_rb.gravityScale = 0;
|
||||
// 瓶子进入机器
|
||||
isInMachine = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 离开指定位置就停止吸附
|
||||
/// </summary>
|
||||
public void Unsnap()
|
||||
{
|
||||
// 重新启用重力
|
||||
_rb.gravityScale = 1;
|
||||
// 瓶子不在机器中
|
||||
isInMachine = false;
|
||||
}
|
||||
|
||||
public void Lock()
|
||||
{
|
||||
isLocked = true;
|
||||
}
|
||||
|
||||
public void Unlock()
|
||||
{
|
||||
isLocked = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,30 @@
|
||||
using DG.Tweening;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
public class CoolingMachineSystem : MonoBehaviour, ICoolingMachine
|
||||
public class CoolingMachineViewer : MonoBehaviour, ICoolingMachine
|
||||
{
|
||||
public bool isMachineEmpty;
|
||||
|
||||
public GameObject bottleSlot;
|
||||
[Header("引用")] public GameObject bottleSlot;
|
||||
public CoolingBottle bottle;
|
||||
public GameObject pumpHead;
|
||||
public GameObject lockSwitch;
|
||||
public GameObject pumpButton;
|
||||
|
||||
public LockSlider lockSlider;
|
||||
public Transform pumpHead;
|
||||
|
||||
private SpriteButton _button;
|
||||
|
||||
[Header("参数")] public float pumpDuration = 3f;
|
||||
public float resetDuration = 0.5f;
|
||||
public float pumpHeadUpY;
|
||||
public float pumpHeadDownY;
|
||||
|
||||
#region 状态
|
||||
|
||||
[Header("状态")] public bool isMachineEmpty;
|
||||
public bool isLocked;
|
||||
public bool inLiquidChange;
|
||||
|
||||
#endregion
|
||||
|
||||
#region 对外暴露
|
||||
|
||||
public void LinkRobot()
|
||||
@@ -25,30 +38,35 @@ namespace AibisDream
|
||||
/// </summary>
|
||||
public void PumpCooling()
|
||||
{
|
||||
// 泵头下降
|
||||
|
||||
inLiquidChange = true;
|
||||
// 液面上升
|
||||
|
||||
// 完成后液体满了
|
||||
isMachineEmpty = true;
|
||||
bottle.LiquidUp(pumpDuration);
|
||||
// 泵头下降
|
||||
var sq = GenePumpHeadAnime();
|
||||
sq.OnComplete(() =>
|
||||
{
|
||||
inLiquidChange = false;
|
||||
isMachineEmpty = false;
|
||||
});
|
||||
}
|
||||
|
||||
public void UnlockBottle()
|
||||
{
|
||||
// 卡扣上移
|
||||
|
||||
// 瓶子外旋
|
||||
|
||||
// 机器空置
|
||||
// 动画效果拉杆处理了
|
||||
// 触发锁定逻辑
|
||||
isMachineEmpty = false;
|
||||
isLocked = false;
|
||||
bottle?.Unlock();
|
||||
lockSlider.DisableHook();
|
||||
}
|
||||
|
||||
public void MoveOutBottle()
|
||||
{
|
||||
if (bottle == null) return;
|
||||
// 瓶子置空
|
||||
bottle.transform.parent = null;
|
||||
|
||||
|
||||
// 停止吸附
|
||||
bottle?.Unsnap();
|
||||
}
|
||||
|
||||
public void InsertBottle(CoolingBottle newBottle)
|
||||
@@ -56,25 +74,33 @@ namespace AibisDream
|
||||
// 改变瓶子归属
|
||||
newBottle.transform.parent = bottleSlot.transform;
|
||||
bottle = newBottle;
|
||||
|
||||
// 插入瓶子
|
||||
bottle.Snap(bottleSlot.transform.position);
|
||||
}
|
||||
|
||||
public void LockBottle()
|
||||
{
|
||||
// 插槽回旋
|
||||
|
||||
// 卡扣下降
|
||||
|
||||
// 同步液体状态
|
||||
isMachineEmpty = bottle.isEmpty;
|
||||
|
||||
// TODO 同步泵头状态
|
||||
|
||||
// 动画效果在拉杆的地方就处理了
|
||||
// 触发锁定逻辑
|
||||
isMachineEmpty = !bottle || bottle.isEmpty;
|
||||
isLocked = true;
|
||||
bottle?.Lock();
|
||||
// 如果当前没有瓶子,就打开卡扣碰撞
|
||||
if (!bottle) lockSlider.EnableHook();
|
||||
}
|
||||
|
||||
public void InjectCool()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
inLiquidChange = true;
|
||||
// 泵头下降
|
||||
var sq = GenePumpHeadAnime();
|
||||
sq.OnComplete(() =>
|
||||
{
|
||||
inLiquidChange = false;
|
||||
isMachineEmpty = true;
|
||||
});
|
||||
// 液面上升
|
||||
bottle.LiquidDown(pumpDuration);
|
||||
}
|
||||
|
||||
public void UnlinkRobot()
|
||||
@@ -82,8 +108,44 @@ namespace AibisDream
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public bool CanPump()
|
||||
{
|
||||
if (inLiquidChange)
|
||||
{
|
||||
Debug.Log("泵机正在工作");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isLocked)
|
||||
{
|
||||
Debug.Log("卡扣尚未锁定");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!bottle)
|
||||
{
|
||||
Debug.Log("没有瓶子");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
private Sequence GenePumpHeadAnime()
|
||||
{
|
||||
var sequence = DOTween.Sequence();
|
||||
// 下降动画
|
||||
var pumpDownPos = new Vector3(pumpHead.position.x, pumpHeadDownY + transform.position.y,
|
||||
pumpHead.position.z);
|
||||
sequence.Append(pumpHead.DOMove(pumpDownPos, pumpDuration));
|
||||
// 上升动画
|
||||
var pumpUpPos = new Vector3(pumpHead.position.x, pumpHeadUpY + transform.position.y, pumpHead.position.z);
|
||||
sequence.Append(pumpHead.DOMove(pumpUpPos, resetDuration));
|
||||
|
||||
return sequence;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -100,4 +162,4 @@ namespace AibisDream
|
||||
void InjectCool();
|
||||
void UnlinkRobot();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
using AibisDream.Framework;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
public class LockSlider : MonoBehaviour, IMoveable
|
||||
{
|
||||
private Transform _drawBar;
|
||||
private Transform _hook;
|
||||
private CoolingMachineViewer _coolingMachine;
|
||||
private bool _isLocked;
|
||||
|
||||
private float Value
|
||||
{
|
||||
set
|
||||
{
|
||||
var sliderY = value * (offPos.position.y - onPos.position.y) + onPos.position.y;
|
||||
transform.position = new Vector3(_drawBar.position.x, sliderY, _drawBar.position.z);
|
||||
var hookY = value * (lockOffPos.position.y - lockOnPos.position.y) + lockOnPos.position.y;
|
||||
_hook.position = new Vector3(_hook.position.x, hookY, _hook.position.z);
|
||||
}
|
||||
}
|
||||
|
||||
public Transform onPos;
|
||||
public Transform offPos;
|
||||
|
||||
public Transform lockOnPos;
|
||||
public Transform lockOffPos;
|
||||
|
||||
public bool IsBlock => _coolingMachine.inLiquidChange;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_coolingMachine = GetComponentInParent<CoolingMachineViewer>();
|
||||
_drawBar = transform;
|
||||
_hook = transform.parent.Find("活动卡扣");
|
||||
_isLocked = true;
|
||||
}
|
||||
|
||||
public void StartMove()
|
||||
{
|
||||
}
|
||||
|
||||
public void Move(Vector2 mousePos)
|
||||
{
|
||||
var curY = Mathf.Clamp(mousePos.y, onPos.position.y, offPos.position.y);
|
||||
|
||||
Value = (curY - onPos.position.y) / (offPos.position.y - onPos.position.y);
|
||||
}
|
||||
|
||||
public void StopMove()
|
||||
{
|
||||
var curValue = (_drawBar.position.y - onPos.position.y) / (offPos.position.y - onPos.position.y);
|
||||
// 大于0.8或者小于0.2则切换状态,否则弹回去
|
||||
_isLocked = curValue switch
|
||||
{
|
||||
// 移动停止时尝试吸附
|
||||
>= 0.8f => false,
|
||||
<= 0.2f => true,
|
||||
_ => _isLocked
|
||||
};
|
||||
|
||||
Value = _isLocked ? 0 : 1;
|
||||
// 判定开闭锁
|
||||
if (_isLocked)
|
||||
{
|
||||
_coolingMachine.LockBottle();
|
||||
}
|
||||
else
|
||||
{
|
||||
_coolingMachine.UnlockBottle();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打开卡扣碰撞
|
||||
/// </summary>
|
||||
public void EnableHook()
|
||||
{
|
||||
_hook.GetComponent<Collider2D>().enabled = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关闭卡扣碰撞
|
||||
/// </summary>
|
||||
public void DisableHook()
|
||||
{
|
||||
_hook.GetComponent<Collider2D>().enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3e9b9d16043250e43b350ea79cda5e7a
|
||||
guid: 9f15b93b1e22b11459ca121bedee9ba7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -0,0 +1,47 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
public class PumpButton : MonoBehaviour
|
||||
{
|
||||
private SpriteButton _button;
|
||||
private CoolingMachineViewer _coolingMachine;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_coolingMachine = GetComponentInParent<CoolingMachineViewer>();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_button = new SpriteButton(gameObject);
|
||||
_button.OnButtonDown += OnButtonDown;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
_button.OnButtonDown -= OnButtonDown;
|
||||
_button = null;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
_button.CheckButtonClick();
|
||||
}
|
||||
|
||||
private void OnButtonDown()
|
||||
{
|
||||
if (!_coolingMachine.CanPump()) return;
|
||||
|
||||
if (_coolingMachine.isMachineEmpty)
|
||||
{
|
||||
_coolingMachine.PumpCooling();
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("in");
|
||||
_coolingMachine.InjectCool();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c1098201b6934115ac7c06afa1564dab
|
||||
timeCreated: 1733580710
|
||||
@@ -1,21 +1,57 @@
|
||||
using AibisDream.Framework;
|
||||
using AibisDream.Kit;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AibisDream.FixSystem
|
||||
{
|
||||
public class FixSystemCenter : MonoBehaviour
|
||||
public class FixSystemCenter : Singleton<FixSystemCenter>
|
||||
{
|
||||
public static IOCContainer SystemDic = new();
|
||||
public FixState curState;
|
||||
|
||||
private void Awake()
|
||||
public override void OnSingletonInit()
|
||||
{
|
||||
SystemDic ??= new IOCContainer();
|
||||
InitTransitionDic();
|
||||
|
||||
// TODO 这个回头要改
|
||||
curState = FixState.BodyModule;
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
#region 系统索引
|
||||
|
||||
// 容纳System
|
||||
public static IOCContainer SystemDic = new();
|
||||
|
||||
#endregion
|
||||
|
||||
#region 转场管理
|
||||
|
||||
private static readonly StateDictionary<ITransitionCommand> TransitionDic = new();
|
||||
|
||||
private void InitTransitionDic()
|
||||
{
|
||||
SystemDic = null;
|
||||
TransitionDic.Add(FixState.BodyModule, FixState.Engine, new BodyModuleToEngineCommand());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行转场
|
||||
/// </summary>
|
||||
/// <param name="nextState">需要转换的状态</param>
|
||||
public void TransToNextState(FixState nextState)
|
||||
{
|
||||
// 没存过的先打个日志报错
|
||||
if (!TransitionDic.TryGetValue(curState, nextState, out var command))
|
||||
{
|
||||
Debug.Log($"源为{curState.ToString()}, 目标为{nextState.ToString()}, 转场命令不存在");
|
||||
return;
|
||||
}
|
||||
|
||||
// 存过的执行转场命令
|
||||
StartCoroutine(command.Execute());
|
||||
curState = nextState;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using AibisDream.Framework;
|
||||
using UnityEngine;
|
||||
using UnityEngine;
|
||||
using Yarn.Unity;
|
||||
|
||||
namespace AibisDream.FixSystem
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 51102ff352f0a80499cae251e2267fe4
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,175 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a69c67aba0d24b8994271ee886e11d3d
|
||||
timeCreated: 1733712418
|
||||
@@ -15,8 +15,6 @@ namespace AibisDream.Framework
|
||||
public interface ISystem
|
||||
{
|
||||
void Init();
|
||||
void Enable();
|
||||
void Disable();
|
||||
void Deinit();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
<<<<<<<< HEAD:Assets/Scripts/Framework/LifeCycle.meta
|
||||
guid: e83cc72ae645d204ba5edddce2e36596
|
||||
folderAsset: yes
|
||||
========
|
||||
guid: 39db4a518afdbd74f8c0100de0f68c74
|
||||
>>>>>>>> develop:Assets/Scenes/ScanScopeTest.unity.meta
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,51 +0,0 @@
|
||||
using AibisDream.Kit;
|
||||
using Yarn.Unity;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
public class LifeCycleManager : Singleton<LifeCycleManager>
|
||||
{
|
||||
private ILifeCycle _lifeCycle;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
SceneLoader.Instance.LoadSceneEvent += OnInit;
|
||||
SceneLoader.Instance.UnloadSceneEvent += OnSceneUnload;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
SceneLoader.Instance.LoadSceneEvent -= OnInit;
|
||||
SceneLoader.Instance.UnloadSceneEvent -= OnSceneUnload;
|
||||
}
|
||||
|
||||
public void Register(ILifeCycle lifeCycle)
|
||||
{
|
||||
_lifeCycle = lifeCycle;
|
||||
}
|
||||
|
||||
private void OnInit()
|
||||
{
|
||||
_lifeCycle?.OnInit();
|
||||
}
|
||||
|
||||
[YarnCommand("game_start")]
|
||||
public void OnGameStart()
|
||||
{
|
||||
_lifeCycle?.OnGameStart();
|
||||
}
|
||||
|
||||
[YarnCommand("game_end")]
|
||||
public void OnGameEnd()
|
||||
{
|
||||
_lifeCycle?.OnGameEnd();
|
||||
}
|
||||
|
||||
private void OnSceneUnload()
|
||||
{
|
||||
_lifeCycle.OnSceneUnload();
|
||||
_lifeCycle = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
public interface ILifeCycle
|
||||
{
|
||||
void OnInit();
|
||||
|
||||
void OnGameStart();
|
||||
|
||||
void OnGameEnd();
|
||||
|
||||
void OnSceneUnload();
|
||||
}
|
||||
|
||||
public abstract class AbsLifeCycle : MonoBehaviour, ILifeCycle
|
||||
{
|
||||
private void Start()
|
||||
{
|
||||
LifeCycleManager.Instance.Register(this);
|
||||
}
|
||||
|
||||
public abstract void OnInit();
|
||||
public abstract void OnGameStart();
|
||||
public abstract void OnGameEnd();
|
||||
public abstract void OnSceneUnload();
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,8 @@ namespace AibisDream.Framework
|
||||
{
|
||||
public interface IMoveable
|
||||
{
|
||||
bool IsBlock { get; }
|
||||
|
||||
void StartMove();
|
||||
|
||||
void Move(Vector2 mousePos);
|
||||
|
||||
@@ -41,6 +41,7 @@ namespace AibisDream.Framework
|
||||
{
|
||||
_dragObj = hit.collider.gameObject.GetComponent<IMoveable>();
|
||||
if (_dragObj == null) return;
|
||||
if (_dragObj.IsBlock) return;
|
||||
|
||||
_dragObj.StartMove();
|
||||
_offset = hit.collider.transform.position - GetMouseAsWorldPoint();
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
using AibisDream.Kit;
|
||||
using DG.Tweening;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AibisDream.Framework
|
||||
{
|
||||
public class CameraKit : SingletonBase<CameraKit>
|
||||
{
|
||||
private readonly Camera _mainCamera = Camera.main;
|
||||
|
||||
private Vector3 _initPos;
|
||||
private float _initOrthographicSize;
|
||||
|
||||
private CameraKit() {}
|
||||
|
||||
public override void OnSingletonInit()
|
||||
{
|
||||
// 无需初始化
|
||||
}
|
||||
|
||||
public void ResetCamara()
|
||||
{
|
||||
_mainCamera.transform.position = _initPos;
|
||||
_mainCamera.orthographicSize = _initOrthographicSize;
|
||||
}
|
||||
|
||||
public Tween TransCamera(Vector3 targetPos, float targetOrthographicSize, float duration)
|
||||
{
|
||||
var sq = DOTween.Sequence();
|
||||
// 移动
|
||||
sq.Join(_mainCamera.transform.DOMove(targetPos, duration));
|
||||
// 缩放
|
||||
sq.Join(_mainCamera.DOOrthoSize(targetOrthographicSize, duration));
|
||||
|
||||
return sq;
|
||||
}
|
||||
|
||||
public Tween ReturnInitCamera(float duration)
|
||||
{
|
||||
return TransCamera(_initPos, _initOrthographicSize, duration);
|
||||
}
|
||||
|
||||
public Tween TransCamera(Vector3 targetPos, float duration)
|
||||
{
|
||||
return _mainCamera.transform.DOMove(targetPos, duration);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ab36b5f5522a4b42bf6e1054aa92bdce
|
||||
timeCreated: 1733666233
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using AibisDream.FixSystem;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AibisDream.Framework
|
||||
@@ -24,6 +25,7 @@ namespace AibisDream.Framework
|
||||
_iocContainer ??= new IOCContainer();
|
||||
// 在这里添加相应的工具
|
||||
Register(new MoveableSystem());
|
||||
Register(new TransTest());
|
||||
}
|
||||
|
||||
private void Register<T>(T kit) where T : IMonoKit
|
||||
@@ -41,6 +43,17 @@ namespace AibisDream.Framework
|
||||
private void Update() => OnUpdate?.Invoke();
|
||||
}
|
||||
|
||||
public class TransTest : IMonoKit
|
||||
{
|
||||
public void OnUpdate()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.K))
|
||||
{
|
||||
FixSystemCenter.Instance.TransToNextState(FixState.Engine);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface IMonoKit
|
||||
{
|
||||
void OnUpdate();
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using AibisDream.Framework;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
@@ -13,6 +12,8 @@ namespace AibisDream
|
||||
[SerializeField] private float heightY;
|
||||
|
||||
private Vector3 _offset;
|
||||
|
||||
public bool IsBlock { get; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
|
||||
@@ -4,7 +4,9 @@ using AibisDream.FixSystem;
|
||||
using AibisDream.Framework;
|
||||
using AibisDream.Kit;
|
||||
using AibisDream.Utility;
|
||||
using DG.Tweening;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
@@ -12,16 +14,24 @@ namespace AibisDream
|
||||
{
|
||||
public static string DataPath = Application.streamingAssetsPath + "/LevelData/EngineSystem/";
|
||||
|
||||
private SpriteRenderer _cover;
|
||||
|
||||
[Header("系统配置")] [SerializeField] public EngineConfig config;
|
||||
[Header("系统数据")] [SerializeField] private EngineData engineData;
|
||||
|
||||
[FormerlySerializedAs("盖板移动时间")] [SerializeField]
|
||||
private float coverMoveDuration = 5f;
|
||||
[FormerlySerializedAs("盖板移动距离")] [SerializeField]
|
||||
private float coverMoveDistance = 2.8f;
|
||||
|
||||
private bool IsValid => engineData.isValid.Value;
|
||||
|
||||
|
||||
public event Action<EngineData> UpdateDashboard;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
FixSystemCenter.SystemDic.Register(this);
|
||||
_cover = transform.Find("Cover").GetComponent<SpriteRenderer>();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
@@ -58,13 +68,65 @@ namespace AibisDream
|
||||
// 失效期无法加油门
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新引擎气门变化
|
||||
/// </summary>
|
||||
/// <param name="curLevel">当前气门等级</param>
|
||||
public void UpdateAirLevel(int curLevel)
|
||||
{
|
||||
engineData.UpdateAirLevel(curLevel, config.maxLevel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打开盖板
|
||||
/// </summary>
|
||||
/// <returns>动画序列</returns>
|
||||
public Tween OpenCover()
|
||||
{
|
||||
var sq = DOTween.Sequence();
|
||||
// 盖板上移
|
||||
var moveDis = new Vector3(0, coverMoveDistance, 0);
|
||||
sq.Join(_cover.transform.DOBlendableMoveBy(moveDis, coverMoveDuration));
|
||||
// 盖板淡出
|
||||
sq.Join(_cover.DOFade(0, coverMoveDuration));
|
||||
|
||||
// 为引擎系统解锁
|
||||
sq.OnComplete(Unlock);
|
||||
|
||||
return sq;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关闭盖板
|
||||
/// </summary>
|
||||
/// <returns>动画序列</returns>
|
||||
public Tween CloseCover()
|
||||
{
|
||||
var sq = DOTween.Sequence();
|
||||
sq.Join(_cover.DOFade(1, coverMoveDuration));
|
||||
|
||||
var moveDis = new Vector3(0, -coverMoveDistance, 0);
|
||||
sq.Join(_cover.transform.DOBlendableMoveBy(moveDis, coverMoveDuration));
|
||||
|
||||
// 锁定引擎系统
|
||||
sq.OnComplete(Lock);
|
||||
|
||||
return sq;
|
||||
}
|
||||
|
||||
public void Lock()
|
||||
{
|
||||
// 禁止油门和气门
|
||||
|
||||
}
|
||||
|
||||
public void Unlock()
|
||||
{
|
||||
// 开启油门和气门
|
||||
}
|
||||
|
||||
#region 数据加载与保存
|
||||
|
||||
|
||||
private string[] _keyOptions;
|
||||
|
||||
public override string CurDataKey { get; set; }
|
||||
@@ -81,7 +143,7 @@ namespace AibisDream
|
||||
Debug.Log("配置项名称为空");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!ConfigUtil.Instance.TryLoadConfig<EngineConfig>(DataPath + CurDataKey,
|
||||
out var data))
|
||||
{
|
||||
@@ -94,13 +156,14 @@ namespace AibisDream
|
||||
|
||||
public override void Save()
|
||||
{
|
||||
if (string.IsNullOrEmpty(CurDataKey))
|
||||
if (string.IsNullOrEmpty(CurDataKey))
|
||||
{
|
||||
Debug.Log("名称不为空");
|
||||
return;
|
||||
}
|
||||
|
||||
ConfigUtil.Instance.SaveConfig(config, DataPath + CurDataKey);
|
||||
|
||||
|
||||
if (!_keyOptions.Contains(CurDataKey))
|
||||
{
|
||||
// 重新读取key
|
||||
@@ -176,6 +239,8 @@ namespace AibisDream
|
||||
{
|
||||
isValid.Value = false;
|
||||
}
|
||||
|
||||
inAirRange = curInAirRange;
|
||||
}
|
||||
|
||||
public void UpdateAirLevel(int level, int maxLevel)
|
||||
|
||||
@@ -6,8 +6,8 @@ namespace AibisDream
|
||||
{
|
||||
private Transform _pointer;
|
||||
|
||||
[SerializeField] private float leftPosX;
|
||||
[SerializeField] private float rightPosX;
|
||||
[SerializeField] private float leftRot;
|
||||
[SerializeField] private float rightRot;
|
||||
|
||||
protected override void OnStart()
|
||||
{
|
||||
@@ -16,8 +16,9 @@ namespace AibisDream
|
||||
|
||||
protected override void UpdateDashboard(EngineData data)
|
||||
{
|
||||
var targetPosX = (rightPosX - leftPosX) * data.curSpeed + leftPosX;
|
||||
_pointer.localPosition = new Vector3(targetPosX, _pointer.localPosition.y, _pointer.localPosition.y);
|
||||
var targetRot = (rightRot - leftRot) * data.curSpeed + leftRot;
|
||||
|
||||
_pointer.eulerAngles = new Vector3(0, 0, -targetRot);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
public class StoneLifeCycle : AbsLifeCycle
|
||||
{
|
||||
public override void OnInit()
|
||||
{
|
||||
Debug.Log("场景加载");
|
||||
}
|
||||
|
||||
public override void OnGameStart()
|
||||
{
|
||||
GameObject.Find("Gear System").gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
public override void OnGameEnd()
|
||||
{
|
||||
GameObject.Find("Gear System").gameObject.SetActive(false);
|
||||
GameObject.Find("Engine System").gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public override void OnSceneUnload()
|
||||
{
|
||||
Debug.Log("场景卸载");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9d2cedabb95163448b13ee5c471b832a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -15,6 +15,8 @@ namespace AibisDream
|
||||
private SpriteRenderer _spriteRenderer;
|
||||
|
||||
public Shaft targetShaft;
|
||||
|
||||
public bool IsBlock { get; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
|
||||
@@ -109,6 +109,8 @@ namespace AibisDream
|
||||
{
|
||||
Debug.Log("达成目标");
|
||||
}
|
||||
|
||||
|
||||
|
||||
#region 数据保存与加载
|
||||
|
||||
|
||||
Reference in New Issue
Block a user