Exemplo n.º 1
0
 /// <summary>
 /// This OnValidate Method helps assure that the referenced Monobehaviour component implements IMeterable.
 /// </summary>
 private void OnValidate()
 {
     if (Meterable == null && MeterableObject != null)
     {
         if ((MeterableObject as IMeterable) != null)
         {
             Meterable = MeterableObject as IMeterable;
         }
         else
         {
             // If the object is a gameObject or a Monobehaviour, check Monobehaviours on same object.
             GameObject go = (MeterableObject as GameObject);
             if (go == null)
             {
                 MonoBehaviour mb = (MeterableObject as MonoBehaviour);
                 if (mb != null)
                 {
                     go = mb.gameObject;
                 }
             }
             if (go != null)
             {
                 foreach (var behaviour in go.GetComponents <MonoBehaviour>())
                 {
                     if ((behaviour as IMeterable) != null)
                     {
                         MeterableObject = behaviour;
                         Meterable       = (behaviour as IMeterable);
                         break;
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
        private void HandleEventSubscription(bool state)
        {
            //if(!MeterableBehaviour && Meterable == null) return;
            if (Meterable == null && MeterableObject != null)
            {
                var m = MeterableObject as IMeterable;
                if (m != null)
                {
                    Meterable = m;
                }
            }

            if (Meterable != null)
            {
                if (state)
                {
                    if (!IsSubscribed)
                    {
                        Meterable.OnUpdateValue += DoOnUpdateValue;
                    }
                }
                else
                {
                    if (IsSubscribed)
                    {
                        Meterable.OnUpdateValue -= DoOnUpdateValue;
                    }
                }

                IsSubscribed = state;
            }
        }
Exemplo n.º 3
0
 public virtual void SetMeterable(IMeterable meterable)
 {
     if (Meterable != null)
     {
         HandleEventSubscription(false);
     }
     Meterable = meterable;
     HandleEventSubscription(true);
 }
Exemplo n.º 4
0
        public virtual void SetMeterable(IMeterable meterable)
        {
            if (Meterable != null)
            {
                HandleEventSubscription(false);
            }
            Meterable = meterable;
            if (Meterable.GetType().IsAssignableFrom(typeof(UnityEngine.Object)))
            {
                MeterableObject = Meterable as UnityEngine.Object;
            }
            HandleEventSubscription(true);

            if (IsSubscribed)
            {
                UpdateMeter(Meterable.PercentValue);
            }
        }
        public void Initialize(StatusEffectBase statEffect)
        {
            if (statusEffect != null)
            {
                Debug.LogWarning("Status Effect was already assigned!");
            }
            statusEffect = statEffect;

            // Attach meters
            if (meters.Length > 0 && typeof(IMeterable).IsAssignableFrom(statusEffect.GetType()))
            {
                IMeterable m = statusEffect as IMeterable;
                foreach (MeterBase meter in meters)
                {
                    meter.SetMeterable(m);
                }
            }

            OnInitialized();
        }