111 lines
2.5 KiB
C#
111 lines
2.5 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using System.Collections.Generic;
|
|
using Unity.VisualScripting;
|
|
|
|
public class TooslManager : MonoBehaviour
|
|
{
|
|
[System.Serializable]
|
|
public class Tool
|
|
{
|
|
/// <summary>
|
|
/// 工具
|
|
/// </summary>
|
|
public GameObject toolObject;
|
|
|
|
/// <summary>
|
|
/// 复位按钮
|
|
/// </summary>
|
|
public Button returnButton;
|
|
[HideInInspector]
|
|
public Vector3 originalPosition;
|
|
[HideInInspector]
|
|
public Quaternion originalRotation;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<Tool> tools;
|
|
|
|
/// <summary>
|
|
/// 在梯子上使用的工具
|
|
/// </summary>
|
|
// public GameObject[] onladderTools;
|
|
|
|
public Transform PlayercameraTrans;
|
|
|
|
public static TooslManager instance;
|
|
|
|
/// <summary>
|
|
/// 引用Ladder脚本
|
|
/// </summary>
|
|
public Fieldobservation Fieldobservation;
|
|
|
|
public void Awake()
|
|
{
|
|
instance = this;
|
|
}
|
|
|
|
void Start()
|
|
{
|
|
foreach (var tool in tools)
|
|
{
|
|
// 保存每个工具的原始位置和旋转
|
|
tool.originalPosition = tool.toolObject.transform.localPosition;
|
|
tool.originalRotation = tool.toolObject.transform.localRotation;
|
|
Debug.Log("第一个位置:" + tool.originalPosition);
|
|
// 为每个按钮添加点击事件
|
|
tool.returnButton.onClick.AddListener(ResetAllTools);
|
|
}
|
|
}
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
// 返回所有工具到原始位置并隐藏
|
|
public void ResetAllTools()
|
|
{
|
|
foreach (var tool in tools)
|
|
{
|
|
tool.toolObject.transform.SetParent(PlayercameraTrans.transform);
|
|
tool.toolObject.transform.localPosition = tool.originalPosition;
|
|
tool.toolObject.transform.localRotation = tool.originalRotation;
|
|
tool.toolObject.SetActive(false);
|
|
Debug.Log("第二个位置:" + tool.originalPosition);
|
|
}
|
|
}
|
|
|
|
///// <summary>
|
|
///// 梯子上禁用
|
|
///// </summary>
|
|
//void DisableTools()
|
|
//{
|
|
// foreach (GameObject tool in onladderTools)
|
|
// {
|
|
// // 禁用工具
|
|
// tool.SetActive(false);
|
|
// }
|
|
//}
|
|
|
|
///// <summary>
|
|
///// 梯子上可以使用
|
|
///// </summary>
|
|
//void UseTools()
|
|
//{
|
|
// foreach (GameObject tool in onladderTools)
|
|
// {
|
|
// // 启用工具,模拟使用工具的效果
|
|
// tool.SetActive(true);
|
|
// }
|
|
//}
|
|
//void ToggleTools(bool activate)
|
|
//{
|
|
// foreach (GameObject tool in onladderTools)
|
|
// {
|
|
// tool.SetActive(activate);
|
|
// }
|
|
//}
|
|
}
|