增加BodyModule切换功能
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using AibisDream.Framework;
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -10,11 +9,9 @@ namespace AibisDream.FixSystem
|
||||
#region 组件引用
|
||||
|
||||
private const string SocketObjName = "Socket";
|
||||
private const string ModulePicName = "Module Pic";
|
||||
|
||||
public Transform socketPos;
|
||||
|
||||
// public Transform _indicatorPos;
|
||||
private BodyModuleSystem _bodyModuleSystem;
|
||||
private Material _highlightMaterial;
|
||||
private Material _alarmMaterial;
|
||||
@@ -67,12 +64,6 @@ namespace AibisDream.FixSystem
|
||||
public void PlugOut()
|
||||
{
|
||||
}
|
||||
|
||||
public void DeepIn()
|
||||
{
|
||||
if(DialogController.Instance)
|
||||
DialogController.Instance.StartDialogNode(data.DeepInNodeName);
|
||||
}
|
||||
|
||||
public Vector3 GetSocketPos()
|
||||
{
|
||||
@@ -81,41 +72,6 @@ namespace AibisDream.FixSystem
|
||||
|
||||
#endregion
|
||||
|
||||
#region 模块数据保存与卸载
|
||||
|
||||
public void Load(BodyModuleData newData)
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
public BodyModuleData Save()
|
||||
{
|
||||
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,
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 高亮提示和隐藏
|
||||
|
||||
public void Highlight(bool enable)
|
||||
@@ -142,42 +98,11 @@ namespace AibisDream.FixSystem
|
||||
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;
|
||||
|
||||
// 只读
|
||||
[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 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