기존 시퀀스 컨트롤러를 업데이트 했습니다.
이전 글 :
http://ychans.tistory.com/entry/Unity-시퀀스-컨트롤
activeLevel 이라는 변수를 추가 했으며, 이는 다량의 시퀀스를 가지고서 테스트 할시 유용하게 사용 할수 있습니다.
매번 화면상에 play 할때 마다 엄청난 수의 시퀀스를 메모리에 올리는 작업은 시간적 부하가 걸릴수 밖에 없습니다.
그래서 activeLevel을 조정 하여 시퀀스 컨트롤을 적용한 플랜에 단일 시퀀스만 로딩 할수 있게 하거나 엡데이트시에 텍스쳐를 교체 하지 않는 등의 변화를 줄수 있습니다. 또한 Select single Frame Number를 조정하여 원하는 위치의 시퀀스를 장면으로 고정 시킬수 있습니다.
추가된 핵심 변수 입니다.
public int activeLevel = 0;// 0 : 모두 실행, 1 : 단일 이미지, 2 : 아무것도 실행 안함
public int selectSingleFrameNumber = 0; // activeLevel 1 일때 활성화
using UnityEngine;
using System.Collections;
// /////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Developed by ychans in 03 2012
// e-mail: ychans37@gmail.com
//
// Updated
// 1.0 initial
// 1.1 activeLevel, selectSingleFrameNumber 추가
//
// /////////////////////////////////////////////////////////////////////////////////////////////////////////
public class SequenceController : MonoBehaviour
{
public int totalFrame = 476; // 불러올 시퀀스의 수
public string sourceName = "Diver_";
public string sourcePath = "Assets/_assets/Texture/animationSeqence/";
public int zeroLength = 5; // 시퀀스에 넘버링을 제어 하기 위한 변수
public int frameBufferValue = 1; // 프레임 버퍼 용량
public bool direction = true; // 시퀀스 움직임 방향
public int activeLevel = 0;// 0 : 모두 실행, 1 : 단일 이미지, 2 : 아무것도 실행 안함
public int selectSingleFrameNumber = 0;
private int frameBuffer = 0; // 프레임 버퍼
private int curFrame = 0; // 현재 프레임
private Texture2D[] textureArr = null;
void awake () {
}
// Use this for initialization
void Start () {
int i = 0;
if (activeLevel != 0)
{
totalFrame = selectSingleFrameNumber+1;
i = selectSingleFrameNumber;
}
else
{
i = 0;
}
textureArr = new Texture2D[totalFrame];
int zeroNum = 0;
string fileName = "";
string zeroString = "";
for (i = i; i < totalFrame; i++)
{
zeroNum = zeroLength - i.ToString().Length;
if (zeroString.Length == zeroNum)
{
//pass
}
else
{
zeroString = "";
for (int j = 0; j < zeroNum; j++)
{
zeroString += "0";
}
}
if (activeLevel == 1)
{
fileName = sourcePath + sourceName + zeroString + selectSingleFrameNumber.ToString() + ".png";
}
else
fileName = sourcePath + sourceName + zeroString + i.ToString() + ".png";
textureArr[i] = Resources.LoadAssetAtPath(fileName, typeof(Texture2D)) as Texture2D;
}
if(activeLevel == 1)
renderer.material.SetTexture("_MainTex", textureArr[selectSingleFrameNumber]);
}
// Update is called once per frame
void Update () {
if (activeLevel != 0)
{
print("haha");
return;
}
if (frameBuffer == 0)
{
renderer.material.SetTexture("_MainTex", textureArr[curFrame]);
}
if (curFrame == totalFrame-1)
{
curFrame = 0;
}
else
{
//frame++;
if (frameBuffer == frameBufferValue)
{
frameBuffer = 0;
curFrame++;
}
else
{
frameBuffer++;
}
}
}
}