Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

게임 프로그래밍

Project_SHJ 시작 본문

프로그래밍/게임제작

Project_SHJ 시작

Junwe 2019. 12. 16. 16:38

누가 볼지 모르겠지만 앞으로 게임 제작을 하면서 간단하게 글을 올릴 생각이다.

누군가에게 보여주기 위한 목적까지는 아니고 그냥 자기만족.

 

그러므로 Prjoect_SHJ 라는 프로젝트를 시작해볼려고 한다.

 

거창한거는 없고 진짜 간단하게 만든 기획서 몇장이다.

사실 내가 만드는거이기 때문에 기획서를 자세하게 쓰지는 않았다.

1인 개발이어도 자세하게 쓰는게 좋을 수도 있긴 하지만.. 아직 기획능력은 부족한것 같다.

이번 프로젝트를 만들면서 기획능력도 키울수 있도록 해야지

 

정말 간단하게 만들어본 이동 기능.

나는 그래픽을 못하기 때문에 일단 기본 예제들로 만드는중... 그림도 잘 그리고 싶다.

더보기
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using UnityEngine.Events;
public class JoyStick : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
{
    [SerializeField]
    Image _jokyStickBg;
    [SerializeField]
    Image _jokyStick;

    Vector3 _dragStartPos;

    private List<UnityAction<Vector3>> _moveEventAction = new List<UnityAction<Vector3>>();
    private List<UnityAction> _UpEventAction = new List<UnityAction>();

    private bool _isDraging = false;
    
    Vector3 _distance = Vector3.zero;

    // Update is called once per frame
    void Update()
    {
        if(_isDraging)
        {
            Draging();
        }
    }

    private void Draging()
    {
        _distance = Input.mousePosition - _dragStartPos;
        Vector2 size = _jokyStickBg.rectTransform.sizeDelta;
        _distance = new Vector2(Mathf.Clamp(_distance.x, -size.x / 2f, size.x / 2f), Mathf.Clamp(_distance.y, -size.y / 2f, size.y / 2f));
        _jokyStick.transform.localPosition = _distance;
        foreach(var action in _moveEventAction)
        {
            action(_distance);
        }
    }

    public void SetMoveEvent(UnityAction<Vector3> action)
    {
        _moveEventAction.Add(action);
    }

    public void SetUpEvent(UnityAction action)
    {
        _UpEventAction.Add(action);
    }
    public void OnBeginDrag(PointerEventData eventData)
    {
        _dragStartPos = Input.mousePosition;
    }

    public void OnDrag(PointerEventData eventData)
    {
        if(_moveEventAction == null) 
        {
            Debug.LogError(gameObject.name + " : _moveEventAction is null"); 
            return;
        }
        _isDraging = true;
    }

    public void OnEndDrag(PointerEventData eventData)
    {
        _isDraging = false;
        StartCoroutine(Tween.Instance.Move(_jokyStick.rectTransform, _jokyStick.rectTransform.localPosition, Vector3.zero, 0.1f, 0f, AnimationCurve.EaseInOut(0, 0, 1f, 1f)));
        foreach(var action in _UpEventAction)
        {
            action();
        }
    }
}

 정말 간단하게 만든 JokStick 클래스.

 

Comments