Ejemplo n.º 1
0
        public override void Draw()
        {
            GUILayout.Space(10);

            using (new GUILayout.HorizontalScope())
            {
                GUILayout.Label("Faction Id");

                var factionId       = (int)_unitFactory.FactionId;
                var factionIdString = GUILayout.TextField(_unitFactory.FactionId.ToString());

                if (int.TryParse(factionIdString, out factionId))
                {
                    _unitFactory.FactionId = (byte)factionId;
                }
            }

            foreach (var each in _unitFactory.UnitInfos)
            {
                if (GUILayout.Button("Create " + each.Name))
                {
                    _unitFactory.CreateUnit(each);
                }
            }

            GUILayout.Space(10);
            foreach (var each in _unitFactory.BuildingInfos)
            {
                if (GUILayout.Button("Create " + each.Name))
                {
                    _unitFactory.CreateBuilding(each);
                }
            }
        }
        private void CreateWorldData(BaseWorld world)
        {
            // create dummy stockpile
            var stockpile = _unitFactory.CreateBuilding(_unitFactory.
                                                        BuildingInfos.First(info => info.Id == "StockpileBlock"));

            stockpile.SetPosition(Vector3.zero);
            world.Stockpile.AddStockpileBlock(stockpile as StockpileBlock);
        }
Ejemplo n.º 3
0
    public override void Update(float deltaTime)
    {
        var camera = Camera.main;
        var ray    = camera.ScreenPointToRay(Input.mousePosition);

        if (SelectedBuilding != null)
        {
            var plane = new Plane(Vector3.up, Vector3.zero);

            var distance = 0f;

            if (plane.Raycast(ray, out distance))
            {
                var buildingPosition = ray.GetPoint(distance);

                SelectedBuilding.transform.position = buildingPosition;
            }

            if (Input.GetMouseButtonDown(0))
            {
                IsPlacingBuilding = false;
                Object.Destroy(SelectedBuilding);

                var entity = _unitFactory.CreateBuilding(SelectedBuildingInfo);
                entity.SetPosition(SelectedBuilding.transform.position);
            }
        }

        if (IsRemovingBuildings && Input.GetMouseButtonDown(0) && _world != null)
        {
            var entities = _world.EntityMapping.GetEntitiesByType <Workplace>();
            foreach (var each in entities)
            {
                if (each.GetBounds().IntersectRay(ray))
                {
                    //Will later be changed into a disband command
                    //if for some reason we want this to work with soldiers
                    each.DealDamage(each.Health, null);
                }
            }
        }
    }