레이블이 NGUI인 게시물을 표시합니다. 모든 게시물 표시
레이블이 NGUI인 게시물을 표시합니다. 모든 게시물 표시

2014년 7월 8일 화요일

Everyplay in Unity with NGUI_Everyplay HUD camera사용시.


삽질ing...

Everyplay를 활용하여 작업시
NGUI를 사용하고있는경우
NGUI의 일부분만 지우고싶어서 그부분에 해당하는 Camera에
Everyplay HUD camera설정을 적용시
NGUI모두 record가 안되는 현상이발생.
이럴경우
record할 UI에만 record용으로 camera를 따로 배치해주어야 
record가 제대로 동작하는것을 확인.

NGUI를 사용시 Everyplay를 함께 사용하면 발생하는 문제로 보이며
Unity자체의 UI system을 사용할때는 발생하지 않는것으로 파악됨.


2014년 5월 15일 목요일

Unity_Pannel Fade In&Out With NGUI

Explan.
NGUI이용시
Script상에서 UIPannel 의 alpha scale을 조정하면서
페이드 인,아웃 효과를 주는 스크립트.
Tween Alpha를 활용하여 줄수도 있으나
개인적으로 직접 코딩하여 진행하는것이 더편하기에...
UIPannel뿐만아니라 그외의 컴포넌트라도
Alpha 속성이 구현되어있는 놈이라면
동일하게 이용할수있다.
Timescale값은 원하는값으로 수정하면된다.


FadeInOut.cs

using UnityEngine;
using System.Collections;

public class PannelFadeInOut : MonoBehaviour {

    private UIPanel mPannel;

    private float mFadeTime = 1f;
    private float mWaitTime = 1f;
    private bool on = false;
    void Start()
    {
        mPannel = GetComponent<UIPanel>();
        mPannel.enabled = false;
    }

    public void StartFade()
    {
        if(!on)
            StartCoroutine("fadeCoroutine");
    }

    public void StopFade()
    {
        StopCoroutine("fadeCoroutine");
    }

    IEnumerator fadeCoroutine()
    {
        mPannel.enabled = true;
        float startTime = RealTime.time;
        Time.timeScale = .2f; // slow Time scale
        while(RealTime.time - startTime < mFadeTime) // fade in
        {
            mPannel.alpha = Mathf.Lerp(.1f, .95f, (RealTime.time - startTime) / mFadeTime);
            yield return null;
        }

        startTime = RealTime.time;
        while (RealTime.time - startTime < mWaitTime) // wait
            yield return null;
        
        startTime = RealTime.time;
        while (RealTime.time - startTime < mFadeTime) // fade out
        {
            mPannel.alpha = Mathf.Lerp(.95f, 0, (RealTime.time - startTime) / mFadeTime);
            yield return null;
        }
        Time.timeScale = 1f;
        mPannel.alpha = 0; // default 0
    }
}

2014년 5월 13일 화요일

Unity_NGUI Sprite Auto Depth Script with NGUI

Explanation.
NGUI를 사용하여 게임제작시
자동으로 Depth를 조정해주는 스크립트
depth의 범위를 지정안하고 그냥 
포지션의 y값을 가지고와서 depth로 적용.

Todo.
정해진 depth 범위내에서 적용되도록 변경.

기본

Auto Depth 적용전

Auto Depth 적용후

using UnityEngine;
using System.Collections;

public class AutoDepth : MonoBehaviour {

    private UISprite mSprite;
    private Transform mTransform;
    private int waitFrameCount = 15;
    
 void Start () {
        mSprite = GetComponent();
        mTransform = transform;
        StartCoroutine("depthCoroutine");
 }
 
 IEnumerator depthCoroutine()
    {
        for (int i = 0; i < waitFrameCount ; ++i)
            yield return null;
        mSprite.depth = -(int)mTransform.localPosition.y;
        StartCoroutine("depthCoroutine");
    }

}

Unity_2D Movement(Click to move) with NGUI

Explanation.

NGUI로 게임제작시
UI Root        
└Camera
└Pannel
            └2d Object(Sprite)
의 구조로 게임제작을 진행할때 사용하는 Movement
제목처럼 화면클릭시 목표좌표를 계산(NGUI에 맞게)한뒤
움직이는 방법.(Click to Move)
Movement2D.cs
using UnityEngine;
using System.Collections;

//click to move with NGUI
public class Movement2D : MonoBehaviour {
    private int mUIWidth = 720; // UI Root width size
    private int mUIHeight = 1280; // UI Root height size
    private int mScreenWidth = Screen.width;
    private int mScreenHeight = Screen.height;
    private int mSpeed = 200; // pixel per sec

    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            clickToMove(Input.mousePosition);
        }
    }

    void clickToMove(Vector2 mousePos)
    {
        StopCoroutine("move");
        StartCoroutine("move", calcurateTargetPos(mousePos));
    }
    
    IEnumerator move(Vector2 endPos)
    {
        Vector2 startPos = transform.localPosition;
        float startTime = Time.time;
        float movedTime = Vector2.Distance(startPos, endPos) / mSpeed;
        while (Time.time - startTime < movedTime)
        {
            transform.localPosition = Vector2.Lerp(startPos, endPos, (Time.time - startTime) / movedTime);
            yield return null; // wait frame
        }
        transform.localPosition = endPos; // end Position set
    }

    Vector2 calcurateTargetPos(Vector2 mousePos)
    {
        Vector2 result;

        result.x = Mathf.Lerp(-mUIWidth / 2, mUIWidth / 2, mousePos.x / mScreenWidth);
        result.y = Mathf.Lerp(-mUIHeight / 2, mUIHeight / 2, mousePos.y / mScreenHeight);

        return result;
    }
}