예제 #1
0
        protected virtual void Update()
        {
            if (double_timer < 1f)
            {
                double_timer += Time.deltaTime;
            }

            //Hold
            if (is_holding)
            {
                holding_timer += Time.deltaTime;
                if (holding_timer > 0.5f)
                {
                    can_click  = false;
                    is_holding = false;
                    if (onClickLong != null)
                    {
                        onClickLong.Invoke(this);
                    }
                }
            }

            //Keyboard shortcut
            int key_index = (index + 1);

            if (key_index == 10)
            {
                key_index = 0;
            }
            if (key_index < 10 && Input.GetKeyDown(key_index.ToString()))
            {
                if (onPressKey != null)
                {
                    onPressKey.Invoke(this);
                }
            }

            bool use_mouse = PlayerControlsMouse.Get().IsUsingMouse();

            key_hover = false;
            foreach (KeyControlsUI kcontrols in KeyControlsUI.GetAll())
            {
                bool hover = !use_mouse && kcontrols != null && kcontrols.GetFocusedPanel() == parent &&
                             index >= 0 && kcontrols.GetSelectedIndex() == index;
                key_hover = key_hover || hover;
            }
        }
        private void Update()
        {
            if (TheGame.Get().IsPaused())
            {
                return;
            }

            if (IsDead())
            {
                return;
            }

            //Save position
            Data.position = GetPosition();

            //Controls
            PlayerControls controls = PlayerControls.Get(player_id);

            //Stop sleep
            if (is_action || IsMoving() || sleep_target == null)
            {
                StopSleep();
            }

            //Activate Selectable when near
            Vector3 move_dir = auto_move_target - transform.position;

            if (auto_move && !is_action && auto_move_select != null && move_dir.magnitude < auto_move_select.use_range)
            {
                auto_move = false;
                auto_move_select.Use(this, auto_move_target);
                auto_move_select = null;
            }

            //Finish construction when near clicked spot
            Buildable current_buildable = character_craft.GetCurrentBuildable();

            if (auto_move && !is_action && character_craft.ClickedBuild() && current_buildable != null && move_dir.magnitude < current_buildable.build_distance)
            {
                auto_move = false;
                character_craft.StartCraftBuilding(auto_move_target);
            }

            //Stop move & drop when near clicked spot
            if (auto_move && !is_action && move_dir.magnitude < moving_threshold * 2f)
            {
                auto_move = false;
                character_inventory.DropItem(auto_move_drop_inventory, auto_move_drop);
            }

            //Stop attacking if target cant be attacked anymore (tool broke, or target died...)
            if (!character_combat.CanAttack(auto_move_attack))
            {
                auto_move_attack = null;
            }

            //Ride animal
            if (is_riding)
            {
                if (riding_animal == null || riding_animal.IsDead())
                {
                    StopRide();
                    return;
                }

                transform.position = riding_animal.GetRideRoot();
                transform.rotation = Quaternion.LookRotation(riding_animal.transform.forward, Vector3.up);
            }

            //Controls
            if (IsControlsEnabled() && !is_action)
            {
                //Check if panel is focused
                KeyControlsUI ui_controls = KeyControlsUI.Get(player_id);
                bool          panel_focus = controls.gamepad_controls && ui_controls != null && ui_controls.IsPanelFocus();
                if (!panel_focus)
                {
                    //Press Action button
                    if (controls.IsPressAction())
                    {
                        if (character_craft.CanBuild())
                        {
                            character_craft.StartCraftBuilding();
                        }
                        else if (!panel_focus)
                        {
                            InteractWithNearest();
                        }
                    }

                    //Press attack
                    if (Combat.can_attack && controls.IsPressAttack())
                    {
                        AttackNearest();
                    }

                    //Press jump
                    if (character_jump != null && controls.IsPressJump())
                    {
                        character_jump.Jump();
                    }
                }

                if (controls.IsPressUISelect())
                {
                    if (character_craft.CanBuild())
                    {
                        character_craft.StartCraftBuilding();
                    }
                }
            }

            //Stop riding
            if (is_riding && (controls.IsPressJump() || controls.IsPressAction() || controls.IsPressUICancel()))
            {
                StopRide();
            }
        }