Ejemplo n.º 1
0
        private void RegenerateRegion(GameObject regionGo)
        {
            CombatGameState combatState     = UnityGameInstance.BattleTechGame.Combat;
            RegionGameLogic regionGameLogic = regionGo.GetComponent <RegionGameLogic>();
            List <Vector3>  meshPoints      = new List <Vector3>();

            // Get all region points and fix the y height
            foreach (Transform t in regionGo.transform)
            {
                if (t.gameObject.name.StartsWith("RegionPoint"))
                {
                    Vector3 position            = t.position;
                    float   height              = combatState.MapMetaData.GetLerpedHeightAt(position);
                    Vector3 fixedHeightPosition = new Vector3(position.x, height, position.z);
                    t.position = fixedHeightPosition;
                    meshPoints.Add(t.localPosition);
                }
            }

            // Create new mesh from points and set to collider and mesh filter
            MeshCollider collider = regionGo.GetComponent <MeshCollider>();
            MeshFilter   mf       = regionGo.GetComponent <MeshFilter>();
            Mesh         mesh     = MeshTools.CreateHexigon(REGION_RADIUS, meshPoints);

            collider.sharedMesh = mesh;
            mf.mesh             = mesh;

            List <MapEncounterLayerDataCell> cells = SceneUtils.GetMapEncounterLayerDataCellsWithinCollider(regionGo);

            for (int i = 0; i < cells.Count; i++)
            {
                MapEncounterLayerDataCell cell = cells[i];
                cell.AddRegion(regionGameLogic);
            }
        }
Ejemplo n.º 2
0
        public static RegionGameLogic CreateRegion(GameObject parent, string regionGameLogicGuid, string objectiveGuid, string name, string regionDefId, float radius = 0)
        {
            GameObject regionGo     = CreateRegionGameObject(parent, name);
            float      regionRadius = (radius > 0) ? radius : DEFAULT_REGION_RADIUS;

            MeshCollider collider = regionGo.AddComponent <MeshCollider>();
            MeshFilter   mf       = regionGo.AddComponent <MeshFilter>();
            Mesh         mesh     = MeshTools.CreateHexigon(regionRadius);

            collider.sharedMesh = mesh;
            mf.mesh             = mesh;

            regionGo.AddComponent <TerrainDataChangeDetection>();
            regionGo.AddComponent <SnapToTerrain>();
            regionGo.AddComponent <MeshRenderer>();

            RegionGameLogic regionGameLogic = regionGo.AddComponent <RegionGameLogic>();

            regionGameLogic.encounterObjectGuid = regionGameLogicGuid;
            regionGameLogic.radius      = regionRadius;
            regionGameLogic.regionDefId = regionDefId;
            regionGameLogic.alwaysShowRegionWhenActive = true;

            CreateRegionPointGameObject(regionGo, $"RegionPoint1", new Vector3(0, 0, regionRadius));                     // North
            CreateRegionPointGameObject(regionGo, $"RegionPoint2", new Vector3(regionRadius, 0, regionRadius / 2f));     // North-East
            CreateRegionPointGameObject(regionGo, $"RegionPoint3", new Vector3(regionRadius, 0, -(regionRadius / 2f)));  // South-East
            CreateRegionPointGameObject(regionGo, $"RegionPoint4", new Vector3(0, 0, -regionRadius));                    // South
            CreateRegionPointGameObject(regionGo, $"RegionPoint5", new Vector3(-regionRadius, 0, -(regionRadius / 2f))); // South-West
            CreateRegionPointGameObject(regionGo, $"RegionPoint6", new Vector3(-regionRadius, 0, regionRadius / 2f));    // North-West

            return(regionGameLogic);
        }
Ejemplo n.º 3
0
        public static RegionGameLogic CreateWithdrawRegion(GameObject parent, string regionGameLogicGuid, string objectiveGuid, string name = null)
        {
            GameObject withdrawRegionGo = CreateWithdrawRegionGameObject(parent, name);

            MeshCollider collider = withdrawRegionGo.AddComponent <MeshCollider>();
            MeshFilter   mf       = withdrawRegionGo.AddComponent <MeshFilter>();
            Mesh         mesh     = MeshTools.CreateHexigon(REGION_RADIUS);

            collider.sharedMesh = mesh;
            mf.mesh             = mesh;

            withdrawRegionGo.AddComponent <TerrainDataChangeDetection>();
            withdrawRegionGo.AddComponent <SnapToTerrain>();
            withdrawRegionGo.AddComponent <MeshRenderer>();

            RegionGameLogic regionGameLogic = withdrawRegionGo.AddComponent <RegionGameLogic>();

            regionGameLogic.encounterObjectGuid = regionGameLogicGuid;
            regionGameLogic.radius      = REGION_RADIUS;
            regionGameLogic.regionDefId = "regionDef_EvacZone";
            regionGameLogic.alwaysShowRegionWhenActive = true;

            CreateRegionPointGameObject(withdrawRegionGo, $"RegionPoint1", new Vector3(0, 0, REGION_RADIUS));                      // North
            CreateRegionPointGameObject(withdrawRegionGo, $"RegionPoint2", new Vector3(REGION_RADIUS, 0, REGION_RADIUS / 2f));     // North-East
            CreateRegionPointGameObject(withdrawRegionGo, $"RegionPoint3", new Vector3(REGION_RADIUS, 0, -(REGION_RADIUS / 2f)));  // South-East
            CreateRegionPointGameObject(withdrawRegionGo, $"RegionPoint4", new Vector3(0, 0, -REGION_RADIUS));                     // South
            CreateRegionPointGameObject(withdrawRegionGo, $"RegionPoint5", new Vector3(-REGION_RADIUS, 0, -(REGION_RADIUS / 2f))); // South-West
            CreateRegionPointGameObject(withdrawRegionGo, $"RegionPoint6", new Vector3(-REGION_RADIUS, 0, REGION_RADIUS / 2f));    // North-West

            return(regionGameLogic);
        }
Ejemplo n.º 4
0
    public static void Regenerate(this RegionGameLogic regionGameLogic)
    {
        GameObject      regionGo    = regionGameLogic.gameObject;
        CombatGameState combatState = UnityGameInstance.BattleTechGame.Combat;
        List <Vector3>  meshPoints  = new List <Vector3>();

        // Remove old region location from layer data cells
        List <MapEncounterLayerDataCell> beforeCells = SceneUtils.GetMapEncounterLayerDataCellsWithinCollider(regionGo);

        for (int i = 0; i < beforeCells.Count; i++)
        {
            MapEncounterLayerDataCell cell = beforeCells[i];
            cell.RemoveRegion(regionGameLogic);
        }

        // Get all region points and fix the y height
        foreach (Transform t in regionGo.transform)
        {
            if (t.gameObject.name.StartsWith("RegionPoint"))
            {
                Vector3 position            = t.position;
                float   height              = combatState.MapMetaData.GetLerpedHeightAt(position);
                Vector3 fixedHeightPosition = new Vector3(position.x, height, position.z);
                t.position = fixedHeightPosition;
                meshPoints.Add(t.localPosition);
            }
        }

        // Create new mesh from points and set to collider and mesh filter
        MeshCollider collider = regionGo.GetComponent <MeshCollider>();
        MeshFilter   mf       = regionGo.GetComponent <MeshFilter>();
        Mesh         mesh     = MeshTools.CreateHexigon(regionGameLogic.radius, meshPoints);

        collider.sharedMesh = mesh;
        mf.mesh             = mesh;

        List <MapEncounterLayerDataCell> afterCells = SceneUtils.GetMapEncounterLayerDataCellsWithinCollider(regionGo);

        for (int i = 0; i < afterCells.Count; i++)
        {
            MapEncounterLayerDataCell cell = afterCells[i];
            cell.AddRegion(regionGameLogic);
        }
    }