예제 #1
0
        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);
            }
        }
예제 #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);
예제 #3
0
        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;
            }
        }
예제 #4
0
        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);
            }
        }