/* * Construction */ public bool IsPlaceableAt(ThingConfig config, Vector2Int position) { var current = GetThingOnFloor(position); if (current == null) { return(false); } if (ConstructAtPosition(current.Position)) { return(false); } if (config.ConstructionConfig != null && config.ConstructionConfig.BuildOn.HasValue && config.ConstructionConfig.BuildOn != current.Config.TypeOfThing) { return(false); } return(current.Config.BuildSite); }
void OnMouseEnter(ThingConfig thing) { CostPooler.DeactivateAll(); foreach (var required in thing.RequiredToCraft) { var obj = CostPooler.GetPooledObject(); var lineItem = obj.GetComponent <CostLineItem>(); var lineItemThing = _session.Game.ThingConfigs.FirstOrDefault(t => t.TypeOfThing == required); lineItem.Name.text = lineItemThing.Name.ToUppercaseFirst(); lineItem.Amount.text = "x1"; lineItem.Image.sprite = Assets.GetSprite(lineItemThing.Sprite); obj.SetActive(true); } DetailsDescription.text = thing.Description; DetailsPanel.gameObject.SetActive(true); }
ThingConfig GetThingConfigFromParentChild(ThingConfig parent, ThingConfig child) { var properties = parent.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance); var parentCopy = new ThingConfig(); foreach (FieldInfo field in properties) { field.SetValue(parentCopy, field.GetValue(parent)); } var defaultConfig = new ThingConfig(); foreach (FieldInfo field in properties) { var value = field.GetValue(child); var defaultValue = field.GetValue(defaultConfig); if (value == null || value.Equals(defaultValue)) { continue; } field.SetValue(parentCopy, field.GetValue(child)); } return(parentCopy); }
void DrawThing(float x, float y, float width, float height, ThingConfig thing) { DrawThing(x, y, width, height, thing.TypeOfThing); }
void Update() { // if currently over another panel // don't do anything if (MouseOverUIElement.MouseOverElement) { //_spriteRenderer.enabled = false; return; } // if spriteRenderer has been disabled // due to mouse over panel, re-enable // if(!_spriteRenderer.enabled) // _spriteRenderer.enabled = true; // setup example thing on _current from // selected type on game if (!CurrentType.HasValue && _currentToBuild != null) { _currentToBuild = null; } else if (CurrentType.HasValue && (_currentToBuild == null || _currentToBuild.TypeOfThing != CurrentType.Value)) { _currentToBuild = Assets.GetThingConfig(CurrentType.Value); } // update cursor position to mouse position var mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); var position = new Vector3( Mathf.RoundToInt(mousePosition.x), Mathf.RoundToInt(mousePosition.y) ); if (_currentToBuild != null) { _fixCursorPosition = false; } // if cursor has moved to a different grid position if (_cursorPosition != position && !_fixCursorPosition) { _cursorPosition = position; _crosshairCursor.transform.position = position; var posVec2 = position.ToVector2IntFloor(); if (OnCursorMoved != null) { OnCursorMoved(posVec2); } if (_game.IsThingOnFloor(posVec2)) { _mouseOverThing = _game.GetThingOnFloor(posVec2); if (_actionPanel != null) { _actionPanel.Setup(_mouseOverThing); } } } // disable cursor mesh if no current selected // thing being constructed _cursorMeshObj.SetActive(_currentToBuild != null); // check for dragging if (Input.GetKeyDown(KeyCode.Mouse0)) { _mouseDown = true; _down = _crosshairCursor.transform.position; MouseDown(); } // update move position // check if current tile is rule based so we can setup // the correct max/min if (_mouseDown) { _move = _crosshairCursor.transform.position; if (_currentToBuild != null && _currentToBuild.Pipe) { if (_max.x - _min.x > _max.y - _min.y) { _move.y = _down.y; } else { _move.x = _down.x; } } // move mouse callback for drawing previews etc. } else { _down = _crosshairCursor.transform.position; _move = _down; } MouseMove(); // if player has finished interaction // call mouse up event if (Input.GetKeyUp(KeyCode.Mouse0)) { _mouseDown = false; MouseUp(); } // if right click cancel current // tile if (Input.GetKeyDown(KeyCode.Mouse1)) { CurrentType = null; _fixCursorPosition = false; _actionPanel.Clear(); } }
public void Setup(ThingConfig config) { Config = config; Hitpoints = config.Hitpoints; RefreshSprite(); if (!string.IsNullOrEmpty(Config.PathTag)) { Game.UpdateAstarPath(transform.position.ToVector2IntFloor(), Config.PathTag); } // todo: must be a better way... if (config.TileRuleConfig != null) { var type = Type.GetType(config.TileRuleConfig.Type); var instance = (ITileRule)Activator.CreateInstance(type, new object[] { config.TileRuleConfig.Sprites }); TileRule = instance; } if (Config.LightBlocking) { gameObject.AddComponent <BoxCollider2D>(); gameObject.layer = LayerMask.NameToLayer("Blocks Light"); } if (Config.Inventory) { Inventory = gameObject.AddComponent <Inventory>(); } if (Config.FactoryConfig != null) { Factory = gameObject.AddComponent <Factory>(); Factory.Setup(Config.FactoryConfig); } if (Config.Fire) { Fire = gameObject.AddComponent <Fire>(); } if (Config.Storage) { Storage = gameObject.AddComponent <Storage>(); } if (Config.CropConfig != null) { Crop = gameObject.AddComponent <Crop>(); Crop.Setup(Config.CropConfig); } switch (Config.Agent) { case AgentConfig.Villager: Agent = gameObject.AddComponent <Villager>(); break; case AgentConfig.Animal: //Agent = gameObject.AddComponent<Animal>(); break; } }