Esempio n. 1
0
        public override void onAddedToEntity()
        {
            buildingsRenderer = building.components["renderer"] as BuildingRenderer;
            buildingsRenderer?.setEnabled(false);

            if (building.GetPrimitiveObject().GetBuildingType() == BuildingType.Infrastructure)
            {
                constructionRenderers = new ConstructionRenderer[(int) building.GetTileSize().X, (int) building.GetTileSize().Y];
                for (int x = 0; x < building.GetTileSize().X; x++)
                {
                    for (int y = 0; y < building.GetTileSize().Y; y++)
                    {
                        Vector2 offset = building.GetPosition() + new Vector2(x * 100, y * 100) - new Vector2(50, 50);
                        ConstructionRenderer cr = new ConstructionRenderer(offset);
                        cr.setLocalOffset(offset);
                        entity.addComponent(cr);
                        constructionRenderers[x, y] = cr;
                    }
                }
            }
            else
            {
                BuildingStandardGameplayRenderer renderer = building.components["renderer"] as BuildingStandardGameplayRenderer;
                IBuildingStandardGameplayRenderer iRenderer = building.GetPrimitiveObject() as IBuildingStandardGameplayRenderer;

                constructionRenderers = new ConstructionRenderer[1, 1];
                ConstructionRenderer cr = new ConstructionRenderer(entity.position - new Vector2(renderer.GetSpriteAt(new Vector2(0, 0), false).width / 2, renderer.GetSpriteAt(new Vector2(0, 0), false).height / 2));
                entity.addComponent(cr);
                cr.SetWidth(iRenderer.GetTexture().texture2D.Width);
                cr.SetHeight(iRenderer.GetTexture().texture2D.Height);
                constructionRenderers[0, 0] = cr;
            }

            AssignTask();
        }
Esempio n. 2
0
        private void Destory()
        {
            foreach (Component cr in constructionRenderers)
            {
                entity.removeComponent<ConstructionRenderer>();
            }

            building.components.Remove("construction");
            buildingsRenderer = null;
            building = null;
            constructionRenderers = null;
        }