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; } }
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); }
protected virtual void Reset() { this._proxy = this; PollInterfaces(); FindDerivedTypesFromAssembly(); GetAllowedTypesFromHashes(); }
private void Reset() { /// Projectiles need to detect collisions with everything localContactTrigger = GetComponent <IContactTrigger>(); if (ReferenceEquals(localContactTrigger, null)) { localContactTrigger = gameObject.AddComponent <ContactTrigger>(); } }
protected override void Reset() { base.Reset(); trigger = GetComponent <IContactTrigger>(); if (ReferenceEquals(trigger, null)) { trigger = gameObject.AddComponent <ContactTrigger>(); } }
public override void OnAwake() { base.OnAwake(); contactTrigger = GetComponent <IContactTrigger>(); rb = GetComponentInParent <Rigidbody>(); rb2d = GetComponentInParent <Rigidbody2D>(); _hasRigidbody = rb || rb2d; //transform.GetNestedComponentsInChildren<IOnContact, NetObject>(this.OnTriggerCallbacks); }
public override void OnAwakeInitialize(bool isNetObject) { base.OnAwakeInitialize(isNetObject); contactTrigger = transform.GetNestedComponentInParents <IContactTrigger, NetObject>(); hasSyncContact = contactTrigger.SyncContact != null; if (origin == null) { origin = transform; } }
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); }
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>(); }
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); }
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); }
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; } }
public ContactEvent(ContactEvent contactEvent) { this.contactSystem = contactEvent.contactSystem; this.contactTrigger = contactEvent.contactTrigger; this.contactType = contactEvent.contactType; }
protected virtual void Reset() { proxy = this; }
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); } } }
public ContactEvent(IContactSystem contactSystem, IContactTrigger contacter, ContactType contactType) { this.contactSystem = contactSystem; this.contactTrigger = contacter; this.contactType = contactType; }
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)); } }