89 lines
2.7 KiB
C#
89 lines
2.7 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using DG.Tweening;
|
||
using UnityEngine.EventSystems;
|
||
//============================================================
|
||
//支持中文,文件使用UTF-8编码
|
||
//@author YangHua
|
||
//@create 20230914
|
||
//@company QianHuo
|
||
//
|
||
//@description:c常驻工具脚本
|
||
//============================================================
|
||
namespace Components
|
||
{
|
||
public enum ModeName
|
||
{
|
||
defaultName,
|
||
Panel,
|
||
WorkCard
|
||
|
||
}
|
||
public class PermanentToolItem : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
|
||
{
|
||
public string NameSelf;
|
||
public Button selfBtn;
|
||
public Text showName;
|
||
public GameObject tips;
|
||
public GameObject panel;
|
||
public ModeName modeName = ModeName.defaultName;
|
||
|
||
|
||
// Use this for initialization
|
||
private void Start()
|
||
{
|
||
if (modeName == ModeName.Panel)
|
||
panel.SetActive(false);
|
||
selfBtn.onClick.AddListener(() =>
|
||
{
|
||
UIManager.Instance.ToolsItemManager.SwictchToolPanel(false);
|
||
if (modeName == ModeName.Panel)
|
||
OnMobielSelf();
|
||
else if (modeName == ModeName.WorkCard)
|
||
OnWorkCard();
|
||
|
||
});
|
||
}
|
||
|
||
public void OnMobielSelf()
|
||
{
|
||
panel.SetActive(true);
|
||
}
|
||
|
||
public void OnWorkCard()
|
||
{
|
||
SetWorkCardPos();
|
||
UIManager.Instance.ToolsItemManager.recoverBtn.gameObject.SetActive(true);
|
||
UIManager.Instance.ToolsItemManager.bottomToolToggle.interactable = false;
|
||
}
|
||
|
||
private void SetWorkCardPos()
|
||
{
|
||
GameObject objPrefab = Resources.Load<GameObject>("New/Models/工作证");
|
||
GameObject player = GameObject.FindGameObjectWithTag("Player");
|
||
GameObject obj = Instantiate(objPrefab);
|
||
UIManager.Instance.ToolsItemManager.currentTool = obj;
|
||
obj.transform.SetParent(player.transform);
|
||
obj.transform.localPosition = Vector3.zero;
|
||
Vector3 pos = player.transform.position + player.transform.forward * 1f;
|
||
obj.transform.DOMove(new Vector3(pos.x, pos.y + 0.4f, pos.z), 0.5f);
|
||
obj.transform.DOLocalRotate(new Vector3(-30f, 0f, 0f), 0.5f);
|
||
|
||
}
|
||
|
||
public void OnPointerEnter(PointerEventData eventData)
|
||
{
|
||
showName.text = NameSelf;
|
||
tips.transform.position = transform.position + new Vector3(0, 35, 0);
|
||
tips.SetActive(true);
|
||
}
|
||
|
||
public void OnPointerExit(PointerEventData eventData)
|
||
{
|
||
tips.SetActive(false);
|
||
}
|
||
}
|
||
}
|