Beispiel #1
0
        private void panel_SelectRequested(GameObject go)
        {
            EntitasLink el = go.GetComponent <EntitasLink>();

            if (el != null)
            {
                ClearSelection();
                GameEntity toSelect = _game.GetEntityWithID(el.id);
                if (toSelect.isSelectable)
                {
                    toSelect.isSelected = true;
                }
            }
            else
            {
                Debug.LogError("Object was passed from the UI Selection Panel that was not a selectable Entity: " + go.name);
            }
        }
Beispiel #2
0
    private void TurnGridToEntities(GameContext game, HexGridBehaviour grid)
    {
        for (var c = grid.GetCellEnumerator(); c.MoveNext();)
        {
            HexCellBehaviour cell = c.Current;
            GameEntity       ge   = game.CreateEntity();

            Vector3    world = cell.transform.position;
            Vector3    cube  = cell.cubeCoordinates;
            Quaternion rot   = cell.transform.rotation;
            ge.AddHexCell(world.x, world.y, world.z, cube.x, cube.y, cube.z);
            ge.AddGameObject(cell.gameObject);
            ge.AddWorldCoordinates(world.x, world.y, world.z, rot.x, rot.y, rot.z, rot.w);

            //now that the entity has been created with a unique ID,
            //put this ID on the unity GameObject for easy reference:
            EntitasLink el = cell.gameObject.AddComponent <EntitasLink>();
            el.id = ge.iD.value;
        }
    }
Beispiel #3
0
    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);
    }
Beispiel #4
0
        void IExecuteSystem.Execute()
        {
            //ignore interaction with UI:
            if (UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject())
            {
                return;
            }

            InputEntity m = _input.CreateEntity();

            //always add screen coordinates:
            m.AddScreenCoordinates((int)UnityEngine.Input.mousePosition.x, (int)UnityEngine.Input.mousePosition.y);
            //always add time this was created:
            m.AddTimeLine(Time.time);

            //did we click, or just hover?
            //@TODO: do I still need the "hover" component?
            m.isMouseHover = true; //default is hover; this will be set to false in any other case

            if (UnityEngine.Input.GetMouseButtonDown(0))
            {
                RemoveAll(_leftClicks); //previous left click is no longer valid
                m.isMouseLeftDown = true;
                m.isMouseHover    = false;
            }
            else if (UnityEngine.Input.GetMouseButtonUp(0))
            {
                m.isMouseLeftReleased = true;
                m.isMouseHover        = false;
            }
            else if (_leftClicks.count > 0 && !UnityEngine.Input.GetMouseButton(0))
            {
                //we seem to have missed the button "up" event; happens e.g. during debug
                RemoveAll(_leftClicks);
            }

            if (UnityEngine.Input.GetMouseButtonDown(1))
            {
                RemoveAll(_rightClicks); //previous right click is no longer valid
                m.isMouseRightDown = true;
                m.isMouseHover     = false;
            }
            else if (UnityEngine.Input.GetMouseButtonUp(1))
            {
                m.isMouseRightReleased = true;
                m.isMouseHover         = false;
            }
            else if (_rightClicks.count > 0 && !UnityEngine.Input.GetMouseButton(1))
            {
                //we seem to have missed the button "up" event; happens e.g. during debug
                RemoveAll(_rightClicks);
            }


            //now find out what the mouse is pointing at:
            Ray        ray = Camera.main.ScreenPointToRay(UnityEngine.Input.mousePosition);
            RaycastHit hitinfo;

            if (Physics.Raycast(ray, out hitinfo))
            {
                //any gameobject also in entitas should have a component "EntitasLink" in its hierarchy:
                EntitasLink el = hitinfo.collider.gameObject.GetComponentInParent <EntitasLink>();

                if (el != null)
                {
                    m.AddMouseOverEntity(el.id);
                }
                else
                {
                    Debug.LogError("Object with a collider does not have an Entitas link component: " + hitinfo.collider.name);
                }
            }
        }