Beispiel #1
0
        /// <summary>
        /// Gets the corresponding footstep <see cref="Data"/> for the specified <see cref="RaycastHit"/>.
        /// </summary>
        /// <param name="hit"></param>
        /// <returns>The corresponding footstep <see cref="Data"/> for the specified <see cref="RaycastHit"/>.</returns>
        public Data GetData(RaycastHit hit)
        {
            Data data = null;

            // Check for footstep override
            FootstepOverride footstepOverride = hit.collider.GetComponent <FootstepOverride>();

            if (footstepOverride != null)
            {
                data = GetData(footstepOverride.FootstepOverrideName);
            }

            if (data != null)
            {
                return(data);
            }

            Debug.Log(hit.collider.material.name);
            data = GetData(hit.collider.material);

            if (data != null)
            {
                Debug.Log("attempting");
                return(data);
            }


            //// Check for meshes
            //MeshRenderer mr = hit.collider.GetComponent<MeshRenderer>();
            //MeshFilter mf = hit.collider.GetComponent<MeshFilter>();
            //if (mr != null)
            //{
            //    // Check for submeshes materials
            //    if (hit.collider is MeshCollider && mf != null && mf.mesh.subMeshCount > 1 && !mr.isPartOfStaticBatch)
            //    {
            //        Mesh m = mf.sharedMesh;

            //        int limit = hit.triangleIndex * 3;
            //        int submesh;
            //        for (submesh = 0; submesh < m.subMeshCount; submesh++)
            //        {
            //            int numIndices = m.GetTriangles(submesh).Length;
            //            if (numIndices > limit)
            //                break;

            //            limit -= numIndices;
            //        }

            //        PhysicMaterial material = hit.collider.material;
            //        //Material material = mr.sharedMaterials[submesh];
            //        data = GetData(material);

            //        if (data != null)
            //            return data;
            //    }

            //    // Check for material
            //    data = GetData(hit.collider.material);

            //    if (data != null)
            //        return data;

            //    // Check for texture
            //    //data = GetData(mr.sharedMaterial.mainTexture);

            //    if (data != null)
            //        return data;
            //}

            //// Check for terrains
            //Terrain t = hit.collider.GetComponent<Terrain>();
            //if (t != null)
            //{
            //    TerrainData TD = t.terrainData;

            //    if (TD.splatPrototypes.Length > 0)
            //    {
            //        Texture finalTexture = null;

            //        Vector3 position = hit.point;
            //        Vector2 AS = new Vector2(TD.alphamapWidth, TD.alphamapHeight); // Control texture size
            //        Vector3 TS = TD.size; // Terrain size

            //        // Lookup texture we are standing on
            //        int AX = (int)Mathf.Lerp(0, AS.x, Mathf.InverseLerp(t.transform.position.x, t.transform.position.x + TS.x, position.x));
            //        int AY = (int)Mathf.Lerp(0, AS.y, Mathf.InverseLerp(t.transform.position.z, t.transform.position.z + TS.z, position.z));

            //        float[,,] TerrCntrl = TD.GetAlphamaps(AX, AY, 1, 1);

            //        for (int i = 0; i < TD.splatPrototypes.Length; i++)
            //        {
            //            if (TerrCntrl[0, 0, i] >= .5f)
            //            {
            //                finalTexture = TD.splatPrototypes[i].texture;
            //                break;
            //            }
            //        }

            //        // Check for terrain texture we're standing on
            //        data = GetData(finalTexture);

            //        if (data != null)
            //            return data;
            //    }
            //}

            return(DefaultFootsteps);
        }
Beispiel #2
0
 private void Start()
 {
     footstepOverride = FootstepOverrideObject.GetComponent <MFPP.FootstepOverride>();
 }