예제 #1
0
    void Start()
    {
        mouseCursorHoverItem = Resources.Load <UnityAtoms.GameObjectVariable> ("Variables/mouseCursorHoverItem");
        isGrabbing           = Resources.Load <UnityAtoms.BoolVariable> ("Variables/isGrabbing");

        mouseRaycaster = GetComponent <MouseRay> ();
    }
예제 #2
0
파일: Grid3D.cs 프로젝트: Paedow/IPOW
        public void Input_PlaceTower(InputEvent @event)
        {
            if (@event is InputEventMouse)
            {
                InputEventMouse mouseEvent = (InputEventMouse)@event;
                var             ray        = new MouseRay(camera, mouseEvent.GlobalPosition);
                Vector3?        pos        = ray.PositionOnPlane(new Plane(new Vector3(0, 0, 0), new Vector3(1, 0, 0), new Vector3(0, 0, 1)));
                if (mouseEvent.ButtonMask == 1 && lastButtonMask == 0)
                {
                    if (GUITools.IsPointOnGUI(world.GetNode(new NodePath("GUI")), mouseEvent.GlobalPosition))
                    {
                        return;
                    }
                    if (pos.HasValue && pos.Value.x > 0 && pos.Value.z > 0)
                    {
                        Vector2 gPos = new Vector2(pos.Value.x, pos.Value.z);
                        gPos.x = (int)(gPos.x);
                        gPos.y = (int)(gPos.y);
                        if (Grid[(int)gPos.x, (int)gPos.y].CanPlaceOn)
                        {
                            Tile tile = (Tile)sceneTower.Instance();
                            SetTile(tile, (int)gPos.x, (int)gPos.y);
                            pathUpdaterGround.Update(GetGrid(MovementLayer.Ground), endPoints);
                        }
                    }
                }

                if (pos.HasValue)
                {
                    Vector3 iPos = new Vector3(
                        ((int)pos.Value.x),
                        ((int)pos.Value.y),
                        ((int)pos.Value.z));
                    glowTile.Translation  = iPos;
                    placeTile.Translation = iPos;
                    if (iPos.x < 0 || iPos.z < 0 || iPos.x >= Width || iPos.z >= Height)
                    {
                        glowTile.Visible = false;
                    }
                    else
                    {
                        glowTile.Visible = true;
                        Tile t = Grid[(int)iPos.x, (int)iPos.z];
                        if (t.CanPlaceOn)
                        {
                            glowTile.Call("blue");
                        }
                        else
                        {
                            glowTile.Call("red");
                        }
                    }
                }

                lastButtonMask = mouseEvent.ButtonMask;
            }
        }
예제 #3
0
파일: Grid3D.cs 프로젝트: Paedow/IPOW
        public void Input_Select(InputEvent _event)
        {
            if (_event is InputEventMouse)
            {
                InputEventMouse mouseEvent = (InputEventMouse)_event;
                if (mouseEvent.ButtonMask == 1 && lastButtonMask == 0)
                {
                    if (GUITools.IsPointOnGUI(world.GetNode(new NodePath("GUI")), mouseEvent.GlobalPosition))
                    {
                        return;
                    }
                    var  ray   = new MouseRay(camera, mouseEvent.GlobalPosition);
                    Tile t     = ray.SendRayTile();
                    Node panel = world.GetNode(new NodePath("GUI/TowerOptions"));
                    while (panel.GetChildCount() > 0)
                    {
                        Node n = panel.GetChild(0);
                        panel.RemoveChild(n);
                        n.Dispose();
                    }
                    if (t != null)
                    {
                        int x = 0;
                        foreach (string cmd in t.GetCommands())
                        {
                            GD.Print(cmd);
                            Button btn = new Button();
                            btn.Text         = cmd;
                            btn.RectPosition = new Vector2(0, x);
                            x += (int)btn.RectSize.y;
                            panel.AddChild(btn);
                            var binds = new Godot.Collections.Array();
                            binds.Add(cmd);
                            btn.Connect("pressed", t, "RunCommand", binds);
                        }
                    }
                }

                lastButtonMask = mouseEvent.ButtonMask;
            }
        }
예제 #4
0
 public void Update()
 {
     if (ks.IsKeyDown(Keys.X) && ms.WasButtonDown(MouseButton.Button1))//X + Left Mouse = Place building
     {
         Order newOrder = new PlaceBuildingOrder(cam, ks, ms);
         newOrder.OrderExecuted += NewOrder_OrderExecuted;
         newOrder.Execute("atreides-barrack");
         historyOrders.Push(newOrder);
     }
     if (ms.WasButtonDown(MouseButton.Button1))
     {
         MouseRay mouseRay    = new MouseRay((int)ms.X, (int)ms.Y);
         var      queryResult = mouseRay.RayCastQuery();
         if (queryResult.Count > 0)
         {
             Order newOrder = new SelectUnitOrder(cam, ks, ms);
             newOrder.OrderExecuted += NewOrder_OrderExecuted;
             newOrder.Execute(queryResult);
             historyOrders.Push(newOrder);
         }
     }
 }