WXGame/b1/Assets/脚本/锻造材料/ForgingMaterial_Mon.cs
2024-10-23 09:14:01 +08:00

115 lines
2.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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;
}
}