石头Day2
This commit is contained in:
@@ -11,8 +11,6 @@ namespace AibisDream
|
||||
{
|
||||
public class DialogController : Singleton<DialogController>
|
||||
{
|
||||
private const string BookManager = "BookManager";
|
||||
|
||||
private DialogueRunner dialogueRunner;
|
||||
private VariableStorageBehaviour _variableStorage;
|
||||
|
||||
@@ -61,11 +59,6 @@ namespace AibisDream
|
||||
dialogueRunner = GetComponentInChildren<DialogueRunner>();
|
||||
_variableStorage = GetComponentInChildren<InMemoryVariableStorage>();
|
||||
|
||||
// 开关书交互
|
||||
BookManager bookManager = GameObject.Find(BookManager).gameObject.GetComponent<BookManager>();
|
||||
bookManager.OnBookClosed += () => { IsBlock = false; };
|
||||
bookManager.OnBookOpen += () => { IsBlock = true; };
|
||||
|
||||
dialogueRunner.onDialogueStart.AddListener(() =>
|
||||
{
|
||||
OnDialogueStart?.Invoke();
|
||||
|
||||
@@ -30,8 +30,6 @@ namespace AibisDream.FixSystem
|
||||
|
||||
private void InitTransitionDic()
|
||||
{
|
||||
|
||||
|
||||
TransitionDic.Add(FixState.Clinic, FixState.BodyModule, new ClinicToBodyModuleCommand());
|
||||
TransitionDic.Add(FixState.BodyModule, FixState.Clinic, new BodyModuleToClinicCommand());
|
||||
TransitionDic.Add(FixState.BodyModule, FixState.Engine, new BodyModuleToEngineCommand());
|
||||
@@ -48,6 +46,8 @@ namespace AibisDream.FixSystem
|
||||
TransitionDic.Add(FixState.CoolingMachine, FixState.Clinic, new CoolingToClinicCommand());
|
||||
TransitionDic.Add(FixState.BodyModule, FixState.Gear, new BodyModuleToGearCommand());
|
||||
TransitionDic.Add(FixState.Gear, FixState.BodyModule, new GearToBodyModuleCommand());
|
||||
TransitionDic.Add(FixState.Clinic, FixState.Gear, new ClinicToGearCommand());
|
||||
TransitionDic.Add(FixState.Gear, FixState.Clinic, new GearToClinicCommand());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -5,7 +5,6 @@ using UnityEngine;
|
||||
|
||||
namespace AibisDream.FixSystem
|
||||
{
|
||||
|
||||
public struct GearToBodyModuleCommand : ITransitionCommand
|
||||
{
|
||||
private const float Duration = 2f;
|
||||
@@ -15,6 +14,7 @@ namespace AibisDream.FixSystem
|
||||
var gearSystem = FixSystemCenter.SystemDic.Get<GearSystem>();
|
||||
|
||||
// 关盖子
|
||||
yield return gearSystem.CloseGearPanel();
|
||||
yield return gearSystem.CloseCover();
|
||||
// 相机返回
|
||||
yield return CameraKit.Instance.ReturnInitCamera(Duration).WaitForCompletion();
|
||||
@@ -51,6 +51,7 @@ namespace AibisDream.FixSystem
|
||||
|
||||
// 打开引擎盖子
|
||||
yield return gearSystem.OpenCover();
|
||||
yield return gearSystem.OpenGearPanel();
|
||||
}
|
||||
|
||||
public void SetArgs(string arg)
|
||||
@@ -58,4 +59,32 @@ namespace AibisDream.FixSystem
|
||||
_configKey = arg.Trim();
|
||||
}
|
||||
}
|
||||
|
||||
public struct GearToClinicCommand : ITransitionCommand
|
||||
{
|
||||
private const float FadeDuration = 0.5f;
|
||||
|
||||
public IEnumerator Execute()
|
||||
{
|
||||
var clinicSystem = FixSystemCenter.SystemDic.Get<ClinicSystem>();
|
||||
var gearSystem = FixSystemCenter.SystemDic.Get<GearSystem>();
|
||||
|
||||
// 盖上盖子
|
||||
yield return gearSystem.CloseGearPanel();
|
||||
yield return gearSystem.CloseCover();
|
||||
// 黑屏
|
||||
yield return MainUIController.Instance.FadeInSync(FadeDuration);
|
||||
// 相机归位
|
||||
CameraKit.Instance.ResetCamara();
|
||||
// 打开诊所
|
||||
clinicSystem.gameObject.SetActive(true);
|
||||
// 黑屏淡出
|
||||
yield return MainUIController.Instance.FadeOutSync(FadeDuration);
|
||||
}
|
||||
|
||||
public void SetArgs(string arg)
|
||||
{
|
||||
// 没有参数
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -51,13 +51,13 @@ namespace AibisDream.FixSystem
|
||||
var clinicSystem = FixSystemCenter.SystemDic.Get<ClinicSystem>();
|
||||
var engineSystem = FixSystemCenter.SystemDic.Get<EngineSystem>();
|
||||
|
||||
// // 黑屏
|
||||
// 黑屏
|
||||
yield return MainUIController.Instance.FadeInSync(FadeDuration);
|
||||
// 隐藏诊所
|
||||
clinicSystem.gameObject.SetActive(false);
|
||||
// 激活插线系统
|
||||
bodyModuleSystem.gameObject.SetActive(true);
|
||||
// // 黑屏淡出
|
||||
// 黑屏淡出
|
||||
yield return MainUIController.Instance.FadeOutSync(FadeDuration);
|
||||
// 移动相机
|
||||
yield return CameraKit.Instance.TransCameraAsync(CameraPos, OrthographicSize, Duration);
|
||||
@@ -117,4 +117,48 @@ namespace AibisDream.FixSystem
|
||||
// 没有需要设置的
|
||||
}
|
||||
}
|
||||
|
||||
public struct ClinicToGearCommand : ITransitionCommand
|
||||
{
|
||||
private const float FadeDuration = 0.5f;
|
||||
|
||||
// 引擎相机设置
|
||||
private static readonly Vector3 CameraPos = new(-1.09f, -0.07f, -10);
|
||||
private const float OrthographicSize = 1.6f;
|
||||
private const float Duration = 2f;
|
||||
|
||||
private string _configName;
|
||||
|
||||
public IEnumerator Execute()
|
||||
{
|
||||
var bodyModuleSystem = FixSystemCenter.SystemDic.Get<BodyModuleSystem>();
|
||||
var clinicSystem = FixSystemCenter.SystemDic.Get<ClinicSystem>();
|
||||
var gearSystem = FixSystemCenter.SystemDic.Get<GearSystem>();
|
||||
|
||||
// 黑屏
|
||||
// yield return MainUIController.Instance.FadeInSync(FadeDuration);
|
||||
// 隐藏诊所
|
||||
clinicSystem.gameObject.SetActive(false);
|
||||
// 激活插线系统
|
||||
bodyModuleSystem.gameObject.SetActive(true);
|
||||
// 黑屏淡出
|
||||
// yield return MainUIController.Instance.FadeOutSync(FadeDuration);
|
||||
// 移动相机
|
||||
yield return CameraKit.Instance.TransCameraAsync(CameraPos, OrthographicSize, Duration);
|
||||
// 开启引擎玩法
|
||||
if (!string.IsNullOrEmpty(_configName))
|
||||
{
|
||||
gearSystem.CurDataKey = _configName;
|
||||
gearSystem.Load();
|
||||
}
|
||||
|
||||
yield return gearSystem.OpenCover();
|
||||
yield return gearSystem.OpenGearPanel();
|
||||
}
|
||||
|
||||
public void SetArgs(string arg)
|
||||
{
|
||||
_configName = arg.Trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -49,8 +49,7 @@ namespace AibisDream.Framework
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.K))
|
||||
{
|
||||
FixSystemCenter.Instance.curState = FixState.BodyModule;
|
||||
MonoCenter.Mono.StartCoroutine(FixSystemYarnCommand.SwitchFixSystemTo("Gear", "stone_day2_1.json"));
|
||||
MonoCenter.Mono.StartCoroutine(FixSystemYarnCommand.SwitchFixSystemTo("Gear"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,10 +33,9 @@ namespace AibisDream
|
||||
{
|
||||
FixSystemCenter.SystemDic.Register(this);
|
||||
_cover = transform.Find("Cover").GetComponent<SpriteRenderer>();
|
||||
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
private void Start()
|
||||
{
|
||||
engineData = new EngineData(config.invalidTime);
|
||||
DialogController.Instance?.SetVariable("$curAirLevel", 2);
|
||||
@@ -181,7 +180,7 @@ namespace AibisDream
|
||||
|
||||
config = data;
|
||||
// 重置Data
|
||||
OnEnable();
|
||||
Start();
|
||||
}
|
||||
|
||||
public override void Save()
|
||||
@@ -277,8 +276,8 @@ namespace AibisDream
|
||||
if (inAirRange && !curInAirRange && !isSuccess)
|
||||
{
|
||||
// 出界的话
|
||||
if (curAir > curAirMax) DialogController.Instance.StartDialogNode("引擎过速");
|
||||
if (curAir < curAirMin) DialogController.Instance.StartDialogNode("引擎掉速");
|
||||
if (curAir > curAirMax) DialogController.Instance?.StartDialogNode("引擎过速");
|
||||
if (curAir < curAirMin) DialogController.Instance?.StartDialogNode("引擎掉速");
|
||||
|
||||
isValid.Value = false;
|
||||
}
|
||||
|
||||
@@ -7,20 +7,26 @@ namespace AibisDream
|
||||
{
|
||||
public class Gear : MonoBehaviour, IMoveable
|
||||
{
|
||||
private const int ShakeAngle = 15;
|
||||
|
||||
public float radius;
|
||||
public Sprite gearSprite;
|
||||
public bool isBroken;
|
||||
public bool isDisc;
|
||||
|
||||
public float speed;
|
||||
private Tweener _rotationTweener;
|
||||
|
||||
#region 引用
|
||||
|
||||
|
||||
private GearSystem _gearSystem;
|
||||
private CircleCollider2D _circleCollider;
|
||||
private SpriteRenderer _spriteRenderer;
|
||||
|
||||
#endregion;
|
||||
#endregion
|
||||
|
||||
public Shaft targetShaft;
|
||||
|
||||
|
||||
public bool IsBlock { get; }
|
||||
|
||||
private void Awake()
|
||||
@@ -39,7 +45,7 @@ namespace AibisDream
|
||||
/// <summary>
|
||||
/// 设置齿轮信息
|
||||
/// </summary>
|
||||
public void InitGearModel()
|
||||
private void InitGearModel()
|
||||
{
|
||||
// 给齿轮赋值
|
||||
_spriteRenderer.sprite = gearSprite;
|
||||
@@ -48,6 +54,39 @@ namespace AibisDream
|
||||
_spriteRenderer.size = new Vector2(radius * 2, radius * 2);
|
||||
}
|
||||
|
||||
public void UpdateRotation(float newSpeed, float speedScale)
|
||||
{
|
||||
// 初始化速度
|
||||
speed = Mathf.Abs(newSpeed);
|
||||
var target = newSpeed >= 0 ? new Vector3(0, 0, 360) : new Vector3(0, 0, -360);
|
||||
|
||||
_rotationTweener?.Kill();
|
||||
// 打开动画
|
||||
if (isBroken)
|
||||
{
|
||||
_rotationTweener = transform.DORotate(new Vector3(0, 0, ShakeAngle), ShakeAngle / speed / 360,
|
||||
RotateMode.LocalAxisAdd)
|
||||
.SetEase(Ease.Linear)
|
||||
.SetLoops(-1, LoopType.Yoyo)
|
||||
.SetDelay(0.1f);
|
||||
}
|
||||
else
|
||||
{
|
||||
_rotationTweener = transform.DORotate(target, 1 / Mathf.Abs(speed), RotateMode.LocalAxisAdd)
|
||||
.SetEase(Ease.Linear)
|
||||
.SetLoops(-1, LoopType.Incremental);
|
||||
}
|
||||
|
||||
_rotationTweener.timeScale = speedScale;
|
||||
}
|
||||
|
||||
public void UpdateSpeedScale(float speedScale)
|
||||
{
|
||||
_rotationTweener.timeScale = speedScale;
|
||||
}
|
||||
|
||||
#region 移动相关
|
||||
|
||||
public void StartMove()
|
||||
{
|
||||
targetShaft?.PlugOutGear();
|
||||
@@ -74,6 +113,7 @@ namespace AibisDream
|
||||
targetShaft = tempShaft;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ using AibisDream.FixSystem;
|
||||
using AibisDream.Framework;
|
||||
using AibisDream.Kit;
|
||||
using DG.Tweening;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AibisDream
|
||||
@@ -13,18 +14,29 @@ namespace AibisDream
|
||||
{
|
||||
#region 索引
|
||||
|
||||
[SerializeField] private GameObject gearPrefab;
|
||||
[SerializeField] private GameObject shaftPrefab;
|
||||
private Shaft[] _shafts;
|
||||
public GameObject gearPrefab;
|
||||
public GameObject shaftPrefab;
|
||||
private Transform _panel;
|
||||
private SpriteRenderer _cover;
|
||||
private Transform _coverStick;
|
||||
private Transform _needle;
|
||||
|
||||
private ShaftGraph _shaftGraph;
|
||||
|
||||
#endregion
|
||||
|
||||
public Vector3 coverUpPos;
|
||||
public Vector3 coverDownPos;
|
||||
|
||||
private ShaftGraph _shaftGraph;
|
||||
public Vector3 panelOpenPos;
|
||||
public Vector3 panelClosePos;
|
||||
|
||||
public Vector3 needleEmptyPos;
|
||||
public Vector3[] needlePosArr;
|
||||
public float needleDuration;
|
||||
|
||||
private bool _isTargetReached;
|
||||
private bool _isDiscReady;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -36,14 +48,20 @@ namespace AibisDream
|
||||
public void Init()
|
||||
{
|
||||
FixSystemCenter.SystemDic.Register(this);
|
||||
_shafts = GetComponentsInChildren<Shaft>();
|
||||
_cover = transform.Find("Cover").GetComponent<SpriteRenderer>();
|
||||
_coverStick = transform.Find("Cover Stick");
|
||||
_panel = transform.Find("Empty Shafts Panel");
|
||||
_needle = transform.Find("Needle");
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
_shaftGraph = new ShaftGraph(_shafts);
|
||||
_shaftGraph?.Clear();
|
||||
var shafts = transform.Find("Shafts").GetComponentsInChildren<Shaft>();
|
||||
var panelShafts = _panel.GetComponentsInChildren<Shaft>();
|
||||
_shaftGraph = new ShaftGraph(shafts, panelShafts);
|
||||
|
||||
_panel.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -70,25 +88,6 @@ namespace AibisDream
|
||||
return _shaftGraph.CheckGearSuitable(sourceShaft, gearRadius);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成齿轮
|
||||
/// </summary>
|
||||
/// <param name="pos">位置</param>
|
||||
/// <param name="radius">半径</param>
|
||||
/// <param name="sprite">齿轮图片</param>
|
||||
/// <param name="isBroken">齿轮已损坏</param>
|
||||
/// <returns>齿轮Obj</returns>
|
||||
public GameObject InitGear(Vector3 pos, float radius, Sprite sprite, bool isBroken = false)
|
||||
{
|
||||
GameObject gearObj = Instantiate(gearPrefab, pos, Quaternion.identity);
|
||||
gearObj.transform.parent = transform.Find("Gears").transform;
|
||||
Gear gear = gearObj.GetComponent<Gear>();
|
||||
gear.radius = radius;
|
||||
gear.gearSprite = sprite;
|
||||
gear.isBroken = isBroken;
|
||||
return gearObj;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 某个轴上齿轮发生变化时更新临接关系
|
||||
/// </summary>
|
||||
@@ -98,10 +97,32 @@ namespace AibisDream
|
||||
_shaftGraph?.ChangeVertex(shaftId);
|
||||
}
|
||||
|
||||
public void Succeed()
|
||||
#region 胜利状况判断
|
||||
|
||||
public void CheckGearSystemState()
|
||||
{
|
||||
Debug.Log("达成目标");
|
||||
DialogController.Instance.StartDialogNode("齿轮系统状态变化");
|
||||
}
|
||||
|
||||
public void ReachTargetSpeed()
|
||||
{
|
||||
if (!_isTargetReached)
|
||||
{
|
||||
DialogController.Instance?.SetVariable("$speedReached", true);
|
||||
_isTargetReached = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetTargetState()
|
||||
{
|
||||
if (_isTargetReached)
|
||||
{
|
||||
DialogController.Instance?.SetVariable("$speedReached", false);
|
||||
_isTargetReached = false;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public IEnumerator OpenCover()
|
||||
{
|
||||
@@ -125,6 +146,33 @@ namespace AibisDream
|
||||
yield return _coverStick.DORotate(new Vector3(0, 0, 0), 1.5f).WaitForCompletion();
|
||||
}
|
||||
|
||||
public IEnumerator OpenGearPanel()
|
||||
{
|
||||
_panel.gameObject.SetActive(true);
|
||||
yield return _panel.DOLocalMove(panelOpenPos, 1f).WaitForCompletion();
|
||||
}
|
||||
|
||||
public IEnumerator CloseGearPanel()
|
||||
{
|
||||
yield return _panel.DOLocalMove(panelClosePos, 1f).WaitForCompletion();
|
||||
_panel.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public IEnumerator MoveNeedle(int discIdx)
|
||||
{
|
||||
Vector3 target;
|
||||
if (discIdx > needlePosArr.Length || discIdx <= 0)
|
||||
{
|
||||
target = needleEmptyPos;
|
||||
}
|
||||
else
|
||||
{
|
||||
target = needlePosArr[discIdx - 1];
|
||||
}
|
||||
|
||||
yield return _needle.DORotate(target, needleDuration).WaitForCompletion();
|
||||
}
|
||||
|
||||
#region 数据保存与加载
|
||||
|
||||
public static string DataPath = Application.streamingAssetsPath + "/LevelData/GearSystem/";
|
||||
@@ -164,23 +212,51 @@ namespace AibisDream
|
||||
private void LoadByData(GearSystemData gearSystemData)
|
||||
{
|
||||
// 先清除
|
||||
var shaftRoot = transform.Find("Shafts");
|
||||
var shaftsObj = shaftRoot.GetComponentsInChildren<Shaft>();
|
||||
var shaftsObj = GetComponentsInChildren<Shaft>(true);
|
||||
foreach (var oldShaft in shaftsObj)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
DestroyImmediate(oldShaft.gameObject);
|
||||
if (!EditorApplication.isPlaying)
|
||||
{
|
||||
DestroyImmediate(oldShaft.gameObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
Destroy(oldShaft.gameObject);
|
||||
}
|
||||
#else
|
||||
Destory(oldShaft.gameObject);
|
||||
Destroy(oldShaft.gameObject);
|
||||
#endif
|
||||
}
|
||||
|
||||
// 再添加
|
||||
foreach (var shaftData in gearSystemData.shaftLevelDataArray)
|
||||
var shaftRoot = transform.Find("Shafts");
|
||||
var shafts = new Shaft[gearSystemData.shaftLevelDataArray.Length];
|
||||
for (int i = 0; i < gearSystemData.shaftLevelDataArray.Length; i++)
|
||||
{
|
||||
var newShaft = Instantiate(shaftPrefab, shaftRoot).GetComponent<Shaft>();
|
||||
newShaft.Load(shaftData);
|
||||
newShaft.Load(gearSystemData.shaftLevelDataArray[i]);
|
||||
shafts[i] = newShaft;
|
||||
}
|
||||
|
||||
var panelShaftRoot = transform.Find("Empty Shafts Panel");
|
||||
var panelShafts = new Shaft[gearSystemData.panelShaftArray.Length];
|
||||
for (int i = 0; i < gearSystemData.panelShaftArray.Length; i++)
|
||||
{
|
||||
var newShaft = Instantiate(shaftPrefab, panelShaftRoot).GetComponent<Shaft>();
|
||||
newShaft.Load(gearSystemData.panelShaftArray[i]);
|
||||
panelShafts[i] = newShaft;
|
||||
}
|
||||
|
||||
_cover = transform.Find("Cover").GetComponent<SpriteRenderer>();
|
||||
_coverStick = transform.Find("Cover Stick");
|
||||
_panel = transform.Find("Empty Shafts Panel");
|
||||
|
||||
#if UNITY_EDITOR
|
||||
if (!EditorApplication.isPlaying) return;
|
||||
#endif
|
||||
_shaftGraph?.Clear();
|
||||
_shaftGraph = new ShaftGraph(shafts, panelShafts);
|
||||
}
|
||||
|
||||
public override void Save()
|
||||
@@ -197,17 +273,19 @@ namespace AibisDream
|
||||
|
||||
private void SaveByKey(string key)
|
||||
{
|
||||
var shaftsObj = transform.Find("Shafts").GetComponentsInChildren<Shaft>();
|
||||
var shaftDataArray = new ShaftLevelData[shaftsObj.Length];
|
||||
|
||||
for (int i = 0; i < shaftDataArray.Length; i++)
|
||||
{
|
||||
shaftDataArray[i] = shaftsObj[i].Save();
|
||||
}
|
||||
var shaftDataArray = transform.Find("Shafts")
|
||||
.GetComponentsInChildren<Shaft>()
|
||||
.Select(shaft => shaft.Save())
|
||||
.ToArray();
|
||||
var panelShaftArray = transform.Find("Empty Shafts Panel")
|
||||
.GetComponentsInChildren<Shaft>()
|
||||
.Select(shaft => shaft.Save())
|
||||
.ToArray();
|
||||
|
||||
var data = new GearSystemData
|
||||
{
|
||||
shaftLevelDataArray = shaftDataArray
|
||||
shaftLevelDataArray = shaftDataArray,
|
||||
panelShaftArray = panelShaftArray
|
||||
};
|
||||
|
||||
ConfigUtil.Instance.SaveConfig(data, DataPath + key);
|
||||
@@ -226,5 +304,6 @@ namespace AibisDream
|
||||
public struct GearSystemData
|
||||
{
|
||||
public ShaftLevelData[] shaftLevelDataArray;
|
||||
public ShaftLevelData[] panelShaftArray;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System.Collections;
|
||||
using AibisDream.FixSystem;
|
||||
using UnityEngine;
|
||||
using Yarn.Unity;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
public static class GearYarnCommand
|
||||
{
|
||||
[YarnCommand("move_needle")]
|
||||
public static IEnumerator MoveNeedle()
|
||||
{
|
||||
DialogController.Instance.TryGetVariable<float>("$discIdx", out var discIdx);
|
||||
Debug.Log(discIdx);
|
||||
return FixSystemCenter.SystemDic.Get<GearSystem>().MoveNeedle((int) discIdx);
|
||||
}
|
||||
|
||||
[YarnCommand("open_gear_panel")]
|
||||
public static IEnumerator OpenGearPanel()
|
||||
{
|
||||
return FixSystemCenter.SystemDic.Get<GearSystem>().OpenGearPanel();
|
||||
}
|
||||
|
||||
[YarnCommand("close_gear_panel")]
|
||||
public static IEnumerator CloseGearPanel()
|
||||
{
|
||||
return FixSystemCenter.SystemDic.Get<GearSystem>().CloseGearPanel();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 73b9ebccdc5e4c12be4c93d3e0a71e52
|
||||
timeCreated: 1735397288
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using AibisDream.Framework;
|
||||
using AibisDream.Utility;
|
||||
using DG.Tweening;
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine;
|
||||
@@ -9,8 +8,6 @@ namespace AibisDream
|
||||
{
|
||||
public class Shaft : MonoBehaviour
|
||||
{
|
||||
private const int ShakeAngle = 15;
|
||||
|
||||
[SerializeField] private int id;
|
||||
|
||||
[SerializeField] public ShaftType shaftType;
|
||||
@@ -18,10 +15,12 @@ namespace AibisDream
|
||||
// 初始齿轮
|
||||
[SerializeField] private bool hasGear;
|
||||
[SerializeField] private bool isInitGearBroken;
|
||||
[SerializeField] private bool isInitGearDisc;
|
||||
[SerializeField] private float initRadius;
|
||||
[SerializeField] private Sprite initSprite;
|
||||
[SerializeField] private int discIdx;
|
||||
|
||||
[SerializeField] private GameObject childGear;
|
||||
[SerializeField] private Gear childGear;
|
||||
|
||||
// 初始角速度
|
||||
[SerializeField] private float initialSpeed;
|
||||
@@ -31,10 +30,10 @@ namespace AibisDream
|
||||
|
||||
// 当前角速度
|
||||
public float speed;
|
||||
private float _speedScale = 1;
|
||||
|
||||
public bool IsPluggable => shaftType is ShaftType.Pluggable or ShaftType.Driver or ShaftType.Target;
|
||||
|
||||
public bool IsBroken => childGear != null && childGear.GetComponent<Gear>().isBroken;
|
||||
public bool IsBroken => childGear != null && childGear.isBroken;
|
||||
public bool IsDisc => childGear != null && childGear.isDisc;
|
||||
|
||||
/// <summary>
|
||||
/// 当前齿轮半径
|
||||
@@ -48,13 +47,7 @@ namespace AibisDream
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (IsPluggable)
|
||||
{
|
||||
Gear gear = childGear.GetComponent<Gear>();
|
||||
return gear.radius;
|
||||
}
|
||||
|
||||
return initRadius;
|
||||
return childGear.radius;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,63 +63,73 @@ namespace AibisDream
|
||||
/// </summary>
|
||||
public void InitShaft()
|
||||
{
|
||||
_gearSystem = transform.parent.parent.GetComponent<GearSystem>();
|
||||
// 如果不带齿轮
|
||||
if (!hasGear) return;
|
||||
|
||||
// 如果带齿轮,要根据齿轮类型生成
|
||||
childGear = IsPluggable ? InitPluggableGear() : InitStaticGear();
|
||||
childGear = InitGear(initRadius, initSprite, isInitGearBroken, isInitGearDisc);
|
||||
|
||||
speed = initialSpeed;
|
||||
UpdateSpeed();
|
||||
childGear.UpdateRotation(speed, _speedScale);
|
||||
}
|
||||
|
||||
private GameObject InitStaticGear()
|
||||
private Gear InitGear(float radius, Sprite sprite, bool isBroken = false, bool isDisc = false)
|
||||
{
|
||||
GameObject staticGear = transform.GetChild(0).gameObject;
|
||||
|
||||
// 添加齿轮图片
|
||||
staticGear.SetActive(true);
|
||||
var staticGearRenderer = staticGear.GetComponent<SpriteRenderer>();
|
||||
staticGearRenderer.sprite = initSprite;
|
||||
staticGearRenderer.size = new Vector2(initRadius * 2, initRadius * 2);
|
||||
|
||||
// 如果有初速,就要开始转动了
|
||||
if (!CommonUtil.IsZero(initialSpeed))
|
||||
{
|
||||
staticGear.transform.DORotate(new Vector3(0, 0, 360), 1 / initialSpeed, RotateMode.LocalAxisAdd)
|
||||
.SetEase(Ease.Linear).SetLoops(-1, LoopType.Incremental);
|
||||
}
|
||||
|
||||
return staticGear;
|
||||
}
|
||||
|
||||
private GameObject InitPluggableGear()
|
||||
{
|
||||
var gear = _gearSystem.InitGear(transform.position, initRadius, initSprite, isInitGearBroken);
|
||||
gear.GetComponent<Gear>().targetShaft = this;
|
||||
var gear = Instantiate(_gearSystem.gearPrefab, transform).GetComponent<Gear>();
|
||||
gear.radius = radius;
|
||||
gear.gearSprite = sprite;
|
||||
gear.isBroken = isBroken;
|
||||
gear.targetShaft = this;
|
||||
gear.isDisc = isDisc;
|
||||
return gear;
|
||||
}
|
||||
|
||||
public void PlugInGear(Gear gear)
|
||||
{
|
||||
childGear = gear.gameObject;
|
||||
childGear = gear;
|
||||
gear.transform.parent = transform;
|
||||
_gearSystem.ChangeGraphVertex(GetInstanceID());
|
||||
// 面板里的齿轮才能触发
|
||||
if (transform.parent.name == "Shafts")
|
||||
{
|
||||
OnGearPlugIn();
|
||||
_gearSystem.CheckGearSystemState();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnGearPlugIn()
|
||||
{
|
||||
// 破损齿轮插进来就发一次事件,交给yarn处理
|
||||
if (IsBroken)
|
||||
{
|
||||
DialogController.Instance?.StartDialogNode("破损齿轮插入");
|
||||
}
|
||||
|
||||
if (IsDisc)
|
||||
{
|
||||
DialogController.Instance?.SetVariable("$discIdx", discIdx);
|
||||
}
|
||||
}
|
||||
|
||||
public void PlugOutGear()
|
||||
{
|
||||
// 拔出时齿轮停转
|
||||
childGear.UpdateRotation(0, _speedScale);
|
||||
|
||||
childGear.transform.parent = null;
|
||||
childGear = null;
|
||||
_gearSystem.ChangeGraphVertex(GetInstanceID());
|
||||
}
|
||||
|
||||
public void UpdateSpeed()
|
||||
public void ChangeRotateState()
|
||||
{
|
||||
UpdateSpeedAnima();
|
||||
CheckGameState();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 速度修改后改变动画
|
||||
/// 速度修改后改变动画(可能改变方向)
|
||||
/// </summary>
|
||||
private void UpdateSpeedAnima()
|
||||
{
|
||||
@@ -136,46 +139,30 @@ namespace AibisDream
|
||||
return;
|
||||
}
|
||||
|
||||
if (CommonUtil.IsZero(speed))
|
||||
{
|
||||
childGear.transform.DOPause();
|
||||
return;
|
||||
}
|
||||
childGear.UpdateRotation(speed, _speedScale);
|
||||
}
|
||||
|
||||
// 更新动画
|
||||
childGear.transform.DOKill();
|
||||
|
||||
// 对于正常齿轮
|
||||
if (!IsBroken)
|
||||
{
|
||||
if (speed > 0)
|
||||
{
|
||||
childGear.transform.DORotate(new Vector3(0, 0, 360), 1 / speed, RotateMode.LocalAxisAdd)
|
||||
.SetEase(Ease.Linear).SetLoops(-1, LoopType.Incremental);
|
||||
}
|
||||
else
|
||||
{
|
||||
childGear.transform.DORotate(new Vector3(0, 0, -360), 1 / -speed, RotateMode.LocalAxisAdd)
|
||||
.SetEase(Ease.Linear).SetLoops(-1, LoopType.Incremental);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 对于已破碎齿轮
|
||||
childGear.transform.DORotate(new Vector3(0, 0, ShakeAngle), ShakeAngle / Mathf.Abs(speed) / 360,
|
||||
RotateMode.LocalAxisAdd)
|
||||
.SetEase(Ease.Linear).SetLoops(-1, LoopType.Yoyo).SetDelay(0.1f);
|
||||
}
|
||||
public void UpdateSpeedScale(float newSpeedScale)
|
||||
{
|
||||
_speedScale = newSpeedScale;
|
||||
if (!HasChildGear()) return;
|
||||
childGear.UpdateSpeedScale(_speedScale);
|
||||
CheckGameState();
|
||||
}
|
||||
|
||||
private void CheckGameState()
|
||||
{
|
||||
if (shaftType == ShaftType.Target)
|
||||
// 只有目标轴判断
|
||||
if (shaftType != ShaftType.Target) return;
|
||||
|
||||
//
|
||||
if (targetSpeed <= Mathf.Abs(speed * _speedScale))
|
||||
{
|
||||
if (targetSpeed <= Mathf.Abs(speed))
|
||||
{
|
||||
_gearSystem.Succeed();
|
||||
}
|
||||
_gearSystem.ReachTargetSpeed();
|
||||
}
|
||||
else
|
||||
{
|
||||
_gearSystem.ResetTargetState();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,6 +230,16 @@ namespace AibisDream
|
||||
return shaft1.GearRadius / shaft2.GearRadius;
|
||||
}
|
||||
|
||||
public void OnDestroy()
|
||||
{
|
||||
if (childGear != null)
|
||||
{
|
||||
childGear.transform.DOKill();
|
||||
}
|
||||
Destroy(childGear);
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
public void OnDrawGizmos()
|
||||
{
|
||||
Gizmos.color = Color.red;
|
||||
@@ -261,6 +258,8 @@ namespace AibisDream
|
||||
shaftType = levelData.shaftType;
|
||||
hasGear = levelData.hasChildGear;
|
||||
isInitGearBroken = levelData.isGearBroken;
|
||||
isInitGearDisc = levelData.isDisc;
|
||||
discIdx = levelData.discIdx;
|
||||
initialSpeed = levelData.initialSpeed;
|
||||
targetSpeed = levelData.targetSpeed;
|
||||
initRadius = levelData.radius;
|
||||
@@ -276,6 +275,8 @@ namespace AibisDream
|
||||
shaftType = shaftType,
|
||||
hasChildGear = hasGear,
|
||||
isGearBroken = isInitGearBroken,
|
||||
isDisc = isInitGearDisc,
|
||||
discIdx = discIdx,
|
||||
initialSpeed = initialSpeed,
|
||||
targetSpeed = targetSpeed,
|
||||
radius = initRadius
|
||||
@@ -289,7 +290,6 @@ namespace AibisDream
|
||||
{
|
||||
Driver, // 拥有初始速度,没有目标速度,全局仅有一个
|
||||
Target, // 没有初始速度,有目标速度,全局有多个
|
||||
Constant, // 没有初始速度,没有目标速度,不可拖动
|
||||
Pluggable // 没有初始速度,没有目标速度,可拔插
|
||||
}
|
||||
|
||||
@@ -305,6 +305,8 @@ namespace AibisDream
|
||||
public bool hasChildGear;
|
||||
public float radius;
|
||||
public bool isGearBroken;
|
||||
public bool isDisc;
|
||||
public int discIdx;
|
||||
|
||||
// 外形数据
|
||||
public SerializableVector3 shaftPos;
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using AibisDream.FixSystem;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AibisDream
|
||||
@@ -9,6 +11,7 @@ namespace AibisDream
|
||||
private readonly int _vertexSize;
|
||||
// 顶点Map
|
||||
private readonly Shaft[] _vertexArray;
|
||||
private readonly Shaft[] _panelShafts;
|
||||
// 邻接表
|
||||
private float[,] _edgeTable;
|
||||
// 遍历记录
|
||||
@@ -16,24 +19,32 @@ namespace AibisDream
|
||||
// 动力轴序号
|
||||
private readonly int _rootIdx;
|
||||
|
||||
public ShaftGraph(Shaft[] shafts)
|
||||
public ShaftGraph(Shaft[] shafts, Shaft[] panelShafts)
|
||||
{
|
||||
// 为轴赋值
|
||||
_vertexSize = shafts.Length;
|
||||
_vertexRecordArray = new bool[_vertexSize];
|
||||
_vertexArray = shafts;
|
||||
_panelShafts = panelShafts;
|
||||
foreach (var shaft in _vertexArray)
|
||||
{
|
||||
shaft.InitShaft();
|
||||
}
|
||||
foreach (var shaft in _panelShafts)
|
||||
{
|
||||
shaft.InitShaft();
|
||||
}
|
||||
|
||||
// 寻找唯一的驱动轴序号
|
||||
_rootIdx = FindDriverIdx();
|
||||
|
||||
|
||||
// 生成边邻接表
|
||||
GeneEdgeTable();
|
||||
|
||||
UpdateSpeed();
|
||||
|
||||
var engine = FixSystemCenter.SystemDic.Get<EngineSystem>();
|
||||
engine.UpdateDashboard += Accelerate;
|
||||
}
|
||||
|
||||
private int FindDriverIdx()
|
||||
@@ -83,6 +94,7 @@ namespace AibisDream
|
||||
{
|
||||
// 找到对应idx
|
||||
int idx = TranInstanceIDToIdx(instanceID);
|
||||
if (idx == -1) return;
|
||||
|
||||
// 更新该节点对应的邻接表
|
||||
for (int i = 0; i < _vertexSize; i++)
|
||||
@@ -128,7 +140,7 @@ namespace AibisDream
|
||||
/// <summary>
|
||||
/// 更新当前所有轴的速度
|
||||
/// </summary>
|
||||
public void UpdateSpeed()
|
||||
private void UpdateSpeed()
|
||||
{
|
||||
// 清除遍历记录
|
||||
Array.Clear(_vertexRecordArray, 0, _vertexSize);
|
||||
@@ -140,7 +152,7 @@ namespace AibisDream
|
||||
// 更新完速度后统一更新动画
|
||||
foreach (var shaft in _vertexArray)
|
||||
{
|
||||
shaft.UpdateSpeed();
|
||||
shaft.ChangeRotateState();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,7 +178,7 @@ namespace AibisDream
|
||||
// 已遍历的轴加上标记
|
||||
_vertexRecordArray[i] = true;
|
||||
// 如果当前齿轮未破碎,继续更新相邻齿轮
|
||||
if (_vertexArray[i].IsBroken)
|
||||
if (!_vertexArray[i].IsBroken)
|
||||
{
|
||||
UpdateShaftSpeedByIdx(i);
|
||||
}
|
||||
@@ -202,9 +214,11 @@ namespace AibisDream
|
||||
// 查询距离最近的,可吸附的Shaft
|
||||
Shaft closestShaft = null;
|
||||
float minDistance = -1;
|
||||
foreach (var vertex in _vertexArray)
|
||||
|
||||
var totalArray = _vertexArray.Concat(_panelShafts);
|
||||
foreach (var vertex in totalArray)
|
||||
{
|
||||
if (vertex.IsPluggable && !vertex.HasChildGear())
|
||||
if (!vertex.HasChildGear())
|
||||
{
|
||||
float tempDis = Vector3.Distance(vertex.transform.position, pos);
|
||||
if (minDistance < 0 || tempDis < minDistance)
|
||||
@@ -242,7 +256,7 @@ namespace AibisDream
|
||||
{
|
||||
if (i == idx) continue; // 不需要计算和自身的关系
|
||||
float availableDis = Shaft.CalcShaftAvailableDis(sourceShaft.transform.position, _vertexArray[i]);
|
||||
if (availableDis < gearRadius - 0.15f)
|
||||
if (availableDis < gearRadius - 0.05f)
|
||||
{
|
||||
isShaftAvailable = false;
|
||||
break;
|
||||
@@ -251,5 +265,23 @@ namespace AibisDream
|
||||
|
||||
return isShaftAvailable;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过引擎系统加速
|
||||
/// </summary>
|
||||
/// <param name="engineData"></param>
|
||||
private void Accelerate(EngineData engineData)
|
||||
{
|
||||
foreach (var shaft in _vertexArray)
|
||||
{
|
||||
if (shaft.HasChildGear()) shaft.UpdateSpeedScale(1 + engineData.curSpeed);
|
||||
}
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
var engine = FixSystemCenter.SystemDic.Get<EngineSystem>();
|
||||
engine.UpdateDashboard -= Accelerate;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using AibisDream.FixSystem;
|
||||
|
||||
public class UFSystem : MonoBehaviour
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
@@ -9,52 +10,54 @@ public class UFSystem : MonoBehaviour
|
||||
private GameObject _UFModule;
|
||||
|
||||
public GameObject UFPanel;
|
||||
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
FixSystemCenter.SystemDic.Register(this);
|
||||
|
||||
}
|
||||
|
||||
public void OpenUFView()
|
||||
{
|
||||
if(!UFPanel.activeInHierarchy)
|
||||
if (!UFPanel.activeInHierarchy)
|
||||
{
|
||||
UFPanel.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void CloseUFView()
|
||||
{
|
||||
if(UFPanel.activeInHierarchy)
|
||||
if (UFPanel.activeInHierarchy)
|
||||
{
|
||||
UFPanel.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void OpenCover()
|
||||
{
|
||||
var bodyModuleSystem = FixSystemCenter.SystemDic.Get<BodyModuleSystem>();
|
||||
_UFCover = bodyModuleSystem.FindBodyModuleByName("UF").transform.Find("Cover").gameObject;
|
||||
if(_UFCover.activeInHierarchy)
|
||||
if (_UFCover.activeInHierarchy)
|
||||
{
|
||||
_UFCover.SetActive(false);
|
||||
}
|
||||
}
|
||||
public void RemoveUF()
|
||||
|
||||
public void RemoveUF()
|
||||
{
|
||||
var bodyModuleSystem = FixSystemCenter.SystemDic.Get<BodyModuleSystem>();
|
||||
_UFModule = bodyModuleSystem.FindBodyModuleByName("UF").gameObject;
|
||||
if(_UFModule.activeInHierarchy)
|
||||
if (_UFModule.activeInHierarchy)
|
||||
{
|
||||
_UFModule.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user