Unity 3D 순환 스크롤 효과 구현
그리고 SetDepthAndPosition 이라는 방법 을 통 해 그림 의 공간 적 전 개 를 실현 합 니 다.
Z 축 과 Y 축 은 계수 가 같다.
위 에 설치 하 자 공간 이 벌 어 졌 다.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class SelectRole : MonoBehaviour {
public GameObject rolesObj;
private int _half = 0;//
private int _movX = 150;//X
private int _movY = 50;//Y
private int _movZ = 60;//Z
private int count = 3;//
private List<RoleItem> _roleList = new List<RoleItem>();
// Use this for initialization
void Start () {
//
Object[] textureList = (Object[])Resources.LoadAll("Pictures");
int maxDepth = textureList.Length % 2 == 1 ? textureList.Length / 2 + 1 : textureList.Length / 2;//
_half = maxDepth;
for (int i = 0; i < textureList.Length; i++)
{
//
GameObject role = Instantiate(Resources.Load("Role", typeof(GameObject))) as GameObject;
role.transform.parent = rolesObj.transform;
role.transform.localScale = Vector3.one;
EventDelegate.Add(role.GetComponent<UIToggle>().onChange , RoleToggleChange);
RoleItem item = role.GetComponent<RoleItem>();
item.texture.mainTexture = textureList[i] as Texture;
//
role.name = maxDepth.ToString();
if (i > 0)
{
// ,
if (i % 2 == 1)
{
maxDepth--;
role.name = maxDepth.ToString();
}
// ,
else
{
role.name = "-" + maxDepth.ToString();
}
}
SetDepthAndPosition(item,0,0);
_roleList.Add(item);
}
}
private void SetDepthAndPosition(RoleItem role,int dir,int index)
{
int indexDepth = 0;
// ,
if (dir != 0)
{
if (index*dir > _half )
indexDepth = -dir * (_half - 1);
else
indexDepth = index > -1 && index < 1 ? dir : index;
role.name = indexDepth.ToString();
}
else
{
indexDepth = int.Parse(role.name);
}
TweenPosition tp = role.GetComponent<TweenPosition>();
int x = indexDepth < 0 ? -(_half + indexDepth) * _movX : (_half - indexDepth) * _movX;
indexDepth = System.Math.Abs(indexDepth);
tp.to = new Vector3(x, (_half - indexDepth) * _movY, (_half - indexDepth) * _movZ);
role.bg.depth = count * indexDepth;
role.active.depth = 1 + count * indexDepth;
role.texture.depth = 2 + count * indexDepth;
role.GetComponent<UIToggle>().value = indexDepth == _half ? true:false;
tp.PlayForward();
}
/// <summary>
///
/// </summary>
public void LeftClick()
{
//
foreach (RoleItem role in _roleList)
{
int index = int.Parse(role.name);
print(index);
SetDepthAndPosition(role,1,++index);
}
}
/// <summary>
///
/// </summary>
public void RightClick()
{
//
foreach (RoleItem role in _roleList)
{
int index = int.Parse(role.name);
SetDepthAndPosition(role,-1,--index);
}
}
/// <summary>
///
/// </summary>
public void RoleToggleChange()
{
if(UIToggle.current.value)
{
int index = int.Parse(UIToggle.current.name);
int moveCount = _half - System.Math.Abs(index);//
for (int i = 0; i < moveCount;i++ )
{
if (index > 0)
LeftClick();
else
RightClick();
}
}
}
}
이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
photonnetwork.instantiate에서 gamepobject 유형을 생성 한 다음 상태 및 값을 참조하는 방법주로 마지막 기사에서 일어난 일의 수정입니다. 지난번↓ 그럼 주제입니다. (타이틀이 정리되어 없어서 죄송합니다) 우선 전회의 Illegal view ID:0입니다만 photonnetwork.instantiate를 사...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.