Beispiel #1
0
        public void OnVitalChange(Vital vital)
        {
            int cnt = onVitalChangeCallbacks.Count;

            for (int i = 0; i < cnt; ++i)
            {
                onVitalChangeCallbacks[i].OnVitalChange(vital);
            }
        }
Beispiel #2
0
        public override void UpdateGraphics(Vital vital)
        {
            if (vital == null)
            {
                return;
            }

            var vitalDef = vital.VitalDef;

            float val =             /*(vital == null) ? 1 :*/
                        (targetField == TargetField.Value) ? vital.VitalData.Value :
                        (targetField == TargetField.Max) ? vitalDef.FullValue :
                        vitalDef.MaxValue;

            /// NegativeInfinity is my indicator that this vitalData value has no data (may be a delta frame) - so it is not null... its just unknown.
            if (val == float.NegativeInfinity)
            {
                return;
            }

            if (textMesh)
            {
                textMesh.text = ((int)val).ToString();
            }

            if (barSprite)
            {
                barSprite.size = new Vector2((val / vitalDef.MaxValue) * widthMultiplier, barSprite.size.y);
            }

            if (UIText != null)
            {
                UIText.text = ((int)val).ToString();
            }

            // Resize the healthbar
            if (UIImage != null)
            {
                float fullval = vitalDef.MaxValue;

                if (UIImage.type == Image.Type.Filled && UIImage.sprite != null)
                {
                    UIImage.fillAmount = (val / fullval) * widthMultiplier;
                }
                else
                {
                    UIImage.rectTransform.localScale = new Vector3(
                        (val / fullval) * widthMultiplier,
                        UIImage.rectTransform.localScale.y,
                        UIImage.rectTransform.localScale.z);
                }
            }
        }
        /// <summary>
        /// Check if the ITriggeringComponent is an IVitalsComponent, and if so that it has the vital that matches the trigger.
        /// </summary>
        /// <param name="frameInt"></param>
        /// <param name="contactEvent"></param>
        /// <returns>Returns true if this triggerer is a IVitalsComponent, and contains the indicated vital type.</returns>
        public static Vital GetTriggeringVital(this ContactEvent contactEvent, VitalNameType vitalNameType)
        {
            var ivc = (contactEvent.itc as IVitalsComponent);

            if (ReferenceEquals(ivc, null))
            {
                return(null);
            }

            Vitals vitals = ivc.Vitals;
            Vital  vital  = vitals.GetVital(vitalNameType);

            return(vital);
        }
Beispiel #4
0
        public override void OnAwake()
        {
            base.OnAwake();

            vitalArray  = vitals.VitalArray;
            vitalsCount = vitals.vitalDefs.Count;
            rootVital   = vitalArray[0];

            /// subscribe to callbacks to Vitals changes
            vitals.onVitalChangeCallbacks.Add(this);

            lastSentData = new VitalsData(vitals);
            for (int i = 0; i < vitalsCount; ++i)
            {
                vitalArray[i].ResetValues();
            }

            defaultMountingMask = 1 << (defaultMounting.id);
        }
Beispiel #5
0
        public void OnValueChange(Vital vital)
        {
            //int cnt = iOnVitalChange.Count;
            //for (int i = 0; i < cnt; ++i)
            //	iOnVitalChange[i].OnValueChange(vital);

            //Debug.Log(transform.root.name + " " + name + " " + vitalArray[0].intValue);

            if (autoDespawn)
            {
                if (syncState)
                {
                    if (ReferenceEquals(rootVital, vital))
                    {
                        if (vital.VitalData.IntValue <= 0)
                        {
                            syncState.Despawn(false);
                        }
                    }
                }
            }
        }
Beispiel #6
0
        public bool TryTrigger(IOnTrigger trigger, ref ContactEvent contactEvent, int compatibleMounts)
        {
            if (!useHitGroups || validHitGroups != 0)
            {
                var hga         = contactEvent.contacted.GetComponent <HitGroupAssign>();
                int triggermask = hga ? hga.Mask : 0;
                if ((validHitGroups.Mask & triggermask) == 0)
                {
#if UNITY_EDITOR
                    Debug.Log(name + " SyncVitals.TryTrigger() HitGroup Mismatch. Cannot pick up '" + hga.transform.root.name + "' because its has a non-matching HitGroupAssign.");
#endif
                    return(false);
                }
            }

            ///TODO: Make this into an interface rather than this component type
            var otherVitalNameType = (trigger as IVitalsAffector);

            Vital vital = vitals.GetVital(otherVitalNameType.VitalNameType);
            if (vital == null)
            {
                return(false);
            }

            /// If both are set to 0 (Root) then consider that a match, otherwise zero for one but not the other is a mismatch (for now)
            if ((compatibleMounts == defaultMountingMask) || (compatibleMounts & defaultMountingMask) != 0)
            {
                contactEvent = new ContactEvent(contactEvent)
                {
                    triggeringObj = vital
                };
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #7
0
        public void Initialize()
        {
            if (initialized)
            {
                return;
            }


            /// Create Vital for each VitalDefinition at runtime
            vitalCount = vitalDefs.Count;
            vitalArray = new Vital[vitalCount];

            for (int i = 0; i < vitalCount; ++i)
            {
                VitalDefinition vdef  = vitalDefs[i];
                Vital           vital = new Vital(vdef);
                vitalArray[i] = vital;

                vital.Initialize(Time.fixedDeltaTime * SimpleSyncSettings.SendEveryXTick);
                vital.AddIOnVitalChange(this);

                // add all of the vital types to the lookup. Customs use hash, enumerated are added both as hash and by their index
                int hash = vdef.VitalName.hash;
                if (vdef.VitalName.type != VitalType.None)
                {
                    if (!vitalLookup.ContainsKey(hash))
                    {
                        vitalLookup.Add(hash, vital);
                    }
                    else
                    {
                        Debug.LogWarning("VitalNameType hash collison! Vitals cannot have more than one of each Vital Type in its list.");
                    }
                }
            }

            initialized = true;
        }
Beispiel #8
0
 public abstract void UpdateGraphics(Vital vital);
Beispiel #9
0
 public virtual void OnValueChange(Vital vital)
 {
     UpdateGraphics(vital);
 }
Beispiel #10
0
 public void OnVitalChange(Vital vital)
 {
     /// TODO: different update graphics for max/full value changes
 }
Beispiel #11
0
 public void OnVitalChange(Vital vital)
 {
     //int cnt = iOnVitalChange.Count;
     //for (int i = 0; i < cnt; ++i)
     //	iOnVitalChange[i].OnVitalChange(vital);
 }