블로그 이미지
Every unexpected event is a path to learning for you.

카테고리

분류 전체보기 (2731)
Unity3D (814)
Programming (474)
Server (33)
Unreal (4)
Gamebryo (56)
Tip & Tech (228)
협업 (57)
3DS Max (3)
Game (12)
Utility (136)
Etc (96)
Link (32)
Portfolio (19)
Subject (90)
iOS,OSX (51)
Android (14)
Linux (5)
잉여 프로젝트 (2)
게임이야기 (3)
Memories (20)
Interest (38)
Thinking (38)
한글 (30)
PaperCraft (5)
Animation (408)
Wallpaper (2)
재테크 (18)
Exercise (3)
나만의 맛집 (3)
냥이 (10)
육아 (16)
Total
Today
Yesterday
03-29 00:00

링크 : http://hompy.info/664



CoverFlowScroll.unitypackage



요즘 제작중인 RPG 게임 GUI 에서 영웅 생성을 위해 캐릭터를 선택하는 UI 를 커버플로우(Cover Flow)로 구성하게 되어 NGUI 를 조금 응용해서 심플하게 구성해봤습니다. 아래 동영상과 유니티 데모를 보시면 대략 어떤 것인지 아실 수 있을 것이며 혹시나 구현 방법에 대해 관심 있는 분들은 첨부 파일을 받아서 패키지 임포트로 유니티에서 가져가 내용을 살펴 보시면 되겠습니다. NGUI 외에도 트위닝 모션을 위해 HOTween 플러그인을 사용하는 코드가 있으나 수정해서 쓰셔도 되겠습니다. 그리고 데모에 보이는 캐릭터 디자인 소스는 에셋 스토어에서 구입한 것이네요. NGUI 플러그인에 이런 기능도 포함되면 좋을 것 같은데 안된다면 아쉽지만 저처럼 이렇게 구현해야 되겠지요.^^ 여러분은 지금 어떤 기능들을 추가해보고 있나요?

[유니티 데모 링크] http://www.hompydesign.com/tmp/coverflow/

[패키지 첨부파일]  CoverFlowScroll.unitypackage

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Holoville.HOTween;
using Holoville.HOTween.Plugins;

public class HeroTable : MonoBehaviour {
   UISprite[] heros;

   Transform mTrans;
   bool mIsDragging = false;
   Vector3 mPosition, mLocalPosition;
   Vector3 mDragStartPosition;
   Vector3 mDragPosition;
   Vector3 mStartPosition;
   
   public float cellWidth = 160f;
   public float downScale = 0.4f;
   public int cellTotal = 6;
   public int seq = 3;
   
   public UILabel titleLabel;
   
   // Use this for initialization
   void Start () {
       StartCoroutine( DelayStart(1f) );
   }
   void Awake(){
       mTrans = transform;
       mPosition = mTrans.position;
       mLocalPosition = mTrans.localPosition;
   }
   
   IEnumerator DelayStart(float delayTime) {
       yield return new WaitForSeconds(delayTime);
       heros = gameObject.GetComponentsInChildren<UISprite>();
       SetPosition(false);
   }
   
   void SetSequence(bool isRight){
       Vector3 dist = mLocalPosition - mTrans.localPosition;
       float distX = Mathf.Round(dist.x/cellWidth);
       seq = (int)distX;
       if (seq >= cellTotal) seq = cellTotal - 1;
       if (seq <= 0) seq = 0;
   }
   
   void SetPosition(bool isMotion){
       Vector3 pos = mLocalPosition;
       pos -= new Vector3(seq * cellWidth, 0f0f);
       if (isMotion) {
           TweenParms parms = new TweenParms();
           parms.Prop("localPosition", pos);
           parms.Ease(EaseType.Linear);
           HOTween.To(mTrans, 0.1f, parms);
           HOTween.Play();
       else {
           mTrans.localPosition = pos;
       }
       titleLabel.text = heros[seq].spriteName;
   }

   void Drop () {
       Vector3 dist = mDragPosition - mDragStartPosition;
       if (dist.x>0f) SetSequence(true);
       else SetSequence(false);
       SetPosition(true);
   }

   void OnDrag (Vector2 delta) {
       Ray ray = UICamera.currentCamera.ScreenPointToRay(UICamera.lastTouchPosition);
       float dist = 0f;
       Vector3 currentPos = ray.GetPoint(dist);

       if (UICamera.currentTouchID == -|| UICamera.currentTouchID == 0) {
           if (!mIsDragging) {
               mIsDragging = true;
               mDragPosition = currentPos;
           else {
               Vector3 pos = mStartPosition - (mDragStartPosition - currentPos);
               Vector3 cpos = new Vector3(pos.x, mTrans.position.y, mTrans.position.z);
               mTrans.position = cpos;
           }
       }
   }

   void OnPress (bool isPressed) {
       mIsDragging = false;
       Collider col = collider;
       if (col != null) {
           Ray ray = UICamera.currentCamera.ScreenPointToRay(UICamera.lastTouchPosition);
           float dist = 0f;
           mDragStartPosition = ray.GetPoint(dist);
           mStartPosition = mTrans.position;
           col.enabled = !isPressed;
       }
       if (!isPressed) Drop();
   }
}

using UnityEngine;
using System.Collections;

public class HeroItem : MonoBehaviour {
   Transform mTrans, mParent;
   Vector3 scale;
   float cellWidth;
   float downScale;
   HeroTable hTable;

   void Start () {
       mTrans = transform;
       scale = mTrans.localScale;
       mParent = mTrans.parent;
       hTable = mParent.GetComponent<HeroTable>();
       cellWidth = hTable.cellWidth;
       downScale = hTable.downScale;
   }
   
   void Update () {
       Vector3 pos = mTrans.localPosition + mParent.localPosition;
       float dist = Mathf.Clamp(Mathf.Abs(pos.x), 0f, cellWidth);
       mTrans.localScale = ((cellWidth - dist*downScale) / cellWidth) * scale;
   }
}

반응형
Posted by blueasa
, |