Example #1
0
 public bool Cast(Vector3 direction, out RaycastHit hitinfo, float distance, int layerMask, QueryTriggerInteraction query = QueryTriggerInteraction.UseGlobal)
 {
     return Physics.BoxCast(_center, this.Extents, direction, out hitinfo, _orientation, distance, layerMask, query);
 }
Example #2
0
 private static extern Collider[] INTERNAL_CALL_OverlapSphere(ref Vector3 position, float radius, int layerMask, QueryTriggerInteraction queryTriggerInteraction);
 public bool Cast(Vector3 direction, out RaycastHit hitinfo, float distance, int layerMask, QueryTriggerInteraction query = QueryTriggerInteraction.UseGlobal)
 {
     if (_start == _end)
     {
         return Physics.SphereCast(_start, _rad, direction, out hitinfo, distance, layerMask, query);
     }
     else
     {
         return Physics.CapsuleCast(_start, _end, _rad, direction, out hitinfo, distance, layerMask, query);
     }
 }
Example #4
0
 private static bool Internal_BoxCast(Vector3 center, Vector3 halfExtents, Quaternion orientation, Vector3 direction, out RaycastHit hitInfo, float maxDistance, int layermask, QueryTriggerInteraction queryTriggerInteraction)
 {
   return Physics.INTERNAL_CALL_Internal_BoxCast(ref center, ref halfExtents, ref orientation, ref direction, out hitInfo, maxDistance, layermask, queryTriggerInteraction);
 }
Example #5
0
 private static bool Internal_RaycastTest(Vector3 origin, Vector3 direction, float maxDistance, int layermask, QueryTriggerInteraction queryTriggerInteraction)
 {
   return Physics.INTERNAL_CALL_Internal_RaycastTest(ref origin, ref direction, maxDistance, layermask, queryTriggerInteraction);
 }
 public SuperGround(LayerMask walkable, SuperCharacterController controller, QueryTriggerInteraction triggerInteraction)
 {
     this.walkable           = walkable;
     this.controller         = controller;
     this.triggerInteraction = triggerInteraction;
 }
Example #7
0
 private static extern bool INTERNAL_CALL_CheckCapsule(ref Vector3 start, ref Vector3 end, float radius, int layermask, QueryTriggerInteraction queryTriggerInteraction);
 public SuperGround(LayerMask walkable, SuperCharacterController controller, QueryTriggerInteraction triggerInteraction)
 {
     this.walkable = walkable;
     this.controller = controller;
     this.triggerInteraction = triggerInteraction;
 }
Example #9
0
    public override void OnInspectorGUI()
    {
        GUIStyle bold_wrap = EditorStyles.boldLabel;

        bold_wrap.wordWrap = true;
        GUILayout.Label("Navmesh Preprocessor for HTC Vive Locomotion", bold_wrap);
        GUILayout.Label("Adrian Biagioli 2016", EditorStyles.miniLabel);

        GUILayout.Label("Before Using", bold_wrap);
        GUIStyle wrap = EditorStyles.label;

        wrap.wordWrap = true;
        GUILayout.Label(
            "Make sure you bake a Navigation Mesh (NavMesh) in Unity before continuing (Window > Navigation).  When you " +
            "are done, click \"Update Navmesh Data\" below.  This will update the graphic of the playable area " +
            "that the player will see in-game.\n",
            wrap);

        ViveNavMesh mesh = (ViveNavMesh)target;

        serializedObject.Update();

        // Area Mask //
        string[] areas      = GameObjectUtility.GetNavMeshAreaNames();
        int[]    area_index = new int[areas.Length];
        int      temp_mask  = 0;

        for (int x = 0; x < areas.Length; x++)
        {
            area_index[x] = GameObjectUtility.GetNavMeshAreaFromName(areas[x]);
            temp_mask    |= ((p_area.intValue >> area_index[x]) & 1) << x;
        }
        EditorGUI.BeginChangeCheck();
        temp_mask = EditorGUILayout.MaskField("Area Mask", temp_mask, areas);
        if (EditorGUI.EndChangeCheck())
        {
            p_area.intValue = 0;
            for (int x = 0; x < areas.Length; x++)
            {
                p_area.intValue |= (((temp_mask >> x) & 1) == 1 ? 0 : 1) << area_index[x];
            }
            p_area.intValue = ~p_area.intValue;
        }
        serializedObject.ApplyModifiedProperties();

        // Sanity check for Null properties //
        bool HasMesh = (mesh.SelectableMesh != null && mesh.SelectableMesh.vertexCount != 0) || (mesh.SelectableMeshBorder != null && mesh.SelectableMeshBorder.Length != 0);

        // Fixes below error message popping up with prefabs.  Kind of hacky but gets the job done
        bool isPrefab = EditorUtility.IsPersistent(target);

        if (isPrefab && mesh.SelectableMesh == null)
        {
            mesh.SelectableMesh = new Mesh();
        }

        bool MeshNull   = mesh.SelectableMesh == null;
        bool BorderNull = mesh.SelectableMeshBorder == null;

        if (MeshNull || BorderNull)
        {
            string str = "Internal Error: ";
            if (MeshNull)
            {
                str += "Selectable Mesh == null.  ";
            }
            if (BorderNull)
            {
                str += "Border point array == null.  ";
            }
            str += "This may lead to strange behavior or serialization.  Try updating the mesh or delete and recreate the Navmesh object.  ";
            str += "If you are able to consistently get a Vive Nav Mesh object into this state, please submit a bug report.";
            EditorGUILayout.HelpBox(str, MessageType.Error);
        }

        // Update / Clear Navmesh Data //
        if (GUILayout.Button("Update Navmesh Data"))
        {
            Undo.RecordObject(mesh, "Update Navmesh Data");

            NavMeshTriangulation tri = NavMesh.CalculateTriangulation();
            int vert_size, tri_size;
            CullNavmeshTriangulation(ref tri, p_area.intValue, out vert_size, out tri_size);

            Mesh m = ConvertNavmeshToMesh(tri, vert_size, tri_size);
            // Can't use SerializedProperties here because BorderPointSet doesn't derive from UnityEngine.Object
            mesh.SelectableMeshBorder = FindBorderEdges(m);

            serializedObject.Update();
            p_mesh.objectReferenceValue = m;
            serializedObject.ApplyModifiedPropertiesWithoutUndo();
            mesh.SelectableMesh = mesh.SelectableMesh; // Make sure that setter is called
        }

        GUI.enabled = HasMesh;
        if (GUILayout.Button("Clear Navmesh Data"))
        {
            Undo.RecordObject(mesh, "Clear Navmesh Data");

            // Note: Unity does not serialize "null" correctly so we set everything to empty objects
            Mesh m = new Mesh();

            serializedObject.Update();
            p_mesh.objectReferenceValue = m;
            serializedObject.ApplyModifiedPropertiesWithoutUndo();
            mesh.SelectableMesh = mesh.SelectableMesh; // Make sure setter is called

            mesh.SelectableMeshBorder = new BorderPointSet[0];
        }
        GUI.enabled = true;

        GUILayout.Label(HasMesh ? "Status: NavMesh Loaded" : "Status: No NavMesh Loaded");

        // Render Settings //
        EditorGUILayout.LabelField("Render Settings", EditorStyles.boldLabel);

        EditorGUI.BeginChangeCheck();
        EditorGUILayout.PropertyField(p_material);
        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(mesh, "Change Ground Material");
            serializedObject.ApplyModifiedPropertiesWithoutUndo();
            mesh.GroundMaterial = mesh.GroundMaterial; // Reload material
        }

        EditorGUILayout.PropertyField(p_alpha);
        serializedObject.ApplyModifiedProperties();

        // Raycast Settings //
        EditorGUILayout.LabelField("Raycast Settings", EditorStyles.boldLabel);

        int  temp_layer_mask        = p_layer_mask.intValue;
        bool temp_ignore_layer_mask = p_ignore_layer_mask.boolValue;

        EditorGUI.BeginChangeCheck();
        temp_layer_mask = EditorGUILayout.LayerField("Layer Mask", temp_layer_mask);
        if (EditorGUI.EndChangeCheck())
        {
            p_layer_mask.intValue = temp_layer_mask;
        }
        serializedObject.ApplyModifiedProperties();
        EditorGUI.BeginChangeCheck();
        temp_ignore_layer_mask = EditorGUILayout.Toggle("Ignore Layer Mask", temp_ignore_layer_mask);
        if (EditorGUI.EndChangeCheck())
        {
            p_ignore_layer_mask.boolValue = temp_ignore_layer_mask;
        }
        serializedObject.ApplyModifiedProperties();

        QueryTriggerInteraction temp_query_trigger_interaction = (QueryTriggerInteraction)p_query_trigger_interaction.intValue;

        EditorGUI.BeginChangeCheck();
        temp_query_trigger_interaction = (QueryTriggerInteraction)EditorGUILayout.EnumPopup("Query Trigger Interaction", (QueryTriggerInteraction)temp_query_trigger_interaction);
        if (EditorGUI.EndChangeCheck())
        {
            p_query_trigger_interaction.intValue = (int)temp_query_trigger_interaction;
        }
        serializedObject.ApplyModifiedProperties();

        EditorGUILayout.LabelField("Navmesh Settings", EditorStyles.boldLabel);
        GUILayout.Label(
            "Make sure the sample radius below is larger than your Navmesh Voxel Size (see Advanced > Voxel Size " +
            "in the navigation window).  Increase this if the selection disk is not appearing.",
            wrap);
        EditorGUILayout.PropertyField(p_sample_radius);
        serializedObject.ApplyModifiedProperties();
    }
 public int Overlap(ICollection<Collider> results, int layerMask, QueryTriggerInteraction query = QueryTriggerInteraction.UseGlobal)
 {
     return PhysicsUtil.OverlapSphere(this.Center, this.Radius, results, layerMask, query);
 }
 public bool Cast(Vector3 direction, out RaycastHit hitinfo, float distance, int layerMask, QueryTriggerInteraction query = QueryTriggerInteraction.UseGlobal)
 {
     return Physics.SphereCast(_cent, _rad, direction, out hitinfo, distance, layerMask, query);
 }
 public bool TestOverlap(int layerMask, QueryTriggerInteraction query = QueryTriggerInteraction.UseGlobal)
 {
     return Physics.CheckSphere(_cent, _rad, layerMask, query);
 }
Example #13
0
 private static extern GameObject INTERNAL_CALL_RaycastTry(Camera self, ref Ray ray, float distance, int layerMask, QueryTriggerInteraction queryTriggerInteraction);
Example #14
0
 public int CastAll(Vector3 direction, ICollection<RaycastHit> results, float distance, int layerMask, QueryTriggerInteraction query = QueryTriggerInteraction.UseGlobal)
 {
     return PhysicsUtil.BoxCastAll(_center, this.Extents, direction, results, _orientation, distance, layerMask, query);
 }
Example #15
0
 private static extern bool INTERNAL_CALL_SweepTest(Rigidbody self, ref Vector3 direction, out RaycastHit hitInfo, float maxDistance, QueryTriggerInteraction queryTriggerInteraction);
Example #16
0
 private static RaycastHit[] INTERNAL_CALL_SweepTestAll(Rigidbody self, ref Vector3 direction, float maxDistance, QueryTriggerInteraction queryTriggerInteraction)
 {
     throw new NotImplementedException("なにこれ");
 }
Example #17
0
        public RaycastHit[] SweepTestAll(Vector3 direction, float maxDistance)
        {
            QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal;

            return(Rigidbody.INTERNAL_CALL_SweepTestAll(this, ref direction, maxDistance, queryTriggerInteraction));
        }
Example #18
0
    public static RaycastHit[] CastAllPrimitiveColliders(GameObject go, Vector3 direction, float maxDistance = Mathf.Infinity, int layerMask = Physics.DefaultRaycastLayers, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal)
    {
        HashSet <Transform> transformsToIgnore = new HashSet <Transform>();

        foreach (Transform t in go.GetComponentsInChildren <Transform>())
        {
            transformsToIgnore.Add(t);
        }
        List <RaycastHit> hits = new List <RaycastHit>();

        foreach (CapsuleCollider cc in go.GetComponentsInChildren <CapsuleCollider>())
        {
            foreach (RaycastHit h in PhysicsExtensions.CapsuleCastAll(cc, direction, maxDistance, layerMask, queryTriggerInteraction))
            {
                if (!transformsToIgnore.Contains(h.transform))
                {
                    hits.Add(h);
                }
            }
        }
        foreach (BoxCollider bc in go.GetComponentsInChildren <BoxCollider>())
        {
            foreach (RaycastHit h in PhysicsExtensions.BoxCastAll(bc, direction, maxDistance, layerMask, queryTriggerInteraction))
            {
                if (!transformsToIgnore.Contains(h.transform))
                {
                    hits.Add(h);
                }
            }
        }
        foreach (SphereCollider sc in go.GetComponentsInChildren <SphereCollider>())
        {
            foreach (RaycastHit h in PhysicsExtensions.SphereCastAll(sc, direction, maxDistance, layerMask, queryTriggerInteraction))
            {
                if (!transformsToIgnore.Contains(h.transform))
                {
                    hits.Add(h);
                }
            }
        }
        return(hits.ToArray());
    }
Example #19
0
 private static extern int INTERNAL_CALL_CapsuleCastNonAlloc(ref Vector3 point1, ref Vector3 point2, float radius, ref Vector3 direction, RaycastHit[] results, float maxDistance, int layermask, QueryTriggerInteraction queryTriggerInteraction);
        public bool Cast(Vector3 direction, out RaycastHit hitinfo, float distance, int layerMask, QueryTriggerInteraction query)
        {
            foreach (var c in _colliders)
            {
                if (GeomUtil.GetGeom(c).Cast(direction, out hitinfo, distance, layerMask, query))
                {
                    return(true);
                }
            }

            hitinfo = default(RaycastHit);
            return(false);
        }
Example #21
0
 private static extern int INTERNAL_CALL_OverlapBoxNonAlloc(ref Vector3 center, ref Vector3 halfExtents, Collider[] results, ref Quaternion orientation, int layerMask, QueryTriggerInteraction queryTriggerInteraction);
        public int CastAll(Vector3 direction, ICollection <RaycastHit> results, float distance, int layerMask, QueryTriggerInteraction query)
        {
            if (results == null)
            {
                throw new System.ArgumentNullException("results");
            }

            using (var set = TempCollection.GetSet <RaycastHit>())
            {
                foreach (var c in _colliders)
                {
                    GeomUtil.GetGeom(c).CastAll(direction, set, distance, layerMask, query);
                }

                if (set.Count > 0)
                {
                    var e = set.GetEnumerator();
                    while (e.MoveNext())
                    {
                        results.Add(e.Current);
                    }
                    return(set.Count);
                }
            }

            return(0);
        }
Example #23
0
 private static bool Internal_CapsuleCast(Vector3 point1, Vector3 point2, float radius, Vector3 direction, out RaycastHit hitInfo, float maxDistance, int layermask, QueryTriggerInteraction queryTriggerInteraction)
 {
   return Physics.INTERNAL_CALL_Internal_CapsuleCast(ref point1, ref point2, radius, ref direction, out hitInfo, maxDistance, layermask, queryTriggerInteraction);
 }
Example #24
0
        internal GameObject RaycastTry(Ray ray, float distance, int layerMask)
        {
            QueryTriggerInteraction useGlobal = QueryTriggerInteraction.UseGlobal;

            return(INTERNAL_CALL_RaycastTry(this, ref ray, distance, layerMask, useGlobal));
        }
Example #25
0
 private static extern RaycastHit[] INTERNAL_CALL_RaycastAll(ref Vector3 origin, ref Vector3 direction, float maxDistance, int layermask, QueryTriggerInteraction queryTriggerInteraction);
Example #26
0
 internal GameObject RaycastTry(Ray ray, float distance, int layerMask, [UnityEngine.Internal.DefaultValue("QueryTriggerInteraction.UseGlobal")] QueryTriggerInteraction queryTriggerInteraction)
 {
     return(INTERNAL_CALL_RaycastTry(this, ref ray, distance, layerMask, queryTriggerInteraction));
 }
 public bool TestOverlap(int layerMask, QueryTriggerInteraction query = QueryTriggerInteraction.UseGlobal)
 {
     if (_start == _end)
     {
         return Physics.CheckSphere(_start, _rad, layerMask, query);
     }
     else
     {
         return Physics.CheckCapsule(_start, _end, _rad, layerMask, query);
     }
 }
Example #28
0
 private static extern GameObject INTERNAL_CALL_RaycastTry(Camera self, ref Ray ray, float distance, int layerMask, QueryTriggerInteraction queryTriggerInteraction);
Example #29
0
 private static extern bool INTERNAL_CALL_SweepTest(Rigidbody self, ref Vector3 direction, out RaycastHit hitInfo, float maxDistance, QueryTriggerInteraction queryTriggerInteraction);
Example #30
0
        public bool Cast(Vector3 direction, out RaycastHit hitinfo, float distance, int layerMask, QueryTriggerInteraction query = QueryTriggerInteraction.UseGlobal)
        {
            if (_geom == null)
            {
                this.UpdateGeom();
                if (_geom == null)
                {
                    hitinfo = new RaycastHit();
                    return(false);
                }
            }
            if (!(_geom is IPhysicsGeom))
            {
                hitinfo = new RaycastHit();
                return(false);
            }

            return((_geom as IPhysicsGeom).Cast(direction, out hitinfo, distance, layerMask, query));
        }
Example #31
0
        public bool SweepTest(Vector3 direction, out RaycastHit hitInfo, float maxDistance)
        {
            QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal;

            return(Rigidbody.INTERNAL_CALL_SweepTest(this, ref direction, out hitInfo, maxDistance, queryTriggerInteraction));
        }
Example #32
0
        public int CastAll(Vector3 direction, ICollection <RaycastHit> results, float distance, int layerMask, QueryTriggerInteraction query = QueryTriggerInteraction.UseGlobal)
        {
            if (_geom == null)
            {
                this.UpdateGeom();
                if (_geom == null)
                {
                    return(0);
                }
            }
            if (!(_geom is IPhysicsGeom))
            {
                return(0);
            }

            return((_geom as IPhysicsGeom).CastAll(direction, results, distance, layerMask, query));
        }
Example #33
0
 public RaycastHit[] SweepTestAll(Vector3 direction, [DefaultValue("Mathf.Infinity")] float maxDistance, [DefaultValue("QueryTriggerInteraction.UseGlobal")] QueryTriggerInteraction queryTriggerInteraction)
 {
     return(Rigidbody.INTERNAL_CALL_SweepTestAll(this, ref direction, maxDistance, queryTriggerInteraction));
 }
Example #34
0
    public static RaycastHit CapsuleCastIgnoreSelf(Vector3 point1, Vector3 point2, float radius, Vector3 direction, float maxDistance, int mask, QueryTriggerInteraction queryTriggerInteraction, Collider self)
    {
        int n = Physics.CapsuleCastNonAlloc(point1, point2, radius, direction, hits, maxDistance, mask, queryTriggerInteraction);

        if (n > 0)
        {
            RaycastHit best = new RaycastHit();

            for (int i = 0; i < n; i++)
            {
                if (best.collider == null)
                {
                    if (hits[i].collider != self)
                    {
                        best = hits[i];
                    }
                }
                else
                {
                    if (hits[i].distance < best.distance && hits[i].collider != self)
                    {
                        best = hits[i];
                    }
                }
            }

            if (best.collider != null)
            {
                return(best);
            }
        }

        return(new RaycastHit());
    }
Example #35
0
 private static extern RaycastHit[] INTERNAL_CALL_SweepTestAll(Rigidbody self, ref Vector3 direction, float maxDistance, QueryTriggerInteraction queryTriggerInteraction);
 public static bool Raycast(long tick, Transform rootTransform, Vector3 origin, bool rootDirection, Vector3 direction, out RaycastHit hitInfo, float maxDistance = Mathf.Infinity, int layerMask = -5, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal)
 {
     SetGlobalState(tick);
     if (rootTransform == null)
     {
         return(Physics.Raycast(origin, direction, out hitInfo, maxDistance, layerMask, queryTriggerInteraction));
     }
     else if (rootDirection)
     {
         return(Physics.Raycast(rootTransform.TransformPoint(origin), rootTransform.TransformDirection(direction), out hitInfo, maxDistance, layerMask, queryTriggerInteraction));
     }
     else
     {
         return(Physics.Raycast(rootTransform.TransformPoint(origin), direction, out hitInfo, maxDistance, layerMask, queryTriggerInteraction));
     }
 }
Example #37
0
        // Token: 0x06001C4B RID: 7243 RVA: 0x000846D0 File Offset: 0x000828D0
        public static bool CharacterRaycast(GameObject bodyObject, Ray ray, out RaycastHit hitInfo, float maxDistance, LayerMask layerMask, QueryTriggerInteraction queryTriggerInteraction)
        {
            RaycastHit[] array = Physics.RaycastAll(ray, maxDistance, layerMask, queryTriggerInteraction);
            int          num   = -1;
            float        num2  = float.PositiveInfinity;

            for (int i = 0; i < array.Length; i++)
            {
                float distance = array[i].distance;
                if (distance < num2)
                {
                    HurtBox component = array[i].collider.GetComponent <HurtBox>();
                    if (component)
                    {
                        HealthComponent healthComponent = component.healthComponent;
                        if (healthComponent && healthComponent.gameObject == bodyObject)
                        {
                            goto IL_72;
                        }
                    }
                    num  = i;
                    num2 = distance;
                }
                IL_72 :;
            }
            if (num == -1)
            {
                hitInfo = default(RaycastHit);
                return(false);
            }
            hitInfo = array[num];
            return(true);
        }
        public static bool Linecast(long tick, Vector3 start, Vector3 end, out RaycastHit hitInfo, int layerMask = -5, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal)
        {
            Vector3 direction = end - start;

            return(Raycast(tick, null, start, false, direction, out hitInfo, direction.magnitude, layerMask, queryTriggerInteraction));
        }
Example #39
0
 private static extern bool INTERNAL_CALL_CheckSphere(ref Vector3 position, float radius, int layerMask, QueryTriggerInteraction queryTriggerInteraction);
Example #40
0
 public bool SweepTest(Vector3 direction, out RaycastHit hitInfo, [DefaultValue("Mathf.Infinity")] float maxDistance, [DefaultValue("QueryTriggerInteraction.UseGlobal")] QueryTriggerInteraction queryTriggerInteraction)
 {
     return(INTERNAL_CALL_SweepTest(this, ref direction, out hitInfo, maxDistance, queryTriggerInteraction));
 }
Example #41
0
 private static extern bool INTERNAL_CALL_CheckBox(ref Vector3 center, ref Vector3 halfExtents, ref Quaternion orientation, int layermask, QueryTriggerInteraction queryTriggerInteraction);
Example #42
0
        public static RaycastHit[] RaycastLine(Vector3 origin, Vector3 ending, int layerMask = Physics.DefaultRaycastLayers, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.Ignore)
        {
            // Raycast in both directions to identify enter and exit points
            var direction      = ending - origin;
            var distance       = direction.magnitude;
            var forwardHitList = Physics.RaycastAll(origin, direction, distance, layerMask, queryTriggerInteraction);
            var reverseHitList = Physics.RaycastAll(ending, -direction, distance, layerMask, queryTriggerInteraction);

            //Debug.Log("CAST: origin = " + origin.ToString("F7") + ", direction = " + direction.ToString() + ": forward Count = " + forwardHitList.Length + ", reverse Count = " + reverseHitList.Length);

            // Merge and sort by distance from origin
            for (int i = 0; i < reverseHitList.Length; ++i)
            {
                reverseHitList[i].distance = distance - reverseHitList[i].distance;
            }
            var hitList = new List <RaycastHit>(forwardHitList);

            hitList.AddRange(reverseHitList);
            hitList.Sort(
                (less, more) =>
                less.distance <more.distance ? -1 :
                               less.distance> more.distance ? 1 :
                0
                );

            return(hitList.ToArray());
        }
Example #43
0
 private static extern int INTERNAL_CALL_BoxCastNonAlloc(ref Vector3 center, ref Vector3 halfExtents, ref Vector3 direction, RaycastHit[] results, ref Quaternion orientation, float maxDistance, int layermask, QueryTriggerInteraction queryTriggerInteraction);
Example #44
0
        protected override bool Raycast(out RaycastHit hit, LayerMask layerMask, QueryTriggerInteraction queryTriggerInteraction)
        {
            Vector3 s = start.Value, e = end.Value, dir = e - s;

            return(UnityEngine.Physics.Raycast(s, dir, out hit, dir.magnitude, layerMask, queryTriggerInteraction));
        }
Example #45
0
 private static extern bool INTERNAL_CALL_Internal_BoxCast(ref Vector3 center, ref Vector3 halfExtents, ref Quaternion orientation, ref Vector3 direction, out RaycastHit hitInfo, float maxDistance, int layermask, QueryTriggerInteraction queryTriggerInteraction);
Example #46
0
        // Shoot over axis
        public void Shoot(Vector3 shootPosition, Vector3 shootVector)
        {
            // Set trigger state =
            QueryTriggerInteraction trigger = QueryTriggerInteraction.Ignore;

            // Get intersection collider
            RaycastHit hit;
            bool       hitState = Physics.Raycast(shootPosition, shootVector, out hit, maxDistance, mask, trigger);

            // Pos and normal info
            Vector3 impactPoint  = hit.point;
            Vector3 impactNormal = hit.normal;

            // No hits
            if (hitState == false)
            {
                return;
            }

            // Check for tag
            if (tagFilter != "Untagged" && tag != hit.transform.tag)
            {
                return;
            }

            // If mesh collider
            // int triId = hit.triangleIndex;
            // Vector3 bar = hit.barycentricCoordinate;

            // Create impact flash
            if (enableImpactFlash == true)
            {
                ImpactFlash(hit.point, hit.normal);
            }

            // Check for Rigid script
            RayfireRigid scrRigid = hit.transform.GetComponent <RayfireRigid>();

            // NO Rigid script. TODO optional add rigid script
            if (scrRigid == null)
            {
                return;
            }

            // Apply damage if enabled
            if (scrRigid.damage.enable == true)
            {
                // Check for demolition
                bool damageDemolition = scrRigid.ApplyDamage(damage, impactPoint, radius);

                // Target was demolished
                if (damageDemolition == true && scrRigid.HasFragments == true)
                {
                    // Get new fragment target
                    bool dmlHitState = Physics.Raycast(shootPosition, shootVector, out hit, maxDistance, mask, trigger);

                    // Stop. No new target TODO proceed with debris, dust, event
                    if (dmlHitState == false)
                    {
                        return;
                    }
                }
            }

            // Hit data
            impactPoint  = hit.point;
            impactNormal = hit.normal;
            // Rigidbody rb = hit.rigidbody;
            // Collider col = hit.collider;
            scrRigid = hit.transform.GetComponent <RayfireRigid>();

            // NO Rigid script.
            if (scrRigid == null)
            {
                return;
            }

            // Activation of kinematik/inactive
            List <RayfireRigid> rigidList = ActivationCheck(scrRigid, impactPoint, radius);

            // Impact hit
            ImpactHit(rigidList, impactPoint, shootVector, hit.normal);

            // Impact Debris
            ImpactDebris(scrRigid, impactPoint, impactNormal);

            // Impact Dust
            ImpactDust(scrRigid, impactPoint, impactNormal);

            // Event
            shotEvent.InvokeLocalEvent(this);
            RFShotEvent.InvokeGlobalEvent(this);
        }
Example #47
0
 private static extern bool INTERNAL_CALL_Internal_CapsuleCast(ref Vector3 point1, ref Vector3 point2, float radius, ref Vector3 direction, out RaycastHit hitInfo, float maxDistance, int layermask, QueryTriggerInteraction queryTriggerInteraction);
        public override void OnInspectorGUI()
        {
            GUIStyle bold_wrap = EditorStyles.boldLabel;
            bold_wrap.wordWrap = true;
            GUILayout.Label("Navmesh Preprocessor for VR Locomotion", bold_wrap);
            GUILayout.Label("Based on Adrian Biagioli work, 2017", EditorStyles.miniLabel);
            GUILayout.Label("Updated by Arnaud Briche, 2018", EditorStyles.miniLabel);

            EditorGUILayout.Space();

            GUILayout.Label("Before Using", bold_wrap);
            GUIStyle wrap = EditorStyles.label;
            wrap.wordWrap = true;
            GUILayout.Label(
                "Make sure you bake a Navigation Mesh (NavMesh) in Unity before continuing (Window > AI > Navigation).  When you " +
                "are done, click \"Update Navmesh Data\" below.  This will update the graphic of the playable area " +
                "that the player will see in-game.\n",
                wrap);

            TeleportNavMeshAuthoring tnmAuthoring = (TeleportNavMeshAuthoring)target;

            serializedObject.Update();

            // Area Mask //
            string[] areaNames = GameObjectUtility.GetNavMeshAreaNames();
            int[] area_index = new int[areaNames.Length];
            int temp_mask = 0;
            for (int x = 0; x < areaNames.Length; x++)
            {
                area_index[x] = GameObjectUtility.GetNavMeshAreaFromName(areaNames[x]);
                temp_mask |= ((p_area.intValue >> area_index[x]) & 1) << x;
            }
            EditorGUI.BeginChangeCheck();
            temp_mask = EditorGUILayout.MaskField("Area Mask", temp_mask, areaNames);
            if (EditorGUI.EndChangeCheck())
            {
                p_area.intValue = 0;
                for (int x = 0; x < areaNames.Length; x++)
                    p_area.intValue |= (((temp_mask >> x) & 1) == 1 ? 0 : 1) << area_index[x];
                p_area.intValue = ~p_area.intValue;
            }
            serializedObject.ApplyModifiedProperties();

            // Sanity check for Null properties //
            bool HasMesh = tnmAuthoring.SelectableMesh != null && tnmAuthoring.SelectableMesh.vertexCount != 0;

            // Fixes below error message popping up with prefabs.  Kind of hacky but gets the job done
            bool isPrefab = EditorUtility.IsPersistent(target);
            if (isPrefab && tnmAuthoring.SelectableMesh == null)
                tnmAuthoring.SelectableMesh = new Mesh();

            bool MeshNull = tnmAuthoring.SelectableMesh == null;

            if (MeshNull)
            {
                string str = "Internal Error: Selectable Mesh == null. ";
                str += "This may lead to strange behavior or serialization.  Try updating the mesh or delete and recreate the Navmesh object.  ";
                str += "If you are able to consistently get a Vive Nav Mesh object into this state, please submit a bug report.";
                EditorGUILayout.HelpBox(str, MessageType.Error);
            }

            // Update / Clear Navmesh Data //
            if (GUILayout.Button("Update Navmesh Data"))
            {
                Undo.RecordObject(tnmAuthoring, "Update Navmesh Data");

                NavMeshTriangulation tri = NavMesh.CalculateTriangulation();

                Vector3[] verts = tri.vertices;
                int[] tris = tri.indices;
                int[] areas = tri.areas;

                int vert_size = verts.Length;
                int tri_size = tris.Length;
                //RemoveMeshDuplicates(verts, tris, out vert_size, 0.01f);
                DewarpMesh(verts, tnmAuthoring.DewarpingMethod, tnmAuthoring.SampleRadius);
                CullNavmeshTriangulation(verts, tris, areas, p_area.intValue, tnmAuthoring.IgnoreSlopedSurfaces, ref vert_size, ref tri_size);

                Mesh m = ConvertNavmeshToMesh(verts, tris, vert_size, tri_size);

                serializedObject.Update();
                p_mesh.objectReferenceValue = m;
                serializedObject.ApplyModifiedPropertiesWithoutUndo();
            }

            GUI.enabled = HasMesh;
            if (GUILayout.Button("Clear Navmesh Data"))
            {
                Undo.RecordObject(tnmAuthoring, "Clear Navmesh Data");

                // Note: Unity does not serialize "null" correctly so we set everything to empty objects
                Mesh m = new Mesh();

                serializedObject.Update();
                p_mesh.objectReferenceValue = m;
                serializedObject.ApplyModifiedPropertiesWithoutUndo();
            }
            GUI.enabled = true;

            GUILayout.Label(HasMesh ? "Status: NavMesh Loaded" : "Status: No NavMesh Loaded");

            serializedObject.ApplyModifiedProperties();

            EditorGUILayout.Space();

            // Raycast Settings //
            EditorGUILayout.LabelField("Raycast Settings", EditorStyles.boldLabel);
            
            QueryTriggerInteraction temp_query_trigger_interaction = (QueryTriggerInteraction)p_query_trigger_interaction.intValue;

            EditorGUI.BeginChangeCheck();
            temp_query_trigger_interaction = (QueryTriggerInteraction)EditorGUILayout.EnumPopup("Query Trigger Interaction", (QueryTriggerInteraction)temp_query_trigger_interaction);
            if (EditorGUI.EndChangeCheck())
            {
                p_query_trigger_interaction.intValue = (int)temp_query_trigger_interaction;
            }
            serializedObject.ApplyModifiedProperties();
        
            EditorGUILayout.Space();

            // Navmesh Settings //
            EditorGUILayout.LabelField("Navmesh Settings", EditorStyles.boldLabel);
            GUILayout.Label(
                "Make sure the sample radius below is equal to your Navmesh Voxel Size (see Advanced > Voxel Size " +
                "in the navigation window).  Increase this if the selection disk is not appearing.",
                wrap);
            EditorGUILayout.PropertyField(p_sample_radius);
            EditorGUILayout.PropertyField(p_sphereCast_radius);
            EditorGUILayout.PropertyField(p_ignore_sloped_surfaces);
            EditorGUILayout.PropertyField(p_dewarp_method);

            serializedObject.ApplyModifiedProperties();
        }
Example #49
0
 private static extern bool INTERNAL_CALL_Internal_RaycastTest(ref Vector3 origin, ref Vector3 direction, float maxDistance, int layermask, QueryTriggerInteraction queryTriggerInteraction);
Example #50
0
    /// <summary>
    /// 返回离射线原点最近的RaycastHit,如果没有找到将返回new RaycastHit(),使用 RaycastHit.collider==null 来判断是否查询到碰撞器
    /// </summary>
    /// <param name="ray">射线</param>
    /// <param name="ignoreBodies">忽略检测的刚体列表</param>
    /// <param name="layerMask">用于射线计算的LayerMask,如:LayerMask.GetMask("ItemModel")。</param>
    /// <param name="queryTriggerInteraction">定义是否查询isTrigger的碰撞器</param>
    /// <returns></returns>
    public static RaycastHit GetClosestRayCastHitNonAlloc(Ray ray, Rigidbody[] ignoreBodies = null, int layerMask = -1, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal)
    {
        RaycastHit result = new RaycastHit();
        int        count  = Physics.RaycastNonAlloc(ray, RaycastHits, Mathf.Infinity, layerMask, queryTriggerInteraction);

        if (count > 0)
        {
            float minDistance = float.MaxValue;
            for (int i = 0; i < count; i++)
            {
                RaycastHit hit = RaycastHits[i];
                if (ignoreBodies != null && System.Array.IndexOf(ignoreBodies, hit.rigidbody) > -1)
                {
                    continue;
                }
                if (hit.distance < minDistance)
                {
                    minDistance = hit.distance;
                    result      = hit;
                }
            }
        }
        return(result);
    }
Example #51
0
 private static extern int INTERNAL_CALL_RaycastNonAlloc(ref Vector3 origin, ref Vector3 direction, RaycastHit[] results, float maxDistance, int layermask, QueryTriggerInteraction queryTriggerInteraction);
Example #52
0
        public static bool TestCursorOver(Camera cursorCamera, Vector2 cursorPos, out Collider collider, float maxDistance = float.PositiveInfinity, int layerMask = Physics.AllLayers, QueryTriggerInteraction query = QueryTriggerInteraction.UseGlobal)
        {
            collider = null;
            if (cursorCamera == null)
            {
                return(false);
            }

            var        ray = cursorCamera.ScreenPointToRay(cursorPos);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, maxDistance, layerMask, query))
            {
                collider = hit.collider;
                return(true);
            }

            return(false);
        }
Example #53
0
 private static extern int INTERNAL_CALL_OverlapSphereNonAlloc(ref Vector3 position, float radius, Collider[] results, int layerMask, QueryTriggerInteraction queryTriggerInteraction);
Example #54
0
        public static bool TestCursorOverEntity(Camera cursorCamera, Vector2 cursorPos, out SPEntity entity, float maxDistance = float.PositiveInfinity, int layerMask = Physics.AllLayers, QueryTriggerInteraction query = QueryTriggerInteraction.UseGlobal)
        {
            Collider c;

            if (TestCursorOver(cursorCamera, cursorPos, out c, maxDistance, layerMask, query))
            {
                entity = SPEntity.Pool.GetFromSource(c);
                return(!object.ReferenceEquals(entity, null));
            }
            else
            {
                entity = null;
                return(false);
            }
        }
 public int Overlap(ICollection<Collider> results, int layerMask, QueryTriggerInteraction query = QueryTriggerInteraction.UseGlobal)
 {
     return PhysicsUtil.OverlapCapsule(_start, _end, _rad, results, layerMask, query);
 }
Example #56
0
        public static bool TestCursorOverEntity <T>(Camera cursorCamera, Vector2 cursorPos, out T hitTarget, float maxDistance = float.PositiveInfinity, int layerMask = Physics.AllLayers, QueryTriggerInteraction query = QueryTriggerInteraction.UseGlobal) where T : class
        {
            Collider c;

            if (TestCursorOver(cursorCamera, cursorPos, out c, maxDistance, layerMask, query))
            {
                hitTarget = com.spacepuppy.Utils.ComponentUtil.FindComponent <T>(c);
                return(!object.ReferenceEquals(hitTarget, null));
            }
            else
            {
                hitTarget = null;
                return(false);
            }
        }
 public int CastAll(Vector3 direction, ICollection<RaycastHit> results, float distance, int layerMask, QueryTriggerInteraction query = QueryTriggerInteraction.UseGlobal)
 {
     if(_start == _end)
     {
         return PhysicsUtil.SphereCastAll(_start, _rad, direction, results, distance, layerMask, query);
     }
     else
     {
         return PhysicsUtil.CapsuleCastAll(_start, _end, _rad, direction, results, distance, layerMask, query);
     }
 }
Example #58
0
 /// <summary>
 /// Is a gameObject grounded or not ?
 /// </summary>
 /// <param name="target">object to test for grounded</param>
 /// <param name="dirUp">normal up of the object</param>
 /// <param name="distToGround">dist to test</param>
 /// <param name="layerMask">layermask</param>
 /// <param name="queryTriggerInteraction"></param>
 /// <param name="marginDistToGround">aditionnal margin to the distance</param>
 /// <returns></returns>
 public static bool IsGrounded(GameObject target, Vector3 dirUp, float distToGround, int layerMask, QueryTriggerInteraction queryTriggerInteraction, float marginDistToGround = 0.1f)
 {
     return(Physics.Raycast(target.transform.position, -dirUp, distToGround + marginDistToGround, layerMask, queryTriggerInteraction));
 }
Example #59
0
 private static extern RaycastHit[] INTERNAL_CALL_SweepTestAll(Rigidbody self, ref Vector3 direction, float maxDistance, QueryTriggerInteraction queryTriggerInteraction);
Example #60
0
 public int Overlap(ICollection<Collider> results, int layerMask, QueryTriggerInteraction query = QueryTriggerInteraction.UseGlobal)
 {
     return PhysicsUtil.OverlapBox(_center, this.Extents, results, _orientation, layerMask, query);
 }