forked from p7b2slgip/p65rsvefi
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
158 lines
4.0 KiB
158 lines
4.0 KiB
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<GridInfo> gridInfos;
|
|
|
|
/// <summary>
|
|
/// 格子预制
|
|
/// </summary>
|
|
public GameObject gridPrfGo;
|
|
|
|
/// <summary>
|
|
/// 格子数量
|
|
/// </summary>
|
|
public int gridNum;
|
|
|
|
private void Awake()
|
|
{
|
|
InitGrid();
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 实例化零件格子
|
|
/// </summary>
|
|
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>();
|
|
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;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 添加进格子
|
|
/// </summary>
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 清理所有格子信息
|
|
/// </summary>
|
|
public void ResetAllGrid()
|
|
{
|
|
for (int i = 0; i < gridNum; i++)
|
|
{
|
|
gridInfos[i].type = SpareType.Null;
|
|
gridInfos[i].grid.CleraGird();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 零件格子飞入
|
|
/// </summary>
|
|
/// <param name="info"></param>
|
|
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<RawImage>();
|
|
raw.texture = info.grid.GetSpareTex(info.type);
|
|
SpareFly fly = flyGo.AddComponent<SpareFly>();
|
|
fly.FlyAction(info.grid.transform.position,()=> {
|
|
info.grid.SetGridInfo(info.type);
|
|
MessageContainer.SendMessage("temp", this, MsgName.MainViewGrowthBar);
|
|
});
|
|
}
|
|
|
|
}
|
|
|
|
[Serializable]
|
|
public class GridInfo
|
|
{
|
|
/// <summary>
|
|
/// 格子存储数据
|
|
/// </summary>
|
|
public SpareType type;
|
|
/// <summary>
|
|
/// 格子位置信息
|
|
/// </summary>
|
|
public Grid grid;
|
|
}
|
|
|
|
|
|
public enum SpareType {
|
|
Null,
|
|
JiXiang,
|
|
NeiCun,
|
|
YingPan,
|
|
XianKa,
|
|
Cpu,
|
|
DianYuan,
|
|
GuangQu,
|
|
ZhuBan
|
|
}
|
|
|
|
}
|