using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; //============================================================ //支持中文,文件使用UTF-8编码 //@author #AUTHOR# //@create #CREATEDATE# //@company #COMPANY# // //@description: //============================================================ public class ToolItem : MonoBehaviour { public string toolName; public Button closeButton; public Button selfButton; public Image showIcon; public Vector3 originPos = new Vector3(); public Vector3 originAngle = new Vector3(); public GameObject prefab; public Attribute attribute = Attribute.defaultModel; public void SetValue(string name, Transform modelTransform) { toolName = name; closeButton.onClick.AddListener(OnClose); Texture2D icon = Resources.Load("New/UI/" + name); showIcon.sprite = ToSprite(icon); originPos = modelTransform.localPosition; originAngle = modelTransform.localEulerAngles; prefab = Resources.Load("New/Models/" + toolName); attribute = prefab.GetComponent().attribute; } public void SetState(bool isActive) { closeButton.gameObject.SetActive(isActive); selfButton.interactable = !isActive; } /// /// 判断自己是不是可以点击 /// public void SwitchSelfIsClick() { closeButton.gameObject.SetActive(false); if (attribute == Attribute.SafetyToolsAndInstruments) { selfButton.interactable = false; } else if (attribute == Attribute.ToolsAndInstruments) { selfButton.interactable = true; } else { } } private Sprite ToSprite(Texture2D t) { Sprite prite = Sprite.Create(t, new Rect(0, 0, t.width, t.height), new Vector2(0.5f, 0.5f)); return prite; } private void OnClose() { GameObject obj = Instantiate(prefab); obj.name = toolName; obj.transform.localPosition = originPos; obj.transform.localEulerAngles = originAngle; Destroy(gameObject); ToolsItemManager.Instance.RemoveNull(); } }