private GameEntity CreateCommon(EntitasInit unityObject) { GameEntity ge = _game.CreateEntity(); ge.AddGameObject(unityObject.gameObject); Vector3 pos = unityObject.transform.position; Quaternion rot = unityObject.transform.rotation; ge.AddWorldCoordinates(pos.x, pos.y, pos.z, rot.x, rot.y, rot.z, rot.w); HexCellBehaviour cell = _grid.GetCell(_grid.axial_to_cube(_grid.pixel_to_axial(unityObject.transform.position))); if (cell != null) { int id = cell.GetComponent <EntitasLink>().id; ge.AddLocation(cell, id); } HexSelectable selectable = unityObject.GetComponent <HexSelectable>(); if (selectable != null) { ge.isSelectable = true; } TeamColor team = unityObject.GetComponent <TeamColor>(); if (team != null) { ge.AddTeam(team.teamNr); } //now that the entity has been created with a unique ID, //put this ID on the unity GameObject for easy reference: EntitasLink el = unityObject.gameObject.AddComponent <EntitasLink>(); el.id = ge.iD.value; return(ge); }
public void Select(GameObject sel) { if (forward.ContainsKey(sel)) { //this can happen when a previously selected unit is also in the new selection box return; } HexSelectable selectable = sel.GetComponent <HexSelectable>(); Button thumb = Instantiate <Button>(_buttonPrefab); thumb.GetComponent <RectTransform>().SetParent(this.GetComponent <RectTransform>()); thumb.gameObject.SetActive(true); thumb.transform.GetChild(0).GetComponent <Text>().text = sel.name; thumb.transform.GetChild(1).GetComponent <Image>().sprite = selectable.Thumbnail; thumb.onClick.AddListener(() => { if (SelectRequested != null) { SelectRequested.Invoke(sel); } }); forward[sel] = thumb; reverse[thumb] = sel; }