using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using Invector; using Invector.vCharacterController; using UnityEngine.Events; using PixelCrushers.DialogueSystem; using PixelCrushers.Wrappers; using Sirenix.OdinInspector; using PixelCrushers.QuestMachine; using QuestState = PixelCrushers.QuestMachine.QuestState; using Random = UnityEngine.Random; using UnityEngine.UI; using Invector.vCharacterController.vActions; using Invector.vMelee; using static PixelCrushers.DialogueSystem.DialogueSystemEvents; namespace Beyond { [RequireComponent(typeof(AudioSource))] public class Player : MonoBehaviour { [SerializeField] private List m_playerAttributes = new List(); /// /// This array defines thresholds for brightness points. It is used to define multiplier applied to player brightness point on guild. Please see code. /// public static readonly int[] BrightnessPoints_Th = { 30, 20, 0, }; public List Attributes => m_playerAttributes; public GameObject audioSource; public AudioClip[] m_onHitClips, m_noFaithClips, m_cantDoThatYetClips, m_BrightnessLostClips, m_BrightnessGainedClips, m_deathClips; public AudioClip[] consumeDefaultSounds, consumeFaithSounds, consumeGemstoneSounds, equipWeaponSounds, equipConsumablesSounds, equipPowerSounds, unequipWeaponSounds, unequipConsumablesSounds, unequipPowerSounds, changePageSounds, changeCategorySounds, openMenuSounds, acceptGuiltSounds, declineGuiltSounds, fullyChargedSounds; private List weaponTypes = new List { bItemType.Swords, bItemType.Axes }; private List consumablesTypes = new List { bItemType.Consumable, bItemType.ConsumablesFaith }; public Image interactionImage; private Sprite defaultInteractionImage; public Sprite dialogueInteractionImage; protected AudioSource m_audioSource; public AudioSource AudioSource => m_audioSource; private bThirdPersonInput m_vInputs; private bThirdPersonController m_vController; private vMeleeManager m_meleeManager; private Respawner m_Respawner; private bool m_cutScenePlaying = false; private QuestJournal m_questJournal; private PlayerConfessionController m_playerConfessionController; public QuestJournal QuestJournal => m_questJournal; public PlayerConfessionController PlayerConfessionController => m_playerConfessionController; public bThirdPersonInput PlayerInput => m_vInputs; public bThirdPersonController ThirdPersonController => m_vController; public float slowMoOnHtScale = 0.1f; public float slowMoOnHitTime = 0.1f; public vMeleeManager MeleeManager => m_meleeManager; private static Player s_instance; public static Player Instance => s_instance; public bItemManager ItemManager { private set; get; } public WeaponTrail ActiveWeaponTrail { set; get; } private PlayerAttribute faithAttribute; private PlayerAttribute brightnessAttribute; private PlayerAttribute maturityAttribute; private MagicAttacks m_magicAttacks; private bMeleeCombatInput m_meleeCombatInput; public MagicAttacks Magic => m_magicAttacks; public bMeleeCombatInput MeleeCombatInput => m_meleeCombatInput; public PlayerAttribute MaturityAttribute { get { SetMaturityAttributeIfNull(); return maturityAttribute; } } public PlayerAttribute BrightnessAttribute { get { SetBrightnessAttributeIfNull(); return brightnessAttribute; } } public PlayerAttribute FaithAttribute { get { SetFaithAttributeIfNull(); return faithAttribute; } } private void SetMaturityAttributeIfNull() { if (maturityAttribute == null) { maturityAttribute = GetAttribute("Maturity"); } } private void SetBrightnessAttributeIfNull() { if (brightnessAttribute == null) { brightnessAttribute = GetAttribute("BrightnessPoints"); } } private void SetFaithAttributeIfNull() { if (maturityAttribute == null) { faithAttribute = GetAttribute("Faith"); } } [SerializeField] public MenuScroll menuScroll; // [SerializeField] //private int faithRegenValue = 1; // private float faithRegenTime = 1f; // private float faithCurrentTime = 0f; public float sceneDependantFaithRegenMultiplier = 1f, faithRegenMultiplier = 1f; private float healthBaseMaxValue = 200; private float healthBaseRegenValue = 1; private float staminaBaseMaxValue = 200; private float staminaBaseRegenValue = 1.2f; private float faithBaseMaxValue = 100f; private System.Action onMenuScrollClosed; public System.Action onStatsUpdated; private UnityAction onDialogueEnded; private bLockOn m_lockOn; //cached lock on component public bLockOn LockOn => m_lockOn; private vLadderAction ladderAction; public float CurrentHealth => m_vController.currentHealth; public float MaxHealth => m_vController.MaxHealth; public AutoTargetting AutoTarget => m_autoTargetting; private AutoTargetting m_autoTargetting; private void Awake() { if (s_instance == null) { s_instance = this; } else { Debug.LogError($"Player instance already exists! Destroying...({gameObject.name})"); Destroy(gameObject); } m_lockOn = GetComponent(); ladderAction = GetComponent(); m_audioSource = GetComponent(); m_vInputs = GetComponent(); m_vController = GetComponent(); ItemManager = GetComponent(); m_questJournal = GetComponent(); m_Respawner = GetComponent(); m_playerConfessionController = GetComponent(); m_meleeManager = GetComponent(); m_magicAttacks = GetComponent(); m_autoTargetting = GetComponent(); m_meleeCombatInput = GetComponent(); } private void OnEnable() { //InitAttributesValues(); HideUI.SetActive += OnCustcene; if (m_vInputs) m_vInputs.forceWalking = false; } protected void Start() { InitAttributesValues(); InitAttributListeners(); RegisterLuaFunctions(); DialogueManager.instance.conversationStarted += OnConversationStarted; DialogueManager.instance.conversationEnded += OnConversationEnded; m_Respawner.m_onRespawned.AddListener(ResetInputs); // m_Respawner.m_onRespawnedStart.AddListener(ResetAnimator); m_vController.onDead.AddListener(ResetAnimator); //CheckAttributesValues(); if (m_meleeManager) { m_meleeManager.onDamageHit.AddListener(OnDamageHit); } } private void OnDamageHit(vHitInfo arg0) { if (slowMoOnHtScale < 1f - float.Epsilon) { //TimeController.Instance.SetTimeScaleForSec(slowMoOnHtScale, slowMoOnHitTime); TimeController.Instance.Reset(); } } private void OnConversationStarted(Transform transform) { PlayerInput.SetLockAllInput(true); } private void OnConversationEnded(Transform transform) { PlayerInput.SetLockAllInput(false); } private void OnDisable() { HideUI.SetActive -= OnCustcene; } protected void OnDestroy() { RemoveAttributeListeners(); UnregisterLuaFunctions(); if (menuScroll != null) menuScroll.OnClosed -= onMenuScrollClosed; if (DialogueManager.instance != null) DialogueManager.instance.conversationStarted -= OnConversationStarted; if (DialogueManager.instance != null) DialogueManager.instance.conversationEnded -= OnConversationEnded; m_Respawner.m_onRespawned.RemoveListener(ResetInputs); m_Respawner.m_onRespawnedStart.RemoveListener(ResetAnimator); // m_vController.onDead.RemoveListener(ResetAnimatior); } protected void Update() { float faith = faithAttribute.AttributeCurrentValue; faith += Time.deltaTime * faithRegenMultiplier; faithAttribute.SetValue(faith); /* faithCurrentTime += Time.deltaTime; if (faithCurrentTime > faithRegenTime / faithRegenMultiplier) { faithCurrentTime -= faithCurrentTime; float newVal = faithAttribute.AttributeCurrentValue + 1; if (newVal > faithAttribute.AttributeMaxValue) { newVal = faithAttribute.AttributeMaxValue; } else if (newVal < faithAttribute.AttributeMinValue) { newVal = faithAttribute.AttributeMinValue; } faithAttribute.SetValue(newVal); } */ // bThirdPersonController controller = (bThirdPersonController)m_vController; // controller.animatorStateInfos.stateInfos.vToList().ForEach(info => { Debug.Log(info.layer); Debug.Log(info.tags.Count); info.tags.ForEach(tag => Debug.Log(tag)); }); } public void ResetInputs() { // ResetAnimator(); bThirdPersonController controller = (bThirdPersonController)m_vController; //controller.triggerDieBehaviour = false; //m_vInputs.SetLockAllInput(false); //controller.EnableGravityAndCollision(); //controller.StopCharacter(); //controller.disableAnimations = false; controller.triggerDieBehaviour = false; ladderAction = GetComponent(); ladderAction.ResetPlayerSettings(); } public void ResetAnimator(GameObject gameObject) { ResetAnimator(); } public void ResetAnimator() { bThirdPersonController controller = (bThirdPersonController)m_vController; controller.animator.SetInteger(vAnimatorParameters.ActionState, 0); controller.RemoveAnimatorTags(); } public void PlayNoFaithClip() { PlayRandomSound(m_noFaithClips); } private void PlayRandomSound(AudioClip[] sounds) { //so we do not get bunch of sounds at the game start if (Time.timeSinceLevelLoad < 1f) { return; } int soundsCount = sounds.Length; if (audioSource != null && soundsCount > 0) { AudioClip clip = sounds[Random.Range(0, soundsCount)]; GameObject audioObject = Instantiate(audioSource, transform.position, transform.rotation) as GameObject; audioObject.GetComponent().PlayOneShot(clip); } } public void PlayICantDoThatYet() { PlayRandomSound(m_cantDoThatYetClips); } public void PlayBrightnessLost() { PlayRandomSound(m_BrightnessLostClips); } public void PlayBrightnessGained() { PlayRandomSound(m_BrightnessGainedClips); } public void PlayMaturityGained() { PlayRandomSound(m_BrightnessGainedClips); } public void PlayConsumeSound(bItem consumedItem) { if (consumedItem.type == bItemType.ConsumablesFaith) { PlayRandomSound(consumeFaithSounds); } else if (consumedItem.type == bItemType.Gemstones) { PlayRandomSound(consumeGemstoneSounds); } else if (consumedItem.type == bItemType.PowerScroll) { } else { PlayRandomSound(consumeDefaultSounds); } } public void PlayFullyChargedSound() { PlayRandomSound(fullyChargedSounds); } public void PlayEquipSound(bEquipArea equipArea, bItem item) { if (consumablesTypes.Contains(item.type)) { PlayRandomSound(equipConsumablesSounds); } else if (weaponTypes.Contains(item.type)) { PlayRandomSound(equipWeaponSounds); } else { PlayRandomSound(equipPowerSounds); } } public void PlayUnequipSound(bEquipArea equipArea, bItem item) { if (consumablesTypes.Contains(item.type)) { PlayRandomSound(unequipConsumablesSounds); } else if (weaponTypes.Contains(item.type)) { PlayRandomSound(unequipWeaponSounds); } else { PlayRandomSound(unequipPowerSounds); } } public void PlayCategoryChangeSound() { PlayRandomSound(changeCategorySounds); } public void PlayChangePageSound() { PlayRandomSound(changePageSounds); } public void PlayOpenMenuSound() { PlayRandomSound(openMenuSounds); } public void PlayAcceptGuiltSound() { PlayRandomSound(acceptGuiltSounds); } public void PlayDeclineGuiltSound() { PlayRandomSound(declineGuiltSounds); } public void PlayOnHitSound() { PlayRandomSound(m_onHitClips); } public void PlayOnDeathSound() { PlayRandomSound(m_deathClips); } private void OnCustcene(bool b) { m_audioSource.Stop(); m_audioSource.clip = null; //on ui show player should be killable and vice versa m_cutScenePlaying = !b; m_vController.isImmortal = !b; // Debug.LogError("is immortal: " + m_vController.isImmortal); } public void OnReceivedDamage(vDamage damage) { if (m_cutScenePlaying) return; #if UNITY_IOS && !UNITY_EDITOR HapticEngine.ImpactFeedbackHeavy(); #endif if (m_onHitClips != null && m_onHitClips.Length > 0) PlayOnHitSound(); } /// /// death sound canceled as of now /// /// public void OnDead(GameObject gameObject) { if (m_cutScenePlaying) return; #if UNITY_IOS && !UNITY_EDITOR HapticEngine.ImpactFeedbackHeavy(); #endif if (m_deathClips != null && m_deathClips.Length > 0) PlayOnDeathSound(); } public void OnCheckpoint() { if (m_Respawner) { m_Respawner.SaveRespawnPoint(); } } public List GetAllGuilts() { if (!m_questJournal) { Debug.LogError("There is no Players Journal component on player game object"); return null; } List guilts = new List(); for (int i = 0; i < m_questJournal.questList.Count; i++) { if (m_questJournal.questList[i].isTrackable == false) // if in future will be not trackable quest we also should check quest group { guilts.Add(m_questJournal.questList[i]); } } return guilts; } [Button] public void Debug_DisplayAllGuilts() { var guilts = GetAllGuilts(); guilts.ForEach(x => Debug.LogError(x.title)); } public PlayerAttribute GetAttribute(string name) { for (int i = 0; i < m_playerAttributes.Count; i++) { if (m_playerAttributes[i].AttributeName == name) { return m_playerAttributes[i]; } } Debug.LogError("There is no player attribute such " + name); return null; } public void SetAttribute(string name, int value) { PlayerAttribute playerAttribute = GetAttribute(name); if (playerAttribute == null) { return; } playerAttribute.SetValue(value); } public void SetAttribute(PlayerAttribute attribute) { PlayerAttribute playerAttribute = GetAttribute(attribute.AttributeName); if (playerAttribute == null) { return; } playerAttribute.SetValue(attribute); } public void ClearAttributesValue() { m_playerAttributes.ForEach(x => x.ClearValue()); } private void InitAttributesValues() { m_playerAttributes.ForEach(x => x.Init()); } private void InitAttributListeners() { //add listener brightnessAttribute = GetAttribute("BrightnessPoints"); if (brightnessAttribute != null) { brightnessAttribute.OnValueChanged.AddListener(OnBrightnessPointsValueChanged); brightnessAttribute.OnValueChanged.AddListener(UpdatePlayerStatisticsOnBrightnessChange); } else { Debug.LogError("Couldnt get Brightness attribute "); } faithAttribute = GetAttribute("Faith"); if (faithAttribute == null) { Debug.LogError("Couldnt get Faith attribute "); } maturityAttribute = GetAttribute("Maturity"); if (maturityAttribute != null) { maturityAttribute.OnValueChanged.AddListener(UpdatePlayerStatisticsOnMaturityChange); maturityAttribute.OnValueChanged.AddListener(OnMaturityPointsValueChanged); } else { Debug.LogError("Couldnt get Maturity attribute "); } } private void RemoveAttributeListeners() { maturityAttribute.OnValueChanged.RemoveListener(UpdatePlayerStatisticsOnMaturityChange); maturityAttribute.OnValueChanged.RemoveListener(OnMaturityPointsValueChanged); brightnessAttribute.OnValueChanged.RemoveListener(UpdatePlayerStatisticsOnBrightnessChange); } private void RegisterLuaFunctions() { Lua.RegisterFunction("GetBrightness", this, SymbolExtensions.GetMethodInfo(() => GetBrightness())); Lua.RegisterFunction("SetBrightness", this, SymbolExtensions.GetMethodInfo(() => SetBrightness((double)0))); Lua.RegisterFunction("SetMaturity", this, SymbolExtensions.GetMethodInfo(() => SetMaturity((double)0))); Lua.RegisterFunction("GetMaturity", this, SymbolExtensions.GetMethodInfo(() => GetMaturity())); } private void UnregisterLuaFunctions() { Lua.UnregisterFunction("GetBrightness"); Lua.UnregisterFunction("SetBrightness"); Lua.UnregisterFunction("SetMaturity"); Lua.UnregisterFunction("GetMaturity"); } public void UodatePlayerStatistics() { float maturityMupltiplier = (float)(1 + (float)(0.5f * maturityAttribute.AttributeCurrentValue / maturityAttribute.AttributeMaxValue)); float maxBrightness = brightnessAttribute.AttributeMaxValue; float halfB = maxBrightness / 2; float brightnessMultiplier = 1 + (brightnessAttribute.AttributeCurrentValue - halfB) / halfB; float finalMultiplier = maturityMupltiplier * brightnessMultiplier; SetPlayerStatisticsBasedOn(finalMultiplier); } public void UpdatePlayerStatisticsOnBrightnessChange(float val = 0, float prevVal = 0) { float maturityMupltiplier = (float)(1 + (float)(0.5f * maturityAttribute.AttributeCurrentValue / maturityAttribute.AttributeMaxValue)); float maxBrightness = brightnessAttribute.AttributeMaxValue; float halfB = maxBrightness / 2; float brightnessMultiplier = 1 + (val - halfB) / halfB; float finalMultiplier = maturityMupltiplier * brightnessMultiplier; SetPlayerStatisticsBasedOn(finalMultiplier); } private void SetPlayerStatisticsBasedOn(float finalMultiplier) { faithRegenMultiplier = sceneDependantFaithRegenMultiplier * finalMultiplier; faithAttribute.AttributeMaxValue = Mathf.RoundToInt(faithBaseMaxValue * finalMultiplier); m_vController.maxHealth = Mathf.RoundToInt(finalMultiplier * healthBaseMaxValue); if (m_vController.maxHealth < m_vController.currentHealth) { m_vController.ResetHealth(); } m_vController.SetHealthRecovery(finalMultiplier * healthBaseRegenValue); m_vController.maxStamina = Mathf.Round(finalMultiplier * staminaBaseMaxValue); m_vController.staminaRecovery = (finalMultiplier * staminaBaseRegenValue); onStatsUpdated?.Invoke(finalMultiplier); } public void UpdatePlayerStatisticsOnMaturityChange(float val = 0, float prevVal = 0) { float maturityMupltiplier = (float)(1 + ((float)val * 0.5f / maturityAttribute.AttributeMaxValue)); float maxBrightness = brightnessAttribute.AttributeMaxValue; float halfB = maxBrightness / 2f; float brightnessMultiplier = 1 + (brightnessAttribute.AttributeCurrentValue - halfB) / halfB; float finalMultiplier = maturityMupltiplier * brightnessMultiplier; SetPlayerStatisticsBasedOn(finalMultiplier); } [Button] public void UpdateMaturityCurrentValue(int valueChange, int prevVal) { float newVal = maturityAttribute.AttributeCurrentValue + valueChange; if (newVal > maturityAttribute.AttributeMaxValue) { newVal = maturityAttribute.AttributeMaxValue; } else if (newVal < maturityAttribute.AttributeMinValue) { newVal = maturityAttribute.AttributeMinValue; } maturityAttribute.SetValue(newVal); } public float GetCurrentMaturityValue() { return maturityAttribute.AttributeCurrentValue; } public double GetBrightness() { var attr = GetAttribute("BrightnessPoints"); return (double)attr.AttributeCurrentValue; } public void SetBrightness(double value) { brightnessAttribute.SetValue((int)value); //attr.CheckValueWithDatabase(); } public double GetMaturity() { var attr = GetAttribute("Maturity"); return (double)attr.AttributeCurrentValue; } public void SetMaturity(double value) { maturityAttribute.SetValue((int)value); } public void UpdateBrightnessCurrentValue(int points) { UpdateBrightnessCurrentValue((float)points); } [Button] public void UpdateBrightnessCurrentValue(float points) { if (points < 0) { float multiplier = 1f; for (int i = 0; i < BrightnessPoints_Th.Length; i++) { if (brightnessAttribute.AttributeCurrentValue < BrightnessPoints_Th[i]) { multiplier *= 0.5f; } else { break; } } brightnessAttribute.SetValue(brightnessAttribute.AttributeCurrentValue + (int)(points * multiplier)); } else { //add only 50% of points if player is not confesed if (brightnessAttribute.AttributeCurrentValue < 50) { points = points / 2; } brightnessAttribute.SetValue(brightnessAttribute.AttributeCurrentValue + points); } } private void OnBrightnessPointsValueChanged(float value, float prevValues) { if (menuScroll.m_isOpen) { ClearOnMenuScrollClosed(); onMenuScrollClosed = () => { BarkBrightnessChange(value, prevValues); }; menuScroll.OnClosed += onMenuScrollClosed; return; } else if (DialogueManager.instance.IsConversationActive) { onMenuScrollClosed = () => { BarkBrightnessChange(value, prevValues); }; // DialogueManager.instance.OnEndConversation += onMenuScrollClosed; var events = DialogueManager.instance.GetComponent(); onMenuScrollClosed = () => { BarkBrightnessChange(value, prevValues); }; // UnityEvent ev= (transform) => { BarkBrightnessChange(value, prevValues); }; onDialogueEnded = (transform) => { BarkBrightnessChange(value, prevValues); }; // events.onConversationEnd += onDialogueEnded; events.conversationEvents.onConversationEnd.AddListener(onDialogueEnded); return; } BarkBrightnessChange(value, prevValues); } public void OnMaturityPointsValueChanged(float value, float prevValue) { DialogueManager.BarkString("Maturity Gained!", Player.Instance.transform); PlayMaturityGained(); } public void BarkBrightnessChange(float value, float prevValues) { float difference = Mathf.Abs(value - prevValues); if (difference < 1f) { //to not spam with small gains } else if (value > prevValues) { DialogueManager.BarkString("Brightness Points Gained!", Player.Instance.transform); } else { DialogueManager.BarkString("Brightness Points Lost!", Player.Instance.transform); } ClearOnMenuScrollClosed(); } private void ClearOnMenuScrollClosed() { menuScroll.OnClosed -= onMenuScrollClosed; onMenuScrollClosed = null; if (onDialogueEnded != null) { var events = DialogueManager.instance.GetComponent(); events.conversationEvents.onConversationEnd.RemoveListener(onDialogueEnded); onDialogueEnded = null; } } public float GetCurrentFaithValue() { return faithAttribute.AttributeCurrentValue; } public void UpdateFaithCurrentValue(int valueChange) { UpdateFaithCurrentValue((float)valueChange); } public void UpdateFaithCurrentValue(float valueChange) { float newVal = faithAttribute.AttributeCurrentValue + valueChange; faithAttribute.SetValue(newVal); } public void SetInteractableButtonImage(Sprite image) { if (!defaultInteractionImage) { defaultInteractionImage = interactionImage.sprite; } interactionImage.sprite = image; } public void ResetIntaractableButtonImage() { if (!defaultInteractionImage) { defaultInteractionImage = interactionImage.sprite; } interactionImage.sprite = defaultInteractionImage; } public void SetDialogueIntaractableButtonImage() { if (!defaultInteractionImage) { defaultInteractionImage = interactionImage.sprite; } interactionImage.sprite = dialogueInteractionImage; } public void MoveToTransform(Transform t) { ThirdPersonController._rigidbody.MovePosition(t.position); ThirdPersonController._rigidbody.MoveRotation(t.rotation); } public void PlaySingleSound(AudioClip clipToPlay, bool destroyAfterPlaying = true) { // Opcjonalne op�nienie na starcie poziomu, aby unikn�� "spamowania" d�wi�kami if (Time.timeSinceLevelLoad < 0.5f && clipToPlay != null) { // Mo�esz chcie� to odkomentowa�, je�li d�wi�ki na starcie s� problemem // return; } if (this.audioSource == null) // this.audioSource to pole GameObject (prefab) w Player.cs { Debug.LogWarning("Player's 'audioSource' (GameObject prefab) is not assigned in Inspector. Cannot play sound: " + (clipToPlay ? clipToPlay.name : "Unknown clip")); return; } if (clipToPlay == null) { Debug.LogWarning("Attempted to play a null AudioClip."); return; } // Instancjonowanie prefabu d�wi�kowego // Upewnij si�, �e prefab 'audioSource' ma komponent AudioSource GameObject audioObjectInstance = Instantiate(this.audioSource, transform.position, transform.rotation); AudioSource sourceComponent = audioObjectInstance.GetComponent(); if (sourceComponent != null) { // PlayOneShot jest dobre dla efekt�w, nie przerywa innych d�wi�k�w na tym samym source, // je�li s� one odtwarzane przez .Play() i nie u�ywaj� tego samego kana�u. sourceComponent.PlayOneShot(clipToPlay); if (destroyAfterPlaying) { // Niszczymy obiekt GameObject zawieraj�cy AudioSource po zako�czeniu odtwarzania klipu. // Dodajemy ma�y bufor czasowy, aby upewni� si�, �e d�wi�k zd��y si� odtworzy� w ca�o�ci. Destroy(audioObjectInstance, clipToPlay.length + 0.1f); } } else { Debug.LogWarning("The instantiated 'audioSource' prefab (from Player.cs) does not have an AudioSource component. Destroying instance."); Destroy(audioObjectInstance); // Posprz�taj, je�li co� posz�o nie tak } } } [System.Serializable] public class PlayerAttribute { public string AttributeName; public float AttributeCurrentValue; public float AttributeMaxValue; public float AttributeMinValue = 0; public UnityEvent OnValueChanged; public void SetValue(PlayerAttribute attribute) { if (attribute.AttributeName != AttributeName) return; AttributeMaxValue = attribute.AttributeMaxValue; AttributeMinValue = attribute.AttributeMinValue; SetValue(attribute.AttributeCurrentValue); } public void Init() { //var variable = DialogueLua.GetVariable(AttributeName).asInt; //AttributeCurrentValue = variable; DialogueLua.SetVariable(AttributeName, AttributeCurrentValue); } public void SetValue(float value) { if (value != AttributeCurrentValue) { /* if (value > AttributeMaxValue || value < AttributeMinValue) { Debug.LogWarning( $"Can't set variable. Out of range. AttributeName={AttributeName} with value want to be set to: {value}"); return; } */ value = value > AttributeMaxValue ? AttributeMaxValue : value; value = value < AttributeMinValue ? AttributeMinValue : value; OnValueChanged?.Invoke(value, AttributeCurrentValue); AttributeCurrentValue = value; DialogueLua.SetVariable(AttributeName, value); } } /* public void CheckValueWithDatabase() { var variable = DialogueLua.GetVariable(AttributeName).asInt; if (variable == AttributeCurrentValue) { return; } AttributeCurrentValue = variable; OnValueChangedDatabase?.Invoke(variable); } */ public void ClearValue() { AttributeCurrentValue = AttributeMinValue; } } }