Ver.0.3.0.33
This commit is contained in:
@@ -2,6 +2,9 @@ using System;
|
||||
using AibisDream.Framework;
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using DG.Tweening;
|
||||
using AibisDream.Kit;
|
||||
|
||||
namespace AibisDream.FixSystem
|
||||
{
|
||||
@@ -10,11 +13,12 @@ namespace AibisDream.FixSystem
|
||||
#region 组件引用
|
||||
|
||||
private const string SocketObjName = "Socket";
|
||||
private const string ModulePicName = "Module Pic";
|
||||
|
||||
public Transform socketPos;
|
||||
private Transform _socketPos;
|
||||
private Transform _socketLeft;
|
||||
private Transform _socketRight;
|
||||
private Tween _socketTween;
|
||||
|
||||
// public Transform _indicatorPos;
|
||||
private BodyModuleSystem _bodyModuleSystem;
|
||||
private Material _highlightMaterial;
|
||||
private Material _alarmMaterial;
|
||||
@@ -22,11 +26,24 @@ namespace AibisDream.FixSystem
|
||||
|
||||
private SpriteRenderer _targetSpriteRenderer; // 目标的 SpriteRenderer
|
||||
|
||||
private SpriteRenderer _cutSpriteRenderer;
|
||||
private SpriteRenderer _cutTextRenderer; // 添加cutText的SpriteRenderer引用
|
||||
|
||||
private CutLine _cutLine;
|
||||
|
||||
[Header("CutText闪烁效果")] private float cutTextFlickerThreshold = 0.4f; // 开始闪烁的阈值
|
||||
private float cutTextFlickerInterval = 0.1f; // 闪烁间隔
|
||||
private float cutTextFlickerTimer = 0f; // 闪烁计时器
|
||||
private bool isCutTextFlickering = false; // 是否正在闪烁
|
||||
private Coroutine flickerCoroutine; // 闪烁协程引用
|
||||
|
||||
#endregion
|
||||
|
||||
// 模块基本数据
|
||||
[SerializeField] public BodyModuleData data;
|
||||
private bool _available = true;
|
||||
public bool available = true;
|
||||
private bool _cutting;
|
||||
private bool _isOpen;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -36,11 +53,23 @@ namespace AibisDream.FixSystem
|
||||
|
||||
private void InitReference()
|
||||
{
|
||||
socketPos = transform.Find(SocketObjName);
|
||||
_socketPos = transform.Find(SocketObjName);
|
||||
_socketLeft = _socketPos.Find("Left");
|
||||
_socketRight = _socketPos.Find("Right");
|
||||
|
||||
_bodyModuleSystem = transform.parent.parent.GetComponent<BodyModuleSystem>();
|
||||
|
||||
_targetSpriteRenderer = transform.Find("Module Pic").GetComponent<SpriteRenderer>();
|
||||
_originalMaterial = _targetSpriteRenderer.GetComponent<SpriteRenderer>().material;
|
||||
|
||||
_cutSpriteRenderer = transform.Find("Cut Pic")?.GetComponent<SpriteRenderer>();
|
||||
if (_cutSpriteRenderer != null)
|
||||
{
|
||||
_cutTextRenderer =
|
||||
_cutSpriteRenderer.transform.Find("Cut Text")
|
||||
?.GetComponent<SpriteRenderer>(); // 初始化cutText的SpriteRenderer
|
||||
}
|
||||
|
||||
_highlightMaterial = Resources.Load<Material>("Materials/HighlightMaterial");
|
||||
_alarmMaterial = Resources.Load<Material>("Materials/AlarmMaterial");
|
||||
}
|
||||
@@ -49,23 +78,16 @@ namespace AibisDream.FixSystem
|
||||
|
||||
public bool IsAvailable()
|
||||
{
|
||||
return _available;
|
||||
return available;
|
||||
}
|
||||
|
||||
public void SetSocketAvailable(bool isAvailable)
|
||||
{
|
||||
_available = isAvailable;
|
||||
available = isAvailable;
|
||||
}
|
||||
|
||||
public void PlugIn()
|
||||
{
|
||||
// // 插入就在示波器显示图片
|
||||
// if (!_bodyModuleSystem.inHotErr)
|
||||
// {
|
||||
// StartCoroutine(FixSystemCenter.SystemDic.Get<IOscilloscopeSystem>()
|
||||
// ?.ShowScanImage(data.ScreenPic, data.checkPoints));
|
||||
// }
|
||||
|
||||
if (DialogController.Instance)
|
||||
// 然后触发Yarn节点
|
||||
DialogController.Instance.StartDialogNode(_bodyModuleSystem.inHotErr ? "系统发热" : data.PlugInNodeName);
|
||||
@@ -73,58 +95,39 @@ namespace AibisDream.FixSystem
|
||||
|
||||
public void PlugOut()
|
||||
{
|
||||
FixSystemCenter.SystemDic.Get<IOscilloscopeSystem>()?.HideScanImage();
|
||||
|
||||
_bodyModuleSystem.oscilloscopeSystem.MessageBoxSetNull();
|
||||
StartCoroutine(_bodyModuleSystem.oscilloscopeSystem.DisableDeepInButton());
|
||||
|
||||
// TODO 触发Yarn节点(似乎目前没有拔出对话?)
|
||||
}
|
||||
|
||||
public void DeepIn()
|
||||
{
|
||||
if(DialogController.Instance)
|
||||
DialogController.Instance.StartDialogNode(data.DeepInNodeName);
|
||||
}
|
||||
|
||||
public Vector3 GetSocketPos()
|
||||
{
|
||||
return socketPos.position;
|
||||
return _socketPos.position;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 模块数据保存与卸载
|
||||
|
||||
public void Load(BodyModuleData newData)
|
||||
public void OpenPlugSlot()
|
||||
{
|
||||
var modulePic = transform.Find(ModulePicName).GetComponent<SpriteRenderer>();
|
||||
var newSocketPos = transform.Find(SocketObjName);
|
||||
|
||||
gameObject.name = newData.moduleName;
|
||||
// 初始化位置与外形
|
||||
transform.localPosition = newData.ModulePos;
|
||||
modulePic.sprite = newData.ModulePic;
|
||||
newSocketPos.localPosition = newData.SocketPos;
|
||||
// 数据同步
|
||||
data = newData;
|
||||
|
||||
InitReference();
|
||||
if (!_socketLeft) return;
|
||||
|
||||
if (_isOpen) return;
|
||||
_isOpen = true;
|
||||
// 打开插槽
|
||||
if (_socketTween.IsActive() && _socketTween.IsPlaying()) _socketTween.Kill(true);
|
||||
var sequence = DOTween.Sequence();
|
||||
sequence.Join(_socketLeft.DOScale(new Vector3(0, 1, 1), 0.2f).SetEase(Ease.InSine));
|
||||
sequence.Join(_socketRight.DOScale(new Vector3(0, 1, 1), 0.2f).SetEase(Ease.InSine));
|
||||
_socketTween = sequence;
|
||||
}
|
||||
|
||||
public BodyModuleData Save()
|
||||
public void ClosePlugSlot()
|
||||
{
|
||||
var modulePic = transform.Find(ModulePicName).GetComponent<SpriteRenderer>();
|
||||
var newSocketPos = transform.Find(SocketObjName);
|
||||
|
||||
return new BodyModuleData
|
||||
{
|
||||
moduleName = data.moduleName,
|
||||
ModulePic = modulePic.sprite,
|
||||
ModulePos = transform.localPosition,
|
||||
SocketPos = newSocketPos.localPosition,
|
||||
cantStopRunning = data.cantStopRunning,
|
||||
};
|
||||
if (!_socketLeft) return;
|
||||
if (!_isOpen) return;
|
||||
|
||||
_isOpen = false;
|
||||
// 关闭插槽
|
||||
if (_socketTween.IsActive() && _socketTween.IsPlaying()) _socketTween.Kill(true);
|
||||
var sequence = DOTween.Sequence();
|
||||
sequence.Join(_socketLeft.DOScale(new Vector3(1, 1, 1), 0.2f).SetEase(Ease.OutSine));
|
||||
sequence.Join(_socketRight.DOScale(new Vector3(1, 1, 1), 0.2f).SetEase(Ease.OutSine));
|
||||
_socketTween = sequence;
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -149,69 +152,170 @@ namespace AibisDream.FixSystem
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 切割相关
|
||||
|
||||
public void OnCuttingDown()
|
||||
{
|
||||
_bodyModuleSystem.RemoveModule(this);
|
||||
|
||||
DialogController.Instance?.StartDialogNode($"{data.moduleName}CutDown");
|
||||
EnumEventSystem.Global.Send(EventEnum.CutEnd);
|
||||
Destroy(gameObject);
|
||||
DialogController.Instance?.StartDialogNode($"{data.moduleName}CutDown");
|
||||
EnumEventSystem.Global.Send(EventEnum.CutEnd);
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
public void SetCutTextVisible(bool visible)
|
||||
{
|
||||
if (_cutTextRenderer != null)
|
||||
{
|
||||
_cutTextRenderer.enabled = visible;
|
||||
}
|
||||
}
|
||||
|
||||
public SpriteRenderer GetCutSpriteRenderer()
|
||||
{
|
||||
return _cutSpriteRenderer;
|
||||
}
|
||||
public SpriteRenderer GetCutTextSpriteRenderer()
|
||||
{
|
||||
return _cutTextRenderer;
|
||||
}
|
||||
|
||||
public void StartCutTextFlicker()
|
||||
{
|
||||
if (!isCutTextFlickering)
|
||||
{
|
||||
isCutTextFlickering = true;
|
||||
if (flickerCoroutine != null)
|
||||
{
|
||||
StopCoroutine(flickerCoroutine);
|
||||
}
|
||||
|
||||
flickerCoroutine = StartCoroutine(CutTextFlickerCoroutine());
|
||||
}
|
||||
}
|
||||
|
||||
public void StopCutTextFlicker()
|
||||
{
|
||||
isCutTextFlickering = false;
|
||||
if (flickerCoroutine != null)
|
||||
{
|
||||
StopCoroutine(flickerCoroutine);
|
||||
flickerCoroutine = null;
|
||||
}
|
||||
|
||||
// 确保最终状态是可见的
|
||||
SetCutTextVisible(true);
|
||||
}
|
||||
|
||||
private IEnumerator CutTextFlickerCoroutine()
|
||||
{
|
||||
while (isCutTextFlickering)
|
||||
{
|
||||
// 随机决定是否显示
|
||||
bool shouldShow = UnityEngine.Random.value > 0.5f;
|
||||
SetCutTextVisible(shouldShow);
|
||||
|
||||
// 播放相应的音效
|
||||
if (shouldShow)
|
||||
{
|
||||
AudioManager.Instance.PlaySfx("event:/ActionFB/light_flicker_on");
|
||||
}
|
||||
else
|
||||
{
|
||||
AudioManager.Instance.PlaySfx("event:/ActionFB/light_flicker_off");
|
||||
}
|
||||
|
||||
// 随机等待时间,模拟接触不良效果
|
||||
float waitTime = UnityEngine.Random.Range(cutTextFlickerInterval * 0.5f, cutTextFlickerInterval * 1.5f);
|
||||
yield return new WaitForSeconds(waitTime);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateCutProgress(float progress)
|
||||
{
|
||||
// 检查是否达到闪烁阈值
|
||||
if (!isCutTextFlickering && progress >= cutTextFlickerThreshold)
|
||||
{
|
||||
StartCutTextFlicker();
|
||||
}
|
||||
}
|
||||
|
||||
// public void EnableCut()
|
||||
// {
|
||||
// // 打开或获取CutLine
|
||||
// ShowCutLine();
|
||||
// _cutLine.OnCuttingDown += OnCuttingDown;
|
||||
// _cutting = true;
|
||||
|
||||
// EnumEventSystem.Global.Send(EventEnum.CutStart);
|
||||
// }
|
||||
|
||||
// private void OnCut()
|
||||
// {
|
||||
// Vector2 mousePos = CommonUtil.GetMouseWorldPos(Input.mousePosition);
|
||||
// _cutLine.DetectLineClick(mousePos, clickRadius);
|
||||
// }
|
||||
|
||||
// private void OnCuttingDown()
|
||||
// {
|
||||
// _cutLine.OnCuttingDown -= OnCuttingDown;
|
||||
// _cutting = false;
|
||||
// // 模块脱落
|
||||
// _cutLine.HideLine();
|
||||
// _bodyModuleSystem.RemoveModule(this);
|
||||
// ActionKit.Sequence()
|
||||
// .Delay(0.8f)
|
||||
// .DOTween(() => transform.DOMoveY(ConstRef.TweenEndY,
|
||||
// (transform.position.y - ConstRef.TweenEndY) / (ConstRef.FallSpeed * 0.6f))
|
||||
// .SetEase(Ease.InQuad))
|
||||
// .Callback(() => DialogController.Instance?.StartDialogNode($"{data.moduleName}CutDown"))
|
||||
// .Callback(() => EnumEventSystem.Global.Send(EventEnum.CutEnd))
|
||||
// .Start(this, () => Destroy(gameObject));
|
||||
// }
|
||||
|
||||
// private void ShowCutLine()
|
||||
// {
|
||||
// // 切割线不存在,就新建一个
|
||||
// if (!_cutLine)
|
||||
// {
|
||||
// var prefab = ResourceKit.LoadAssetSync<GameObject>(ConstRef.CutLinePrefabName);
|
||||
// var cutLineObj = Instantiate(prefab, transform);
|
||||
// _cutLine = cutLineObj.GetComponent<CutLine>();
|
||||
// }
|
||||
|
||||
// // 对切割线进行初始化
|
||||
// var shapePoints = new List<Vector2>();
|
||||
// _targetSpriteRenderer.sprite.GetPhysicsShape(0, shapePoints);
|
||||
// if (shapePoints.Count <= 0)
|
||||
// {
|
||||
// Debug.LogWarning($"{name} has no shape");
|
||||
// return;
|
||||
// }
|
||||
|
||||
// // 本地坐标转世界坐标
|
||||
// var shapePointsV3 = shapePoints
|
||||
// .Select(item => _targetSpriteRenderer.transform.TransformPoint(item))
|
||||
// .ToList();
|
||||
|
||||
// _cutLine.Init(shapePointsV3, clickRadius);
|
||||
// }
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public struct BodyModuleData
|
||||
{
|
||||
public const string PlugInNodeTemplate = "{0}PlugIn";
|
||||
public const string DeepInTemplate = "{0}DeepIn";
|
||||
|
||||
// ID
|
||||
public string moduleName;
|
||||
|
||||
// 外形信息
|
||||
public string modulePicPath;
|
||||
public SerializableVector3 modulePos;
|
||||
public SerializableVector3 socketPos;
|
||||
|
||||
// 功能信息
|
||||
[Header("功能参数")] public bool cantStopRunning;
|
||||
|
||||
public string showPicPath;
|
||||
public CheckPoint[] checkPoints;
|
||||
|
||||
// 只读
|
||||
[JsonIgnore] public string PlugInNodeName => string.Format(PlugInNodeTemplate, moduleName);
|
||||
[JsonIgnore] public string DeepInNodeName => string.Format(DeepInTemplate, moduleName);
|
||||
|
||||
[JsonIgnore]
|
||||
public Sprite ModulePic
|
||||
{
|
||||
get => !string.IsNullOrEmpty(modulePicPath) ? ResourceKit.LoadSpriteFromPsd(modulePicPath) : null;
|
||||
set => modulePicPath = ResourceKit.SaveSprite(value);
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public Sprite ScreenPic =>
|
||||
!string.IsNullOrEmpty(showPicPath) ? ResourceKit.LoadSpriteFromPsd(showPicPath) : null;
|
||||
|
||||
[JsonIgnore]
|
||||
public Vector3 ModulePos
|
||||
{
|
||||
get => modulePos.ToVector3();
|
||||
set => modulePos = new SerializableVector3(value);
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public Vector3 SocketPos
|
||||
{
|
||||
get => socketPos.ToVector3();
|
||||
set => socketPos = new SerializableVector3(value);
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public struct CheckPoint
|
||||
{
|
||||
public string id;
|
||||
private SerializableVector3 _serializablePos3;
|
||||
|
||||
[JsonIgnore]
|
||||
public Vector3 PointPos
|
||||
{
|
||||
get => _serializablePos3.ToVector3();
|
||||
set => _serializablePos3 = new SerializableVector3(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user