可配置模块
This commit is contained in:
@@ -1,32 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using AibisDream.Framework;
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AibisDream.FixSystem
|
||||
{
|
||||
public class BodyModule : MonoBehaviour
|
||||
public class BodyModule : MonoBehaviour, ISocket
|
||||
{
|
||||
#region 组件引用
|
||||
|
||||
private const string SocketObjName = "Socket";
|
||||
public Socket Socket { get; private set; }
|
||||
private const string ModulePicName = "Module Pic";
|
||||
private Transform _socketPos;
|
||||
|
||||
#endregion
|
||||
|
||||
public Vector3 SocketPos => Socket.transform.position;
|
||||
|
||||
// 模块基本数据
|
||||
[SerializeField] public BodyModuleData moduleData;
|
||||
|
||||
public ISocketCommand curPlugInCommand;
|
||||
|
||||
#region Module状态
|
||||
|
||||
public bool isPlugIn;
|
||||
public bool isFirstPlugIn;
|
||||
public string curCommandType;
|
||||
|
||||
#endregion
|
||||
[SerializeField] public BodyModuleData data;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -36,24 +26,123 @@ namespace AibisDream.FixSystem
|
||||
|
||||
private void InitReference()
|
||||
{
|
||||
Socket = transform.Find(SocketObjName).GetComponent<Socket>();
|
||||
_socketPos = transform.Find(SocketObjName);
|
||||
}
|
||||
|
||||
#region 插槽功能
|
||||
|
||||
public void PlugIn()
|
||||
{
|
||||
|
||||
// 插入后先播放wave
|
||||
ShowWave();
|
||||
// 然后触发Yarn节点
|
||||
// DialogController.Instance.StartDialogNode(data.PlugInNodeName);
|
||||
}
|
||||
|
||||
public void PlugOut()
|
||||
{
|
||||
// 先关闭wave
|
||||
CloseWave();
|
||||
// TODO 触发Yarn节点(似乎目前没有拔出对话?)
|
||||
}
|
||||
|
||||
public void DeepIn()
|
||||
{
|
||||
if (!data.waveHasError) return;
|
||||
// 如果有错误并且已经深入了
|
||||
DialogController.Instance.StartDialogNode(data.DeepInNodeName);
|
||||
}
|
||||
|
||||
private void CloseWave()
|
||||
{
|
||||
FixSystemCenter.SystemDic.Get<OscilloscopeSystem>().StopWave();
|
||||
}
|
||||
|
||||
private void ShowWave()
|
||||
{
|
||||
FixSystemCenter.SystemDic.Get<OscilloscopeSystem>().PlayWave(data.waveformType, data.waveHasError);
|
||||
}
|
||||
|
||||
public Vector3 GetSocketPos()
|
||||
{
|
||||
return _socketPos.position;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 模块数据保存与卸载
|
||||
|
||||
public void Load(BodyModuleData newData)
|
||||
{
|
||||
var modulePic = transform.Find(ModulePicName).GetComponent<SpriteRenderer>();
|
||||
var socketPos = transform.Find(SocketObjName);
|
||||
|
||||
gameObject.name = newData.moduleName;
|
||||
// 初始化位置与外形
|
||||
transform.localPosition = newData.ModulePos;
|
||||
modulePic.sprite = newData.ModulePic;
|
||||
socketPos.localPosition = newData.SocketPos;
|
||||
// 数据同步
|
||||
data = newData;
|
||||
}
|
||||
|
||||
public BodyModuleData Save()
|
||||
{
|
||||
var modulePic = transform.Find(ModulePicName).GetComponent<SpriteRenderer>();
|
||||
var socketPos = transform.Find(SocketObjName);
|
||||
|
||||
return new BodyModuleData
|
||||
{
|
||||
moduleName = data.moduleName,
|
||||
modulePicPath = ResourceKit.SavePsdSprite(modulePic.sprite),
|
||||
ModulePos = transform.localPosition,
|
||||
SocketPos = socketPos.localPosition,
|
||||
waveformType = data.waveformType,
|
||||
waveHasError = data.waveHasError
|
||||
};
|
||||
}
|
||||
|
||||
#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;
|
||||
|
||||
// 功能信息
|
||||
public WaveformType waveformType;
|
||||
|
||||
|
||||
public bool waveHasError;
|
||||
|
||||
public List<string> modulePicList;
|
||||
// 只读
|
||||
[JsonIgnore] public string PlugInNodeName => string.Format(PlugInNodeTemplate, moduleName);
|
||||
[JsonIgnore] public string DeepInNodeName => string.Format(DeepInTemplate, moduleName);
|
||||
|
||||
public Vector3 modulePos;
|
||||
[JsonIgnore]
|
||||
public Sprite ModulePic =>
|
||||
!string.IsNullOrEmpty(modulePicPath) ? ResourceKit.LoadSpriteFromPsd(modulePicPath) : 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user