Files
BABA_YAGA/Assets/Third Parties/Opsive/UltimateCharacterController/Demo/Scripts/Objects/HealingCrate.cs
Scove 3e39117acc Consolidate third-party plugins into Assets/Plugins
Move and consolidate many third-party plugin files and metadata from various locations (notably Assets/Third Parties/Plugins 1 and scattered Opsive/Photon folders) into a unified Assets/Plugins directory. Includes DOTween, PrimeTween, Native/BackroomsNoise, Sirenix/Odin Inspector, and Opsive UltimateCharacterController/shared libs, plus updates to several .meta files and removal of obsolete installer/legacy files. This standardizes plugin layout and cleans up duplicate/obsolete assets.
2026-06-16 18:41:44 +07:00

75 lines
2.6 KiB
C#

/// ---------------------------------------------
/// Ultimate Character Controller
/// Copyright (c) Opsive. All Rights Reserved.
/// https://www.opsive.com
/// ---------------------------------------------
namespace Opsive.UltimateCharacterController.Demo.Objects
{
using Opsive.Shared.Events;
using Opsive.UltimateCharacterController.Traits;
using UnityEngine;
/// <summary>
/// A healing crate will update its material if it is healed.
/// </summary>
public class HealingCrate : MonoBehaviour
{
[Tooltip("The material representing a damaged crate.")]
[SerializeField] protected Material m_DamagedMaterial;
[Tooltip("The material representing a healed crate.")]
[SerializeField] protected Material m_HealedMaterial;
[Tooltip("The crate is healed when the Health attribute is greater than the specified value.")]
[SerializeField] protected float m_HealedAttributeValue = 40;
private Renderer m_Renderer;
private Attribute m_HealthAttribute;
private float m_StartingAttributeValue;
/// <summary>
/// Initialize the default values.
/// </summary>
private void Awake()
{
m_Renderer = gameObject.GetComponent<Renderer>();
var attributeManager = gameObject.GetComponent<AttributeManager>();
m_HealthAttribute = attributeManager.GetAttribute("Health");
m_StartingAttributeValue = m_HealthAttribute.Value;
EventHandler.RegisterEvent<Attribute>(gameObject, "OnAttributeUpdateValue", OnUpdateValue);
}
/// <summary>
/// The attribute value has beeen updated.
/// </summary>
/// <param name="attribute">The attribute that has been updated.</param>
private void OnUpdateValue(Attribute attribute)
{
if (attribute != m_HealthAttribute) {
return;
}
if (attribute.Value >= m_HealedAttributeValue) {
m_Renderer.sharedMaterial = m_HealedMaterial;
} else {
m_Renderer.sharedMaterial = m_DamagedMaterial;
}
}
/// <summary>
/// Revert the health attribute value when the object is disabled.
/// </summary>
private void OnDisable()
{
m_HealthAttribute.Value = m_StartingAttributeValue;
}
/// <summary>
/// The object has been destroyed.
/// </summary>
private void OnDestroy()
{
EventHandler.UnregisterEvent<Attribute>(gameObject, "OnAttributeUpdateValue", OnUpdateValue);
}
}
}