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.
322 lines
8.5 KiB
322 lines
8.5 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using System;
|
|
using UnityEngine.EventSystems;
|
|
|
|
namespace DisComputer
|
|
{
|
|
/*
|
|
* @func 格子控制
|
|
* @author lz
|
|
* @date 2020/05/28
|
|
*/
|
|
public class Grid : MonoBehaviour
|
|
{
|
|
|
|
|
|
//零件详细信息
|
|
public SpareInfo spareInfo;
|
|
|
|
//零件图片挂载
|
|
public RawImage spare_img;
|
|
//零件名称
|
|
public Text spareName_txt;
|
|
|
|
//零件类型
|
|
public SpareType type;
|
|
//零件贴图
|
|
public List<SpareTex> spareTexs;
|
|
|
|
//初始位置信息
|
|
[HideInInspector]
|
|
public Vector3 initPos;
|
|
|
|
/// <summary>
|
|
/// 当前检测的零件标签
|
|
/// </summary>
|
|
public string chectSpareTag;
|
|
|
|
//鼠标响应层
|
|
public Image mouse_Btn;
|
|
|
|
//零件列表
|
|
public GameObject scrollGo;
|
|
//content
|
|
public Transform scrollRootTran;
|
|
//item
|
|
public SpareScrollItem item;
|
|
|
|
|
|
private void Awake()
|
|
{
|
|
EventTrigger trigger = mouse_Btn.GetComponent<EventTrigger>();
|
|
//点击下事件
|
|
EventTrigger.Entry entryDown = new EventTrigger.Entry();
|
|
entryDown.eventID = EventTriggerType.PointerDown;
|
|
entryDown.callback.AddListener((data)=>
|
|
{
|
|
OnPressDownSpare((PointerEventData)data);
|
|
});
|
|
trigger.triggers.Add(entryDown);
|
|
|
|
EventTrigger.Entry entryOnPoint = new EventTrigger.Entry();
|
|
entryOnPoint.eventID = EventTriggerType.PointerClick;
|
|
entryOnPoint.callback.AddListener((data) => {
|
|
OnClickPoint((PointerEventData)data);
|
|
});
|
|
trigger.triggers.Add(entryOnPoint);
|
|
|
|
|
|
mouse_Btn.gameObject.SetActive(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 设置格子信息
|
|
/// </summary>
|
|
/// <param name="spare"></param>
|
|
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);
|
|
mouse_Btn.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
spare_img.gameObject.SetActive(true);
|
|
mouse_Btn.gameObject.SetActive(true);
|
|
}
|
|
//创建滚动列表
|
|
CreateScrollItem(spare);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置格子信息
|
|
/// </summary>
|
|
/// <param name="info"></param>
|
|
public void SetGridInfo(SpareInfo info)
|
|
{
|
|
this.spareInfo = info;
|
|
type = info.type;
|
|
spareName_txt.text = CommonTool.GetSpareName(info.type);
|
|
|
|
spare_img.texture = info.texture;
|
|
if (spare_img.texture == null)
|
|
{
|
|
spare_img.gameObject.SetActive(false);
|
|
mouse_Btn.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
spare_img.gameObject.SetActive(true);
|
|
mouse_Btn.gameObject.SetActive(true);
|
|
}
|
|
//创建滚动列表
|
|
CreateScrollItem(info.type);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 设置详细信息
|
|
/// </summary>
|
|
/// <param name="spare"></param>
|
|
/// <param name="info"></param>
|
|
public void SetGridInfo(SpareType spare,SpareInfo info)
|
|
{
|
|
type = spare;
|
|
this.spareInfo = info;
|
|
spareName_txt.text = CommonTool.GetSpareName(spare);
|
|
|
|
spare_img.texture = info.texture;
|
|
if (spare_img.texture == null)
|
|
{
|
|
spare_img.gameObject.SetActive(false);
|
|
mouse_Btn.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
spare_img.gameObject.SetActive(true);
|
|
mouse_Btn.gameObject.SetActive(true);
|
|
}
|
|
|
|
|
|
if(info.type!= SpareType.ZhuBan || info.type != SpareType.JiXiang)
|
|
{
|
|
//创建滚动列表
|
|
CreateScrollItem(spare);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 清理格子信息
|
|
/// </summary>
|
|
public void CleraGird()
|
|
{
|
|
spareName_txt.text = "";
|
|
type = SpareType.Null;
|
|
spare_img.texture = null;
|
|
spare_img.gameObject.SetActive(false);
|
|
mouse_Btn.gameObject.SetActive(false);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 设置当前选择零件
|
|
/// </summary>
|
|
/// <param name="info"></param>
|
|
public void SetCurSpareInfo(SpareInfo info)
|
|
{
|
|
|
|
spareInfo = info;
|
|
spare_img.texture = info.texture;
|
|
Debug.LogFormat(">>>>>>>>>>>> name {0}", info.name);
|
|
//对应零件切换皮肤
|
|
PcControl.Instance.ChangeCurSpareSkin(info);
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 加入零件列表
|
|
/// </summary>
|
|
/// <param name="spare"></param>
|
|
void CreateScrollItem(SpareType spare)
|
|
{
|
|
|
|
if (GameConfig.state == GameState.Unload)
|
|
return;
|
|
|
|
if (scrollRootTran.childCount>1)
|
|
return;
|
|
|
|
SpareInfoConfig infoConfig = null;
|
|
for (int i = 0; i < GameDataConfig.Instance.infoConfig.Count; i++)
|
|
{
|
|
|
|
if(GameDataConfig.Instance.infoConfig[i].type == spare)
|
|
{
|
|
//Debug.LogFormat(">>>> >>>> {0}", spare);
|
|
infoConfig = GameDataConfig.Instance.infoConfig[i];
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (infoConfig == null)
|
|
return;
|
|
|
|
|
|
int[] randomArr = LzFramework.FuncTools.CreateRanArrVal(infoConfig.infos.Count, infoConfig.infos.Count).ToArray();
|
|
|
|
for (int k = 0;k < infoConfig.infos.Count; k++)
|
|
{
|
|
|
|
GameObject tempItem = Instantiate(item.gameObject);
|
|
tempItem.transform.SetParent(scrollRootTran);
|
|
SpareScrollItem itemTemp = tempItem.GetComponent<SpareScrollItem>();
|
|
itemTemp.RegistGrid(this);
|
|
tempItem.SetActive(true);
|
|
tempItem.transform.localScale = new Vector3(1, 1, 1);
|
|
//itemTemp.spareInfo = infoConfig.infos[k];
|
|
itemTemp.spareInfo = infoConfig.infos[randomArr[k]];
|
|
itemTemp.SetScrollItem();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 点击零件
|
|
/// </summary>
|
|
void OnPressDownSpare(PointerEventData data)
|
|
{
|
|
if (Input.GetMouseButton(0))
|
|
{
|
|
scrollGo.SetActive(false);
|
|
}
|
|
|
|
MouseControl.Instance.SetDragSpare(this,()=>
|
|
{
|
|
this.spare_img.gameObject.SetActive(false);
|
|
mouse_Btn.gameObject.SetActive(false);
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 鼠标点击选择零件
|
|
/// </summary>
|
|
/// <param name="data"></param>
|
|
void OnClickPoint(PointerEventData data)
|
|
{
|
|
if(GameConfig.state == GameState.Load)
|
|
{
|
|
if(GameDataConfig.Instance.pcId == 1)
|
|
{
|
|
if (spareInfo.type != SpareType.JiXiang || spareInfo.type != SpareType.ZhuBan)
|
|
scrollGo.SetActive(!scrollGo.activeSelf);
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 显示零件图片
|
|
/// </summary>
|
|
public void ShowSpareImg()
|
|
{
|
|
this.spare_img.gameObject.SetActive(true);
|
|
mouse_Btn.gameObject.SetActive(true);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 设置格子零件图片
|
|
/// </summary>
|
|
/// <param name="spare"></param>
|
|
/// <returns></returns>
|
|
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;
|
|
}
|
|
}
|
|
|