void OnValidate()
 {
     if (PhysicsLayer == null)
     {
         PhysicsLayer = PhysicsLayer.GetLayer(Layer.Object);
     }
 }
예제 #2
0
        /// <summary>
        ///     Process the collision between objects and check if it should be ignored
        /// </summary>
        /// <param name="objectCollider"></param>
        /// <param name="collision"></param>
        public bool ProcessCollision(Collider objectCollider, Collision collision)
        {
            PhysicsLayer otherLayer;

            if (!_physicsObjects.ContainsKey(collision.transform))
            {
                otherLayer = PhysicsLayer.GetLayer(Layer.UnityDefault);
            }
            else
            {
                otherLayer = _physicsObjects[collision.transform].PhysicsLayer;
            }

            PhysicsObject physicsObject = null;

            if (GetPhysicsObject(objectCollider.gameObject, out physicsObject))
            {
                if (physicsObject.PhysicsLayer == null)
                {
                    physicsObject.PhysicsLayer = PhysicsLayer.GetLayer(Layer.UnityDefault);
                    Debug.LogWarning("PhysicsLayer not assigned. UnityDefault layer automatically inserted instead.");
                }
                if (!physicsObject.PhysicsLayer.CanCollideWith(otherLayer))
                {
                    Physics.IgnoreCollision(objectCollider, collision.collider, true);
                    return(false);
                }
            }
            return(true);
        }
예제 #3
0
        //public void ResetPreferenceSuggestions()
        //{
        //    PhysicsPreferences.ShouldPromptGravitySettings = true;
        //    PhysicsPreferences.ShouldPromptDefaultSolverIterations = true;
        //    PhysicsPreferences.ShouldPromptDefaultSolverVelocityIterations = true;
        //    PhysicsPreferences.ShouldPromptFixedTimestep = true;
        //}

        IEnumerator RegisterNonPhysicsObjects()
        {
            var sceneColliders = GameObject.FindObjectsOfType <Collider>();

            yield return(null);

            List <Collider> physicsobjectColliders = new List <Collider>();

            foreach (var pObject in _physicsObjects.Values)
            {
                physicsobjectColliders.AddRange(pObject.Colliders);
            }
            sceneColliders = sceneColliders.Except(physicsobjectColliders).Where(coll => coll != null && !coll.isTrigger).ToArray();
            var defaultLayer = PhysicsLayer.GetLayer(Layer.UnityDefault);

            IgnoreCollidersCollisionOnLayers(sceneColliders, defaultLayer.DisallowedCollisions);
        }
        // Use this for initialization
        void Awake()
        {
            Rigidbody = gameObject.GetComponent <Rigidbody>();
            if (Rigidbody == null)
            {
                Rigidbody = gameObject.AddComponent <Rigidbody>();
            }

            Rigidbody.collisionDetectionMode = CollisionDetectionMode.Discrete;
            Rigidbody.useGravity             = false;
            Detector = gameObject.AddComponent <CollisionDetector>();

            var layer = PhysicsLayer.GetLayer(Layer.Phalange);

            Detector.PhysicsLayers = layer.AllowedCollisions;
            PhysicsManager.Instance.Register(GetComponents <Collider>(), GetComponent <Rigidbody>(), layer);
        }
예제 #5
0
 public IEnumerable <PhysicsObject> GetTriggerObjectsInLayer(Layer layer)
 {
     return(GetTriggerObjectsInLayer(PhysicsLayer.GetLayer(layer)));
 }
예제 #6
0
 public IEnumerable <PhysicsObject> GetCollidingObjectsInLayer(Layer layer)
 {
     return(GetCollidingObjectsInLayer(PhysicsLayer.GetLayer(layer)));
 }
        /// <summary>
        /// Happens when the manus hand exits a trigger
        /// </summary>
        /// <param name="collider"></param>
        void OnTriggerExit(Collider collider)
        {
            PhysicsObject physicsObject = null;

            if (!PhysicsManager.Instance.GetPhysicsObject(collider.gameObject, out physicsObject) || physicsObject.PhysicsLayer == PhysicsLayer.GetLayer(Layer.Phalange))
            {
                return;
            }

            var interactable = collider.GetComponent <Interactable>();

            if (interactable == null)
            {
                interactable = physicsObject.GameObject.GetComponent <Interactable>();
            }
            _collidingInteractables.Remove(interactable);
        }