コード例 #1
0
        public virtual void Awake()
        {
            if (_proxy == null)
            {
                _proxy = this;
            }

            GetAllowedTypesFromHashes();

            PollInterfaces();

            netObj      = transform.GetParentComponent <NetObject>();
            syncContact = GetComponent <ISyncContact>();

            /// Associate a group assign with this component.
            contactGroupsAssign = GetComponent <ContactGroupAssign>();
            // If no group assign on this node, find parent and use that if set to apply to children
            if (ReferenceEquals(contactGroupsAssign, null))
            {
                var found = transform.GetNestedComponentInParent <IContactGroupsAssign, NetObject>();
                if (found != null && found.ApplyToChildren)
                {
                    contactGroupsAssign = found;
                }
            }

            // cache the mask of ContactTypes that will be responded to
            foreach (IOnContactEvent cb in OnContactEventCallbacks)
            {
                usedContactTypes |= cb.TriggerOn;
            }
        }
コード例 #2
0
        private void Awake()
        {
            rb                  = GetComponentInParent <Rigidbody>();
            rb2d                = GetComponentInParent <Rigidbody2D>();
            _hasRigidBody       = rb || rb2d;
            useRbForces         = rb && !rb.isKinematic;
            useRb2dForces       = rb2d && !rb2d.isKinematic;
            useRBGravity        = (rb && rb.useGravity) || (rb2d && rb.useGravity);
            needsSnapshot       = !_hasRigidBody || (rb && rb.isKinematic) || (rb2d && rb2d.isKinematic);
            localContactTrigger = GetComponent <IContactTrigger>();
            /// Register timing callbacks with Master.
            /// TODO: We likely should slave timings off of the owner
            if (needsSnapshot)
            {
                NetMasterCallbacks.RegisterCallbackInterfaces(this);
            }

            /// No need for the interpolation callback if we are using forces.
            if (_hasRigidBody)
            {
                NetMasterCallbacks.onPreUpdates.Remove(this);
            }

            /// Find interfaces for termination callbacks
            GetComponents(onHit);
            GetComponents(onTerminate);
        }
コード例 #3
0
        protected virtual void Reset()
        {
            this._proxy = this;
            PollInterfaces();

            FindDerivedTypesFromAssembly();
            GetAllowedTypesFromHashes();
        }
コード例 #4
0
 private void Reset()
 {
     /// Projectiles need to detect collisions with everything
     localContactTrigger = GetComponent <IContactTrigger>();
     if (ReferenceEquals(localContactTrigger, null))
     {
         localContactTrigger = gameObject.AddComponent <ContactTrigger>();
     }
 }
コード例 #5
0
        protected override void Reset()
        {
            base.Reset();

            trigger = GetComponent <IContactTrigger>();
            if (ReferenceEquals(trigger, null))
            {
                trigger = gameObject.AddComponent <ContactTrigger>();
            }
        }
コード例 #6
0
        public override void OnAwake()
        {
            base.OnAwake();

            contactTrigger = GetComponent <IContactTrigger>();

            rb            = GetComponentInParent <Rigidbody>();
            rb2d          = GetComponentInParent <Rigidbody2D>();
            _hasRigidbody = rb || rb2d;

            //transform.GetNestedComponentsInChildren<IOnContact, NetObject>(this.OnTriggerCallbacks);
        }
コード例 #7
0
ファイル: SyncShootBase.cs プロジェクト: ajinkya2020/FPS-GAME
        public override void OnAwakeInitialize(bool isNetObject)
        {
            base.OnAwakeInitialize(isNetObject);

            contactTrigger = transform.GetNestedComponentInParents <IContactTrigger, NetObject>();
            hasSyncContact = contactTrigger.SyncContact != null;

            if (origin == null)
            {
                origin = transform;
            }
        }
コード例 #8
0
        public override void OnAwake()
        {
            base.OnAwake();

            trigger = GetComponent <IContactTrigger>();
            if (ReferenceEquals(trigger, null))
            {
                trigger = gameObject.AddComponent <ContactTrigger>();
            }

            rb            = GetComponentInParent <Rigidbody>();
            rb2d          = GetComponentInParent <Rigidbody2D>();
            _hasRigidbody = rb || rb2d;

            transform.GetNestedComponentsInChildren(onTriggerCallbacks);
        }
コード例 #9
0
        public override void OnAwake()
        {
            base.OnAwake();

            /// If no prefab was designated, we need a dummy
            if (projPrefab == null)
            {
                projPrefab = ProjectileHelpers.GetPlaceholderProj();
                Pool.AddPrefabToPool(projPrefab, 8, 8, null, true);
            }
            else
            {
                Pool.AddPrefabToPool(projPrefab);
            }

            contactTrigger = transform.GetNestedComponentInParents <IContactTrigger>();
        }
コード例 #10
0
        protected bool CheckIsNested(IContactTrigger first, IContactTrigger second)
        {
            var firstNO  = first.NetObj;
            var secondNO = second.NetObj;

            var testNO = firstNO;

            while (!ReferenceEquals(testNO, null))
            {
                if (ReferenceEquals(testNO, secondNO))
                {
                    return(true);
                }

                var par = testNO.transform.parent;

                if (ReferenceEquals(par, null))
                {
                    break;
                }

                testNO = par.GetParentComponent <NetObject>();
            }

            testNO = secondNO;

            while (!ReferenceEquals(testNO, null))
            {
                if (ReferenceEquals(testNO, firstNO))
                {
                    return(true);
                }

                var par = testNO.transform.parent;

                if (ReferenceEquals(par, null))
                {
                    break;
                }

                testNO = par.GetParentComponent <NetObject>();
            }

            return(false);
        }
コード例 #11
0
        private bool IsCompatibleSystem(IContactSystem system, IContactTrigger ct)
        {
            var sysType = system.GetType();

            foreach (var ignored in ignoredSystems)
            {
                //Debug.Log(sysType + " <b> compare </b> " + ignored + " " + sysType.CheckIsAssignableFrom(ignored) + ":" + ignored.CheckIsAssignableFrom(sysType));

                //if (sysType.CheckIsAssignableFrom(ignored))
                if (ignored.CheckIsAssignableFrom(sysType))
                {
                    return(false);
                }
            }

            //Debug.Log(name + " <> " + (ct as Component).name  + " <b>match</b> " + sysType.Name);
            return(true);
        }
コード例 #12
0
        protected virtual void Awake()
        {
            transform.GetNestedComponentsInChildren(onContactEventCallbacks);

            rb    = GetComponentInParent <Rigidbody>();
            rb2d  = GetComponentInParent <Rigidbody2D>();
            hasRB = rb || rb2d;

            if (preventRepeats)
            {
                triggeringHitscans = new HashSet <IContacting>();
                triggeringEnters   = new HashSet <IContacting>();
                triggeringStays    = new HashSet <IContacting>();
            }

            /// Default to no proxy
            if (!(proxy as Component))
            {
                proxy = this;
            }
        }
コード例 #13
0
ファイル: ContactEvent.cs プロジェクト: ajinkya2020/FPS-GAME
 public ContactEvent(ContactEvent contactEvent)
 {
     this.contactSystem  = contactEvent.contactSystem;
     this.contactTrigger = contactEvent.contactTrigger;
     this.contactType    = contactEvent.contactType;
 }
コード例 #14
0
 protected virtual void Reset()
 {
     proxy = this;
 }
コード例 #15
0
        public virtual void OnContact(IContactTrigger otherCT, ContactType contactType)
        {
            if (GetComponent <ContactProjectile>() && contactType == ContactType.Enter)
            {
                Debug.Log("Prj Contact");
            }



            /// Check each system that is part of this contact event, to see if what it contacted with is applicable
            List <IContactSystem> systems = otherCT.Proxy.ContactSystems;

            int systemsCount = systems.Count;

            if (systemsCount == 0)
            {
                return;
            }

            /// May be important in preventing race conditions when objects first spawn in, where they might trigger contacts by starting in the wrong state.
            if (netObj != null && !this._proxy.NetObj.AllObjsAreReady)
            {
                //Debug.LogError(Time.time + name + " " + _proxy.NetObj.photonView.OwnerActorNr + " Not ready so ignoring contact");
                return;
            }

            var otherNetObj = otherCT.Proxy.NetObj;

            if (otherNetObj != null && !otherNetObj.AllObjsAreReady)
            {
                Debug.Log(Time.time + name + " " + otherNetObj.photonView.OwnerActorNr + " Other object not ready so ignoring contact");
                return;
            }

            for (int i = 0; i < systemsCount; i++)
            {
                var system = systems[i];

                if (!IsCompatibleSystem(system, otherCT))
                {
                    continue;
                }

                //Debug.Log(name + " " + GetType().Name + " <> " + ics.GetType().Name + " <b>PASSED</b>");
                /// Check to see if we have already reacted to this collision (multiple colliders/etc)
                if (preventRepeats)
                {
                    switch (contactType)
                    {
                    case ContactType.Enter:
                    {
                        if (triggeringEnters.Contains(system))
                        {
                            continue;
                        }

                        triggeringEnters.Add(system);
                        break;
                    }

                    case ContactType.Stay:
                    {
                        if (triggeringStays.Contains(system))
                        {
                            continue;
                        }

                        triggeringStays.Add(system);
                        break;
                    }

                    case ContactType.Exit:
                    {
                        if (!triggeringEnters.Contains(system))
                        {
                            continue;
                        }

                        triggeringEnters.Remove(system);
                        break;
                    }

                    case ContactType.Hitscan:
                    {
                        if (triggeringHitscans.Contains(system))
                        {
                            continue;
                        }

                        triggeringHitscans.Add(system);
                        break;
                    }
                    }
                }

                //Debug.Log("Other " + (otherCT as Component).name + " : " + (otherCT as Component).GetType().Name);

                /// Ignore contact types we have no reactors for. This runs after the above loop, because Enter/Stay/Exit all need to be processed for PreventRepeats to work.
                if ((usedContactTypes & contactType) == 0)
                {
                    return;
                }

                /// If there is an ISyncContact, pass contactEvents to it rather than executing them.
                var contactEvent = new ContactEvent(system, otherCT, contactType);

                if (ReferenceEquals(Proxy.SyncContact, null))
                {
                    ContactCallbacks(contactEvent);
                }
                else
                {
                    syncContact.SyncContactEvent(contactEvent);
                }
            }
        }
コード例 #16
0
ファイル: ContactEvent.cs プロジェクト: ajinkya2020/FPS-GAME
 public ContactEvent(IContactSystem contactSystem, IContactTrigger contacter, ContactType contactType)
 {
     this.contactSystem  = contactSystem;
     this.contactTrigger = contacter;
     this.contactType    = contactType;
 }
コード例 #17
0
        public virtual void OnContact(IContactTrigger otherCT, Component otherCollider, ContactType contactType)
        {
            Debug.Log("contact " + name);

            ///// Ignore collisions if the HitGroups don't check out
            //var otherHGS = otherCollider.GetComponent<HitGroupAssign>();
            //int otherMask = otherHGS ? otherHGS.LayerMask : 0;
            //if (validHitGroups != 0 && (otherMask & validHitGroups) == 0)
            //	return;

            /// Find an ITriggering component on other
            if (ReferenceEquals(otherCT.Proxy, otherCT))
            {
                otherCollider.transform.GetNestedComponentsInParents(reusableITriggering);
            }
            else
            {
                (otherCT.Proxy as Component).transform.GetNestedComponentsInParents(reusableITriggering);
            }

            //if (contactType == ContactType.Enter)
            //	Debug.Log(name + " <b>" + contactType + "</b> " + otherCollider.name + ":" + otherCollider.GetType().Name +
            //		" ticCnt: " + reusableTriggeringComponents.Count);

            /// Check to see if we have already reacted to this collision (multiple colliders/etc)
            int cnt = reusableITriggering.Count;

            for (int i = 0; i < cnt; i++)
            {
                var itc = reusableITriggering[i];
                if (preventRepeats)
                {
                    switch (contactType)
                    {
                    case ContactType.Enter:
                    {
                        if (triggeringEnters.Contains(itc))
                        {
                            continue;
                        }

                        triggeringEnters.Add(itc);
                        break;
                    }

                    case ContactType.Stay:
                    {
                        if (triggeringStays.Contains(itc))
                        {
                            continue;
                        }

                        triggeringStays.Add(itc);
                        break;
                    }

                    case ContactType.Exit:
                    {
                        if (!triggeringEnters.Contains(itc))
                        {
                            continue;
                        }

                        triggeringEnters.Remove(itc);
                        break;
                    }

                    case ContactType.Hitscan:
                    {
                        if (triggeringHitscans.Contains(itc))
                        {
                            continue;
                        }

                        triggeringHitscans.Add(itc);
                        break;
                    }
                    }
                }

                //if (contactType == ContactType.Enter)
                //	Debug.Log(name + " " + (reusableTriggeringComponents[i] as Component).name + " : " + reusableTriggeringComponents[i].GetType());

                Trigger(new ContactEvent(null, itc, this, otherCollider, contactType));
            }
        }