コード例 #1
0
ファイル: Structures.cs プロジェクト: will3/vox
        private static IPlaceableObject LoadObject(StructureData structureData)
        {
            var path      = $"models/{structureData.modelName}";
            var textAsset = Resources.Load <TextAsset>(path);
            var model     = JsonUtility.FromJson <Model>(textAsset.text);

            return(new ModelObject(model));
        }
コード例 #2
0
ファイル: Structures.cs プロジェクト: will3/vox
        public bool TryPlaceBuilding(IEnumerable <BuildingTile> tileList, StructureData structureData)
        {
            var tl = tileList.ToArray();

            if (tl.Any(t => t.hasBuilding))
            {
                return(false);
            }

            var buildingCoord = tl
                                .OrderBy(t => t.bounds.min.x)
                                .ThenBy(t => t.bounds.min.z)
                                .First()
                                .GetBuildingCoord();

            if (structureData.modelName != null)
            {
                var modelObject = LoadObject(structureData);
                ObjectPlacer.Place(chunks, modelObject, buildingCoord, Time.frameCount % 4);
            }

            var grids = structureData.numGrids;

            var structureGo = Instantiate(structurePrefab, transform);

            structureGo.transform.position = buildingCoord + new Vector3(grids.x * this.tiles.gridSize / 2f, 0,
                                                                         grids.y * this.tiles.gridSize / 2.0f);

            var structure = structureGo.GetComponent <Structure>();

            structure.chunks        = chunks;
            structure.ground        = ground;
            structure.origin        = buildingCoord;
            structure.gridSize      = tiles.gridSize;
            structure.numGrids      = structureData.numGrids;
            structure.structureType = structureData.type;
            var y = Mathf.Max(buildingCoord.y, water.config.waterLevel);

            structure.wallHeight = (Mathf.CeilToInt(y / (float)wallHeightMultiplier) + 3)
                                   * wallHeightMultiplier;
            _structures.Add(buildingCoord, structureGo);

            foreach (var tile in tl)
            {
                tile.hasBuilding = true;
            }

            return(true);
        }