Exemple #1
0
        private void Update()
        {
            if (!Term.IsVisible())
            {
                // Don't do any "gameplay stuff" if the debug console is up

                // Handle inputs
                // Movement
                Vector3 Move = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
                if (Move.sqrMagnitude != 0)
                {
                    Character.Move(Character.transform.TransformDirection(Move));
                }
                else if (Character.Moving())
                {
                    Character.Stop();
                }

                // Rotation (only when cursor is locked
                if (CursorHandler.Locked())
                {
                    Rotation.y += Input.GetAxis("Mouse X") * CursorHandler.GetMouseSensitivityX();
                    Rotation.x  = Mathf.Clamp(Rotation.x - Input.GetAxis("Mouse Y") * CursorHandler.GetMouseSensitivityY(), -89, 89);
                    Character.SetRotation(Rotation);
                }

                // Interactions
                bool       Interacted     = false;
                GameObject LookedAtObject = CameraUtil.GetLookedAtGameObject(Camera, Character.InteractionDistance);
                if (LookedAtObject != null)
                {
                    Interactable LookingAt = LookedAtObject.GetComponent <Interactable>();
                    if (LookingAt != null && (LookingAt.transform.position - Character.GetPosition()).magnitude < Character.InteractionDistance)
                    {
                        if (Input.GetButtonDown("Activate"))
                        {
                            InteractWith(LookingAt, InteractionType.Activate);
                            Interacted = true;
                        }
                        if (Input.GetButtonUp("Activate"))
                        {
                            InteractWith(LookingAt, InteractionType.Deactivate);
                            Interacted = true;
                        }
                        if (LookedAtObject != LastLookedAt)
                        {
                            InteractWith(LookingAt, InteractionType.Enter);
                            if (LastLookedAt != null)
                            {
                                InteractWith(LastLookedAt.GetComponent <Interactable>(), InteractionType.Exit);
                            }
                        }
                        LastLookedAt = LookedAtObject;
                    }
                }
                else if (LastLookedAt != null)
                {
                    InteractWith(LastLookedAt.GetComponent <Interactable>(), InteractionType.Exit);
                    LastLookedAt = null;
                }

                // Equipment actions
                if (!Interacted && !InventoryInterface.IsOpen())
                {
                    // Don't use equipment if you're interacting with something
                    // (ie. don't shoot at the buttons)
                    if (Input.GetButtonDown("Use Item (R)"))
                    {
                        Character.Inventory.UseItemInSlot(EquipSlot.RightHand);
                        Client.Send(PktType.InventoryAction, Character.Inventory.ActionHandler.BuildUseItem(EquipSlot.RightHand));
                    }
                    if (Input.GetButtonDown("Use Item (L)"))
                    {
                        Character.Inventory.UseItemInSlot(EquipSlot.LeftHand);
                        Client.Send(PktType.InventoryAction, Character.Inventory.ActionHandler.BuildUseItem(EquipSlot.LeftHand));
                    }
                }
            }
            else if (Character.Moving())
            {
                // The debug console is open, stop the player.
                Character.Stop();
            }
        }
Exemple #2
0
 /// <summary>
 /// Sets the Singleton.
 /// </summary>
 public CursorHandler()
 {
     Singleton = this;
 }
Exemple #3
0
        private void Update()
        {
            if (Term.IsVisible())
            {
                return;
            }

            if (Input.GetButtonDown("Inventory"))
            {
                InventoryOpen    = !InventoryOpen;
                Hologram.Visible = InventoryOpen;
                CursorHandler.RequestLockState(!InventoryOpen);
            }

            int        CurrentIndex = -1;
            RaycastHit LookedAt     = CameraUtil.GetLookedAtHit(Camera, 1f, true);

            if (LookedAt.collider != null)
            {
                MeshRenderer Mesh = LookedAt.collider.GetComponent <MeshRenderer>();
                if (ItemGridCells.Contains(LookedAt.collider.transform))
                {
                    // Interacting with the item list
                    CurrentIndex = int.Parse(LookedAt.collider.name.Split(' ')[1]);
                    if (GrabbedItem == null)
                    {
                        // Nothing is currently being dragged, continue as normal
                        if (Input.GetButton("Activate") &&
                            (Input.GetAxis("Mouse X") != 0 || Input.GetAxis("Mouse Y") != 0) &&
                            ItemGridSelectedIndex == CurrentIndex)
                        {
                            // This item has been selected for at least a frame,
                            // and the mouse is moving, this counts as dragging
                            GrabbedItem      = LookedAt.collider.transform;
                            GrabbedItemIndex = CurrentIndex;
                        }
                        if (Input.GetButtonDown("Activate") || Input.GetButtonDown("Equip"))
                        {
                            // Select things
                            ItemGridSelectedIndex = CurrentIndex;
                        }
                        if (Input.GetButtonDown("Equip"))
                        {
                            // Equip things
                            Item SelectedItem = Inventory.Drive.GetItemAt(ItemGridSelectedIndex);
                            if (SelectedItem != null)
                            {
                                Item Equipped = Inventory.Drive.GetSlot(SelectedItem.Slot);
                                if (Equipped != null && Equipped.ID == SelectedItem.ID)
                                {
                                    Inventory.Drive.UnequipSlot(SelectedItem.Slot);
                                    Client.Send(PktType.InventoryAction, Inventory.ActionHandler.BuildClearSlot(SelectedItem.Slot));
                                }
                                else
                                {
                                    Inventory.Drive.EquipItem(ItemGridSelectedIndex);
                                    Client.Send(PktType.InventoryAction, Inventory.ActionHandler.BuildEquipItem(ItemGridSelectedIndex));
                                }
                            }
                        }
                    }
                    else
                    {
                        // Something is grabbed, make things react to this
                        ItemGridSelectedIndex = CurrentIndex;
                        if (Input.GetButtonUp("Activate"))
                        {
                            // Grab was released, drop item here
                            if (GrabbedItemIndex == CurrentIndex)
                            {
                                // The item was dropped in place, reset the position
                                if (ItemGridCells[GrabbedItemIndex].childCount > 0)
                                {
                                    ItemGridCells[GrabbedItemIndex].GetChild(0).localPosition = new Vector3();
                                }
                            }
                            else
                            {
                                // Lerp things (if the models are set)
                                Vector3 ReturnToPos = ItemGridCells[GrabbedItemIndex].position;
                                ItemGridCells[GrabbedItemIndex].position = ItemGridCells[CurrentIndex].position;
                                Lerper.LerpTransformPosition(ItemGridCells[GrabbedItemIndex], ReturnToPos, 20f);

                                // Switch items
                                Inventory.Drive.SwitchSlots(GrabbedItemIndex, CurrentIndex);
                                Client.Send(PktType.InventoryAction, Inventory.ActionHandler.BuildSlotSwitch(GrabbedItemIndex, CurrentIndex));
                            }

                            // Reset grabbing
                            GrabbedItem      = null;
                            GrabbedItemIndex = -1;
                        }
                        else
                        {
                            if (ItemGridCells[GrabbedItemIndex].childCount > 0)
                            {
                                ItemGridCells[GrabbedItemIndex].GetChild(0).position = LookedAt.point;
                            }
                        }
                    }
                }
                else if (Mesh != null)
                {
                    float  InvBrightness = 1.1f;
                    float  StsBrightness = 1f;
                    float  SclBrightness = 1f;
                    float  MapBrightness = 1f;
                    string SelectedIcon  = "";

                    if (Mesh == IconInventory)
                    {
                        InvBrightness = 1.2f;
                        SelectedIcon  = "Storage";
                    }
                    else if (Mesh == IconStatus)
                    {
                        StsBrightness = 1.2f;
                        SelectedIcon  = "Status";
                    }
                    else if (Mesh == IconSocial)
                    {
                        SclBrightness = 1.2f;
                        SelectedIcon  = "Social";
                    }
                    else if (Mesh == IconMap)
                    {
                        MapBrightness = 1.2f;
                        SelectedIcon  = "Map";
                    }

                    TextTextureProperties Props = IconExplainerText.TextProperties;
                    Props.Text = SelectedIcon;
                    IconExplainerText.SetTextProperties(Props);


                    IconInventory.material.SetColor("_EmissionColor", new Color(IconInventoryColor.r * InvBrightness,
                                                                                IconInventoryColor.g * InvBrightness, IconInventoryColor.b * InvBrightness));
                    IconStatus.material.SetColor("_EmissionColor", new Color(IconStatusColor.r * StsBrightness,
                                                                             IconStatusColor.g * StsBrightness, IconStatusColor.b * StsBrightness));
                    IconSocial.material.SetColor("_EmissionColor", new Color(IconSocialColor.r * SclBrightness,
                                                                             IconSocialColor.g * SclBrightness, IconSocialColor.b * SclBrightness));
                    IconMap.material.SetColor("_EmissionColor", new Color(IconMapColor.r * MapBrightness,
                                                                          IconMapColor.g * MapBrightness, IconMapColor.b * MapBrightness));
                }
            }
            else
            {
                // Outside of the inventory, clicking will unselect
                if (Input.GetButtonDown("Activate"))
                {
                    ItemGridSelectedIndex = -1;
                }
            }
            RebuildItemGrid(CurrentIndex);
        }