using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using System; using UnityEngine.EventSystems; namespace DisComputer { /* * @func 格子控制 * @author lz * @data 2020/05/28 */ public class Grid : MonoBehaviour { public RawImage spare_img; public Text spareName_txt; public SpareType type; public List spareTexs; [HideInInspector] public Vector3 initPos; /// /// 当前检测的零件标签 /// public string chectSpareTag; /// /// 设置格子信息 /// /// public void SetGridInfo(SpareType spare) { type = spare; spareName_txt.text = CommonTool.GetSpareName(spare); spare_img.texture = GetSpareTex(spare); if(spare_img.texture == null) { spare_img.gameObject.SetActive(false); } else { spare_img.gameObject.SetActive(true); } } /// /// 清理格子信息 /// public void CleraGird() { spareName_txt.text = ""; type = SpareType.Null; spare_img.texture = null; spare_img.gameObject.SetActive(false); } /// /// 点击零件 /// public void OnPressDownSpare() { Debug.LogFormat("选取零件{0}", type.ToString()); this.spare_img.gameObject.SetActive(false); MouseControl.Instance.SetDragSpare(this); } /// /// 显示零件图片 /// public void ShowSpareImg() { this.spare_img.gameObject.SetActive(true); } /// /// 设置格子零件图片 /// /// /// public Texture2D GetSpareTex(SpareType spare) { for(int i=0;i< spareTexs.Count; i++) { if(spareTexs[i].type == spare) { return spareTexs[i].texture; } } return null; } } [Serializable] public class SpareTex { public Texture2D texture; public SpareType type; } }