Example #1
0
    void LateUpdate()
    {
        //Rotate
        PlayerControls controls = PlayerControls.Get();
        Vector3        rot      = controls.GetRotateCam();

        if (rot.magnitude > 0.01)
        {
            rotated_offset = Quaternion.Euler(0, rotate_speed * -rot.x * Time.deltaTime, 0) * rotated_offset;
            transform.RotateAround(follow_target.transform.position, Vector3.up, rotate_speed * -rot.x * Time.deltaTime);
        }

        //Zoom
        PlayerControlsMouse mouse = PlayerControlsMouse.Get();

        current_zoom  += mouse.GetMouseScroll() * zoom_speed;
        current_zoom   = Mathf.Clamp(current_zoom, -zoom_out_max, zoom_in_max);
        current_offset = rotated_offset - rotated_offset * current_zoom;

        Vector3 target_pos = follow_target.transform.position + current_offset;

        transform.position = Vector3.SmoothDamp(transform.position, target_pos, ref current_vel, 1f / move_speed);
        Quaternion targ_rot = Quaternion.LookRotation(-current_offset, Vector3.up);

        transform.rotation = Quaternion.Slerp(transform.rotation, targ_rot, 10f * rotate_speed * Time.deltaTime);

        //Shake FX
        if (shake_timer > 0f)
        {
            shake_timer        -= Time.deltaTime;
            shake_vector        = new Vector3(Mathf.Cos(shake_timer * Mathf.PI * 8f) * 0.02f, Mathf.Sin(shake_timer * Mathf.PI * 7f) * 0.02f, 0f);
            transform.position += shake_vector * shake_intensity;
        }
    }
Example #2
0
    private void OnClickSlot(int slot, CraftData item)
    {
        PlayerControlsMouse controls = PlayerControlsMouse.Get();

        ItemSlot islot = InventoryBar.Get().GetSelectedSlot();
        ItemSlot eslot = GetSlot(slot);

        selected_right_slot = -1;

        //Merge items
        if (eslot != null && islot != null)
        {
            ItemSlot slot1   = eslot;
            ItemSlot slot2   = islot;
            ItemData item1   = slot1.GetItem();
            ItemData item2   = slot2.GetItem();
            MAction  action1 = item1 != null?item1.FindMergeAction(item2) : null;

            MAction action2 = item2 != null?item2.FindMergeAction(item1) : null;

            if (action1 != null && action1.CanDoAction(PlayerCharacter.Get(), slot2))
            {
                action1.DoAction(PlayerCharacter.Get(), slot1, slot2);
                TheUI.Get().CancelSelection();
                return;
            }

            else if (action2 != null && action2.CanDoAction(PlayerCharacter.Get(), slot1))
            {
                action2.DoAction(PlayerCharacter.Get(), slot2, slot1);
                TheUI.Get().CancelSelection();
                return;
            }
        }

        if (islot != null)
        {
            ItemData idata = islot.GetItem();
            if (idata != null && idata.type == ItemType.Equipment)
            {
                PlayerData.Get().EquipItemTo(islot.slot_index, ItemData.GetEquipIndex(idata.equip_slot));
                TheUI.Get().CancelSelection();
            }
        }
        else if (item != null && slot != selected_slot)
        {
            TheUI.Get().CancelSelection();
            selected_slot = slot;
        }
        else
        {
            CancelSelection();
        }

        if (onClickSlot != null && eslot != null)
        {
            onClickSlot.Invoke(eslot);
        }
    }
Example #3
0
    private void OnClickFloor(Vector3 pos)
    {
        MoveTo(pos);

        auto_move_drop       = PlayerControlsMouse.Get().GetInventorySelectedSlotIndex();
        auto_move_drop_equip = PlayerControlsMouse.Get().GetEquippedSelectedSlotIndex();
        clicked_build        = (current_construction != null);
    }
Example #4
0
    private void Start()
    {
        if (!TheGame.IsMobile() && ItemSelectedFX.Get() == null)
        {
            Instantiate(GameData.Get().item_select_fx, transform.position, Quaternion.identity);
        }

        PlayerControlsMouse.Get().onRightClick += (Vector3) => { CancelSelection(); };
    }
Example #5
0
    void Update()
    {
        if (outline != null)
        {
            if (is_hovered != outline.activeSelf)
            {
                outline.SetActive(is_hovered);
            }
        }

        last_pos   = transform.position;
        is_hovered = PlayerControlsMouse.Get().IsInRaycast(gameObject);
    }
Example #6
0
    void Update()
    {
        PlayerControlsMouse controls = PlayerControlsMouse.Get();

        float target_alpha = controls.IsJoystickActive() ? 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;
    }
Example #7
0
 void Update()
 {
     if (building_mode)
     {
         PlayerControlsMouse mouse = PlayerControlsMouse.Get();
         if (mouse.IsUsingMouse())
         {
             transform.position = mouse.GetPointingPos();
         }
         is_overlap = overlap_list.Count > 0;
         Color color = is_overlap ? Color.red : Color.white;
         SetModelColor(new Color(color.r, color.g, color.b, 0.5f));
         //Debug.Log(is_overlap);
     }
 }
Example #8
0
    private void Start()
    {
        PlayerControlsMouse mouse_controls = PlayerControlsMouse.Get();

        mouse_controls.onClickFloor  += OnClickFloor;
        mouse_controls.onClickObject += OnClickObject;
        mouse_controls.onClick       += OnClick;
        mouse_controls.onRightClick  += OnRightClick;

        //Init attributes
        foreach (AttributeData attr in attributes)
        {
            if (!PlayerData.Get().HasAttribute(attr.type))
            {
                PlayerData.Get().SetAttributeValue(attr.type, attr.start_value);
            }
        }
    }
Example #9
0
    void Update()
    {
        transform.position = PlayerControlsMouse.Get().GetPointingPos();
        transform.rotation = Quaternion.LookRotation(TheCamera.Get().transform.forward, Vector3.up);

        ItemSlot   islot   = InventoryBar.Get().GetSelectedSlot();
        ItemSlot   eslot   = EquipBar.Get().GetSelectedSlot();
        ItemSlot   slot    = eslot != null ? eslot : islot;
        Selectable select  = Selectable.GetNearestHover(transform.position);
        MAction    maction = slot != null && slot.GetItem() != null?slot.GetItem().FindMergeAction(select) : null;

        title.enabled = maction != null;
        title.text    = maction != null ? maction.title : "";

        if ((slot != null) != icon_group.activeSelf)
        {
            icon_group.SetActive(slot != null);
        }

        if (slot != null && slot.GetItem())
        {
            icon.sprite = slot.GetItem().icon;
        }
    }
Example #10
0
 private void Start()
 {
     PlayerControlsMouse.Get().onClick      += (Vector3) => { CancelSubSelection(); };
     PlayerControlsMouse.Get().onRightClick += (Vector3) => { CancelSelection(); };
 }
Example #11
0
 private void Start()
 {
     //PlayerControlsMouse.Get().onClick += OnMouseClick;
     PlayerControlsMouse.Get().onRightClick += OnMouseClick;
 }
Example #12
0
    void FixedUpdate()//프레임과 상관없이 일정 시간의 지나면 실행됨 update보다 자주 실행됨, 물리적 구현 사용
    {
        if (TheGame.Get().IsPaused())
        {
            rigid.velocity = Vector3.zero;
            return;
        }

        if (is_dead)
        {
            return;
        }


        //죽지 않으면 실행되는 구현
        PlayerControls      controls  = PlayerControls.Get();
        PlayerControlsMouse mcontrols = PlayerControlsMouse.Get();
        Vector3             tmove     = Vector3.zero;

        //Navmesh
        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++;
            }
        }

        //Moving
        auto_move_timer += Time.fixedDeltaTime;
        if (auto_move && auto_move_timer > 0.02f)
        {
            if (!use_navmesh || !calculating_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(move_speed * move_speed_mult, move_dir.magnitude * 10f);
                tmove = move_dir.normalized * move_dist;
            }
        }
        else
        {
            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 * move_speed * move_speed_mult;
        }

        if (is_action)
        {
            tmove = Vector3.zero;
        }

        DetectGrounded();

        //Falling
        if (!is_grounded)
        {
            tmove += Vector3.down * fall_speed;
        }

        //Do move
        move           = Vector3.Lerp(move, tmove, move_accel * Time.fixedDeltaTime);
        rigid.velocity = move;

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

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

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

        //Fronted
        DetectFronted();

        //Traveled calcul
        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)
        {
            StopMove();
        }

        if (controls.IsMoving() || mcontrols.IsJoystickActive())
        {
            StopAction();
        }
    }