protected override void Start()
        {
            base.Start();

            //PlayerControlsMouse.Get().onClick += OnMouseClick;
            PlayerControlsMouse.Get().onRightClick += OnMouseClick;

            onClickSlot   += OnClick;
            onPressAccept += OnAccept;
            onPressCancel += OnCancel;
            onPressUse    += OnCancel;
        }
        void Update()
        {
            if (outline != null)
            {
                if (is_hovered != outline.activeSelf)
                {
                    outline.SetActive(is_hovered);
                }
            }

            is_hovered = PlayerControlsMouse.Get().IsInRaycast(this);
        }
示例#3
0
        protected override void Start()
        {
            base.Start();

            PlayerControlsMouse.Get().onClick      += (Vector3) => { CancelSubSelection(); };
            PlayerControlsMouse.Get().onRightClick += (Vector3) => { CancelSelection(); };

            onClickSlot   += OnClick;
            onPressAccept += OnAccept;
            onPressCancel += OnCancel;

            RefreshCategories();
        }
        void Update()
        {
            PlayerControlsMouse controls = PlayerControlsMouse.Get();

            float target_alpha = controls.IsJoystickActive() && !PlayerUI.GetFirst().IsBuildMode() ? 1f : 0f;

            canvas.alpha = Mathf.MoveTowards(canvas.alpha, target_alpha, 4f * Time.deltaTime);

            Vector2 screenPos = controls.GetJoystickPos();

            rect.anchoredPosition = TheUI.Get().ScreenPointToCanvasPos(screenPos);
            pin.anchoredPosition  = controls.GetJoystickDir() * 50f;
        }
        protected override void Start()
        {
            base.Start();

            PlayerControlsMouse.Get().onRightClick += (Vector3) => { CancelSelection(); };

            onClickSlot      += OnClick;
            onRightClickSlot += OnClickRight;
            onPressAccept    += OnClick;
            onPressUse       += OnClickRight;
            onPressCancel    += OnCancel;

            InitPanel();
        }
示例#6
0
        void RefreshTooltip()
        {
            if (target != null)
            {
                rect.anchoredPosition = TheUI.Get().ScreenPointToCanvasPos(Input.mousePosition);
                //transform.position = PlayerControlsMouse.Get().GetPointingPos();
                //transform.rotation = Quaternion.LookRotation(TheCamera.Get().transform.forward, Vector3.up);

                PlayerControlsMouse mouse = PlayerControlsMouse.Get();
                if (!target.IsHovered() || mouse.IsMovingMouse())
                {
                    Hide();
                }
            }
        }
        protected override void Start()
        {
            base.Start();

            PlayerCharacter ui_player = GetPlayer();

            if (ui_player != null)
            {
                ui_player.Combat.onDamaged += DoDamageFX;
            }

            PlayerControlsMouse mouse = PlayerControlsMouse.Get();

            mouse.onRightClick += (Vector3 pos) => { CancelSelection(); };
        }
        private void Start()
        {
            PlayerControlsMouse mouse_controls = PlayerControlsMouse.Get();

            mouse_controls.onClickFloor  += OnClickFloor;
            mouse_controls.onClickObject += OnClickObject;
            mouse_controls.onClick       += OnClick;
            mouse_controls.onRightClick  += OnRightClick;
            mouse_controls.onHold        += OnMouseHold;
            mouse_controls.onRelease     += OnMouseRelease;

            if (player_id < 0)
            {
                Debug.LogError("Player ID should be 0 or more: -1 is reserved to indicate neutral (no player)");
            }
        }
示例#9
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;
            }
        }
示例#10
0
        void Update()
        {
            if (building_mode && building_character != null)
            {
                PlayerControls      constrols = PlayerControls.Get(building_character.player_id);
                PlayerControlsMouse mouse     = PlayerControlsMouse.Get();

                if (!position_set)
                {
                    if (constrols.IsGamePad())
                    {
                        //Controller Game Pad building
                        transform.position = building_character.transform.position + building_character.transform.forward * build_distance;
                        transform.rotation = Quaternion.Euler(0f, manual_rotate, 0f) * Quaternion.LookRotation(building_character.GetFacing(), Vector3.up);
                    }
                    else
                    {
                        //Mouse/Touch controls
                        transform.position = mouse.GetPointingPos();
                        transform.rotation = Quaternion.Euler(0f, manual_rotate, 0f) * TheCamera.Get().GetFacingRotation();
                    }

                    //Snap to grid
                    FindAutoPosition();

                    //Show/Hide on mobile
                    if (TheGame.IsMobile())
                    {
                        SetBuildVisible(mouse.IsMouseHold());
                    }
                }

                bool  can_build = CheckIfCanBuild();
                Color color     = can_build ? Color.white : Color.red * 0.9f;
                SetModelColor(new Color(color.r, color.g, color.b, 0.5f), !can_build);
            }

            update_timer += Time.deltaTime;
            if (update_timer > 0.5f)
            {
                update_timer = Random.Range(-0.02f, 0.02f);
                SlowUpdate(); //Optimization
            }
        }
示例#11
0
        void Update()
        {
            if (TheGame.Get().IsPaused())
            {
                return;
            }

            if (IsDead())
            {
                return;
            }

            if (rider != null)
            {
                PlayerControls      controls  = PlayerControls.Get(rider.player_id);
                PlayerControlsMouse mcontrols = PlayerControlsMouse.Get();
                Vector3             tmove     = Vector3.zero;
                Vector3             cam_move  = TheCamera.Get().GetRotation() * controls.GetMove();
                if (mcontrols.IsJoystickActive())
                {
                    Vector2 joystick = mcontrols.GetJoystickDir();
                    cam_move = TheCamera.Get().GetRotation() * new Vector3(joystick.x, 0f, joystick.y);
                }
                tmove = cam_move * ride_speed;
                if (tmove.magnitude > 0.1f)
                {
                    character.DirectMoveToward(tmove);
                }

                //Character stuck
                if (tmove.magnitude < 0.1f && character.IsStuck())
                {
                    character.Stop();
                }
            }

            //Animations
            if (animator.enabled)
            {
                animator.SetBool("Move", IsMoving());
                animator.SetBool("Run", IsMoving());
            }
        }
示例#12
0
 void Update()
 {
     if (TooltipUI.Get() != null)
     {
         PlayerControlsMouse mouse = PlayerControlsMouse.Get();
         if (select.IsHovered() && !mouse.IsMovingMouse(0.25f) && TooltipUI.Get().GetTarget() != this)
         {
             if (type == TooltipTargetType.Custom)
             {
                 TooltipUI.Get().Set(select, title, text, icon);
             }
             else
             {
                 if (construct != null)
                 {
                     TooltipUI.Get().Set(select, construct.data);
                 }
                 else if (plant != null)
                 {
                     TooltipUI.Get().Set(select, plant.data);
                 }
                 else if (item != null)
                 {
                     TooltipUI.Get().Set(select, item.data);
                 }
                 else if (character != null)
                 {
                     TooltipUI.Get().Set(select, character.data);
                 }
                 else
                 {
                     TooltipUI.Get().Set(select, title, text, icon);
                 }
             }
         }
     }
 }
        void FixedUpdate()
        {
            if (TheGame.Get().IsPaused())
            {
                rigid.velocity = Vector3.zero;
                return;
            }

            if (IsDead())
            {
                return;
            }

            PlayerControls      controls  = PlayerControls.Get(player_id);
            PlayerControlsMouse mcontrols = PlayerControlsMouse.Get();
            Vector3             tmove     = Vector3.zero;

            //Update auto move for moving targets
            GameObject auto_move_obj = null;

            if (auto_move_select != null && auto_move_select.type == SelectableType.Interact)
            {
                auto_move_obj = auto_move_select.gameObject;
            }
            if (auto_move_attack != null)
            {
                auto_move_obj = auto_move_attack.gameObject;
            }

            if (auto_move && auto_move_obj != null)
            {
                Vector3 diff = auto_move_obj.transform.position - auto_move_target;
                if (diff.magnitude > 1f)
                {
                    auto_move_target      = auto_move_obj.transform.position;
                    auto_move_target_next = auto_move_obj.transform.position;
                    CalculateNavmesh(); //Recalculate navmesh because target moved
                }
            }

            //Navmesh calculate next path
            if (auto_move && use_navmesh && path_found && path_index < nav_paths.Length)
            {
                auto_move_target_next = nav_paths[path_index];
                Vector3 move_dir_total = auto_move_target_next - transform.position;
                move_dir_total.y = 0f;
                if (move_dir_total.magnitude < 0.2f)
                {
                    path_index++;
                }
            }

            //AUTO Moving (after mouse click)
            auto_move_timer += Time.fixedDeltaTime;
            if (auto_move && auto_move_timer > 0.02f) //auto_move_timer to let the navmesh time to calculate a path
            {
                Vector3 move_dir_total = auto_move_target - transform.position;
                Vector3 move_dir_next  = auto_move_target_next - transform.position;
                Vector3 move_dir       = move_dir_next.normalized * Mathf.Min(move_dir_total.magnitude, 1f);
                move_dir.y = 0f;

                float move_dist = Mathf.Min(GetMoveSpeed(), move_dir.magnitude * 10f);
                tmove = move_dir.normalized * move_dist;
            }
            //Keyboard/gamepad moving
            else if (IsControlsEnabled())
            {
                Vector3 cam_move = TheCamera.Get().GetRotation() * controls.GetMove();
                if (mcontrols.IsJoystickActive() && !character_craft.IsBuildMode())
                {
                    Vector2 joystick = mcontrols.GetJoystickDir();
                    cam_move = TheCamera.Get().GetRotation() * new Vector3(joystick.x, 0f, joystick.y);
                }
                tmove = cam_move * GetMoveSpeed();
            }

            //CancelAction
            if (is_action && can_cancel_action && tmove.magnitude > 0.1f)
            {
                CancelAction();
            }

            //Stop moving if doing action
            if (is_action)
            {
                tmove = Vector3.zero;
            }

            //Check if grounded
            DetectGrounded();

            //Add Falling to the move vector
            if (!is_grounded || IsJumping())
            {
                if (!IsJumping())
                {
                    fall_vect = Vector3.MoveTowards(fall_vect, Vector3.down * fall_speed, fall_gravity * Time.fixedDeltaTime);
                }
                tmove += fall_vect;
            }
            //Add slope angle
            else if (is_grounded)
            {
                tmove = Vector3.ProjectOnPlane(tmove.normalized, ground_normal).normalized *tmove.magnitude;
            }

            //Apply the move calculated previously
            move           = Vector3.Lerp(move, tmove, move_accel * Time.fixedDeltaTime);
            rigid.velocity = move;

            //Calculate Facing
            if (!is_action && IsMoving())
            {
                facing = new Vector3(move.x, 0f, move.z).normalized;
            }

            //Rotate character with right joystick when not in free rotate mode
            bool freerotate = TheCamera.Get().IsFreeRotation();

            if (!is_action && !freerotate && controls.IsGamePad())
            {
                Vector2 look  = controls.GetFreelook();
                Vector3 look3 = TheCamera.Get().GetRotation() * new Vector3(look.x, 0f, look.y);
                if (look3.magnitude > 0.5f)
                {
                    facing = look3.normalized;
                }
            }

            //Apply the facing
            Quaternion targ_rot = Quaternion.LookRotation(facing, Vector3.up);

            rigid.MoveRotation(Quaternion.RotateTowards(rigid.rotation, targ_rot, rotate_speed * Time.fixedDeltaTime));

            //Fronted (need to be done after facing to avoid issues)
            DetectFronted();

            //Check the average traveled movement (allow to check if character is stuck)
            Vector3 last_frame_travel = transform.position - prev_pos;

            move_average = Vector3.MoveTowards(move_average, last_frame_travel, 1f * Time.fixedDeltaTime);
            prev_pos     = transform.position;

            //Stop auto move
            bool stuck_somewhere = move_average.magnitude <0.02f && auto_move_timer> 1f;

            if (stuck_somewhere)
            {
                auto_move = false;
            }

            //Stop the click auto move when moving with keyboard/joystick/gamepad
            if (controls.IsMoving() || mcontrols.IsJoystickActive() || mcontrols.IsDoubleTouch())
            {
                StopAutoMove();
            }
        }
示例#14
0
 void Awake()
 {
     _instance = this;
     last_pos  = Input.mousePosition;
 }