added new power buttons implementation
This commit is contained in:
@@ -1,20 +0,0 @@
|
|||||||
%YAML 1.1
|
|
||||||
%TAG !u! tag:unity3d.com,2011:
|
|
||||||
--- !u!114 &11400000
|
|
||||||
MonoBehaviour:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 0}
|
|
||||||
m_Enabled: 1
|
|
||||||
m_EditorHideFlags: 0
|
|
||||||
m_Script: {fileID: 11500000, guid: de5210ce93b60c74b910290c522cd727, type: 3}
|
|
||||||
m_Name: EditorStartupPrefs
|
|
||||||
m_EditorClassIdentifier:
|
|
||||||
welcomeScreenVersion: '1.9.0 '
|
|
||||||
playmakerVersion:
|
|
||||||
showWelcomeScreen: 0
|
|
||||||
showUpgradeGuide: 0
|
|
||||||
lastAutoUpdateSignature: 6000.0.39f1__G:/PROJEKTY/BEYOND/BeyonGit/Assets__0.0.0.0
|
|
||||||
useLegacyNetworking: 0
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: d5e80c80ad3d44097a0269f941b7f876
|
|
||||||
NativeFormatImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
mainObjectFileID: 11400000
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -80,7 +80,9 @@ namespace Beyond
|
|||||||
private PlayerAttribute faithAttribute;
|
private PlayerAttribute faithAttribute;
|
||||||
private PlayerAttribute brightnessAttribute;
|
private PlayerAttribute brightnessAttribute;
|
||||||
private PlayerAttribute maturityAttribute;
|
private PlayerAttribute maturityAttribute;
|
||||||
|
private MagicAttacks m_magicAttacks;
|
||||||
|
|
||||||
|
public MagicAttacks Magic => m_magicAttacks;
|
||||||
public PlayerAttribute MaturityAttribute
|
public PlayerAttribute MaturityAttribute
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -179,6 +181,7 @@ namespace Beyond
|
|||||||
m_Respawner = GetComponent<Respawner>();
|
m_Respawner = GetComponent<Respawner>();
|
||||||
m_playerConfessionController = GetComponent<PlayerConfessionController>();
|
m_playerConfessionController = GetComponent<PlayerConfessionController>();
|
||||||
m_meleeManager = GetComponent<vMeleeManager>();
|
m_meleeManager = GetComponent<vMeleeManager>();
|
||||||
|
m_magicAttacks = GetComponent<MagicAttacks>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1976,7 +1976,7 @@ namespace Beyond
|
|||||||
|
|
||||||
inCollectItemRoutine = true;
|
inCollectItemRoutine = true;
|
||||||
|
|
||||||
yield return new WaitForSeconds(onCollectDelay);
|
yield return new WaitForSeconds(onCollectDelay);
|
||||||
|
|
||||||
List<CollectedItemInfo> collectedItems = new List<CollectedItemInfo>();
|
List<CollectedItemInfo> collectedItems = new List<CollectedItemInfo>();
|
||||||
for (int i = 0; i < inventory.equipAreas.Length; i++)
|
for (int i = 0; i < inventory.equipAreas.Length; i++)
|
||||||
|
|||||||
267
Assets/Scripts/UI/ItemButtonController.cs
Normal file
267
Assets/Scripts/UI/ItemButtonController.cs
Normal file
@@ -0,0 +1,267 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using Language.Lua;
|
||||||
|
using PixelCrushers.DialogueSystem;
|
||||||
|
using Sirenix.Utilities;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
using UnityStandardAssets.CrossPlatformInput;
|
||||||
|
|
||||||
|
namespace Beyond {
|
||||||
|
|
||||||
|
public class ItemButtonController : MonoBehaviour
|
||||||
|
{
|
||||||
|
public bEquipSlot equipSlot;
|
||||||
|
private bEquipArea equipArea;
|
||||||
|
public Image image;
|
||||||
|
public GameObject imageParent;
|
||||||
|
private int currentIndex = 0;
|
||||||
|
private string imagePath = "";
|
||||||
|
public string InputNameToPress = "M";
|
||||||
|
private bool isLocked = false;
|
||||||
|
private float lockDuration = 0.5f;
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
private bItemType itemType = 0;
|
||||||
|
[SerializeField]
|
||||||
|
private bItemType itemType2 = 0;
|
||||||
|
[SerializeField]
|
||||||
|
private ImagePulser imagePulser;
|
||||||
|
[SerializeField]
|
||||||
|
private bool pulseImage = true;
|
||||||
|
//override
|
||||||
|
private float pulseSpeed = 10f;
|
||||||
|
/// <summary>
|
||||||
|
/// to set image properly for disabled
|
||||||
|
/// </summary>
|
||||||
|
private event Action onEnabled;
|
||||||
|
private bool m_currentWeaponGemable = false;
|
||||||
|
private bItem m_currentItem = null;
|
||||||
|
private bItemAttribute m_weaponPowerAttribute;
|
||||||
|
private PlayerAttribute faith;
|
||||||
|
// Start is called before the first frame update
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
//SetConsumableButton();
|
||||||
|
equipSlot.onAddItem.AddListener(SetButton);
|
||||||
|
equipSlot.onRemoveItem.AddListener(SetButton);
|
||||||
|
Player.Instance.ItemManager.onEquipItem.AddListener(OnEquipItem);
|
||||||
|
Player.Instance.ItemManager.onUnequipItem.AddListener(OnUnequipItem);
|
||||||
|
//start with 0, end on 2. On consume, equipped recheck binding here
|
||||||
|
equipArea = equipSlot.GetComponentInParent<bEquipArea>();
|
||||||
|
bool thisSlot = false;
|
||||||
|
for (int i=0; i<equipArea.equipSlots.Count; i++)
|
||||||
|
{
|
||||||
|
if (equipArea.equipSlots[i] == equipSlot)
|
||||||
|
{
|
||||||
|
currentIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
faith = Player.Instance.GetAttribute("Faith");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MatchesType(bItemType type)
|
||||||
|
{
|
||||||
|
return itemType == type || itemType2 == type;
|
||||||
|
}
|
||||||
|
//this 2 methods are only for gems - to check if button should be visible for gemable weapon
|
||||||
|
private void OnEquipItem(bEquipArea area, bItem item)
|
||||||
|
{
|
||||||
|
if (!MatchesType(item.type))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Debug.Log("On Unequiped weapon in area: "+area.name+" weapon: "+weapon.name);
|
||||||
|
//if current button type is gemstone, check if button should be active
|
||||||
|
//check if this slot was equiped
|
||||||
|
|
||||||
|
if (area.currentEquippedItem == equipSlot.item)
|
||||||
|
{
|
||||||
|
//m_weaponPowerAttribute = item.GetItemAttribute(bItemAttributes.Power);
|
||||||
|
//m_currentWeaponGemable = m_weaponPowerAttribute !=null;
|
||||||
|
SetButton(item);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnUnequipItem(bEquipArea area, bItem item)
|
||||||
|
{
|
||||||
|
if (!MatchesType(item.type))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//Debug.Log("On Unequiped weapon in area: "+area.name+" weapon: "+weapon.name);
|
||||||
|
if (m_currentWeaponGemable && item.GetItemAttribute(bItemAttributes.Power) !=null)
|
||||||
|
{
|
||||||
|
m_currentWeaponGemable = false;
|
||||||
|
m_weaponPowerAttribute = null;
|
||||||
|
}
|
||||||
|
if (item == m_currentItem)
|
||||||
|
{
|
||||||
|
SetButton(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void EnablePulsing(bool e)
|
||||||
|
{
|
||||||
|
if (!imagePulser)
|
||||||
|
return;
|
||||||
|
pulseImage = e;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
if (imagePulser == null || !pulseImage)
|
||||||
|
return;
|
||||||
|
float value;
|
||||||
|
imagePulser.speed = pulseSpeed;
|
||||||
|
imagePulser.scaleAmount = 1.2f;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
switch (itemType)
|
||||||
|
{
|
||||||
|
case bItemType.Consumable:
|
||||||
|
value = Player.Instance.CurrentHealth / Player.Instance.MaxHealth;
|
||||||
|
if (value > 0.25)
|
||||||
|
imagePulser.StopPulsing();
|
||||||
|
else
|
||||||
|
imagePulser.StartPulsing();
|
||||||
|
break;
|
||||||
|
case bItemType.ConsumablesFaith:
|
||||||
|
value = faith.AttributeCurrentValue / faith.AttributeMaxValue;
|
||||||
|
if (value > 0.25)
|
||||||
|
imagePulser.StopPulsing();
|
||||||
|
else
|
||||||
|
imagePulser.StartPulsing();
|
||||||
|
break;
|
||||||
|
case bItemType.Gemstones:
|
||||||
|
if (m_weaponPowerAttribute != null)
|
||||||
|
{
|
||||||
|
if (m_weaponPowerAttribute.value > 1)
|
||||||
|
{
|
||||||
|
imagePulser.StopPulsing();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
imagePulser.StartPulsing();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnEnable()
|
||||||
|
{
|
||||||
|
//because unloaded in menu image needs to be reloaded again
|
||||||
|
if (imagePath.Length > 1)
|
||||||
|
{
|
||||||
|
image.sprite = Resources.Load<Sprite>(imagePath);
|
||||||
|
}
|
||||||
|
isLocked = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnDestroy()
|
||||||
|
{
|
||||||
|
if (equipSlot)
|
||||||
|
{
|
||||||
|
equipSlot.onAddItem.RemoveListener(SetButton);
|
||||||
|
equipSlot.onRemoveItem.RemoveListener(SetButton);
|
||||||
|
Player.Instance.ItemManager.onEquipItem.RemoveListener(OnEquipItem);
|
||||||
|
Player.Instance.ItemManager.onEquipItem.RemoveListener(OnUnequipItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetButton(bItem item = null)
|
||||||
|
{
|
||||||
|
|
||||||
|
imagePath = "";
|
||||||
|
if (item != null)
|
||||||
|
{
|
||||||
|
TryToUnloadOldImage();
|
||||||
|
imagePath = item.iconPath;
|
||||||
|
image.sprite = Resources.Load<Sprite>(imagePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//if current weapon is geamable, then show button only if button type is gemstone
|
||||||
|
if (item == null)
|
||||||
|
{
|
||||||
|
imageParent.SetActive(false);
|
||||||
|
}
|
||||||
|
else if (item.type == bItemType.Gemstones)
|
||||||
|
{
|
||||||
|
imageParent.SetActive(m_currentWeaponGemable);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
imageParent.SetActive(true);
|
||||||
|
}
|
||||||
|
m_currentItem = item;
|
||||||
|
|
||||||
|
onEnabled = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void TryToUnloadOldImage()
|
||||||
|
{
|
||||||
|
if (image.sprite != null)
|
||||||
|
{
|
||||||
|
Resources.UnloadAsset(image.sprite);
|
||||||
|
//Resources.UnloadUnusedAssets();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ConsumeItem()
|
||||||
|
{
|
||||||
|
if (isLocked)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_currentItem.type == bItemType.QuantaPower || m_currentItem.type == bItemType.PowerScroll)
|
||||||
|
{
|
||||||
|
Player.Instance.Magic.SelectPowerBasedOnArea(currentIndex);
|
||||||
|
if (!InputNameToPress.IsNullOrWhitespace())
|
||||||
|
{
|
||||||
|
CrossPlatformInputManager.SetButtonDown(InputNameToPress);
|
||||||
|
CrossPlatformInputManager.SetButtonUp(InputNameToPress);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
equipArea.UseItem(equipArea.equipSlots[currentIndex]);
|
||||||
|
}
|
||||||
|
//short button lock would be nice here
|
||||||
|
|
||||||
|
if (equipSlot.item == null)
|
||||||
|
{
|
||||||
|
SetButton(null);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
isLocked = true;
|
||||||
|
StartCoroutine(UnlockButtonCoroutine());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerator UnlockButtonCoroutine()
|
||||||
|
{
|
||||||
|
yield return new WaitForSeconds(lockDuration);
|
||||||
|
isLocked = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
2
Assets/Scripts/UI/ItemButtonController.cs.meta
Normal file
2
Assets/Scripts/UI/ItemButtonController.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 49dbd9efc01aa453e8c3038757b40979
|
||||||
Reference in New Issue
Block a user