unity ToolTip
来源:互联网 发布:mac上类似美图秀秀 编辑:程序博客网 时间:2024/05/16 23:44
UGUI
using UnityEngine;using System.Collections;using UnityEngine.EventSystems;using UnityEngine.UI;public class ToolTipManager : MonoBehaviour { public static ToolTipManager instance; private RectTransform rect; public Text name; public Image icon; public Text att; public Text introduce;// Use this for initialization void Awake() { instance = this; }void Start () { rect = GetComponent<RectTransform>(); SetToolTipPanelHide();}// Update is called once per framevoid Update () {} public void SetToolTipPanelShow(PointerEventData eventData,int itemID) { gameObject.SetActive(true); SetPosition(eventData); SetValue(itemID); } public void SetToolTipPanelHide() { gameObject.SetActive(false); } public void SetValue(int itemID) { BaseItem item = BaseItemMangager.instance.GetData(itemID); name.text = item.itemName; icon.sprite = (Sprite)Resources.Load("Texture/Shop/" +item.itemIcon, typeof(Sprite)); introduce.text = item.itemIntroduce; string str = ""; switch (item.itemType) { case ItemType.Equip: ItemEquipment tempEquipment = (ItemEquipment)item; str = "伤害:" + tempEquipment.itemATK + "\n" + "防御:" + tempEquipment.itemDEF + "\n" + "速度:" + tempEquipment.itemMS; break; case ItemType.Drug: ItemDrug tempDrug = (ItemDrug)item; str = "加蓝:" + tempDrug.itemAMP + "\n" + "加血:" + tempDrug.itemAHP + "\n"; break; } att.text = str; } public void SetPosition(PointerEventData eventData) { Vector3 worldPos; if(RectTransformUtility.ScreenPointToWorldPointInRectangle(rect,eventData.position,eventData.pressEventCamera,out worldPos)) { rect.position = worldPos; } }}
NGUI
using UnityEngine;using System.Collections;public class Tooltip : MonoBehaviour { public static Tooltip instance; public UILabel name; public UISprite icon; public UILabel att; public UILabel introduce; //private RectTransform itemRect; //private CanvasGroup canvasGroup; private bool isShow = false;// Use this for initializationvoid Start () { instance = this; //itemRect = GetComponent<RectTransform>(); //canvasGroup = GetComponent<CanvasGroup>(); //canvasGroup.alpha = 0; SetSelfActive(false);}// Update is called once per framevoid Update () { if (isShow) { SetPosition(); }} public void Show(Item item, ItemData itemData) { //eventD = eventData; SetPosition(); SetValue(item, itemData); //canvasGroup.alpha = 1; SetSelfActive(true); } public void Hide() { //canvasGroup.alpha = 0; SetSelfActive(false); } void SetSelfActive(bool b) { gameObject.SetActive(b); isShow = b; } public void SetValue(Item item, ItemData itemData) { name.text = itemData.itemName; icon.spriteName = item.itemImage.spriteName; introduce.text = itemData.itemIntroduce; string str = ""; switch(itemData.itemType) { case 0: ItemEquipment tempEquipment =(ItemEquipment)itemData ; str = "伤害:" + tempEquipment.itemDamage + "\n" + "命中:" + tempEquipment.itemHit + "\n" + "耐久:" + tempEquipment.itemDurable; break; case 1: ItemDrug tempDrug = (ItemDrug)itemData; str = "品质:" + tempDrug.itemQuality + "\n" + "恢复气血:" + tempDrug.itemAddHP + "\n" + "等级:" + tempDrug.itemLv; break; } att.text = str; } private void SetPosition() { transform.position = UICamera.currentCamera.ScreenToWorldPoint(Input.mousePosition); }}
0 0
- unity ToolTip
- ToolTip
- tooltip
- Tooltip
- tooltip
- tooltip
- How to change tooltip background color in Unity?
- tooltip , mask
- ToolTip练习
- DropDownList tooltip
- DropDownList tooltip
- ToolTip类
- 透明ToolTip
- 自定义ToolTip
- 自定义ToolTip
- Gridview Tooltip
- ToolTip换行
- ToolTip自定义
- Java网络编程(UDP)
- 关键字-分节2(static)
- webview系列:Html5页面和Native App怎么进行交互
- 关键字分节3(基本数据类型-short、int、long、char、float、double)
- reset css
- unity ToolTip
- 我的Direct3D之路2:学习第一个三角形绘制程序以及一些注意点
- 关键字-分节4(sizeof)
- 第三周项目3——求集合并集
- react-native笔记
- 考思科认证NA过程的学习笔记
- Remove Invalid Parentheses
- 关于ThreadLocal的一道面试题(酷我公司)
- spark 处理遇到的问题解决方法