private void OnHexSelected(HexCell hex) { var pos = HexUtility.FindIntersectingHexCell(new int2(-4, 2), hex.Position); var middleHex = new HexCell(pos); m_Item = HexHighlighter.PlaceHighlighter(middleHex, Highlighter.blue, m_Item); }
public virtual void Awake() { var HexCell = new HexCell(HexUtility.WorldPointToHex(transform.position, 1)); Cell = HexCell.Position; if (SnapToGridOnStart) { transform.position = HexCell.WorldPosition + new Vector3(0, transform.localScale.y / 2, 0); } }
private void HandleHoveringHighlight() { var ray = Camera.main.ScreenPointToRay(InputManager.mousePosition); if (Physics.Raycast(ray, out RaycastHit hit, 500f, LayerMask.GetMask(Layer.Ground, Layer.Selectable))) { var selectableBehaviour = hit.collider.gameObject.transform.parent.gameObject.GetComponent <SelectableBehaviour>(); if (!selectableBehaviour) // Only select hex and deselect selectable if it was selected before { var pos = HexUtility.WorldPointToHex(hit.point, 1); IsUnderCell = true; IsUnderSelectable = false; SetSelectableUnderMouse(default);
public void Start() { ObjectMap = new Dictionary <Selectable, T>(); var behaviours = GameObject.FindObjectsOfType <T>(); foreach (var el in behaviours) { var cell = HexUtility.WorldPointToHex(el.gameObject.transform.position, 1); var selectable = HexDatabase.GetSelectable(cell); if (selectable == default) { Debug.LogError("Selectable component was in scene but not in the database. Default selectable was assigned in BehaviourCollector. Did you forget to rebuild the database?"); continue; } ObjectMap[selectable] = el; } }
public static void BuildHexDatabase() { foreach (var scene in GetAllScenes()) { var path = string.Format(k_AssetDatabaseDataFile, scene.name); var db = SaveableScriptableObject.Load <MapDatabaseData>(path); db.Map.ClearMapData(); var gos = scene.GetRootGameObjects(); foreach (var snap in gos.SelectMany(g => g.GetComponentsInChildren <SnapToGrid>())) { // Mark tile type which determine if they are walkable or not var pos = HexUtility.WorldPointToHex(snap.transform.position, 1); db.Map.HexTypeData.Add(new Map.HexTypeElement(pos, GetHexType(snap))); // Add objects from map to the database if (snap is UnitBehaviour unit) { unit.Cell = pos; db.Map.UnitData.Add(unit.GetFieldIfExist("m_Unit") as Unit); } else if (snap is MovableBehaviour move) { move.Cell = pos; db.Map.MovableData.Add(move.GetFieldIfExist("m_Movable") as Movable); } else if (snap is SelectableBehaviour sel) { sel.Cell = pos; db.Map.SelectableData.Add(sel.GetFieldIfExist("m_Selectable") as Selectable); } } db.SceneName = scene.name; db.Save(path); } }
IEnumerator MovePosition(Action <Unit> callback, Unit unit, MovableBehaviour obj, IEnumerable <int2> pathInReverse) { var transform = obj.gameObject.transform; var height = new Vector3(0, transform.position.y, 0); foreach (var nextCell in pathInReverse) { var startPos = Vector3.Scale(transform.position, new Vector3(1, 0, 1)); var targetPos = HexUtility.HexToWorldPoint(nextCell, 1); var direction = Vector3.Scale((targetPos - startPos), new Vector3(1, 0, 1)); for (int i = 0; i < k_FramesToLerp; i++) { var pos = Vector3.Slerp(startPos, targetPos, i * 1f / k_FramesToLerp) + height; transform.SetPositionAndRotation(pos, Quaternion.LookRotation(direction, Vector3.up)); yield return(null); } obj.Cell = nextCell; transform.position = targetPos + height; } callback.Invoke(unit); }