Unity2015. 11. 16. 22:50

Unity3D, 2D, Page Curl Effect, Page Flip Effect, UI, Canvas, 페이지 넘김 효과, 페이지 넘기기


page-curl effect with 2d mask tweak.

유니티 UI의 Mask기능을 이용한 간단한 페이지 넘기기 예제입니다. 



소스코드입니다. 의외로 간단하게 구현되버려서 깜짝 놀랐습니다만, 

경계선 테스트등이 빠져있습니다.(일정영역을 벗어나면 오작동을 합니다.)


<CurlEf.cs>

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
32
33
34
35
36
using UnityEngine;
using System.Collections;
 
[ExecuteInEditMode]
public class CurlEf : MonoBehaviour {
 
    public Transform _Front;
    public Transform _Mask;
    public Transform _GradOutter;
    public Vector3 _Pos = new Vector3(-240.0f, -470.0f, 0.0f) * 0.01f;
 
    void LateUpdate()
    {
        transform.position = _Pos;
        transform.eulerAngles = Vector3.zero;
 
        Vector3 pos = _Front.localPosition;
        float theta = Mathf.Atan2(pos.y, pos.x) * 180.0f / Mathf.PI;
 
        if (theta <= 0.0f || theta >= 90.0f) return;
 
        float deg = -(90.0f - theta) * 2.0f;
        _Front.eulerAngles = new Vector3(0.0f, 0.0f, deg);
 
        _Mask.position = (transform.position + _Front.position) * 0.5f;
        _Mask.eulerAngles = new Vector3(0.0f, 0.0f, deg*0.5f);
 
        _GradOutter.position = _Mask.position;
        _GradOutter.eulerAngles = new Vector3(0.0f, 0.0f, deg * 0.5f + 90.0f);
 
        transform.position = _Pos;
        transform.eulerAngles = Vector3.zero;
    }
}
 
 
cs


동작은 Front의 position만 조정하면 됩니다.( For testing, you should control a point of 'Front'.)


DOWNLOAD Unity3D v5.2.2 Project file (프로젝트 파일을 첨부합니다.)

SimplePageCurl.7z



Posted by GNUPart
Dev.2015. 9. 25. 15:22

Sigmoid function


y = tanh(x)




y = 1 / (1 + exp(-x))








Posted by GNUPart
Unity/Notes2015. 9. 2. 22:02

* 터치가 UI오브젝트 위에 있는지 검사

 EventSystem.current.IsPointerOverGameObject()를 사용하면 PC의 마우스 입력으로는 잘 검사되는데, Android에서 실행하니까 false를 내뱉으며 동작하지 않았다.

 => 구글링: http://forum.unity3d.com/threads/ispointerovereventsystemobject-always-returns-false-on-mobile.265372/

> mwk888이란 사람이 포스팅한 코드중 발췌

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 
bool IsPointerOverUIObject()
{
    // Referencing this code for GraphicRaycaster 
    // https://gist.github.com/stramit/ead7ca1f432f3c0f181f
    // the ray cast appears to require only eventData.position.
    PointerEventData eventDataCurrentPosition 
        = new PointerEventData(EventSystem.current);
    eventDataCurrentPosition.position 
        = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
 
    List<RaycastResult> results = new List<RaycastResult>();
    EventSystem.current.RaycastAll(eventDataCurrentPosition, results);
    return results.Count > 0;
}
cs


* Animator CrossFade vs. CrossFadeInFixedTime

 CrossFade는 상태(state)가 천이(transition)하는 도중에는 적용되지 않는다. 상태 천이 도중 강제로 다른 상태로 전환하고자 할 때 CrossFadeInFixedTime을 사용한다. (Unity3D 5.1부터 적용)

  => CrossFade( "state", duration, -1, 0.0f )를 사용해도 된다.


* Serializing Enumeration :  당연하게 숫자로 저장된다!!. 


* GameObject::OnMouseDown 순서: 카메라 거리가 가장 가까운 오브젝트가 검출

  => 2D에서는(ortho-camera) 오브젝트의 z값으로 순서를 정할수 있다.







Posted by GNUPart