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.
280 lines
7.5 KiB
280 lines
7.5 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using System;
|
|
using UnityEngine.UI;
|
|
|
|
namespace DisComputer
|
|
{
|
|
/*
|
|
* @func 零件格子
|
|
* @author lz
|
|
* @date 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);
|
|
|
|
//ResetSpareGrids();
|
|
ResetSpareInfoGrids();
|
|
if (isShow)
|
|
{
|
|
OnHide();
|
|
return;
|
|
}
|
|
}
|
|
|
|
private bool isInit = false;
|
|
|
|
|
|
/// <summary>
|
|
/// 初始化格子信息
|
|
/// </summary>
|
|
private void ResetSpareInfoGrids()
|
|
{
|
|
if (isInit)
|
|
return;
|
|
|
|
ResetAllGrid();
|
|
isInit = true;
|
|
|
|
SpareType[] spares = GameConfig.GetItemInfos;
|
|
List<SpareInfo> spareInfos = new List<SpareInfo>();
|
|
if(GameDataConfig.Instance.pcId == 1)
|
|
{
|
|
spareInfos = GameDataConfig.Instance.AllSpareInfos();
|
|
}else
|
|
{
|
|
spareInfos = GameDataConfig.Instance.gameSpareInfos();
|
|
}
|
|
|
|
|
|
if (GameConfig.state == GameState.Load) {
|
|
|
|
for (int i = 0; i < gridNum; i++)
|
|
{
|
|
|
|
for(int j = 0;j < spareInfos.Count; j++)
|
|
{
|
|
|
|
if(spares[i] == spareInfos[j].type)
|
|
{
|
|
if (i >= GameConfig.curProgressIndex)
|
|
{
|
|
if (gridInfos[i].type == SpareType.Null)
|
|
{
|
|
gridInfos[i].type = spares[i];
|
|
|
|
gridInfos[i].grid.SetGridInfo(spareInfos[j]);
|
|
}
|
|
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
else
|
|
{
|
|
|
|
for (int i = 0; i < gridNum; i++)
|
|
{
|
|
for(int j = 0;j < spareInfos.Count; j++)
|
|
{
|
|
|
|
if(spares[i] == spareInfos[j].type)
|
|
{
|
|
if (i <= GameConfig.curProgressIndex - 1)
|
|
{
|
|
if (gridInfos[i].type == SpareType.Null)
|
|
{
|
|
gridInfos[i].type = spares[i];
|
|
Debug.LogFormat(">>>>>>>> j {0}",j);
|
|
gridInfos[i].grid.SetGridInfo(spareInfos[j]);
|
|
}
|
|
|
|
}
|
|
break;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 添加进格子
|
|
/// </summary>
|
|
public void AddSpareToGrid(SpareType _type)
|
|
{
|
|
|
|
for (int i = 0; i < gridNum; i++)
|
|
{
|
|
|
|
if (gridInfos[i].type == SpareType.Null)
|
|
{
|
|
|
|
gridInfos[i].type = _type;
|
|
FlySpareAct(gridInfos[i]);
|
|
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void AddSpareToGrid(SpareInfo info)
|
|
{
|
|
|
|
for (int i = 0; i < gridNum; i++)
|
|
{
|
|
|
|
if (gridInfos[i].type == SpareType.Null)
|
|
{
|
|
|
|
gridInfos[i].type = info.type;
|
|
FlySpareAct(gridInfos[i],info);
|
|
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 清理所有格子信息
|
|
/// </summary>
|
|
public void ResetAllGrid()
|
|
{
|
|
for (int i = 0; i < gridNum; i++)
|
|
{
|
|
gridInfos[i].type = SpareType.Null;
|
|
gridInfos[i].grid.CleraGird();
|
|
}
|
|
isInit = false;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 零件格子飞入
|
|
/// </summary>
|
|
/// <param name="info"></param>
|
|
void FlySpareAct(GridInfo _gridInfo)
|
|
{
|
|
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 = _gridInfo.grid.GetSpareTex(_gridInfo.type);
|
|
SpareFly fly = flyGo.AddComponent<SpareFly>();
|
|
fly.FlyAction(_gridInfo.grid.transform.position,()=> {
|
|
_gridInfo.grid.SetGridInfo(_gridInfo.type);
|
|
MessageContainer.SendMessage("temp", this, MsgName.MainViewGrowthBar);
|
|
});
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 零件格子飞入
|
|
/// </summary>
|
|
/// <param name="_gridInfo"></param>
|
|
/// <param name="info"></param>
|
|
void FlySpareAct(GridInfo _gridInfo,SpareInfo 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.texture;
|
|
SpareFly fly = flyGo.AddComponent<SpareFly>();
|
|
fly.FlyAction(_gridInfo.grid.transform.position, () => {
|
|
_gridInfo.grid.SetGridInfo(_gridInfo.type,info);
|
|
MessageContainer.SendMessage("temp", this, MsgName.MainViewGrowthBar);
|
|
});
|
|
}
|
|
|
|
}
|
|
|
|
[Serializable]
|
|
public class GridInfo
|
|
{
|
|
/// <summary>
|
|
/// 格子存储数据
|
|
/// </summary>
|
|
public SpareType type;
|
|
/// <summary>
|
|
/// 格子位置信息
|
|
/// </summary>
|
|
public Grid grid;
|
|
}
|
|
|
|
|
|
public enum SpareType {
|
|
JiXiang,
|
|
NeiCun,
|
|
YingPan,
|
|
XianKa,
|
|
Cpu,
|
|
DianYuan,
|
|
GuangQu,
|
|
ZhuBan,
|
|
Null
|
|
}
|
|
|
|
}
|