Esempio n. 1
0
    public override void OnInit(float dmg, ShipRefs r, E_WEAPONS wClass)
    {
        base.OnInit(dmg, r, wClass);

        // get current track section
        currentSection = r.initialSection;
    }
Esempio n. 2
0
        /// <summary>
        /// Get the rotation of a section.
        /// </summary>
        /// <param name="section"></param>
        /// <returns></returns>
        public static Quaternion SectionGetRotation(TrSection section)
        {
            // get positions
            Vector3 sectionPosition = section.SECTION_POSITION;
            Vector3 nextPosition = section.SECTION_NEXT.SECTION_POSITION;

            // get the forward direction from positions and then the normal
            Vector3 forward = (nextPosition - sectionPosition);
            Vector3 normal = section.SECTION_NORMAL;

            // return lookat
            return Quaternion.LookRotation(forward.normalized, normal.normalized);
        }
Esempio n. 3
0
    private void UpdateInitialSection()
    {
        // try to find track section using a raycast
        RaycastHit hit;
        if (Physics.Raycast(transform.position, -transform.up, out hit, 1000.0f, 1 << LayerMask.NameToLayer("TrackFloor")))
        {
            int tri = hit.triangleIndex;
            TrTile tile = TrackDataHelper.TileFromTriangleIndex(hit.triangleIndex, E_TRACKMESH.FLOOR, RaceSettings.trackData.TRACK_DATA);
            TrSection section = tile.TILE_SECTION;

            bool canUpdate = true;
            if (section.SECTION_TYPE == E_SECTIONTYPE.JUMP_START)
            {
                onJump = true;
                expectedLandSection = section.SECTION_NEXT;
            }

            if (section.SECTION_TYPE == E_SECTIONTYPE.JUMP_END)
            {
                onJump = false;
                if (section != expectedLandSection)
                    canUpdate = false;
            }

            if (canUpdate)
            {
                r.initialSection = section;
                iSectionIndex = section.SECTION_INDEX;
                r.currentSection = r.initialSection;
                cSectionIndex = section.SECTION_INDEX;
            }
            iSectionFound = true;
        } else
        {
            iSectionFound = false;
        }
    }
Esempio n. 4
0
    private static void UpdateSection()
    {
        if (Event.current.type == EventType.keyDown && Event.current.keyCode == KeyCode.LeftControl)
        {
            HandleUtility.Repaint();

            Ray ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, 1 << LayerMask.NameToLayer("TrackFloor")))
            {
                Mesh m = hit.transform.GetComponent<MeshFilter>().sharedMesh;
                TrTile tile = TrackDataHelper.TileFromTriangleIndex(hit.triangleIndex, E_TRACKMESH.FLOOR, managerData.TRACK_DATA);
                if (settingNextSection && selectedSection != null)
                {
                    selectedSection.SECTION_NEXT = tile.TILE_SECTION;
                    settingNextSection = false;
                } else
                {
                    selectedSection = tile.TILE_SECTION;
                }
                managerData.SECTION_CURRENT = selectedSection.SECTION_INDEX;
                managerData.SECTION_NEXT = selectedSection.SECTION_NEXT.SECTION_INDEX;

            }
        }
    }
Esempio n. 5
0
        public static TrGenData GenerateTrack(Mesh trackFloor, Mesh trackWall, Transform floorT, Transform floorW)
        {
            if (trackFloor == null || trackWall == null)
            {
                Debug.LogError("TRGEN: track floor and/or track wall meshes not present!");
                return null;
            }

            TrGenData gen = new TrGenData();

            // re-build floor mesh so all tris have unique verts
            Vector3[] newVertices = new Vector3[trackFloor.triangles.Length];
            Vector2[] newUV = new Vector2[trackFloor.triangles.Length];
            Vector3[] newNormals = new Vector3[trackFloor.triangles.Length];
            int[] newTriangles = new int[trackFloor.triangles.Length];
            int triLength = trackFloor.triangles.Length;
            for (int i = 0; i < triLength; i++)
            {
                newVertices[i] = trackFloor.vertices[trackFloor.triangles[i]];
                newUV[i] = trackFloor.uv[trackFloor.triangles[i]];
                newNormals[i] = trackFloor.normals[trackFloor.triangles[i]];
                newTriangles[i] = i;
            }

            trackFloor.vertices = newVertices;
            trackFloor.uv = newUV;
            trackFloor.normals = newNormals;
            trackFloor.triangles = newTriangles;

            // re-build wall mesh
            newVertices = new Vector3[trackWall.triangles.Length];
            newUV = new Vector2[trackWall.triangles.Length];
            newNormals = new Vector3[trackWall.triangles.Length];
            newTriangles = new int[trackWall.triangles.Length];
            triLength = trackWall.triangles.Length;

            for (int i = 0; i < triLength; i++)
            {
                newVertices[i] = trackWall.vertices[trackWall.triangles[i]];
                newUV[i] = trackWall.uv[trackWall.triangles[i]];
                newNormals[i] = trackWall.normals[trackWall.triangles[i]];
                newTriangles[i] = i;
            }

            trackWall.vertices = newVertices;
            trackWall.uv = newUV;
            trackWall.normals = newNormals;
            trackWall.triangles = newTriangles;

            #region TEMPS

            // verts
            Vector3[] verts = trackFloor.vertices;
            Vector3[] verts2 = trackWall.vertices;

            // section data
            TrSection newSection = new TrSection();
            TrTile[] tiles = new TrTile[2];

            // mesh triangles
            int[] tris = trackFloor.triangles;
            int[] tris2 = trackWall.triangles;

            // tiles to be mapped to indicies
            TrTile[] mappedFloor = new TrTile[tris.Length];
            TrTile[] mappedWall = new TrTile[tris.Length];

            // mesh normals
            Vector3[] normals = trackFloor.normals;
            Vector3[] normals2 = trackWall.normals;

            // vertex positions
            Vector3 p1 = Vector3.zero;
            Vector3 p2 = Vector3.zero;
            Vector3 pMid = Vector3.zero;

            // vertex normals
            Vector3 n1 = Vector3.zero;
            Vector3 n2 = Vector3.zero;
            Vector3 nMid = Vector3.zero;

            #endregion

            // create floor tiles
            int index = 0;
            for (int i = 0; i < tris.Length - 3; i += 6)
            {
                // create new tile
                TrTile newTile = new TrTile();

                // add tile indicies
                newTile.TILE_INDICES.Add(tris[i + 0]);
                newTile.TILE_INDICES.Add(tris[i + 1]);
                newTile.TILE_INDICES.Add(tris[i + 2]);
                newTile.TILE_INDICES.Add(tris[i + 4]);

                // get mid position of all vertices
                p1 = floorT.TransformPoint(verts[tris[i]]);
                p2 = floorT.TransformPoint(verts[tris[i + 1]]);
                pMid = (p1 + p2) / 2;

                // set default tile settings
                newTile.TILE_TYPE = E_TILETYPE.FLOOR;
                newTile.TILE_COLOR = Color.white;
                newTile.TILE_POSITION = pMid;
                newTile.TILE_INDEX = index;

                // add tile to list
                gen.TILES_FLOOR.Add(newTile);

                mappedFloor[i + 0] = newTile;
                mappedFloor[i + 1] = newTile;
                mappedFloor[i + 2] = newTile;
                mappedFloor[i + 3] = newTile;

                index++;
            }

            /*
            // create wall tiles
            index = 0;
            for (int i = 0; i < tris2.Length - 3; i += 6)
            {
                // create new tile
                TrTile newTile = new TrTile();

                // add tile indicies
                newTile.TILE_INDICES.Add(tris2[i + 0]);
                newTile.TILE_INDICES.Add(tris2[i + 1]);
                newTile.TILE_INDICES.Add(tris2[i + 2]);
                newTile.TILE_INDICES.Add(tris2[i + 4]);

                // get mid position of all vertices
                p1 = floorT.TransformPoint(verts2[tris2[i]]);
                p2 = floorT.TransformPoint(verts2[tris2[i + 1]]);
                pMid = (p1 + p2) / 2;

                // set default tile settings
                newTile.TILE_TYPE = E_TILETYPE.FLOOR;
                newTile.TILE_COLOR = Color.white;
                newTile.TILE_POSITION = pMid;
                newTile.TILE_INDEX = 0;

                // add tile to list
                gen.TILES_WALL.Add(newTile);

                mappedWall[i + 0] = newTile;
                mappedWall[i + 1] = newTile;
                mappedWall[i + 2] = newTile;
                mappedWall[i + 4] = newTile;

                index++;
            }
            */

            // create sections
            index = 0;
            for (int i = 0; i < gen.TILES_FLOOR.Count - 1; i += 2)
            {
                // setup section and get tiles
                newSection = new TrSection();

                tiles[0] = gen.TILES_FLOOR[i + 0];
                tiles[1] = gen.TILES_FLOOR[i + 1];

                // set section defaults
                newSection.SECTION_TYPE = E_SECTIONTYPE.NORMAL;
                newSection.SECTION_TILES = tiles;
                newSection.SECTION_INDEX = index;

                // set section position
                p1 = floorT.transform.TransformPoint(verts[tiles[0].TILE_INDICES[0]]);
                p2 = floorT.transform.TransformPoint(verts[tiles[1].TILE_INDICES[1]]);
                pMid = (p1 + p2) / 2;

                newSection.SECTION_POSITION = pMid;

                // set section normal
                n1 = floorT.transform.TransformDirection(normals[tiles[0].TILE_INDICES[0]]);
                n2 = floorT.transform.TransformDirection(normals[tiles[1].TILE_INDICES[1]]);
                nMid = (n1 + n2) / 2;

                newSection.SECTION_NORMAL = nMid;

                // add section
                gen.SECTIONS.Add(newSection);

                // add section to tiles
                tiles[0].TILE_SECTION = newSection;
                tiles[1].TILE_SECTION = newSection;
                tiles[1].TILE_SECOND = true;

                index++;
            }

            // set next sections
            for (int i = 0; i < gen.SECTIONS.Count; i++)
            {
                if (i == gen.SECTIONS.Count - 1)
                    gen.SECTIONS[i].SECTION_NEXT = gen.SECTIONS[0];
                else
                    gen.SECTIONS[i].SECTION_NEXT = gen.SECTIONS[i + 1];
            }

            // add mapped tiles to gendata
            for (int i = 0; i < mappedFloor.Length; i++)
                gen.TILES_FLOOR_MAPPED.Add(mappedFloor[i]);

            return gen;
        }
Esempio n. 6
0
 /// <summary>
 /// Get all tiles in a section.
 /// </summary>
 /// <param name="section"></param>
 /// <returns></returns>
 public static TrTile[] SectionGetTiles(TrSection section)
 {
     return section.SECTION_TILES;
 }
Esempio n. 7
0
        public static TrGenData GenerateTrack(Mesh trackFloor, Mesh trackWall, Transform floorT, Transform floorW)
        {
            if (trackFloor == null || trackWall == null)
            {
                Debug.LogError("TRGEN: track floor and/or track wall meshes not present!");
                return(null);
            }

            TrGenData gen = new TrGenData();


            // re-build floor mesh so all tris have unique verts
            Vector3[] newVertices  = new Vector3[trackFloor.triangles.Length];
            Vector2[] newUV        = new Vector2[trackFloor.triangles.Length];
            Vector3[] newNormals   = new Vector3[trackFloor.triangles.Length];
            int[]     newTriangles = new int[trackFloor.triangles.Length];

            for (int i = 0; i < trackFloor.triangles.Length; i++)
            {
                newVertices[i]  = trackFloor.vertices[trackFloor.triangles[i]];
                newUV[i]        = trackFloor.uv[trackFloor.triangles[i]];
                newNormals[i]   = trackFloor.normals[trackFloor.triangles[i]];
                newTriangles[i] = i;
            }


            trackFloor.vertices  = newVertices;
            trackFloor.uv        = newUV;
            trackFloor.normals   = newNormals;
            trackFloor.triangles = newTriangles;

            // re-build wall mesh
            newVertices  = new Vector3[trackWall.triangles.Length];
            newUV        = new Vector2[trackWall.triangles.Length];
            newNormals   = new Vector3[trackWall.triangles.Length];
            newTriangles = new int[trackWall.triangles.Length];

            for (int i = 0; i < trackWall.triangles.Length; i++)
            {
                newVertices[i]  = trackWall.vertices[trackWall.triangles[i]];
                newUV[i]        = trackWall.uv[trackWall.triangles[i]];
                newNormals[i]   = trackWall.normals[trackWall.triangles[i]];
                newTriangles[i] = i;
            }


            trackWall.vertices  = newVertices;
            trackWall.uv        = newUV;
            trackWall.normals   = newNormals;
            trackWall.triangles = newTriangles;

            #region TEMPS

            // verts
            Vector3[] verts  = trackFloor.vertices;
            Vector3[] verts2 = trackWall.vertices;

            // section data
            TrSection newSection = new TrSection();
            TrTile[]  tiles      = new TrTile[2];

            // mesh triangles
            int[] tris  = trackFloor.triangles;
            int[] tris2 = trackWall.triangles;

            // tiles to be mapped to indicies
            TrTile[] mappedFloor = new TrTile[tris.Length];
            TrTile[] mappedWall  = new TrTile[tris.Length];

            // mesh normals
            Vector3[] normals  = trackFloor.normals;
            Vector3[] normals2 = trackWall.normals;

            // vertex positions
            Vector3 p1   = Vector3.zero;
            Vector3 p2   = Vector3.zero;
            Vector3 pMid = Vector3.zero;

            // vertex normals
            Vector3 n1   = Vector3.zero;
            Vector3 n2   = Vector3.zero;
            Vector3 nMid = Vector3.zero;

            #endregion

            // create floor tiles
            int index = 0;
            for (int i = 0; i < tris.Length - 3; i += 6)
            {
                // create new tile
                TrTile newTile = new TrTile();

                // add tile indicies
                newTile.TILE_INDICES.Add(tris[i + 0]);
                newTile.TILE_INDICES.Add(tris[i + 1]);
                newTile.TILE_INDICES.Add(tris[i + 2]);
                newTile.TILE_INDICES.Add(tris[i + 4]);

                // get mid position of all vertices
                p1   = floorT.TransformPoint(verts[tris[i]]);
                p2   = floorT.TransformPoint(verts[tris[i + 1]]);
                pMid = (p1 + p2) / 2;

                // set default tile settings
                newTile.TILE_TYPE     = E_TILETYPE.FLOOR;
                newTile.TILE_COLOR    = Color.white;
                newTile.TILE_POSITION = pMid;
                newTile.TILE_INDEX    = index;

                // add tile to list
                gen.TILES_FLOOR.Add(newTile);

                mappedFloor[i + 0] = newTile;
                mappedFloor[i + 1] = newTile;
                mappedFloor[i + 2] = newTile;
                mappedFloor[i + 3] = newTile;

                index++;
            }

            // create wall tiles
            index = 0;
            for (int i = 0; i < tris2.Length - 3; i += 6)
            {
                // create new tile
                TrTile newTile = new TrTile();

                // add tile indicies
                newTile.TILE_INDICES.Add(tris2[i + 0]);
                newTile.TILE_INDICES.Add(tris2[i + 1]);
                newTile.TILE_INDICES.Add(tris2[i + 2]);
                newTile.TILE_INDICES.Add(tris2[i + 4]);

                // get mid position of all vertices
                p1   = floorT.TransformPoint(verts2[tris2[i]]);
                p2   = floorT.TransformPoint(verts2[tris2[i + 1]]);
                pMid = (p1 + p2) / 2;

                // set default tile settings
                newTile.TILE_TYPE     = E_TILETYPE.FLOOR;
                newTile.TILE_COLOR    = Color.white;
                newTile.TILE_POSITION = pMid;
                newTile.TILE_INDEX    = 0;

                // add tile to list
                gen.TILES_WALL.Add(newTile);

                mappedWall[i + 0] = newTile;
                mappedWall[i + 1] = newTile;
                mappedWall[i + 2] = newTile;
                mappedWall[i + 4] = newTile;

                index++;
            }

            // create sections
            index = 0;
            for (int i = 0; i < gen.TILES_FLOOR.Count - 1; i += 2)
            {
                // setup section and get tiles
                newSection = new TrSection();

                tiles[0] = gen.TILES_FLOOR[i + 0];
                tiles[1] = gen.TILES_FLOOR[i + 1];

                // set section defaults
                newSection.SECTION_TYPE  = E_SECTIONTYPE.NORMAL;
                newSection.SECTION_TILES = tiles;
                newSection.SECTION_INDEX = index;

                // set section position
                p1   = floorT.transform.TransformPoint(verts[tiles[0].TILE_INDICES[0]]);
                p2   = floorT.transform.TransformPoint(verts[tiles[1].TILE_INDICES[1]]);
                pMid = (p1 + p2) / 2;

                newSection.SECTION_POSITION = pMid;

                // set section normal
                n1   = floorT.transform.TransformDirection(normals[tiles[0].TILE_INDICES[0]]);
                n2   = floorT.transform.TransformDirection(normals[tiles[1].TILE_INDICES[1]]);
                nMid = (n1 + n2) / 2;

                newSection.SECTION_NORMAL = nMid;

                // add section
                gen.SECTIONS.Add(newSection);

                // add section to tiles
                tiles[0].TILE_SECTION = newSection;
                tiles[1].TILE_SECTION = newSection;
                tiles[1].TILE_SECOND  = true;

                index++;
            }

            // set next sections
            for (int i = 0; i < gen.SECTIONS.Count; i++)
            {
                if (i == gen.SECTIONS.Count - 1)
                {
                    gen.SECTIONS[i].SECTION_NEXT = gen.SECTIONS[0];
                }
                else
                {
                    gen.SECTIONS[i].SECTION_NEXT = gen.SECTIONS[i + 1];
                }
            }

            // add mapped tiles to gendata
            for (int i = 0; i < mappedFloor.Length; i++)
            {
                gen.TILES_FLOOR_MAPPED.Add(mappedFloor[i]);
            }


            return(gen);
        }