public void OnVitalParamChange(Vital vital) { for (int i = 0, cnt = OnVitalParamChangeCallbacks.Count; i < cnt; ++i) { OnVitalParamChangeCallbacks[i].OnVitalParamChange(vital); } }
public override void OnAwake() { base.OnAwake(); this.transform.EnsureRootComponentExists <ContactManager, NetObject>(); if (netObj) { syncState = netObj.GetComponent <SyncState>(); } vitalArray = vitals.VitalArray; vitalsCount = vitals.vitalDefs.Count; rootVital = vitalArray[0]; /// subscribe to callbacks to Vitals changes vitals.OnVitalValueChangeCallbacks.Add(this); lastSentData = new VitalsData(vitals); for (int i = 0; i < vitalsCount; ++i) { vitalArray[i].ResetValues(); } defaultMountingMask = 1 << (defaultMounting.id); }
public void OnVitalParamChange(Vital vital) { Debug.LogError("Not implemented"); for (int i = 0, cnt = OnVitalsParamChange.Count; i < cnt; ++i) { OnVitalsParamChange[i].OnVitalParamChange(vital); } }
public void OnVitalValueChange(Vital vital) { if (vital.VitalData.Value <= 0) { RootVitalBecameZero(vital); } for (int i = 0, cnt = OnVitalsValueChange.Count; i < cnt; ++i) { OnVitalsValueChange[i].OnVitalValueChange(vital); } }
public override void UpdateGraphics(Vital vital) { if (vital == null) { return; } var vitalDef = vital.VitalDef; double 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((float)((val / vitalDef.MaxValue) * widthMultiplier), barSprite.size.y); } if (UIText != null) { UIText.text = ((int)val).ToString(); } // Resize the healthbar if (UIImage != null) { double fullval = vitalDef.MaxValue; if (UIImage.type == Image.Type.Filled && UIImage.sprite != null) { UIImage.fillAmount = (float)((val / fullval) * widthMultiplier); } else { UIImage.rectTransform.localScale = new Vector3( (float)((val / fullval) * widthMultiplier), UIImage.rectTransform.localScale.y, UIImage.rectTransform.localScale.z); } } }
protected virtual void RootVitalBecameZero(Vital vital) { for (int i = 0, cnt = OnRootVitalBecameZero.Count; i < cnt; ++i) { OnRootVitalBecameZero[i].OnRootVitalBecameZero(vital, null); } if (autoDespawn) { if (syncState) { if (ReferenceEquals(rootVital, vital)) { syncState.Despawn(false); } } } }
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(TickEngineSettings.netTickInterval); 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 collision! Vitals cannot have more than one of each Vital Type in its list."); } } } initialized = true; }
public Consumption TryTrigger(IContactReactor icontactReactor, ContactEvent contactEvent, int compatibleMounts) { var reactor = (icontactReactor as IVitalsContactReactor); if (ReferenceEquals(reactor, null)) { return(Consumption.None); } /// First test to see if the contacting and contacted are a groups match - if not return false. if (contactGroups != 0) { //var groups = (reactor as Component).GetComponent<ContactGroupAssign>(); IContactGroupsAssign groups = contactEvent.contactTrigger.ContactGroupsAssign; int triggermask = ReferenceEquals(groups, null) ? 0 : groups.Mask; if ((contactGroups.Mask & triggermask) == 0) { #if UNITY_EDITOR Debug.Log(name + " SyncVitals.TryTrigger() ContactGroup Mismatch. Cannot pick up '" + (contactEvent.contactTrigger as Component).transform.root.name + "' because its has a non-matching ContactGroupAssign."); #endif return(Consumption.None); } } /// 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) { return(Consumption.None); } Vital vital = vitals.GetVital(reactor.VitalNameType); if (vital == null) { return(Consumption.None); } /// Apply changes resulting from the trigger. Return true if affected/consumed. This bool is used to inform whether the trigger should despawn/pickup. //double charge = vpr.Charge; Consumption consumed; double amountConsumed; { /// Apply to vital if vital has authority. if (IsMine) { double discharge = reactor.DischargeValue(contactEvent.contactType); amountConsumed = vitals.ApplyCharges(discharge, reactor.AllowOverload, reactor.Propagate); } /// Vital does not belong to us, but we want to know IF it would have been consumed for prediction purposes. else { amountConsumed = vital.TestApplyChange(reactor, contactEvent); } } var consumable = icontactReactor as IVitalsConsumable; if (!ReferenceEquals(consumable, null)) { consumed = TestConsumption(amountConsumed, consumable, contactEvent); } else { consumed = Consumption.None; } return(consumed); }
public abstract void UpdateGraphics(Vital vital);
public virtual void OnVitalValueChange(Vital vital) { UpdateGraphics(vital); }
public void OnVitalParamChange(Vital vital) { /// TODO: different update graphics for max/full value changes }