public void SetMesh(string name, ValidateMouseDelegate validationFunction) { Clear(); _meshName = name; var structure = Loc.GetStructureController().InstantiateNewStructureMeshRenderer(name, transform); structure.SetAllMaterial(Loc.GetFileController().BlueprintMaterial); _meshRenderer = structure; Validate = validationFunction; }
public BlueprintRenderer SpawnBlueprint(Blueprint blueprint) { var meshRenderer = InstantiateNewStructureMeshRenderer(blueprint.StructureName, transform); meshRenderer.SetAllMaterial(Loc.GetFileController().BlueprintMaterial); meshRenderer.transform.name = $"Blueprint: {blueprint.StructureName}"; var blueprintRenderer = meshRenderer.gameObject.AddComponent <BlueprintRenderer>(); blueprintRenderer.Load(blueprint); return(blueprintRenderer); }
public static IBehaviour GetBehaviour(string behaviourName) { try { var type = Loc.GetFileController().AllBehaviourTypes.First(behaviour => behaviour.Name.Equals(behaviourName, StringComparison.OrdinalIgnoreCase)); return(Activator.CreateInstance(type, null) as IBehaviour); } catch { Debug.LogError($"Could not load behaviour {behaviourName}"); throw; } }
public void Initialize() { ItemTypeFileMap = new Dictionary <string, string>(); ItemDataReference = new Dictionary <string, ItemData>(); foreach (var itemFile in Loc.GetFileController().ItemFiles) { try { var data = ItemData.GetFromJson(itemFile.text); ItemTypeFileMap.Add(data.Name, itemFile.text); ItemDataReference.Add(data.Name, data); } catch (Exception ex) { Debug.LogError($"Unable to load item {itemFile}: {ex.Message}"); } } }
private void ValidateCursor(Cell startCell) { if (Validate?.Invoke(startCell) == false) { _meshRenderer?.SetAllMaterial(Loc.GetFileController().InvalidBlueprintMaterial); if (MouseSpriteRenderer != null) { MouseSpriteRenderer.color = ColorConstants.RedAccent; } } else { _meshRenderer?.SetAllMaterial(Loc.GetFileController().BlueprintMaterial); if (MouseSpriteRenderer != null) { MouseSpriteRenderer.color = ColorConstants.WhiteAccent; } } }
private void ShowCursorEffects(List <Cell> selectedCells) { if (!string.IsNullOrEmpty(_meshName)) { if (selectedCells == null || selectedCells.Count == 0) { return; } foreach (var cell in selectedCells) { MeshRenderer cellRenderer; if (!_draggedRenderers.ContainsKey(cell)) { cellRenderer = Loc.GetStructureController().InstantiateNewStructureMeshRenderer(_meshName, Loc.GetMap().transform); cellRenderer.transform.position = new Vector3(cell.Vector.x, cell.Vector.y, cell.Vector.z); _draggedRenderers.Add(cell, cellRenderer); } else { cellRenderer = _draggedRenderers[cell]; } if (Validate?.Invoke(cell) == false) { cellRenderer.SetAllMaterial(Loc.GetFileController().InvalidBlueprintMaterial); } else { cellRenderer.SetAllMaterial(Loc.GetFileController().BlueprintMaterial); } } foreach (var cell in _draggedRenderers.Keys.ToList()) { if (!selectedCells.Contains(cell)) { Destroy(_draggedRenderers[cell].gameObject); _draggedRenderers.Remove(cell); } } } }
public void Initialize() { StructureTypes = ReflectionHelper.GetAllTypes(typeof(Structure)); StructureTypeFileMap = new Dictionary <string, string>(); StructureDataReference = new Dictionary <string, Structure>(); foreach (var structureFile in Loc.GetFileController().StructureJson) { try { var data = LoadStructureFromJson(structureFile.text); StructureTypeFileMap.Add(data.Name, structureFile.text); StructureDataReference.Add(data.Name, data); } catch (Exception ex) { Debug.LogError($"Unable to load structure {structureFile}: {ex.Message}"); } } }
public void ConstructTypeClicked() { Loc.Current.Get <CursorController>().SetSelectionPreference(SelectionPreference.Cell); if (Loc.GetGameController().OrderTrayController.gameObject.activeInHierarchy) { DisableAndReset(); } else { EnableAndClear(); foreach (var construct in Loc.GetFileController().Constructs) { var title = $"{construct.Name} ({construct.Height}x{construct.Width})"; var button = CreateOrderButton(() => ConstructClicked(construct), () => ShowConstructInfo(construct), construct.GetSprite()); button.name = title; } } }
internal void SetDefaultMaterial() { GetComponent <MeshRenderer>().SetAllMaterial(Loc.GetFileController().BlueprintMaterial); }