ShanxiKnowledgeBase/SXElectricalInspection/Assets/Script/Tool objects/Tools_object_UI.cs

79 lines
2.0 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class Tools_object_UI : MonoBehaviour
{
/// <summary>
/// 工具间的UI基础脚本
/// </summary>
//[HideInInspector]
public string UI_name;
[HideInInspector]
//public string sprite_name;
//public TMPro.TMP_Text text;
public Image sprite;
//[HideInInspector]
public GameObject targetobject;
public Button ;
// Start is called before the first frame update
void Start()
{
.onClick.AddListener(Destroy);
}
// Update is called once per frame
void Update()
{
}
public void change()
{
//
string name = KeepChinese(UI_name);
Debug.Log(name);
//if (Resources.Load("UI/" + name) != null)
//{
//Debug.Log(sprite_name);
Texture2D tubiao = Resources.Load("UI/"+ name) as Texture2D;
Debug.Log(tubiao);
Texture2D tubiao2 = Instantiate(tubiao) as Texture2D;
Sprite sprite3 = Sprite.Create(tubiao2, new Rect(0, 0, tubiao2.width, tubiao2.height), new Vector2(0.5f, 0.5f));
Debug.Log(sprite3);
sprite.GetComponent<Image>().sprite = sprite3;
// }
}
public void Destroy()
{
Destroy(gameObject);
targetobject.SetActive(true);
GameManager_Tools gameManager_Tools;
gameManager_Tools = GameObject.Find("GameManager_Tools").GetComponent<GameManager_Tools>();
gameManager_Tools.Remove_tool_Objects_Base(targetobject);
}
public static string KeepChinese(string str)
{
//声明存储结果的字符串
string chineseString = "";
//将传入参数中的中文字符添加到结果字符串中
for (int i = 0; i < str.Length; i++)
{
if (str[i] >= 0x4E00 && str[i] <= 0x9FA5) //汉字
{
chineseString += str[i];
}
}
//返回保留中文的处理结果
return chineseString;
}
}