还原现场触发物场景

This commit is contained in:
liuyu 2024-09-03 16:09:24 +08:00
parent aa02fffc38
commit 2adbebe563
3 changed files with 49 additions and 9 deletions

View File

@ -6,9 +6,20 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
//用于记录现场中各项出发物品信息
[Serializable]
public class ReconnectTriggerInfo
{
public int triggerID;
public string triggerName;
public Vector3 selfPosInScene;
public Vector3 selfRotInScene;
}
//用于记录场景中物品的信息 //用于记录场景中物品的信息
[Serializable] [Serializable]
public class ReconnetItemInfo public class ReconnectItemInfo
{ {
public int toolId; public int toolId;
public int triggerID; public int triggerID;
@ -38,9 +49,13 @@ public class TB_UserExamStat
/// </summary> /// </summary>
public string sceneName = ""; public string sceneName = "";
/// <summary>
/// 当前场景内的所有装备和材料
/// </summary>
public List<ReconnectItemInfo> currentSceneTools = new List<ReconnectItemInfo>();
/// <summary> /// <summary>
/// 当前场景内的所有可触发物品 /// 当前场景内的所有可触发物品
/// </summary> /// </summary>
public List<ReconnetItemInfo> currentSceneTools = new List<ReconnetItemInfo>(); public List<ReconnectTriggerInfo> currentSceneTriggers = new List<ReconnectTriggerInfo>();
} }

View File

@ -328,7 +328,7 @@ public class ProcessManager : BaseManager<ProcessManager>
if (countDown_AutoSave <= 0) if (countDown_AutoSave <= 0)
{ {
ReconnectMgr.Instance.RealtimeStatWriter();//需要在GameManager里面初始化 ReconnectMgr.Instance.RealtimeStatWriter();//需要在GameManager里面初始化
Debug.Log("完成状态自动保存"); //Debug.Log("完成状态自动保存");
countDown_AutoSave = time; countDown_AutoSave = time;
} }
} }

View File

@ -76,8 +76,8 @@ public class ReconnectMgr : SingletonMono<ReconnectMgr>
BaseToolOrDevice[] allThings = FindObjectsOfType<BaseToolOrDevice>(); BaseToolOrDevice[] allThings = FindObjectsOfType<BaseToolOrDevice>();
foreach (BaseToolOrDevice item in allThings) foreach (BaseToolOrDevice item in allThings)
{ {
Debug.Log(item.itemInfo.toolName); //Debug.Log(item.itemInfo.toolName);
ReconnetItemInfo rec = new ReconnetItemInfo(); ReconnectItemInfo rec = new ReconnectItemInfo();
rec.toolId = item.itemInfo.toolId; rec.toolId = item.itemInfo.toolId;
rec.toolName = item.itemInfo.toolName; rec.toolName = item.itemInfo.toolName;
rec.triggerID = item.itemInfo.triggerID; rec.triggerID = item.itemInfo.triggerID;
@ -87,15 +87,21 @@ public class ReconnectMgr : SingletonMono<ReconnectMgr>
} }
//获取场景内(现场)所有可以出发的装置 //获取场景内(现场)所有可以出发的装置
UserExamStat.currentSceneTriggers.Clear();
PermanentTriggerBase[] allPermanentTriggers = FindObjectsOfType<PermanentTriggerBase>(); PermanentTriggerBase[] allPermanentTriggers = FindObjectsOfType<PermanentTriggerBase>();
foreach (PermanentTriggerBase item in allPermanentTriggers) foreach (PermanentTriggerBase item in allPermanentTriggers)
{ {
Debug.Log("场景内涉及的物品:" + item.gameObject.name); ReconnectTriggerInfo ret = new ReconnectTriggerInfo();
ret.triggerName = item.triggerName;
ret.triggerID = item.triggerID;
ret.selfPosInScene = item.transform.localPosition;
ret.selfRotInScene = item.transform.localEulerAngles;
UserExamStat.currentSceneTriggers.Add(ret);
} }
//转换为JSON //转换为JSON
string UserJson = JsonConvert.SerializeObject(UserExamStat, Formatting.Indented); string UserJson = JsonConvert.SerializeObject(UserExamStat, Formatting.Indented);
Debug.Log("用户当前状态" + UserJson); Debug.Log("自动保存成功");
File.WriteAllText(localStatPath, UserJson); File.WriteAllText(localStatPath, UserJson);
} }
@ -140,13 +146,14 @@ public class ReconnectMgr : SingletonMono<ReconnectMgr>
foreach (BaseToolOrDevice item in allThings) foreach (BaseToolOrDevice item in allThings)
{ {
item.gameObject.SetActive(false);//先全部隐藏 item.gameObject.SetActive(false);//先全部隐藏
foreach (ReconnetItemInfo rec in UserExamStat.currentSceneTools) foreach (ReconnectItemInfo rec in UserExamStat.currentSceneTools)
{ {
if (item.itemInfo.toolName.Equals(rec.toolName) && item.itemInfo.toolId == rec.toolId) if (item.itemInfo.toolName.Equals(rec.toolName) && item.itemInfo.toolId == rec.toolId)
{ {
if (item.itemInfo.selfPosInToolRoom.Equals(rec.selfPosInToolRoom)) if (item.itemInfo.selfPosInToolRoom.Equals(rec.selfPosInToolRoom))
{ {
item.gameObject.SetActive(true); item.gameObject.SetActive(true);
break;
} }
} }
} }
@ -165,6 +172,24 @@ public class ReconnectMgr : SingletonMono<ReconnectMgr>
{ {
PacksackBagMgr.Instance.WearItemState(item, true); PacksackBagMgr.Instance.WearItemState(item, true);
} }
//恢复场景内各个触发器状态
PermanentTriggerBase[] allPermanentTriggers = FindObjectsOfType<PermanentTriggerBase>();
List<ReconnectTriggerInfo> allReconTrigs = UserExamStat.currentSceneTriggers;
foreach (PermanentTriggerBase item in allPermanentTriggers)
{
item.gameObject.SetActive(false);
foreach (ReconnectTriggerInfo ret in allReconTrigs)
{
if (item.triggerName == ret.triggerName)
{
item.gameObject.SetActive(true);
item.transform.localPosition = ret.selfPosInScene;
item.transform.localEulerAngles = ret.selfRotInScene;
break;
}
}
}
}); });
} }
// Start is called before the first frame update // Start is called before the first frame update