223 lines
7.8 KiB
C#
223 lines
7.8 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
|
|
public class TooRoomMannger : SingletonMono<TooRoomMannger>
|
|
{
|
|
public List<BaseToolOrDevice> allTMDs;
|
|
public Transform toolParent;
|
|
public Transform headSlot;
|
|
public Transform bodySlot;
|
|
public Transform handSlot;
|
|
public Transform shoesSlot;
|
|
private List<Material> _cancel; //未穿戴材质球
|
|
private List<Material> _wear; //穿戴材质球
|
|
private FirstPersonController firstPersonController;
|
|
void Start()
|
|
{
|
|
allTMDs = toolParent.GetComponentsInChildren<BaseToolOrDevice>(true).ToList();
|
|
firstPersonController = GameObject.FindGameObjectWithTag("Player").GetComponent<FirstPersonController>();
|
|
GameManager.EventMgr.AddEventListener<bool>(Enum_EventType.PlayerCanMove, SwitchFirstPersonControllerMove);
|
|
_cancel = new List<Material>();
|
|
_wear = new List<Material>();
|
|
_cancel = Resources.LoadAll<Material>("Materials/CharacterEquip/Cancel").ToList();
|
|
_wear = Resources.LoadAll<Material>("Materials/CharacterEquip/Wear").ToList();
|
|
GameManager.EventMgr.EventTrigger(Enum_EventType.InitializationUI);
|
|
foreach (var tmd in allTMDs)
|
|
{
|
|
tmd.GetInfo();
|
|
}
|
|
RemoveRepeat();
|
|
CheckWearByWearDic();
|
|
|
|
if (GameManager.RunModelMgr.ModeType == E_ModeType.Study)
|
|
{
|
|
GameManager.EventMgr.AddEventListener<int>(Enum_EventType.SwitchSubProcess, SwitchSubProcess);
|
|
}
|
|
|
|
InitializationUI();
|
|
}
|
|
private void SwitchSubProcess(int subProcess)
|
|
{
|
|
if (!GameManager.UIMgr.GetPanel<UI_TopTipPanel>())
|
|
{
|
|
GameManager.UIMgr.ShowPanel<UI_TopTipPanel>(E_UI_Layer.Mid, (panel) =>
|
|
{
|
|
panel.Init($"{GameManager.ProcessMgr.d_Scheme.CurrentProcess.processName}:<color=#00EEE6>{GameManager.ProcessMgr.d_Scheme.CurrentProcess.CurrentSubProcess.subProcessName}</color>", $"{GameManager.ProcessMgr.d_Scheme.CurrentProcess.CurrentSubProcess.tips}", false);
|
|
});
|
|
}
|
|
else
|
|
{
|
|
GameManager.UIMgr.GetPanel<UI_TopTipPanel>().Init($"{GameManager.ProcessMgr.d_Scheme.CurrentProcess.processName}:<color=#00EEE6>{GameManager.ProcessMgr.d_Scheme.CurrentProcess.CurrentSubProcess.subProcessName}</color>", $"{GameManager.ProcessMgr.d_Scheme.CurrentProcess.CurrentSubProcess.tips}", false);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 通过wearDic数据检测是否穿衣
|
|
/// </summary>
|
|
public void CheckWearByWearDic()
|
|
{
|
|
var wearData = GameManager.PacksackBagMgr.wearDic;
|
|
if (wearData.Count > 0)
|
|
{
|
|
foreach (var item in wearData)
|
|
{
|
|
Wear(item.Key, true);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Wear("国网安全帽", false);
|
|
Wear("工作服", false);
|
|
Wear("绝缘手套", false);
|
|
Wear("绝缘靴", false);
|
|
}
|
|
}
|
|
|
|
public void SwitchFirstPersonControllerMove(bool isMove)
|
|
{
|
|
firstPersonController.playerCanMove = isMove;
|
|
}
|
|
/// <summary>
|
|
/// /移除重复问题
|
|
/// </summary>
|
|
public void RemoveRepeat()
|
|
{
|
|
var bagDatas = GameManager.PacksackBagMgr.GetCurrentBagData();
|
|
foreach (var item in bagDatas.Values)
|
|
{
|
|
foreach (var itemI in item)
|
|
{
|
|
for (int i = 0; i < allTMDs.Count; i++)
|
|
{
|
|
int index = i;
|
|
if (itemI.selfPosInToolRoom == allTMDs[index].itemInfo.selfPosInToolRoom)
|
|
{
|
|
Destroy(allTMDs[index].gameObject);
|
|
allTMDs.Remove(allTMDs[index]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 与模型联动
|
|
/// </summary>
|
|
/// <param name="equipName"></param>
|
|
/// <param name="isChange"></param>
|
|
public void Wear(string equipName, bool isChange)
|
|
{
|
|
Material ma = null;
|
|
if (isChange)
|
|
{
|
|
ma = _wear.SingleOrDefault(s => s.name == equipName);
|
|
}
|
|
else
|
|
{
|
|
ma = _cancel.SingleOrDefault(s => s.name == equipName);
|
|
}
|
|
|
|
switch (equipName)
|
|
{
|
|
case "国网安全帽":
|
|
headSlot.GetComponent<SkinnedMeshRenderer>().material = ma;
|
|
break;
|
|
case "工作服":
|
|
bodySlot.GetComponent<SkinnedMeshRenderer>().material = ma;
|
|
break;
|
|
case "绝缘手套":
|
|
handSlot.GetComponent<SkinnedMeshRenderer>().material = ma;
|
|
break;
|
|
case "绝缘靴":
|
|
shoesSlot.GetComponent<MeshRenderer>().material = ma;
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void InitializationUI()
|
|
{
|
|
if (!GameManager.UIMgr.GetPanel<UI_TaskListPanel>())
|
|
{
|
|
GameManager.UIMgr.ShowPanel<UI_TaskListPanel>(E_UI_Layer.Bot, (panel) =>
|
|
{
|
|
panel.Init(GameManager.ProcessMgr.subProcessId);
|
|
});
|
|
}
|
|
if (GameManager.RunModelMgr.ModeType == E_ModeType.Study)
|
|
{
|
|
GameManager.EventMgr.EventTrigger<string>(Enum_EventType.SwitchSubProcessStepTriggerID, ProcessManager.Instance.subProcessStepTriggerID);
|
|
GameManager.EventMgr.EventTrigger(Enum_EventType.SwitchSubProcess, GameManager.ProcessMgr.subProcessId);
|
|
}
|
|
if (!GameManager.UIMgr.GetPanel<UI_MenuBar>())
|
|
{
|
|
GameManager.UIMgr.ShowPanel<UI_MenuBar>(E_UI_Layer.Mid, (panel) =>
|
|
{
|
|
panel.Init();
|
|
GameManager.EventMgr.EventTrigger(Enum_EventType.SwitchScene, GameManager.RunModelMgr.SceneType);
|
|
});
|
|
}
|
|
GameManager.EventMgr.EventTrigger(Enum_EventType.SwitchMode);
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
GameManager.EventMgr.RemoveEventListener<bool>(Enum_EventType.PlayerCanMove, SwitchFirstPersonControllerMove);
|
|
GameManager.UIMgr.toolTips.HideTips();
|
|
GameManager.UIMgr.imageTips.HideTips();
|
|
if (GameManager.UIMgr.GetPanel<UI_MiddleTipPanel>())
|
|
{
|
|
GameManager.UIMgr.HidePanel<UI_MiddleTipPanel>();
|
|
}
|
|
Debug.Log("toolroomManager disable");
|
|
}
|
|
|
|
//private void OnDisable()
|
|
//{
|
|
// GameManager.EventMgr.RemoveEventListener<bool>(Enum_EventType.PlayerCanMove, SwitchFirstPersonControllerMove);
|
|
//}
|
|
|
|
public void CreateTool()
|
|
{
|
|
var bagDatas = GameManager.PacksackBagMgr.GetCurrentBagData();
|
|
var wearDate = GameManager.PacksackBagMgr.wearDic;
|
|
foreach (var item in bagDatas.Keys)
|
|
{
|
|
List<ItemInfo> temp = bagDatas[item];
|
|
for (int j = 0; j < temp.Count; j++)
|
|
{
|
|
int indexJ = j;
|
|
if (temp[indexJ].selfPosInToolRoom != Vector3.zero)
|
|
{
|
|
GameObject obj = Instantiate(temp[indexJ].objPrefab, toolParent);
|
|
obj.name = temp[indexJ].toolName;
|
|
obj.transform.position = temp[indexJ].selfPosInToolRoom;
|
|
obj.transform.eulerAngles = temp[indexJ].selfAngleInToolRoom;
|
|
obj.GetComponent<Tool_SelectComponent>().itemInfo = temp[indexJ];
|
|
obj.GetComponent<Tool_SelectComponent>().GetInfo();
|
|
}
|
|
}
|
|
}
|
|
allTMDs.Clear();
|
|
allTMDs = toolParent.GetComponentsInChildren<BaseToolOrDevice>(true).ToList();
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 工具架工具配置
|
|
/// </summary>
|
|
//public class ToolRoomSettingData
|
|
//{
|
|
// public string objname;
|
|
// public Vector3 initPostion;
|
|
|
|
// public ToolRoomSettingData(string objname, Vector3 initPostion)
|
|
// {
|
|
// this.e_ToolOrDeviceOrMaterials = e_toolOrDeviceOrMaterials;
|
|
// this.initPostion = initPostion;
|
|
// }
|
|
//}
|