using System.Collections; using System.Collections.Generic; using UnityEngine; using System; using UnityEngine.UI; namespace DisComputer { /* * @func 零件格子 * @author lz * @data 2020/05/28 * */ public class SpareGrids : UIShowOrHide { [Header("格子信息")] public List gridInfos; /// /// 格子预制 /// public GameObject gridPrfGo; /// /// 格子数量 /// public int gridNum; private void Awake() { InitGrid(); } /// /// 实例化零件格子 /// void InitGrid() { for(int i = 0; i < gridNum; i++) { GameObject tempGridGo = Instantiate(gridPrfGo, this.transform); tempGridGo.transform.localPosition = new Vector3((-650+93*i),0,0); tempGridGo.SetActive(true); Grid grid = tempGridGo.GetComponent(); grid.initPos = tempGridGo.transform.position; GridInfo info = new GridInfo(); info.type = grid.type; info.grid = grid; gridInfos.Add(info); } } public override void OnShow(object data = null) { base.OnShow(data); if (data != null) { bool isDoubleHide = (bool)data; if (!isDoubleHide) return; } if(isShow) { OnHide(); return; } } /// /// 添加进格子 /// public void AddSpareToGrid(SpareType _type) { // Debug.LogFormat(">>>>>>>>>>>>> Add Fly Spare Type {0}", _type); for (int i = 0; i < gridNum; i++) { //Debug.LogFormat(">>>>>>>>>>>>> Add gridInfos[i].type {0}", gridInfos[i].type); if (gridInfos[i].type == SpareType.Null) { //Debug.LogFormat(">>>>>>>>>>>>> Add Fly Spare Type {0}",_type); gridInfos[i].type = _type; FlySpareAct(gridInfos[i]); break; } } } /// /// 清理所有格子信息 /// public void ResetAllGrid() { for (int i = 0; i < gridNum; i++) { gridInfos[i].type = SpareType.Null; gridInfos[i].grid.CleraGird(); } } /// /// 零件格子飞入 /// /// void FlySpareAct(GridInfo info) { GameObject flyGo = new GameObject("FlySpare"); flyGo.layer = 5; flyGo.transform.SetParent(this.transform.parent); flyGo.transform.localScale = new Vector3(1, 1, 1); flyGo.transform.localPosition = new Vector3(0, 0, 0); RawImage raw = flyGo.AddComponent(); raw.texture = info.grid.GetSpareTex(info.type); SpareFly fly = flyGo.AddComponent(); fly.FlyAction(info.grid.transform.position,()=> { info.grid.SetGridInfo(info.type); MessageContainer.SendMessage("temp", this, MsgName.MainViewGrowthBar); }); } } [Serializable] public class GridInfo { /// /// 格子存储数据 /// public SpareType type; /// /// 格子位置信息 /// public Grid grid; } public enum SpareType { Null, JiXiang, NeiCun, YingPan, XianKa, Cpu, DianYuan, GuangQu, ZhuBan } }