2020년 8월 19일 수요일

[Unity] UI animation (Feat. Platinio Tween ), UI 효과 주기

 무료에셋 중에


Platinio Tween라는 앱이 있는데 상당히 사용하기 쉽고 좋다


간단하게 2가지 사용할만한게 있는데

Platinio.Popup은 Ui에 바로 붙여서 효과를 적용할수있다


간단하게 커스텀한 코드

using UnityEngine;
using Platinio.TweenEngine;
using Platinio.UI;

namespace Platinio
{
    public class Popup : MonoBehaviour
    {
        [SerializeFieldprivate Vector2 startPosition = Vector2.zero;
        [SerializeFieldprivate Vector2 desirePosition = Vector2.zero;
        [SerializeFieldprivate RectTransform canvas = null;      
        [SerializeFieldprivate float time = 0.5f;
        [SerializeFieldprivate Ease enterEase = Ease.EaseInOutExpo;
        [SerializeFieldprivate Ease exitEase = Ease.EaseInOutExpo;

        private bool isVisible    = false;
        private bool isBusy       = false;       
        private RectTransform thisRect = null;

        private void Start()
        {
            thisRect = GetComponent<RectTransform>();   
            
            thisRect.anchoredPosition = thisRect.FromAbsolutePositionToAnchoredPosition(startPosition , canvas);
        }

        public void Show()
        {
            thisRect.MoveUIdesirePositioncanvastime).SetEase(enterEase).SetOnComplete(delegate
            {
                isBusy = false;
                isVisible = true;
            });
            
        }

        ///좌우로 움직이게 만들기위해 커스텀한 코드
        public void MoveSide(Vector2 targetPosition)
        {
            thisRect.MoveUI(targetPositioncanvastime).SetEase(enterEase).SetOnComplete(delegate
            {
                isBusy = false;
                isVisible = true;
            });
        }
        ///좌우로 움직이게 만들기위해 커스텀한 코드

        public void Hide()
        {
            thisRect.MoveUIstartPositioncanvastime).SetEase(exitEase).SetOnComplete(delegate
            {
                isBusy = false;
                isVisible = false;
            });
        }

        public void Toggle()
        {
            if (isBusy)
                return;

            isBusy = true;

            if (isVisible)
                Hide();
            else
                Show();
        }
    }

}




PopUp이 달린 객체들을 왼쪽 오른쪽으로 움직여주는 함수


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//using Platinio.UI;
using Platinio;

public class SceneChange : MonoBehaviour
{

    public Popup[] Popups;
    public Vector2 CenterPos;
    public Vector2 LeftPos;
    public Vector2 RightPos;
    public int currentIdx;
    public int max;
    // Start is called before the first frame update
    void Start()
    {
        max = Popups.Length;
    }

    // Update is called once per frame
    void Update()
    {
        if(Input.GetKeyDown("1"))
        {
            Next();
        }

        if (Input.GetKeyDown("2"))
        {
            Prev();
        }
    }

    public void Next()
    {
        if (currentIdx+1 > max)
            return;

        Popups[currentIdx].MoveSide(LeftPos);
        Popups[++currentIdx].MoveSide(CenterPos);

    }
    public void Prev()
    {
        if (currentIdx - 1 < 0)
            return;

        Popups[currentIdx].MoveSide(RightPos);
        Popups[--currentIdx].MoveSide(CenterPos);
    }
}



댓글 없음:

댓글 쓰기

git rejected error(feat. cherry-pick)

 문제 아무 생각 없이 pull을 받지않고 로컬에서 작업! 커밋, 푸시 진행을 해버렷다. push에선 remote와 다르니 당연히 pull을 진행해라고 하지만 로컬에서 작업한 내용을 백업하지 않고 진행하기에는 부담스럽다(로컬작업 유실 가능성) 해결하려...