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.
124 lines
2.6 KiB
124 lines
2.6 KiB
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<SpareTex> spareTexs;
|
|
|
|
[HideInInspector]
|
|
public Vector3 initPos;
|
|
|
|
/// <summary>
|
|
/// 当前检测的零件标签
|
|
/// </summary>
|
|
public string chectSpareTag;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <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);
|
|
}
|
|
else
|
|
{
|
|
spare_img.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 清理格子信息
|
|
/// </summary>
|
|
public void CleraGird()
|
|
{
|
|
spareName_txt.text = "";
|
|
type = SpareType.Null;
|
|
spare_img.texture = null;
|
|
spare_img.gameObject.SetActive(false);
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 点击零件
|
|
/// </summary>
|
|
public void OnPressDownSpare()
|
|
{
|
|
Debug.LogFormat("选取零件{0}", type.ToString());
|
|
this.spare_img.gameObject.SetActive(false);
|
|
MouseControl.Instance.SetDragSpare(this);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 显示零件图片
|
|
/// </summary>
|
|
public void ShowSpareImg()
|
|
{
|
|
this.spare_img.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;
|
|
}
|
|
}
|
|
|