コード例 #1
0
        // Update is called once per frame
        void Update()
        {
            if (Input.GetKeyDown(AddHealthKey))
            {
                vitals.ApplyCharges(vitalType, amount, false, false);
            }

            if (Input.GetKeyDown(RemHealthKey))
            {
                vitals.ApplyCharges(vitalType, -amount, false, true);
            }

            if (Input.GetKeyDown(DamagehKey))
            {
                vitals.ApplyCharges(amount, false, true);
            }
        }
コード例 #2
0
ファイル: SyncVitals.cs プロジェクト: ajinkya2020/FPS-GAME
        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);
        }