public void CollisionStarted() { GameObject linkedContainer = GameObject.CreatePrimitive(PrimitiveType.Cube); CollisionNotifier linkedNotifier = linkedContainer.AddComponent <CollisionNotifier>(); GameObject unlinkedContainer = GameObject.CreatePrimitive(PrimitiveType.Cube); CollisionNotifier unlinkedNotifier = unlinkedContainer.AddComponent <CollisionNotifier>(); UnityEventListenerMock collisionStartedListenerMock = new UnityEventListenerMock(); subject.CollisionStarted.AddListener(collisionStartedListenerMock.Listen); UnityEventListenerMock linkedCollisionStartedListenerMock = new UnityEventListenerMock(); linkedNotifier.CollisionStarted.AddListener(linkedCollisionStartedListenerMock.Listen); UnityEventListenerMock unlinkedCollisionStartedListenerMock = new UnityEventListenerMock(); unlinkedNotifier.CollisionStarted.AddListener(unlinkedCollisionStartedListenerMock.Listen); subject.CollisionStartedMock(linkedContainer.GetComponent <Collider>()); Assert.IsTrue(collisionStartedListenerMock.Received); Assert.IsTrue(linkedCollisionStartedListenerMock.Received); Assert.IsFalse(unlinkedCollisionStartedListenerMock.Received); Assert.AreEqual("{ ForwardSource = New Game Object (Test.Zinnia.Tracking.Collision.CollisionNotifierTest/CollisionNotifierMock) | IsTrigger = False | CollisionData = [null] | ColliderData = Cube (UnityEngine.BoxCollider) }", subject.GetEventData().ToString()); Object.DestroyImmediate(linkedContainer); Object.DestroyImmediate(unlinkedContainer); }
public override void ControlledStart() { if (this.ragdollRoot == null || this.ragdollHips == null) { Debug.LogWarning(this.gameObject.name + ": No Ragdoll found!"); this.isValid = false; return; } // Set up the notifier on the ragdoll CollisionNotifier notifier = this.ragdollRoot.gameObject.AddComponent <CollisionNotifier>(); notifier.target = this.gameObject; notifier.PropagateDetectors(); // Copy over the names this._notAffected = new HashSet <string>(); this._notAffectedBelow = new HashSet <string>(); for (int i = 0; i < this.notAffected.Length; i++) { this._notAffected.Add(this.notAffected[i].name); } for (int i = 0; i < this.notAffectedBelow.Length; i++) { this._notAffectedBelow.Add(this.notAffectedBelow[i].name); } this.ToggleKinematic(this.ragdollHips, true); }
public void LinkedNotifierCollisionNotProcessedOnDisable() { GameObject linkedContainer = GameObject.CreatePrimitive(PrimitiveType.Cube); CollisionNotifier linkedNotifier = linkedContainer.AddComponent <CollisionNotifier>(); GameObject unlinkedContainer = GameObject.CreatePrimitive(PrimitiveType.Cube); CollisionNotifier unlinkedNotifier = unlinkedContainer.AddComponent <CollisionNotifier>(); UnityEventListenerMock collisionStartedListenerMock = new UnityEventListenerMock(); subject.CollisionStarted.AddListener(collisionStartedListenerMock.Listen); UnityEventListenerMock linkedCollisionStartedListenerMock = new UnityEventListenerMock(); linkedNotifier.CollisionStarted.AddListener(linkedCollisionStartedListenerMock.Listen); UnityEventListenerMock unlinkedCollisionStartedListenerMock = new UnityEventListenerMock(); unlinkedNotifier.CollisionStarted.AddListener(unlinkedCollisionStartedListenerMock.Listen); linkedNotifier.ProcessCollisionsWhenDisabled = false; linkedNotifier.enabled = false; subject.CollisionStartedMock(linkedContainer.GetComponent <Collider>()); Assert.IsTrue(collisionStartedListenerMock.Received); Assert.IsFalse(linkedCollisionStartedListenerMock.Received); Assert.IsFalse(unlinkedCollisionStartedListenerMock.Received); Object.DestroyImmediate(linkedContainer); Object.DestroyImmediate(unlinkedContainer); }
public void CollisionChanged() { GameObject linkedContainer = GameObject.CreatePrimitive(PrimitiveType.Cube); CollisionNotifier linkedNotifier = linkedContainer.AddComponent <CollisionNotifier>(); GameObject unlinkedContainer = GameObject.CreatePrimitive(PrimitiveType.Cube); CollisionNotifier unlinkedNotifier = unlinkedContainer.AddComponent <CollisionNotifier>(); UnityEventListenerMock collisionChangedListenerMock = new UnityEventListenerMock(); subject.CollisionChanged.AddListener(collisionChangedListenerMock.Listen); UnityEventListenerMock linkedCollisionChangedListenerMock = new UnityEventListenerMock(); linkedNotifier.CollisionChanged.AddListener(linkedCollisionChangedListenerMock.Listen); UnityEventListenerMock unlinkedCollisionChangedListenerMock = new UnityEventListenerMock(); unlinkedNotifier.CollisionChanged.AddListener(unlinkedCollisionChangedListenerMock.Listen); subject.CollisionChangedMock(linkedContainer.GetComponent <Collider>()); Assert.IsTrue(collisionChangedListenerMock.Received); Assert.IsTrue(linkedCollisionChangedListenerMock.Received); Assert.IsFalse(unlinkedCollisionChangedListenerMock.Received); Object.DestroyImmediate(linkedContainer); Object.DestroyImmediate(unlinkedContainer); }
public NormalState(AIInput owner, float wanderStrength, CollisionNotifier collisionNotifier) { this.owner = owner; this.wanderStrength = wanderStrength; this.collisionNotifier = collisionNotifier; coinMask = LayerMask.GetMask("Coin"); collisionDelegate = new CollisionNotifier.OnCollision(OnCollision); }
public AggressiveState(AIInput owner, float wanderStrength, float guidePointDistance, float time, CollisionNotifier collisionNotifier) { this.owner = owner; this.wanderStrength = wanderStrength; this.guidePointDistance = guidePointDistance; maxTime = time; this.collisionNotifier = collisionNotifier; collisionDelegate = new CollisionNotifier.OnCollision(OnCollision); }
private void OnTriggerEnter2D(Collider2D other) { CollisionNotifier collisionNotifier = other.GetComponent <CollisionNotifier>(); if (collisionNotifier != null) { return; } DestroyProjectile(); }
public CharacterPhysicsController(Character character) { _character = character; _rigidBody = character.GetComponentInChildren<Rigidbody>(); _capsule = character.GetComponentInChildren<CapsuleCollider>(); _bottomCollisionNotifier = character.transform.Find("Capsule/Collisions/BottomSphere").GetComponent<CollisionNotifier>(); _frontCollisionNotifier = character.transform.Find("Capsule/Collisions/FrontSphere").GetComponent<CollisionNotifier>(); _rigidBody.constraints = RigidbodyConstraints.FreezeRotation; UpdateBendedState(); }
private void RemoveEntity(int entityID) { CCollider cCollider = GetComponent <CCollider>(entityID); CollisionNotifier notifier = cCollider.Collider.GetComponent <CollisionNotifier>(); if (m_collisioNotifiers.Has(notifier) > -1 - 1) { m_collisioNotifiers.Set(entityID, null); notifier.OnCollisionBegin -= OnCollisionBegin; notifier.OnCollisionEnd -= OnCollisionEnd; GameObject.Destroy(notifier); } }
private void Start() { _decisionPointModifier = GetComponent <DecisionPointModifier>(); _decisionItem = GetComponent <DecisionItem>(); _collisionNotifier = GetComponentInChildren <CollisionNotifier>(); _collisionNotifier.OnTriggerEntered += HandleOnTriggerEnter; _collisionNotifier.OnTriggerExited += HandleOnTriggerExit; // Debug Check for Position if (decisionPointPosition == null) { Debug.LogError($"Warning No Decision Position: {gameObject.name}"); } }
private void Start() { m_collisionNotifier = m_rigidbody.gameObject.AddComponent<CollisionNotifier>(); m_renderer = GetComponent<MeshRenderer>(); m_renderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; GameObject particles = Instantiate(m_particlePrefab, transform, false) as GameObject; ParticleSystem particleSystem = particles.GetComponent<ParticleSystem>(); ParticleSystem.ShapeModule shape = particleSystem.shape; shape.meshRenderer = m_renderer; m_emission = particleSystem.emission; float scale = m_renderer.bounds.extents.magnitude; m_baseEmissionRate = m_emission.rate.constant * scale; m_renderer.material.SetFloat("_Displacement", m_renderer.material.GetFloat("_Displacement") * scale); m_renderer.material.SetFloat("_Amplitude", m_renderer.material.GetFloat("_Amplitude") * scale); m_renderer.material.SetFloat("_SpatialFrequency", m_renderer.material.GetFloat("_SpatialFrequency") / scale); m_color.a = 0; m_emissionFraction = 0; }
void Awake() { // state machine setup CollisionNotifier collisionNotifier = transform.Find("Sphere").GetComponent <CollisionNotifier>(); stateMachine = new InputStateMachine(); NormalState normalState = new NormalState(this, wanderStrength, collisionNotifier); stateMachine.AddState(normalState); AggressiveState aggressiveState = new AggressiveState(this, wanderStrength, guidePointDistance, aggressiveTime, collisionNotifier); stateMachine.AddState(aggressiveState); stateMachine.ChangeToState <NormalState>(); // decision tree setup treeRoot = new DecisionQuery <AIInput, Path> { Test = (ai) => ai.currentPath.CheckIfOnCriticalSection(ai.car.position), Positive = new DecisionResult <AIInput, Path>(null), Negative = new DecisionQuery <AIInput, Path> { Test = (ai) => ai.behaviour.boostCount < ai.minBoost, Positive = new DecisionResult <AIInput, Path>(coinPath), Negative = new DecisionQuery <AIInput, Path> { Test = (ai) => ai.otherCar.boostCount > ai.behaviour.boostCount, Positive = new DecisionResult <AIInput, Path>(coinPath), Negative = new DecisionResult <AIInput, Path>(fastPath) } } }; }
private void AddEntity(int entityID) { CCollider cCollider = GetComponent <CCollider>(entityID); if (cCollider.Collider == null) { return; } CollisionNotifier notifier = cCollider.Collider.GetComponent <CollisionNotifier>(); if (notifier == null) { notifier = cCollider.Collider.gameObject.AddComponent <CollisionNotifier>(); } if (m_collisioNotifiers.Has(notifier) == -1) { m_collisioNotifiers.Set(entityID, notifier); notifier.OnCollisionBegin += OnCollisionBegin; notifier.OnCollisionEnd += OnCollisionEnd; } }
private void Awake() { registry.Add(this); rb = GetComponent <Rigidbody>(); if (!centerOfMass) { centerOfMass = new GameObject("CenterOfMass").transform; centerOfMass.transform.parent = rb.transform; centerOfMass.transform.localPosition = rb.centerOfMass; } for (int t = 0; t < targets.Count; t++) { if (targets[t].enabled) { EnableTarget(targets[t]); } } if (!collisionNotifier) { collisionNotifier = rb.GetComponent <CollisionNotifier>(); } if (!collisionNotifier) { collisionNotifier = rb.gameObject.AddComponent <CollisionNotifier>(); } UpdateCollidersAndTriggerNotifiers(); ignoring.Clear(); onInit.Invoke(); }
public IEnumerator CollisionDoesNotEndOnTrackerGameObjectDisable() { WaitForFixedUpdate yieldInstruction = new WaitForFixedUpdate(); GameObject trackerContainer = GameObject.CreatePrimitive(PrimitiveType.Cube); trackerContainer.GetComponent <Collider>().isTrigger = true; trackerContainer.AddComponent <Rigidbody>().isKinematic = true; trackerContainer.transform.position = Vector3.forward; CollisionTrackerMock tracker = trackerContainer.AddComponent <CollisionTrackerMock>(); tracker.SetStopCollisionsOnDisable(false); GameObject notifierContainer = GameObject.CreatePrimitive(PrimitiveType.Cube); notifierContainer.GetComponent <Collider>().isTrigger = true; notifierContainer.AddComponent <Rigidbody>().isKinematic = true; notifierContainer.transform.position = Vector3.back; CollisionNotifier notifier = notifierContainer.AddComponent <CollisionNotifier>(); UnityEventListenerMock trackerCollisionStartedListenerMock = new UnityEventListenerMock(); UnityEventListenerMock trackerCollisionChangedListenerMock = new UnityEventListenerMock(); UnityEventListenerMock trackerCollisionStoppedListenerMock = new UnityEventListenerMock(); tracker.CollisionStarted.AddListener(trackerCollisionStartedListenerMock.Listen); tracker.CollisionChanged.AddListener(trackerCollisionChangedListenerMock.Listen); tracker.CollisionStopped.AddListener(trackerCollisionStoppedListenerMock.Listen); UnityEventListenerMock notifierCollisionStartedListenerMock = new UnityEventListenerMock(); UnityEventListenerMock notifierCollisionChangedListenerMock = new UnityEventListenerMock(); UnityEventListenerMock notifierCollisionStoppedListenerMock = new UnityEventListenerMock(); notifier.CollisionStarted.AddListener(notifierCollisionStartedListenerMock.Listen); notifier.CollisionChanged.AddListener(notifierCollisionChangedListenerMock.Listen); notifier.CollisionStopped.AddListener(notifierCollisionStoppedListenerMock.Listen); yield return(yieldInstruction); Assert.IsFalse(trackerCollisionStartedListenerMock.Received); Assert.IsFalse(trackerCollisionChangedListenerMock.Received); Assert.IsFalse(trackerCollisionStoppedListenerMock.Received); Assert.IsFalse(notifierCollisionStartedListenerMock.Received); Assert.IsFalse(notifierCollisionChangedListenerMock.Received); Assert.IsFalse(notifierCollisionStoppedListenerMock.Received); trackerCollisionStartedListenerMock.Reset(); trackerCollisionChangedListenerMock.Reset(); trackerCollisionStoppedListenerMock.Reset(); notifierCollisionStartedListenerMock.Reset(); notifierCollisionChangedListenerMock.Reset(); notifierCollisionStoppedListenerMock.Reset(); trackerContainer.transform.position = Vector3.zero; notifierContainer.transform.position = Vector3.zero; yield return(yieldInstruction); Assert.IsTrue(trackerCollisionStartedListenerMock.Received); Assert.IsTrue(trackerCollisionChangedListenerMock.Received); Assert.IsFalse(trackerCollisionStoppedListenerMock.Received); Assert.IsTrue(notifierCollisionStartedListenerMock.Received); Assert.IsTrue(notifierCollisionChangedListenerMock.Received); Assert.IsFalse(notifierCollisionStoppedListenerMock.Received); trackerCollisionStartedListenerMock.Reset(); trackerCollisionChangedListenerMock.Reset(); trackerCollisionStoppedListenerMock.Reset(); notifierCollisionStartedListenerMock.Reset(); notifierCollisionChangedListenerMock.Reset(); notifierCollisionStoppedListenerMock.Reset(); trackerContainer.SetActive(false); yield return(yieldInstruction); Assert.IsFalse(trackerCollisionStartedListenerMock.Received); Assert.IsFalse(trackerCollisionChangedListenerMock.Received); Assert.IsFalse(trackerCollisionStoppedListenerMock.Received); Assert.IsFalse(notifierCollisionStartedListenerMock.Received); Assert.IsFalse(notifierCollisionChangedListenerMock.Received); Assert.IsFalse(notifierCollisionStoppedListenerMock.Received); Object.DestroyImmediate(trackerContainer); Object.DestroyImmediate(notifierContainer); }
private int GetEntityByCollider(CollisionNotifier collisionNotifier) { return(m_collisioNotifiers.Has(collisionNotifier)); }
private void OnCollisionBegin(CollisionNotifier collisionNotifier, Collider collider) { int entityID = m_collisioNotifiers.Has(collisionNotifier); AddCollision(entityID, collider); }
private void SetBelowCollision(CollisionNotifier notifier) { if(notifier != _belowCollisionNotifier) { if(_belowCollisionNotifier != null) _belowCollisionNotifier.OnCollision = null; _belowCollisionNotifier = notifier; _belowCollisionNotifier.OnCollision = CheckForIsLanded; } }
void SetupPhysics(SlaveHandModel slaveHand, Transform wristOffset, Vector3 meanPoint, float palmRadius, float fingerRadius) { // Wrist collider GameObject palmObj = BasicHelpers.InstantiateEmptyChild(wristOffset.gameObject); palmObj.name = "Palm.Collider"; palmObj.transform.position = meanPoint; MeshCollider palm = palmObj.AddComponent <MeshCollider>(); palm.sharedMesh = defaultPalmMesh; palm.convex = true; palm.material = skinPhysMat; Vector3 localScale = new Vector3(2.0f * palmRadius, fingerRadius, 2.0f * palmRadius); palmObj.transform.localScale = localScale; // Wrist rb Rigidbody wristRb = wristOffset.gameObject.AddComponent <Rigidbody>(); wristRb.useGravity = false; wristRb.interpolation = RigidbodyInterpolation.Interpolate; wristRb.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic; // Wrist joint ConfigurableJoint wristJoint = wristRb.gameObject.AddComponent <ConfigurableJoint>(); ConfigureJoint(wristJoint, Space.World); // Palm collision notifier CollisionNotifier palmNotifier = wristRb.gameObject.AddComponent <CollisionNotifier>(); // Add refs (slaveHand.wrist as SlaveBoneModel).colliderRef = palm; (slaveHand.wrist as SlaveBoneModel).rigidbodyRef = wristRb; (slaveHand.wrist as SlaveBoneModel).jointRef = wristJoint; slaveHand.palmCollisionNotifier = palmNotifier; // Bones for (int f = 0; f < slaveHand.fingers.Length; f++) { for (int b = 0; b < slaveHand.fingers[f].bones.Length; b++) { Transform parent = slaveHand.fingers[f].bones[b].transformRef; Transform child; if (b == slaveHand.fingers[f].bones.Length - 1) { child = slaveHand.fingers[f].fingerTip; } else { child = slaveHand.fingers[f].bones[b + 1].transformRef; } // Bone collider GameObject capsuleObj = BasicHelpers.InstantiateEmptyChild(parent.gameObject); capsuleObj.transform.position = (parent.position + child.position) / 2.0f; capsuleObj.transform.name = parent.name + ".Collider"; // Collider alignment capsuleObj.transform.LookAt(child.position); CapsuleCollider capsule = capsuleObj.AddComponent <CapsuleCollider>(); capsule.direction = 2; // Along Z axis (as we use .lookAt()) capsule.height = Vector3.Distance(parent.position, child.position); capsule.radius = fingerRadius; // Phys material capsule.material = skinPhysMat; // Bone rb Rigidbody boneRb = slaveHand.fingers[f].bones[b].transformRef.gameObject.AddComponent <Rigidbody>(); boneRb.useGravity = false; boneRb.interpolation = RigidbodyInterpolation.Interpolate; boneRb.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic; // Bone joint ConfigurableJoint boneJoint = boneRb.gameObject.AddComponent <ConfigurableJoint>(); if (b == 0) { boneJoint.connectedBody = (slaveHand.wrist as SlaveBoneModel).rigidbodyRef; } else { boneJoint.connectedBody = (slaveHand.fingers[f].bones[b - 1] as SlaveBoneModel).rigidbodyRef; } ConfigureJoint(boneJoint, Space.Self); // Add refs (slaveHand.fingers[f].bones[b] as SlaveBoneModel).colliderRef = capsule; (slaveHand.fingers[f].bones[b] as SlaveBoneModel).rigidbodyRef = boneRb; (slaveHand.fingers[f].bones[b] as SlaveBoneModel).jointRef = boneJoint; } //Generate CollisionNotifiers CollisionNotifier notifier = slaveHand.fingers[f].distal.transformRef.gameObject.AddComponent <CollisionNotifier>(); slaveHand.fingers[f].fingerTipCollisionNotifier = notifier; } }
private void OnCollisionEnd(CollisionNotifier collisionNotifier, Collider collider) { int entityID = m_collisioNotifiers.Has(collisionNotifier); RemoveCollision(entityID, collider); }
private void CheckForIsLanded(CollisionNotifier.CollisionData data) { //Debug.Log("data.state = " + data.state); switch(data.state) { case CollisionNotifier.State.Enter: //case CollisionNotifier.State.Stay: if(!_isLanded) { _isLanded = true; _isGoingUp = false; _isGoingDown = false; } break; } }
void Start() { _collisionNotifier = GetComponent<CollisionNotifier>(); }