225 lines
6.3 KiB
C#
225 lines
6.3 KiB
C#
using MotionFramework;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using DefaultNamespace.ProcessMode;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
/// <summary>
|
|
/// 点击背包中的工具场景出现
|
|
/// </summary>
|
|
public class ToolManager : MonoBehaviour
|
|
{
|
|
//public GameObject toolPrefab; // 要生成的工具预制体
|
|
public Transform generateArea; // 生成区域的Transform
|
|
|
|
private GenerateArea generateAreaScript;
|
|
|
|
public GameObject ui;
|
|
public Button processBt;
|
|
/// <summary>
|
|
/// 放回背包按钮
|
|
/// </summary>
|
|
public Button PutBack;
|
|
public GameObject[] Tool;
|
|
|
|
/// <summary>
|
|
/// 收回工具按钮
|
|
/// </summary>
|
|
public Button[] RetractBtn;
|
|
|
|
public bool inthis = false;
|
|
|
|
public static ToolManager instans;
|
|
|
|
private void Awake()
|
|
{
|
|
instans = this;
|
|
}
|
|
void Start()
|
|
{
|
|
|
|
//inthis = true;
|
|
generateAreaScript = generateArea.GetComponent<GenerateArea>();
|
|
MotionEngine.GetModule<AnimationProcessManager>().OnUIEvent += UIEvent;
|
|
|
|
PutBack.onClick.AddListener(() =>
|
|
{
|
|
if (Tool[0].activeInHierarchy)
|
|
{
|
|
Tool[0].gameObject.SetActive(false);
|
|
Ladder.instance.closed();
|
|
}
|
|
if (Tool[1].activeInHierarchy)
|
|
{
|
|
Tool[1].gameObject.SetActive(false);
|
|
}
|
|
if (Tool[2].activeInHierarchy)
|
|
{
|
|
Tool[2].gameObject.SetActive(false);
|
|
}
|
|
if (Tool[3].activeInHierarchy)
|
|
{
|
|
Tool[3].gameObject.SetActive(false);
|
|
}
|
|
if (Tool[4].activeInHierarchy)
|
|
{
|
|
Tool[4].gameObject.SetActive(false);
|
|
}
|
|
if (Tool[5].activeInHierarchy)
|
|
{
|
|
Tool[5].gameObject.SetActive(false);
|
|
}
|
|
if (Tool[7].activeInHierarchy)
|
|
{
|
|
Tool[7].gameObject.SetActive(false);
|
|
}
|
|
});
|
|
processBt.onClick.AddListener(delegate
|
|
{
|
|
ui.SetActive(false);
|
|
});
|
|
MotionEngine.GetModule<ToolsPackManager>().OnStringEvent += HandleStringEvents;
|
|
|
|
//MotionEngine.GetModule<ToolsPackManager>().OnStringEvent += HandleStringEvent;
|
|
|
|
}
|
|
private void Update()
|
|
{
|
|
//if (RoleMove.instance.isup)
|
|
//{
|
|
// MotionEngine.GetModule<ToolsPackManager>().OnStringEvent += HandleStringEvent;
|
|
// Debug.Log("在梯子上:");
|
|
//}
|
|
//else
|
|
//{
|
|
// MotionEngine.GetModule<ToolsPackManager>().OnStringEvent -= HandleStringEvent;
|
|
// Debug.Log("不在梯子上:");
|
|
//}
|
|
// Debug.Log("是否在梯子上:" + RoleMove.instance.isup);
|
|
}
|
|
private void UIEvent()
|
|
{
|
|
ui.SetActive(true);
|
|
}
|
|
|
|
|
|
|
|
public void HandleTiZiEvent(string message)
|
|
{
|
|
if (generateAreaScript.IsPlayerInArea())
|
|
{
|
|
if (message == "梯子")
|
|
{
|
|
Tool[0].gameObject.SetActive(true);
|
|
Ladder.instance.Init();
|
|
}
|
|
}
|
|
}
|
|
public void HandleStringEvent(string message)
|
|
{
|
|
if (generateAreaScript.IsPlayerInArea())
|
|
{
|
|
if (message == "梯子")
|
|
{
|
|
Tool[0].gameObject.SetActive(true);
|
|
Ladder.instance.Init();
|
|
}
|
|
if (message == "工作证")
|
|
{
|
|
Tool[1].gameObject.SetActive(true);
|
|
}
|
|
if (message == "剥线钳")
|
|
{
|
|
Tool[2].gameObject.SetActive(true);
|
|
RetractBtn[0].gameObject.SetActive(true);
|
|
}
|
|
if (message == "验电笔")
|
|
{
|
|
Tool[3].gameObject.SetActive(true);
|
|
RetractBtn[1].gameObject.SetActive(true);
|
|
}
|
|
if (message == "螺丝刀")
|
|
{
|
|
Tool[4].gameObject.SetActive(true);
|
|
RetractBtn[2].gameObject.SetActive(true);
|
|
}
|
|
if (message == "绝缘胶带")
|
|
{
|
|
Tool[5].gameObject.SetActive(true);
|
|
RetractBtn[3].gameObject.SetActive(true);
|
|
}
|
|
|
|
if (message == "l型集中器")
|
|
{
|
|
Tool[6].gameObject.SetActive(true);
|
|
RetractBtn[4].gameObject.SetActive(true);
|
|
}
|
|
if (message == "盒装封印")
|
|
{
|
|
Tool[7].gameObject.SetActive(true);
|
|
RetractBtn[5].gameObject.SetActive(true);
|
|
}
|
|
|
|
Debug.Log("Received message: " + message);
|
|
}
|
|
}
|
|
public void HandleStringEvents(string message)
|
|
{
|
|
if (generateAreaScript.IsPlayerInArea())
|
|
{
|
|
if (message == "梯子")
|
|
{
|
|
Tool[0].gameObject.SetActive(true);
|
|
Ladder.instance.Init();
|
|
}
|
|
if (message == "验电笔")
|
|
{
|
|
Tool[3].gameObject.SetActive(true);
|
|
RetractBtn[1].gameObject.SetActive(true);
|
|
}
|
|
if (message == "工作证")
|
|
{
|
|
Tool[1].gameObject.SetActive(true);
|
|
}
|
|
}
|
|
if (RoleMove.instance.isup)
|
|
{
|
|
|
|
if (generateAreaScript.IsPlayerInArea())
|
|
{
|
|
if (message == "剥线钳")
|
|
{
|
|
Tool[2].gameObject.SetActive(true);
|
|
RetractBtn[0].gameObject.SetActive(true);
|
|
}
|
|
|
|
if (message == "螺丝刀")
|
|
{
|
|
Tool[4].gameObject.SetActive(true);
|
|
RetractBtn[2].gameObject.SetActive(true);
|
|
}
|
|
if (message == "绝缘胶带")
|
|
{
|
|
Tool[5].gameObject.SetActive(true);
|
|
RetractBtn[3].gameObject.SetActive(true);
|
|
}
|
|
|
|
if (message == "l型集中器")
|
|
{
|
|
Tool[6].gameObject.SetActive(true);
|
|
// RetractBtn[4].gameObject.SetActive(true);
|
|
}
|
|
if (message == "盒装封印")
|
|
{
|
|
Tool[7].gameObject.SetActive(true);
|
|
RetractBtn[4].gameObject.SetActive(true);
|
|
}
|
|
|
|
Debug.Log("Received message: " + message);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|