the script loads three images from resources and assigns it a iguiimge and tested and works well for purpose to reproduce a sequence but I want to know if anyone knows a better way or some improvement.
using System.Collections.Generic;
using UnityEngine;
using System.Collections;
public class AnimationSequenceLoader : MonoBehaviour
{
public iGUI.iGUIImage Projection;
public Texture2D[] images = new Texture2D[3];
public int max = 100;
public string path = "Animations/1/sequence01_";
void Start ()
{
StartCoroutine(PlaySequence(path));
}
private IEnumerator PlaySequence(string fullpath)
{
//assets are unloaded before starting the cycle
Resources.UnloadUnusedAssets();
for (int i = 0, e = 0,unload=0; i <= max; unload++)
{
//assigned only when the three previous images and were used
if (e == 0)
{
//unload assets
Resources.UnloadAsset(images[0]);
Resources.UnloadAsset(images[1]);
Resources.UnloadAsset(images[2]);
//increment index and assign first image
i++;
images[0] =
Resources.Load(
string.Format("{0}{1}",fullpath, i)) as
Texture2D;
//increment index and assign second image
i++;
images[1] =
Resources.Load(
string.Format("{0}{1}", fullpath, i)) as
Texture2D;
//increment index and assign three image
i++;
images[2] =
Resources.Load(
string.Format("{0}{1}", fullpath, i)) as
Texture2D;
}
yield return new WaitForSeconds(0.08f);
if(images[e]!=null)
Projection.image = images[e];
//increment index of image display
e++;
//if index is equal 3 resets to 0
if (e == 3)
{
e = 0;
}
//this is for a loop sequence
//reset index to load image
if (i > (max-1))
{
i = 0;
}
}
}
}
be grateful for any comments they may make the script ![]()