Unity类银河恶魔城学习记录12-18,19 p140 Options UI-p141 Finalising ToolTip源代码

  Alex教程每一P的教程原代码加上我自己的理解初步理解写的注释,可供学习Alex教程的人参考
此代码仅为较上一P有所改变的代码

【Unity教程】从0编程制作类银河恶魔城游戏_哔哩哔哩_bilibili

 

UI_ToolTip.cs
using TMPro;
using UnityEngine;public class UI_ToolTip : MonoBehaviour
{[SerializeField] private float xLimit = 960;[SerializeField] private float yLimit = 540;[SerializeField] private float xOffset = 150;[SerializeField] private float yOffset = 150;public virtual void AdjustPosition()//设置toolTip位置函数{Vector2 mousePosition = Input.mousePosition;float newXoffset = 0;float newYoffset = 0;if (mousePosition.x > xLimit){newXoffset = -xOffset;}else{newXoffset = xOffset;}if (mousePosition.y > yLimit){newYoffset = -yOffset;}else{newYoffset = yOffset;}transform.position = new Vector2(mousePosition.x + newXoffset, mousePosition.y + newYoffset);Debug.Log(123);}public void AdjustFontSize(TextMeshProUGUI _text) //调试文字大小函数{if(_text.text.Length > 12){_text.fontSize = _text.fontSize * .8f;}}
}
Ui_SkillToolTip.cs
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;public class Ui_SkillToolTip : UI_ToolTip//制作一个可以检查每个技能的描述的窗口
{[SerializeField] private TextMeshProUGUI skillDescription;[SerializeField] private TextMeshProUGUI skillName;[SerializeField] private TextMeshProUGUI skillCost;[SerializeField] private float defaultNameFontSize;public void ShowToolTip(string _skillDescription,string _skillName,string _SkillCost){skillDescription.text = _skillDescription;skillName.text = _skillName;skillCost.text = "Cost : " +  _SkillCost;AdjustPosition();AdjustFontSize(skillName);gameObject.SetActive(true);}public void HideToolTip(){skillName.fontSize = defaultNameFontSize;gameObject.SetActive(false);}}

UI_SkillTreeSlot.cs
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;public class UI_SkillTreeSlot : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{[SerializeField] private int skillCost;[SerializeField] private string skillName;[TextArea][SerializeField] private string skillDescription;[SerializeField] private Color lockedSkillColor;private UI ui;public bool unlocked;//一个表示是否解锁的bool值private Image skillImage;[SerializeField] private UI_SkillTreeSlot[] shouldBeUnlocked;[SerializeField] private UI_SkillTreeSlot[] shouldBeLocked;//应该解锁和不该解锁的Slot组和Imageprivate void OnValidate(){gameObject.name = "SkillTreeSlot_UI - " + skillName;}private void Awake(){GetComponent<Button>().onClick.AddListener(() => UnlockSkillSlot());}private void Start(){skillImage = GetComponent<Image>();skillImage.color = lockedSkillColor;ui = GetComponentInParent<UI>();}public void UnlockSkillSlot()//一个判断此Skill是否可以解锁的函数{if (PlayerManager.instance.HaveEnoughMoney(skillCost) == false)return;Debug.Log("Slot unlocked");for (int i = 0; i < shouldBeUnlocked.Length; i++){if (shouldBeUnlocked[i].unlocked == false){Debug.Log("Cannot unlock skill");return;}}for (int i = 0; i < shouldBeLocked.Length; i++){if (shouldBeLocked[i].unlocked == true){Debug.Log("Cannot unlock skill");return;}}unlocked = true;skillImage.color = Color.white;}public void OnPointerEnter(PointerEventData eventData){ui.skillToolTip.ShowToolTip(skillDescription, skillName,skillCost.ToString());}public void OnPointerExit(PointerEventData eventData){ui.skillToolTip.HideToolTip();}
}
UI_statTooltip.cs
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;public class UI_statToolTip : UI_ToolTip
{[SerializeField] private TextMeshProUGUI description;public void ShowStatToolTip(string _text){Debug.Log(3);if (_text == null)return;Debug.Log(4);description.text = _text;AdjustPosition();gameObject.SetActive(true);}public void HideStatToolTip(){description.text = "";gameObject.SetActive(false);}
}

UI_itemTooltip.cs
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;public class UI_itemTooltip : UI_ToolTip
{[SerializeField] private TextMeshProUGUI itemNameText;[SerializeField] private TextMeshProUGUI itemTypeText;[SerializeField] private TextMeshProUGUI itemDescription;[SerializeField] private int defaultFontSize = 32;public void ShowToolTip(ItemData_Equipment item)//将item里面的数据读取到对应的text上并显示此组件{if (item == null)return;itemNameText.text = item.itemName;itemTypeText.text = item.equipmentType.ToString();itemDescription.text = item.GetDescription();AdjustFontSize(itemNameText);AdjustPosition();gameObject.SetActive(true);}public void HideToolTip()//关闭此组件{itemNameText.fontSize = defaultFontSize;//防止字体越来越小gameObject.SetActive(false);}
}
UI_itemSlot.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using UnityEngine.EventSystems;public class UI_itemSlot : MonoBehaviour ,IPointerDownHandler, IPointerEnterHandler, IPointerExitHandler
{[SerializeField] protected Image itemImage;[SerializeField] protected TextMeshProUGUI itemText;protected UI ui;public InventoryItem item;protected virtual void Start(){ui = GetComponentInParent<UI>();}public void UpdateSlots(InventoryItem _newItem){item = _newItem;itemImage.color = Color.white;if (item != null){itemImage.sprite = item.data.icon;if (item.stackSize > 1){itemText.text = item.stackSize.ToString();}else{itemText.text = "";}}}public void CleanUpSlot()//解决出现UI没有跟着Inventory变化的bug{item = null;itemImage.sprite = null;itemImage.color = Color.clear;itemText.text = "";}public virtual void OnPointerDown(PointerEventData eventData){if(item == null)//修复点击空白处会报错的bug{return;}if(Input.GetKey(KeyCode.LeftControl)){Inventory.instance.RemoveItem(item.data);ui.itemToolTip.HideToolTip();return;}if (item.data.itemType == ItemType.Equipment)Inventory.instance.EquipItem(item.data);ui.itemToolTip.HideToolTip();//修复已经装备了装备还会出现详细信息栏的bug}public void OnPointerEnter(PointerEventData eventData){if (item == null || item.data == null)return;ui.itemToolTip.ShowToolTip(item.data as ItemData_Equipment);}public void OnPointerExit(PointerEventData eventData){if (item == null || item.data == null)return;ui.itemToolTip.HideToolTip();}
}
ItemEffect.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class ItemEffect : ScriptableObject
{[TextArea]public string effectDescription;public virtual void ExecuteEffect(Transform _respawnPosition){Debug.Log("Effect executed");}
}
ItemData_Equipment.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public enum EquipmentType
{Weapon,Armor,Amulet,Flask}[CreateAssetMenu(fileName = "New Item Data", menuName = "Data/Equipment")]
public class ItemData_Equipment : ItemData
{public EquipmentType equipmentType;[Header("Unique effect")]public float itemCooldown;public ItemEffect[] itemEffects;[Header("Major stats")]public int strength; // 力量 增伤1点 爆伤增加 1% 物抗public int agility;// 敏捷 闪避 1% 闪避几率增加 1%public int intelligence;// 1 点 魔法伤害 1点魔抗 public int vitality;//加血的[Header("Offensive stats")]public int damage;public int critChance;      // 暴击率public int critPower;       //150% 爆伤[Header("Defensive stats")]public int health;public int armor;public int evasion;//闪避值public int magicResistance;[Header("Magic stats")]public int fireDamage;public int iceDamage;public int lightingDamage;[Header("Craft requirements")]public List<InventoryItem> craftingMaterials;public int descriptionLength;public void AddModifiers(){PlayerStats playerStats = PlayerManager.instance.player.GetComponent<PlayerStats>();playerStats.strength.AddModifier(strength);playerStats.agility.AddModifier(agility);playerStats.intelligence.AddModifier(intelligence);playerStats.vitality.AddModifier(vitality);playerStats.damage.AddModifier(damage);playerStats.critChance.AddModifier(critChance);playerStats.critPower.AddModifier(critPower);playerStats.Health.AddModifier(health);playerStats.armor.AddModifier(armor);playerStats.evasion.AddModifier(evasion);playerStats.magicResistance.AddModifier(magicResistance);playerStats.fireDamage.AddModifier(fireDamage);playerStats.iceDamage.AddModifier(iceDamage);playerStats.lightingDamage.AddModifier(lightingDamage);}public void RemoveModifiers(){PlayerStats playerStats = PlayerManager.instance.player.GetComponent<PlayerStats>();playerStats.strength.RemoveModifier(strength);playerStats.agility.RemoveModifier(agility);playerStats.intelligence.RemoveModifier(intelligence);playerStats.vitality.RemoveModifier(vitality);playerStats.damage.RemoveModifier(damage);playerStats.critChance.RemoveModifier(critChance);playerStats.critPower.RemoveModifier(critPower);playerStats.Health.RemoveModifier(health);playerStats.armor.RemoveModifier(armor);playerStats.evasion.RemoveModifier(evasion);playerStats.magicResistance.RemoveModifier(magicResistance);playerStats.fireDamage.RemoveModifier(fireDamage);playerStats.iceDamage.RemoveModifier(iceDamage);playerStats.lightingDamage.RemoveModifier(lightingDamage);}public void Effect(Transform _enemyPosition)//循环调用Effect类里的Effect的函数{foreach(var item in itemEffects){item.ExecuteEffect(_enemyPosition);}}public override string GetDescription()//让外界能够拿到拼出字符串的函数{sb.Length = 0;descriptionLength = 0;AddItemDescription(strength, "strength");AddItemDescription(agility, "agility");AddItemDescription(intelligence, "intelligence");AddItemDescription(vitality, "vitality");AddItemDescription(damage, "damage");AddItemDescription(critChance, "critChance");AddItemDescription(critPower, "critPower");AddItemDescription(health, "health");AddItemDescription(evasion, "evasion");AddItemDescription(armor, "armor");AddItemDescription(magicResistance, "magicResistance");AddItemDescription(fireDamage, "fireDamage");AddItemDescription(iceDamage, "iceDamage");AddItemDescription(lightingDamage, "lightingDamage");for(int i =0; i < itemEffects.Length;i++){if (itemEffects[i].effectDescription.Length > 0){sb.AppendLine();sb.AppendLine("Unique: " +itemEffects[i].effectDescription);descriptionLength++;}}if(descriptionLength < 5)//使窗口拥有最小尺寸{for(int i = 0;i < 5- descriptionLength;i++){sb.AppendLine();sb.Append("");}}return sb.ToString();}private void AddItemDescription(int _value,string _name)//通过判断拼出想要的字符串的函数{if(_value != 0){if(sb.Length >= 0)sb.AppendLine();//这是控制行数的if(_value > 0)sb.Append(" + "+_value + " " + _name);//这是实打实添加字符串的descriptionLength++;}}
}
Dogge_Skill.cs
using UnityEngine;
using UnityEngine.UI;public class Dogge_Skill : Skill
{[Header("Dodge")][SerializeField] private UI_SkillTreeSlot unlockDoggeButton;[SerializeField] private int evasionAmount;public bool doggeUnlocked;[Header("Mirage dodge")][SerializeField] private UI_SkillTreeSlot unlockMirageDoggeButton;public bool dodgemirageUnlocked;protected override void Start(){base.Start();unlockDoggeButton.GetComponent<Button>().onClick.AddListener(UnlockDodge);unlockMirageDoggeButton.GetComponent<Button>().onClick.AddListener(UnlockMirageDogge);}private void UnlockDodge(){if (unlockDoggeButton.unlocked && !doggeUnlocked){player.stats.evasion.AddModifier(evasionAmount);Inventory.instance.UpdateStatsUI();doggeUnlocked = true;}}private void UnlockMirageDogge(){if (unlockMirageDoggeButton.unlocked)dodgemirageUnlocked = true;}public void CreateMirageOnDoDogge(){if (dodgemirageUnlocked)SkillManager.instance.clone.CreateClone(player.transform, Vector3.zero);}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/623920.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

第十一章数据仓库和商务智能10分

【数据仓库-后端&#xff0c;商务智能-前端】 基本算法&#xff1a;关联关系&#xff08;牵手-谈恋爱&#xff09;&#xff0c;集群关系&#xff08;杭州人爱吃酸甜口&#xff09;&#xff0c;决策树&#xff0c;线性回归&#xff0c;贝叶斯&#xff0c;神经网络&#xff0c;时…

Vue3(二):报错调试,vue3响应式原理、computed和watch,ref,props,接口

一、准备工作调试 跟着张天禹老师看前几集的时候可能会遇到如下问题&#xff1a; 1.下载插件&#xff1a;Vue Language Features (Volar)或者直接下载vue-offical 2.npm run serve时运行时出现错误&#xff1a;Error: vitejs/plugin-vue requires vue (&#xff1e;3.2.13) …

【DA-CLIP】图像退化类型检测功能演示代码

背景 在CLIP基础上微调而来&#xff0c;使用图像控制器编码生成退化类型embedding并在训练中对图像编码器进行控制。针对十种退化类型进行了训练。 解决CLIP模型在图像纹理等层面无法针对退化类型识别或识别率较低的问题。 训练数据集情况 GitHub有对应数据集连接 完整代码 项…

零基础小白如何才能学好网络安全?(附:学习路线图及学习资料)

经常有小伙伴在后台留言&#xff0c;问如何才能学好网络安全。比如有小伙伴说&#xff0c;听人说可以先学网页基础&#xff0c;但是自己学了html、CSS&#xff0c;感觉跟网络安全挨不着边&#xff0c;不知道如何入手学习。 其实&#xff0c;网络安全没有大家想的那么神秘&#…

Jenkins上面使用pnpm打包

问题 前端也想用Jenkins的CI/CD工作流。 步骤 Jenkins安装NodeJS插件 安装完成&#xff0c;记得重启Jenkins。 全局配置nodejs Jenksinfile pipeline {agent anytools {nodejs "18.15.0"}stages {stage(Check tool version) {steps {sh node -vnpm -vnpm config…

华硕ROG幻16笔记本电脑模式切换管理工具完美替代华硕奥创中心管理工具

文章目录 华硕ROG幻16笔记本电脑模式切换管理工具完美替代华硕奥创中心管理工具1. 介绍2. 下载3. 静音模式、平衡模式、增强模式配置4. 配置电源方案与模式切换绑定5. 启动Ghelper控制面板6. 目前支持的设备型号 华硕ROG幻16笔记本电脑模式切换管理工具完美替代华硕奥创中心管理…

软件架构动态演化

动态演化是在系统运行期间的演化&#xff0c;需要在不停止系统功能的情况下完成演化&#xff0c;较之静态演化更加困难。 1.动态演化的需求 架构的动态演化主要来自两类需求&#xff1a;①软件内部执行所导致的体系结构改变&#xff0c;例如&#xff0c;许多服务器端软件会在客…

目标检测——YOLO系列学习(一)YOLOv1

YOLO可以说是单阶段的目标检测方法的集大成之作&#xff0c;必学的经典论文&#xff0c;从准备面试的角度来学习一下yolo系列。 YOLOv1 1.RCNN系列回顾 RCNN系列&#xff0c;无论哪种算法&#xff0c;核心思路都是Region Proposal&#xff08;定位&#xff09; classifier&am…

【数据结构】遍历二叉树(递归和非递归遍历的先序、中序和后序遍历、层次遍历法)

目录 【数据结构】遍历二叉树&#xff08;递归和非递归遍历的先序、中序和后序遍历、层次遍历法&#xff09;一、递归算法先&#xff08;根&#xff09;序的遍历算法中&#xff08;根&#xff09;序的遍历算法后&#xff08;根&#xff09;序的遍历算法 二、非递归算法层次遍历…

【vue】Pinia-2 安装Pinia,使用store

1. 安装Pinia 在项目路径下执行npm install pinia 在package.json中查看 2. 使用store 在main.js中添加 import { createPinia } from pinia const pinia createPinia()修改createApp方法 最后示例如下&#xff08;三处修改&#xff09; import { createApp } from vue //…

JRT多服务器同步程序

之前的JRT只部署在一个服务器&#xff0c;实际运用可能会有数台、数十台、或者更多服务器。那么多台服务器就需要程序同步机制。这里借助Rsync同步&#xff0c;但是有个问题是Rsync同步jar之后他不知道是否需要重启站点&#xff0c;为此实现java控制台驱动Rsync&#xff0c;重定…

车载摄像头畸变校正解决方案,打造无畸变高清视界

在车载摄像头日益普及的今天&#xff0c;摄像头图像的畸变问题成为了制约图像质量提升的一大瓶颈。畸变不仅影响画面的美观度&#xff0c;更关键的是它可能导致智能驾驶系统对环境的误判&#xff0c;进而威胁到行车安全。美摄科技凭借其在图像处理领域的深厚实力&#xff0c;推…