void Update() { Player player = Utils.ClientLocalPlayer(); panel.SetActive(player != null); // hide while not in the game world if (!player) { return; } // instantiate/destroy enough slots UIUtils.BalancePrefabs(slotPrefab.gameObject, player.skillbar.Length, content); // refresh all for (int i = 0; i < player.skillbar.Length; ++i) { UISkillbarSlot slot = content.GetChild(i).GetComponent <UISkillbarSlot>(); slot.dragAndDropable.name = i.ToString(); // drag and drop index // hotkey overlay (without 'Alpha' etc.) string pretty = player.skillbar[i].hotKey.ToString().Replace("Alpha", ""); slot.hotkeyText.text = pretty; // skill, inventory item or equipment item? int skillIndex = player.GetSkillIndexByName(player.skillbar[i].reference); int inventoryIndex = player.GetInventoryIndexByName(player.skillbar[i].reference); int equipmentIndex = player.GetEquipmentIndexByName(player.skillbar[i].reference); if (skillIndex != -1) { Skill skill = player.skills[skillIndex]; // hotkey pressed and not typing in any input right now? if (Input.GetKeyDown(player.skillbar[i].hotKey) && !UIUtils.AnyInputActive() && player.CastCheckSelf(skill)) // checks mana, cooldowns, etc.) { player.CmdUseSkill(skillIndex); } // refresh skill slot slot.button.interactable = player.CastCheckSelf(skill); // check mana, cooldowns, etc. slot.button.onClick.SetListener(() => { player.CmdUseSkill(skillIndex); }); slot.tooltip.enabled = true; slot.tooltip.text = skill.ToolTip(); slot.dragAndDropable.dragable = true; slot.image.color = Color.white; slot.image.sprite = skill.image; float cooldown = skill.CooldownRemaining(); slot.cooldownOverlay.SetActive(cooldown > 0); slot.cooldownText.text = cooldown.ToString("F0"); slot.cooldownCircle.fillAmount = skill.cooldown > 0 ? cooldown / skill.cooldown : 0; slot.amountOverlay.SetActive(false); } else if (inventoryIndex != -1) { ItemSlot itemSlot = player.inventory[inventoryIndex]; // hotkey pressed and not typing in any input right now? if (Input.GetKeyDown(player.skillbar[i].hotKey) && !UIUtils.AnyInputActive()) { player.CmdUseInventoryItem(inventoryIndex); } // refresh inventory slot slot.button.onClick.SetListener(() => { player.CmdUseInventoryItem(inventoryIndex); }); slot.tooltip.enabled = true; slot.tooltip.text = itemSlot.ToolTip(); slot.dragAndDropable.dragable = true; slot.image.color = Color.white; slot.image.sprite = itemSlot.item.image; slot.cooldownOverlay.SetActive(false); slot.cooldownCircle.fillAmount = 0; slot.amountOverlay.SetActive(itemSlot.amount > 1); slot.amountText.text = itemSlot.amount.ToString(); } else if (equipmentIndex != -1) { ItemSlot itemSlot = player.equipment[equipmentIndex]; // refresh equipment slot slot.button.onClick.RemoveAllListeners(); slot.tooltip.enabled = true; slot.tooltip.text = itemSlot.ToolTip(); slot.dragAndDropable.dragable = true; slot.image.color = Color.white; slot.image.sprite = itemSlot.item.image; slot.cooldownOverlay.SetActive(false); slot.cooldownCircle.fillAmount = 0; slot.amountOverlay.SetActive(itemSlot.amount > 1); slot.amountText.text = itemSlot.amount.ToString(); } else { // clear the outdated reference player.skillbar[i].reference = ""; // refresh empty slot slot.button.onClick.RemoveAllListeners(); slot.tooltip.enabled = false; slot.dragAndDropable.dragable = false; slot.image.color = Color.clear; slot.image.sprite = null; slot.cooldownOverlay.SetActive(false); slot.cooldownCircle.fillAmount = 0; slot.amountOverlay.SetActive(false); } } }
void Update() { GameObject player = Player.player; panel.SetActive(player != null); // hide while not in the game world if (!player) { return; } // get components Skillbar skillbar = player.GetComponent <Skillbar>(); PlayerSkills skills = player.GetComponent <PlayerSkills>(); PlayerInventory inventory = player.GetComponent <PlayerInventory>(); PlayerEquipment equipment = player.GetComponent <PlayerEquipment>(); PlayerLook look = player.GetComponent <PlayerLook>(); // instantiate/destroy enough slots UIUtils.BalancePrefabs(slotPrefab.gameObject, skillbar.slots.Length, content); // refresh all for (int i = 0; i < skillbar.slots.Length; ++i) { UISkillbarSlot slot = content.GetChild(i).GetComponent <UISkillbarSlot>(); slot.dragAndDropable.name = i.ToString(); // drag and drop index // hotkey overlay (without 'Alpha' etc.) string pretty = skillbar.slots[i].hotKey.ToString().Replace("Alpha", ""); slot.hotkeyText.text = pretty; // skill, inventory item or equipment item? int skillIndex = skills.GetSkillIndexByName(skillbar.slots[i].reference); int inventoryIndex = inventory.GetItemIndexByName(skillbar.slots[i].reference); int equipmentIndex = equipment.GetItemIndexByName(skillbar.slots[i].reference); if (skillIndex != -1) { Skill skill = skills.skills[skillIndex]; bool canUse = skill.CanCast(player) && !look.IsFreeLooking(); // hotkey pressed and not typing in any input right now? if (Input.GetKeyDown(skillbar.slots[i].hotKey) && !UIUtils.AnyInputActive() && canUse) { skills.StartCast(skillIndex); } // refresh skill slot slot.button.interactable = canUse; slot.button.onClick.SetListener(() => { skills.StartCast(skillIndex); }); slot.tooltip.enabled = true; slot.tooltip.text = skill.ToolTip(); slot.dragAndDropable.dragable = true; slot.image.color = Color.white; slot.image.sprite = skill.image; float cooldown = skill.CooldownRemaining(); slot.cooldownOverlay.SetActive(cooldown > 0); slot.cooldownText.text = cooldown.ToString("F0"); slot.cooldownCircle.fillAmount = skill.cooldown > 0 ? cooldown / skill.cooldown : 0; slot.amountOverlay.SetActive(false); } else if (inventoryIndex != -1) { ItemSlot itemSlot = inventory.slots[inventoryIndex]; // hotkey pressed and not typing in any input right now? if (Input.GetKeyDown(skillbar.slots[i].hotKey) && !UIUtils.AnyInputActive()) { inventory.UseItem(inventoryIndex); } // refresh inventory slot slot.button.onClick.SetListener(() => { inventory.UseItem(inventoryIndex); }); slot.tooltip.enabled = true; slot.tooltip.text = itemSlot.ToolTip(); slot.dragAndDropable.dragable = true; slot.image.color = Color.white; slot.image.sprite = itemSlot.item.image; slot.cooldownOverlay.SetActive(false); slot.cooldownCircle.fillAmount = 0; slot.amountOverlay.SetActive(itemSlot.amount > 1); slot.amountText.text = itemSlot.amount.ToString(); } else if (equipmentIndex != -1) { ItemSlot itemSlot = equipment.slots[equipmentIndex]; // refresh equipment slot slot.button.onClick.RemoveAllListeners(); slot.tooltip.enabled = true; slot.tooltip.text = itemSlot.ToolTip(); slot.dragAndDropable.dragable = true; slot.image.color = Color.white; slot.image.sprite = itemSlot.item.image; slot.cooldownOverlay.SetActive(false); slot.cooldownCircle.fillAmount = 0; slot.amountOverlay.SetActive(itemSlot.amount > 1); slot.amountText.text = itemSlot.amount.ToString(); } else { // clear the outdated reference skillbar.slots[i].reference = ""; // refresh empty slot slot.button.onClick.RemoveAllListeners(); slot.tooltip.enabled = false; slot.dragAndDropable.dragable = false; slot.image.color = Color.clear; slot.image.sprite = null; slot.cooldownOverlay.SetActive(false); slot.cooldownCircle.fillAmount = 0; slot.amountOverlay.SetActive(false); } } }
// ----------------------------------------------------------------------------------- // UCE_SlowUpdate // ----------------------------------------------------------------------------------- private void UCE_SlowUpdate() { Player player = Player.localPlayer; if (player != null) { // instantiate/destroy enough slots UIUtils.BalancePrefabs(slotPrefab.gameObject, player.skillbar.Length, content); // refresh all for (int i = 0; i < player.skillbar.Length; ++i) { UISkillbarSlot slot = content.GetChild(i).GetComponent <UISkillbarSlot>(); slot.dragAndDropable.name = i.ToString(); // drag and drop index // hotkey overlay (without 'Alpha' etc.) string pretty = player.skillbar[i].hotKey.ToString().Replace("Alpha", ""); slot.hotkeyText.text = pretty; // skill, inventory item or equipment item? int skillIndex = player.GetSkillIndexByName(player.skillbar[i].reference); int inventoryIndex = player.GetInventoryIndexByName(player.skillbar[i].reference); int equipmentIndex = player.GetEquipmentIndexByName(player.skillbar[i].reference); if (skillIndex != -1) { Skill skill = player.skills[skillIndex]; bool canCast = player.CastCheckSelf(skill); // refresh skill slot slot.button.interactable = canCast; // check mana, cooldowns, etc. slot.button.onClick.SetListener(() => { // try use the skill or walk closer if needed player.TryUseSkill(skillIndex); }); // only build tooltip while it's actually shown. this // avoids MASSIVE amounts of StringBuilder allocations. slot.tooltip.enabled = true; if (slot.tooltip.IsVisible()) { slot.tooltip.text = skill.ToolTip(); } slot.dragAndDropable.dragable = true; slot.image.color = Color.white; slot.image.sprite = skill.image; float cooldown = skill.CooldownRemaining(); slot.cooldownOverlay.SetActive(cooldown > 0); slot.cooldownText.text = cooldown.ToString("F0"); slot.cooldownCircle.fillAmount = skill.cooldown > 0 ? cooldown / skill.cooldown : 0; slot.amountOverlay.SetActive(false); } else if (inventoryIndex != -1) { ItemSlot itemSlot = player.inventory[inventoryIndex]; // refresh inventory slot slot.button.onClick.SetListener(() => { player.CmdUseInventoryItem(inventoryIndex); }); // only build tooltip while it's actually shown. this // avoids MASSIVE amounts of StringBuilder allocations. slot.tooltip.enabled = true; if (slot.tooltip.IsVisible()) { slot.tooltip.text = itemSlot.ToolTip(); } slot.dragAndDropable.dragable = true; slot.image.color = Color.white; slot.image.sprite = itemSlot.item.image; slot.cooldownOverlay.SetActive(false); slot.cooldownCircle.fillAmount = 0; slot.amountOverlay.SetActive(itemSlot.amount > 1); slot.amountText.text = itemSlot.amount.ToString(); } else if (equipmentIndex != -1) { ItemSlot itemSlot = player.equipment[equipmentIndex]; // refresh equipment slot slot.button.onClick.RemoveAllListeners(); // only build tooltip while it's actually shown. this // avoids MASSIVE amounts of StringBuilder allocations. slot.tooltip.enabled = true; if (slot.tooltip.IsVisible()) { slot.tooltip.text = itemSlot.ToolTip(); } slot.dragAndDropable.dragable = true; slot.image.color = Color.white; slot.image.sprite = itemSlot.item.image; slot.cooldownOverlay.SetActive(false); slot.cooldownCircle.fillAmount = 0; slot.amountOverlay.SetActive(itemSlot.amount > 1); slot.amountText.text = itemSlot.amount.ToString(); } else { // clear the outdated reference player.skillbar[i].reference = ""; // refresh empty slot slot.button.onClick.RemoveAllListeners(); slot.tooltip.enabled = false; slot.dragAndDropable.dragable = false; slot.image.color = Color.clear; slot.image.sprite = null; slot.cooldownOverlay.SetActive(false); slot.cooldownCircle.fillAmount = 0; slot.amountOverlay.SetActive(false); } } } }
// ----------------------------------------------------------------------------------- // Update // ----------------------------------------------------------------------------------- private void Update() { if (Time.time > fInterval) { UCE_SlowUpdate(); fInterval = Time.time + updateInterval; } Player player = Player.localPlayer; if (player != null) { if (content.childCount <= 0) { return; } panel.SetActive(true); // instantiate/destroy enough slots UIUtils.BalancePrefabs(slotPrefab.gameObject, player.skillbar.Length, content); // refresh all for (int i = 0; i < player.skillbar.Length; ++i) { UISkillbarSlot slot = content.GetChild(i).GetComponent <UISkillbarSlot>(); // skill, inventory item or equipment item? int skillIndex = player.GetSkillIndexByName(player.skillbar[i].reference); int inventoryIndex = player.GetInventoryIndexByName(player.skillbar[i].reference); if (skillIndex != -1) { Skill skill = player.skills[skillIndex]; bool canCast = player.CastCheckSelf(skill); // hotkey pressed and not typing in any input right now? if (Input.GetKeyDown(player.skillbar[i].hotKey) && !UIUtils.AnyInputActive() && canCast) // checks mana, cooldowns, etc.) { { // try use the skill or walk closer if needed player.TryUseSkill(skillIndex); } } else if (inventoryIndex != -1) { ItemSlot itemSlot = player.inventory[inventoryIndex]; // hotkey pressed and not typing in any input right now? if (Input.GetKeyDown(player.skillbar[i].hotKey) && !UIUtils.AnyInputActive()) { player.CmdUseInventoryItem(inventoryIndex); } } } } else { panel.SetActive(false); } }
void Update() { Player player = Player.localPlayer; if (player != null) { panel.SetActive(true); // instantiate/destroy enough slots UIUtils.BalancePrefabs(slotPrefab.gameObject, player.skillbar.slots.Length, content); // refresh all for (int i = 0; i < player.skillbar.slots.Length; ++i) { SkillbarEntry entry = player.skillbar.slots[i]; UISkillbarSlot slot = content.GetChild(i).GetComponent <UISkillbarSlot>(); slot.dragAndDropable.name = i.ToString(); // drag and drop index // hotkey overlay (without 'Alpha' etc.) string pretty = entry.hotKey.ToString().Replace("Alpha", ""); slot.hotkeyText.text = pretty; // skill, inventory item or equipment item? int skillIndex = player.skills.GetSkillIndexByName(entry.reference); int inventoryIndex = player.inventory.GetItemIndexByName(entry.reference); int equipmentIndex = player.equipment.GetItemIndexByName(entry.reference); if (skillIndex != -1) { Skill skill = player.skills.skills[skillIndex]; bool canCast = player.skills.CastCheckSelf(skill); // if movement does NOT support navigation then we need to // check distance too. otherwise distance doesn't matter // because we can navigate anywhere. if (!player.movement.CanNavigate()) { canCast &= player.skills.CastCheckDistance(skill, out Vector3 _); } // hotkey pressed and not typing in any input right now? if (Input.GetKeyDown(entry.hotKey) && !UIUtils.AnyInputActive() && canCast) // checks mana, cooldowns, etc.) { { // try use the skill or walk closer if needed ((PlayerSkills)player.skills).TryUse(skillIndex); } // refresh skill slot slot.button.interactable = canCast; // check mana, cooldowns, etc. slot.button.onClick.SetListener(() => { // try use the skill or walk closer if needed ((PlayerSkills)player.skills).TryUse(skillIndex); }); // only build tooltip while it's actually shown. this // avoids MASSIVE amounts of StringBuilder allocations. slot.tooltip.enabled = true; if (slot.tooltip.IsVisible()) { slot.tooltip.text = skill.ToolTip(); } slot.dragAndDropable.dragable = true; slot.image.color = Color.white; slot.image.sprite = skill.image; float cooldown = skill.CooldownRemaining(); slot.cooldownOverlay.SetActive(cooldown > 0); slot.cooldownText.text = cooldown.ToString("F0"); slot.cooldownCircle.fillAmount = skill.cooldown > 0 ? cooldown / skill.cooldown : 0; slot.amountOverlay.SetActive(false); } else if (inventoryIndex != -1) { ItemSlot itemSlot = player.inventory.slots[inventoryIndex]; // hotkey pressed and not typing in any input right now? if (Input.GetKeyDown(entry.hotKey) && !UIUtils.AnyInputActive()) { player.inventory.CmdUseItem(inventoryIndex); } // refresh inventory slot slot.button.onClick.SetListener(() => { player.inventory.CmdUseItem(inventoryIndex); }); // only build tooltip while it's actually shown. this // avoids MASSIVE amounts of StringBuilder allocations. slot.tooltip.enabled = true; if (slot.tooltip.IsVisible()) { slot.tooltip.text = itemSlot.ToolTip(); } slot.dragAndDropable.dragable = true; // use durability colors? if (itemSlot.item.maxDurability > 0) { if (itemSlot.item.durability == 0) { slot.image.color = brokenDurabilityColor; } else if (itemSlot.item.DurabilityPercent() < lowDurabilityThreshold) { slot.image.color = lowDurabilityColor; } else { slot.image.color = Color.white; } } else { slot.image.color = Color.white; // reset for no-durability items } slot.image.sprite = itemSlot.item.image; slot.cooldownOverlay.SetActive(false); // cooldown if usable item if (itemSlot.item.data is UsableItem usable) { float cooldown = player.GetItemCooldown(usable.cooldownCategory); slot.cooldownCircle.fillAmount = usable.cooldown > 0 ? cooldown / usable.cooldown : 0; } else { slot.cooldownCircle.fillAmount = 0; } slot.amountOverlay.SetActive(itemSlot.amount > 1); slot.amountText.text = itemSlot.amount.ToString(); } else if (equipmentIndex != -1) { ItemSlot itemSlot = player.equipment.slots[equipmentIndex]; // refresh equipment slot slot.button.onClick.RemoveAllListeners(); // only build tooltip while it's actually shown. this // avoids MASSIVE amounts of StringBuilder allocations. slot.tooltip.enabled = true; if (slot.tooltip.IsVisible()) { slot.tooltip.text = itemSlot.ToolTip(); } slot.dragAndDropable.dragable = true; // use durability colors? if (itemSlot.item.maxDurability > 0) { if (itemSlot.item.durability == 0) { slot.image.color = brokenDurabilityColor; } else if (itemSlot.item.DurabilityPercent() < lowDurabilityThreshold) { slot.image.color = lowDurabilityColor; } else { slot.image.color = Color.white; } } else { slot.image.color = Color.white; // reset for no-durability items } slot.image.sprite = itemSlot.item.image; slot.cooldownOverlay.SetActive(false); // cooldown if usable item if (itemSlot.item.data is UsableItem usable) { float cooldown = player.GetItemCooldown(usable.cooldownCategory); slot.cooldownCircle.fillAmount = usable.cooldown > 0 ? cooldown / usable.cooldown : 0; } else { slot.cooldownCircle.fillAmount = 0; } slot.amountOverlay.SetActive(itemSlot.amount > 1); slot.amountText.text = itemSlot.amount.ToString(); } else { // clear the outdated reference // (need to assign directly because it's a struct) player.skillbar.slots[i].reference = ""; // refresh empty slot slot.button.onClick.RemoveAllListeners(); slot.tooltip.enabled = false; slot.dragAndDropable.dragable = false; slot.image.color = Color.clear; slot.image.sprite = null; slot.cooldownOverlay.SetActive(false); slot.cooldownCircle.fillAmount = 0; slot.amountOverlay.SetActive(false); } } } else { panel.SetActive(false); } }