115 lines
2.8 KiB
C#
115 lines
2.8 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using TMPro;
|
||
using UnityEngine;
|
||
using UnityEngine.EventSystems;
|
||
using UnityEngine.UI;
|
||
/// <summary>
|
||
/// 锻造材料脚本
|
||
/// </summary>
|
||
public class ForgingMaterial_Mon : MonoBehaviour, IDragHandler, IBeginDragHandler, IEndDragHandler
|
||
{
|
||
/// <summary>
|
||
/// 材料组件储存的材料id
|
||
/// </summary>
|
||
private int id;
|
||
|
||
/// <summary>
|
||
/// 材料数量
|
||
/// </summary>
|
||
private TextMeshProUGUI textMeshProUGUI;
|
||
/// <summary>
|
||
/// 材料图标
|
||
/// </summary>
|
||
private Image image;
|
||
/// <summary>
|
||
/// 拖动状态:false未拖动,true正在拖动
|
||
/// </summary>
|
||
private bool dragstate;
|
||
/// <summary>
|
||
/// 初始化游戏加载相关组件
|
||
/// </summary>
|
||
private void LoadGame()
|
||
{
|
||
this.textMeshProUGUI = this.transform.GetChild(1).GetComponent<TextMeshProUGUI>();
|
||
this.image=this.transform.GetChild(0).GetComponent<Image>();
|
||
this.dragstate = false;
|
||
|
||
|
||
|
||
|
||
}
|
||
/// <summary>
|
||
/// 设置材料显示
|
||
/// </summary>
|
||
/// <param name="article_">材料</param>
|
||
/// <param name="mun_">数量</param>
|
||
public void setArticle(Article article_ ,int mun_)
|
||
{
|
||
this.textMeshProUGUI.text=mun_.ToString();
|
||
this.image.sprite=article_.getIcon();
|
||
this.id=article_.getId();
|
||
}
|
||
private void Awake()
|
||
{
|
||
this.LoadGame();
|
||
}
|
||
void Start()
|
||
{
|
||
|
||
}
|
||
|
||
void Update()
|
||
{
|
||
}
|
||
/// <summary>
|
||
/// 返回材料组件对应的材料id
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public int getId() {
|
||
return id;
|
||
}
|
||
|
||
|
||
public void OnDrag(PointerEventData eventData)
|
||
{
|
||
//Debug.Log("拖拽");
|
||
|
||
|
||
}
|
||
|
||
public void OnBeginDrag(PointerEventData eventData)
|
||
{
|
||
|
||
if (GameObject.FindGameObjectWithTag("铁匠玩家").GetComponent<BlacksmithPlayer_Mon>().GetBlacksmithType() != BlacksmithType.WAIT)
|
||
{
|
||
Debug.LogError("未开店请检测店铺状态");
|
||
return;
|
||
}
|
||
//Debug.Log("开始拖动");
|
||
GameObject go_ = Instantiate(Resources.Load<GameObject>("预制件/拖动对象"));
|
||
go_.transform.SetParent(GameObject.Find("UI").transform);
|
||
go_.transform.position = this.transform.position;
|
||
go_.GetComponent<DragObject_Mon>().setforgingMaterial_Mon(this);
|
||
//切换拖动状态
|
||
this.dragstate = true;
|
||
}
|
||
|
||
public void OnEndDrag(PointerEventData eventData)
|
||
{
|
||
//Debug.Log("拖动结束");
|
||
//拖动状态结束
|
||
this.dragstate=false;
|
||
|
||
}
|
||
/// <summary>
|
||
/// 获取材料组建的拖动状态
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public bool getdrastate()
|
||
{
|
||
return this.dragstate;
|
||
}
|
||
}
|
||
|