static bool Prefix(ref SkaterXL.Core.SurfaceTags _surfaceTag, ref float rps) { LevelSoundManager lvlManager = GameObject.FindObjectOfType <LevelSoundManager>(); // Always grab the first component if (!lvlManager) { return(true); // Continue to original function, collection does not exist. } PlayerController player = PlayerController.Instance; RaycastHit hit; Vector3 direction = -player.skaterController.skaterTransform.up; Ray ray = new Ray(player.boardController.boardTransform.position, direction); if (!Physics.Raycast(ray, out hit)) { return(true); // Continue to original function, no ray hit no object below us. } MeshCollider meshCollider = hit.collider as MeshCollider; MeshRenderer meshRenderer = hit.transform.GetComponent <MeshRenderer>(); if (!meshCollider || !meshCollider.sharedMesh) { return(true); // Continue to original function if we don't have a mesh collider we can't continue. } Mesh mesh = meshCollider.sharedMesh; if (mesh.subMeshCount <= 1) { return(true); // Continue to original function. Single submesh means there's no alternative material. } int triangleIdx = hit.triangleIndex; int[] lookupIdx = new int[3] { mesh.triangles[triangleIdx * 3], mesh.triangles[triangleIdx * 3 + 1], mesh.triangles[triangleIdx * 3 + 2] }; int submeshCount = mesh.subMeshCount; for (int i = 0; i < submeshCount; ++i) { int[] tris = mesh.GetTriangles(i); for (int j = 0; j < tris.Length; j += 3) { if (tris[j] == lookupIdx[0] && tris[j + 1] == lookupIdx[1] && tris[j + 2] == lookupIdx[2]) { // Get the surface tag from the scriptable object by material int tag = lvlManager.tagCollection.GetSurfaceTagByMaterial(meshRenderer.sharedMaterials[i]); _surfaceTag = tag == 0 ? _surfaceTag : (SkaterXL.Core.SurfaceTags)tag; return(true); } } } return(true); }
void Awake() { _instance = this; }