Пример #1
0
        public void Initialize(BuildingInstance buildingInput)
        {
            DFHack.DFCoord pos = new DFHack.DFCoord(
                (buildingInput.pos_x_min + buildingInput.pos_x_max) / 2,
                (buildingInput.pos_y_min + buildingInput.pos_y_max) / 2,
                buildingInput.pos_z_max);

            //always update building rotation because that depends on outside stuff
            if (MapDataStore.Main[pos] != null && rotationType != RotationType.BuildingDirection)
            {
                transform.localRotation = MeshContent.TranslateRotation(rotationType, MapDataStore.Main[pos]);
            }

            if (originalBuilding != null &&
                originalBuilding.active == buildingInput.active &&
                originalBuilding.items.Count == buildingInput.items.Count &&
                originalBuilding.pos_x_min == buildingInput.pos_x_min &&
                originalBuilding.pos_y_min == buildingInput.pos_y_min)
            {
                return; //There's nothing changed.
            }
            originalBuilding = buildingInput;

            foreach (var part in parts)
            {
                part.UpdatePart(buildingInput);
            }


            var group = GetComponent <LODGroup>();

            if (group == null)
            {
                group = gameObject.AddComponent <LODGroup>();
                var lods = new LOD[1];
                lods[0] = new LOD(0.05f, GetComponentsInChildren <MeshRenderer>());
                group.SetLODs(lods);
                group.RecalculateBounds();
            }

            UpdateTilePositions(buildingInput);

            foreach (var item in GetComponentsInChildren <Collider>())
            {
                if (item.GetComponent <BuildingSelect>() == null)
                {
                    item.gameObject.AddComponent <BuildingSelect>().root = this;
                }
            }
        }
Пример #2
0
 private DFCoord2d GetRotatedLocalCoord(DFCoord worldCoord, BuildingInstance building)
 {
     switch (building.direction)
     {
         case BuildingDirection.NORTH:
             return new DFCoord2d(worldCoord.x - building.pos_x_min, worldCoord.y - building.pos_y_min);
         case BuildingDirection.EAST:
             return new DFCoord2d(worldCoord.y - building.pos_y_min, building.pos_x_max - worldCoord.x);
         case BuildingDirection.SOUTH:
             return new DFCoord2d(building.pos_x_max - worldCoord.x, building.pos_y_max - worldCoord.y);
         case BuildingDirection.WEST:
             return new DFCoord2d(building.pos_y_max - worldCoord.y, worldCoord.x - building.pos_x_min);
         default:
             return new DFCoord2d(worldCoord.x - building.pos_x_min, worldCoord.y - building.pos_y_min);
     }
 }