protected Frame[] GetFrames() { List <Frame> frames = new List <Frame>(); if (framesets.Length > 0) { int index = 0; for (int f = 0; f < framesets.Length; f++) { OTAnimationFrameset fs = framesets[f]; fs.startIndex = index; index += fs.frameCount; int[] framesetFrames = fs.frameNumbers; foreach (int frameIndex in framesetFrames) { Frame curFrame = new Frame(); curFrame.container = fs.container; curFrame.frameIndex = frameIndex; frames.Add(curFrame); } } } return(frames.ToArray()); }
public void playAnimation(OTAnimationFrameset _anim, float speed = 1f) { if (_animSprite.animationFrameset != _anim.name) { _animSprite.animationFrameset = _anim.name; _animSprite.speed = speed; } }
void InitAnimation() { if (animationFrameset != "") { frameset = animation.GetFrameset(animationFrameset); if (frameset != null) { framesetName = frameset.name.ToLower(); animationFramesetLower = animationFrameset.ToLower(); } frDuration = animation.GetDuration(frameset); frCount = animation.GetFrameCount(frameset); } else { frameset = null; frDuration = animation.duration; frCount = animation.frameCount; } frDurationDelta = frDuration / frCount; frTime = 0; if (frCount == 0) { return; } if (startAtRandomFrame) { time = frDurationDelta * (Mathf.Floor(frCount * Random.value)); } else { if (startFrame != -1) { time = frDurationDelta * startFrame; if (endFrame != -1) { endTime = frDurationDelta * (endFrame + 1) - 0.001f; } } else { time = 0; } } System.Array.Resize <OTAnimation.Frame>(ref frames, frCount); // cache the animation frames for quicker lookup for (int i = 0; i < frCount; i++) { frames[i] = animation.GetFrame(i * frDurationDelta, direction, frameset); } }
/// <summary> /// Get number of frames in this animaation /// </summary> /// <remarks> /// If no <see cref="OTAnimationFrameset" /> is provided the number of frames of the entire animation is returned. If an OTAnimationFrameset is provided /// this method will return the number of frames of that particular frameset. /// </remarks> /// <param name="frameset">Get number of frames of a perticular animation frameset.</param> /// <returns>number of frames</returns> public int GetFrameCount(OTAnimationFrameset frameset) { if (frameset != null) { return(frameset.frameCount); } else { return(frameCount); } }
public float GetDuration(OTAnimationFrameset frameset) { if (frameset != null) { return((frameset.singleDuration != 0) ? frameset.singleDuration : frameset.frameCount / fps); } else { return(duration); } }
bool Ready() { if (!isReady) { _isReady = true; for (int f = 0; f < framesets.Length; f++) { OTAnimationFrameset fs = framesets[f]; if (fs.container != null && !fs.container.isReady) { _isReady = false; } } } return(_isReady); }
int GetIndex(float time, int direction, OTAnimationFrameset frameset) { int index = 0; int fc = GetFrameCount(frameset); index = (int)Mathf.Floor((float)fc * (time / GetDuration(frameset))); while (index > fc - 1) { index -= fc; } if (direction == -1) { index = fc - 1 - index; } return(index); }
/// <summary> /// Retrieve the animation frame that is active at a specific time. /// </summary> /// <param name="time">Animation time in seconds.</param> /// <param name="direction">Animation direction, 1 = forward, -1 = backward</param> /// <param name="frameset">The animation frameset of which a frame is requested</param> /// <returns>Retrieved animation frame.</returns> public Frame GetFrame(float time, int direction, OTAnimationFrameset frameset) { if (frames.Length == 0) { return(new Frame()); } else { if (frameset != null) { return(frames[frameset.startIndex + GetIndex(time, direction, frameset)]); } else { return(frames[GetIndex(time, direction, null)]); } } }
// Create an walking man animation frameset with 15 images // INFO : Because our walking man sprite sheet contains 8 direction // animations of 15 frames. We will put these into seperate animation // framesets, so they can be played quickly when needed. OTAnimationFrameset WalkingFrameset(string name, int row, OTContainer sheet) { // Create a new frameset OTAnimationFrameset frameset = new OTAnimationFrameset(); // Give this frameset a name for later reference frameset.name = name; // Link our provided sprite sheet frameset.container = sheet; // Set the correct start frame frameset.startFrame = (row - 1) * 15; // Set the correct end frame frameset.endFrame = ((row - 1) * 15) + 14; // Set this frameset's animation duration that will only // be used when the frameset is played as a single animation frameset.singleDuration = 0.95f; // Return this new frameset return(frameset); }
// Create an walking man animation frameset with 15 images // INFO : Because our walking man sprite sheet contains 8 direction // animations of 15 frames. We will put these into seperate animation // framesets, so they can be played quickly when needed. OTAnimationFrameset WalkingFrameset(string name, int row, OTContainer sheet) { // Create a new frameset OTAnimationFrameset frameset = new OTAnimationFrameset(); // Give this frameset a name for later reference frameset.name = name; // Link our provided sprite sheet frameset.container = sheet; // Set the correct start frame frameset.startFrame = (row - 1) * 15; // Set the correct end frame frameset.endFrame = ((row - 1) * 15) + 14; // Set this frameset's animation duration that will only // be used when the frameset is played as a single animation frameset.singleDuration = 0.95f; // Return this new frameset return frameset; }
void EditorPreview() { if (animationPreview < 0) { animationPreview = 0; } else if (animationPreview > 100) { animationPreview = 100; } if (!Application.isPlaying && animation != null && animation.isReady) { if (animationFrameset != "" && (frameset == null || (frameset != null && framesetName != animationFramesetLower))) { frameset = animation.GetFrameset(animationFrameset); frCount = animation.GetFrameCount(frameset); frDuration = animation.GetDuration(frameset); System.Array.Resize <OTAnimation.Frame>(ref frames, 0); } else { frCount = animation.frameCount; frDuration = animation.duration; } frDurationDelta = frDuration / frCount; if (frames.Length == 0) { System.Array.Resize <OTAnimation.Frame>(ref frames, frCount); // cache the animation frames for quicker lookup for (int i = 0; i < frCount; i++) { frames[i] = animation.GetFrame(i * frDurationDelta, direction, frameset); } } frDuration = animation.GetDuration(frameset); if (frameset != null && frameset.name == "") { frameset = null; } time = ((frDuration / 100) * animationPreview); if (time == frDuration) { time -= 0.001f; } if (time != _time) { UpdateFrame(); _time = time; } } else if (animation != null && animation.isReady) { if (spriteContainer == null) { spriteContainer = animation.GetFrame(0, 1, null).container; } } }
void InitAnimation() { if (animationFrameset != "") { frameset = animation.GetFrameset(animationFrameset); if (frameset!=null) { framesetName = frameset.name.ToLower(); animationFramesetLower = animationFrameset.ToLower(); } frDuration = animation.GetDuration(frameset); frCount = animation.GetFrameCount(frameset); } else { frameset = null; frDuration = animation.duration; frCount = animation.frameCount; } frDurationDelta = frDuration/frCount; frTime = 0; if (frCount==0) return; if (startAtRandomFrame) time = frDurationDelta * (Mathf.Floor(frCount * Random.value)); else { if (startFrame != -1) { time = frDurationDelta * startFrame; if (endFrame != -1) endTime = frDurationDelta * (endFrame + 1) - 0.001f; } else time = 0; } System.Array.Resize<OTAnimation.Frame>(ref frames,frCount); // cache the animation frames for quicker lookup for (int i=0; i<frCount; i++) frames[i] = animation.GetFrame(i * frDurationDelta, direction, frameset); }
// Update is called once per frame protected override void Update() { if (animation == null && _animationName != null) { animation = OT.AnimationByName(_animationName); } if (spriteContainer != null && !spriteContainer.isReady) { return; } if (speed < 0) { speed = 0; } if (Application.isPlaying && animation != null && animation.isReady && _playing) { if (waiting) { if (waitTime >= delay) { waitTime = 0; delay = 0; if (animationFrameset != "") { frameset = animation.GetFrameset(animationFrameset); frDuration = animation.GetDuration(frameset); frCount = animation.GetFrameCount(frameset); } else { frameset = null; frDuration = animation.duration; frCount = animation.frameCount; } if (frCount == 0) { return; } if (startAtRandomFrame) { time = (frDuration / frCount) * (Mathf.Floor(frCount * Random.value)); } else { if (startFrame != -1) { time = (frDuration / frCount) * startFrame; if (endFrame != -1) { endTime = (frDuration / frCount) * (endFrame + 1) - 0.001f; } } else { time = 0; } } waiting = false; if (onAnimationStart != null) { onAnimationStart(this); } if (!CallBack("onAnimationStart", new object[] { this })) { CallBack("OnAnimationStart", new object[] { this }); } } else { waitTime += Time.deltaTime; } } if (!waiting) { UpdateFrame(); } } else { if (animationPreview < 0) { animationPreview = 0; } else if (animationPreview > 100) { animationPreview = 100; } if (!Application.isPlaying && animation != null && animation.isReady) { if (animationFrameset != "" && (frameset == null || (frameset != null && frameset.name.ToLower() != animationFrameset.ToLower()))) { frameset = animation.GetFrameset(animationFrameset); frCount = animation.GetFrameCount(frameset); } frDuration = animation.GetDuration(frameset); if (frameset != null && frameset.name == "") { frameset = null; } time = ((frDuration / 100) * animationPreview); if (time == frDuration) { time -= 0.001f; } if (time != _time) { UpdateFrame(); _time = time; } } else if (animation != null && animation.isReady) { if (spriteContainer == null) { spriteContainer = animation.GetFrame(0, 1, null).container; } } } base.Update(); }
void HandleWaiting() { if (waitTime >= delay) { waitTime = 0; delay = 0; if (animationFrameset != "") { frameset = animation.GetFrameset(animationFrameset); if (frameset != null) { framesetName = frameset.name.ToLower(); animationFramesetLower = animationFrameset.ToLower(); } frDuration = animation.GetDuration(frameset); frCount = animation.GetFrameCount(frameset); } else { frameset = null; frDuration = animation.duration; frCount = animation.frameCount; } frDurationDelta = frDuration / frCount; if (frCount == 0) { return; } if (startAtRandomFrame) { time = frDurationDelta * (Mathf.Floor(frCount * Random.value)); } else { if (startFrame != -1) { time = frDurationDelta * startFrame; if (endFrame != -1) { endTime = frDurationDelta * (endFrame + 1) - 0.001f; } } else { time = 0; } } System.Array.Resize <OTAnimation.Frame>(ref frames, frCount); // cache the animation frames for quicker lookup for (int i = 0; i < frCount; i++) { frames[i] = animation.GetFrame(i * frDurationDelta, direction, frameset); } waiting = false; if (onAnimationStart != null) { onAnimationStart(this); } if (!CallBack("onAnimationStart", new object[] { this })) { CallBack("OnAnimationStart", new object[] { this }); } } else { waitTime += Time.deltaTime; } }
/// <summary> /// Get number of frames in this animaation /// </summary> /// <remarks> /// If no <see cref="OTAnimationFrameset" /> is provided the number of frames of the entire animation is returned. If an OTAnimationFrameset is provided /// this method will return the number of frames of that particular frameset. /// </remarks> /// <param name="frameset">Get number of frames of a perticular animation frameset.</param> /// <returns>number of frames</returns> public int GetFrameCount(OTAnimationFrameset frameset) { if (frameset != null) return frameset.frameCount; else return frameCount; }
private void createInitialFrameset() { this.initialFrameSet = new OTAnimationFrameset(); this.initialFrameSet.container = this.atlas; this.initialFrameSet.startFrame = 0; this.initialFrameSet.endFrame = 4; }
void CreateSpriteSheets() { imageIdx = 0; createdSheets.Clear(); for (int t = 1; t <= texCount; t++) CreateSpriteSheetTexture(t); if (addToScene) { OTAnimation animation = OT.AnimationByName("Animation-" + containerName); if (animation == null) animation = OT.CreateObject(OTObjectType.Animation).GetComponent<OTAnimation>(); animation.name = "Animation-" + containerName; List<OTAnimationFrameset> fs = new List<OTAnimationFrameset>(); int frCount = (int)(framesXY.x * framesXY.y); int frIdx = 0; for (int t = 1; t <= texCount; t++) { OTSpriteSheet sheet = createdSheets[t - 1] as OTSpriteSheet; if (sheet != null) { OTAnimationFrameset fr = new OTAnimationFrameset(); fr.container = sheet; fr.startFrame = 0; if (frIdx + frCount <= images.Count) fr.endFrame = frCount - 1; else fr.endFrame = (images.Count - frIdx) - 1; fs.Add(fr); frIdx += frCount; } } animation.framesets = fs.ToArray(); OTAnimatingSprite sprite = OT.ObjectByName(containerName) as OTAnimatingSprite; if (sprite == null) sprite = OT.CreateObject(OTObjectType.AnimatingSprite).GetComponent<OTAnimatingSprite>(); if (sprite != null) { sprite.name = containerName; sprite.animation = animation; sprite.animationFrameset = ""; } } }
void HandleWaiting() { if (waitTime >= delay) { waitTime = 0; delay = 0; if (animationFrameset != "") { frameset = animation.GetFrameset(animationFrameset); if (frameset!=null) { framesetName = frameset.name.ToLower(); animationFramesetLower = animationFrameset.ToLower(); } frDuration = animation.GetDuration(frameset); frCount = animation.GetFrameCount(frameset); } else { frameset = null; frDuration = animation.duration; frCount = animation.frameCount; } frDurationDelta = frDuration/frCount; if (frCount==0) return; if (startAtRandomFrame) time = frDurationDelta * (Mathf.Floor(frCount * Random.value)); else { if (startFrame != -1) { time = frDurationDelta * startFrame; if (endFrame != -1) endTime = frDurationDelta * (endFrame + 1) - 0.001f; } else time = 0; } System.Array.Resize<OTAnimation.Frame>(ref frames,frCount); // cache the animation frames for quicker lookup for (int i=0; i<frCount; i++) frames[i] = animation.GetFrame(i * frDurationDelta, direction, frameset); waiting = false; if (onAnimationStart != null) onAnimationStart(this); if (!CallBack("onAnimationStart", new object[] { this })) CallBack("OnAnimationStart", new object[] { this }); } else waitTime += Time.deltaTime; }
TextMesh stagemesh2; // textmesh for stage 1 menu item // Create all objects fo r the star stage by code void AnimatingGreenStarStage() { // To create a scrolling background, first create a filled sprite object back = OT.CreateObject(OTObjectType.FilledSprite).GetComponent <OTFilledSprite>(); // Set the image to the tile texture back.image = whiteTile; // Set material reference to 'custom' blue material back.materialReference = "blue"; // Set size to match the screen resolution so it will fill the entire screen back.size = new Vector2(Screen.width, Screen.height); // Set the display depth all the way back so everything else will come on top back.depth = 1000; // Set fill image size to 50 x 50 pixels back.fillSize = new Vector2(50, 50); // Set scroll speed so we will scroll horizontally 20 px / second back.scrollSpeed = new Vector2(20, 0); // To create the animating star we first have to create the sprite sheet object that will // hold our texture/animation frames OTSpriteSheet sheet = OT.CreateObject(OTObjectType.SpriteSheet).GetComponent <OTSpriteSheet>(); // Give our sheet a name sheet.name = "mySheet"; // Assign texture sheet.texture = greenStarsAnimation; // Specify how many columns and rows we have (frames) sheet.framesXY = new Vector2(25, 3); // Because we have some overhead space to the right and bottom of our texture we have to // specify the original texture size and the original frame size so that the right texture // scale and offsetting can be calculated. sheet.sheetSize = new Vector2(2048, 256); sheet.frameSize = new Vector2(80, 80); // Next thing is to create the animation that our animating sprite will use OTAnimation animation = OT.CreateObject(OTObjectType.Animation).GetComponent <OTAnimation>(); // This animation will use only one frameset with all animating star frames. OTAnimationFrameset frameset = new OTAnimationFrameset(); // Link up the sprite sheet to this animation's frameset frameset.container = sheet; // Frameset animation will start at frame index 0 frameset.startFrame = 0; // Frameset animation will end at frame index 69 frameset.endFrame = 69; // Assign this frameset to the animation. // HINT : by asigning more than one frameset it is possible to create an animation that will span // across mutiple framesets // HINT : Because it is possible (and very easy) to play a specific frameset of an animation // One could pack a lot of animations into one animation object. animation.framesets = new OTAnimationFrameset[] { frameset }; // Set the duration of this animation // HINT : By using the OTAnimationSprite.speed setting one can speed up or slow down a // running animation without changing the OTAnimation.fps or .duration setting. animation.duration = .95f; // Lets give our animation a name animation.name = "star-animation"; // To finally get the animatiing star on screen we will create our animation sprite object star = OT.CreateObject(OTObjectType.AnimatingSprite).GetComponent <OTAnimatingSprite>(); // Link up the animation star.animation = animation; // Lets start at a random frame star.startAtRandomFrame = true; // Lets auto-start this animation star.playOnStart = true; // start invisible and make visible when containers are ready. star.visible = false; star.name = "star"; star.spriteContainer = sheet; // INFO : This animation 'star' will be center (0,0) positioned and act as a prototype // to create more moveing and animating (additive) 'stars'. }
private OTAnimationFrameset CreateFrameset(string name, OTContainer container, int startFrameIndex, int endFrameIndex) { MZDebug.Log( "Add frameset: " + name ); OTAnimationFrameset frameset = new OTAnimationFrameset(); frameset.name = name; frameset.container = container; frameset.startFrame = startFrameIndex; frameset.endFrame = endFrameIndex; return frameset; }
// Update is called once per frame /// <exclude /> protected override void Update() { if (spriteContainer != null && !spriteContainer.isReady) return; if (speed < 0) speed = 0; if (Application.isPlaying && animation != null && animation.isReady && _playing) { if (waiting) { if (waitTime >= delay) { waitTime = 0; delay = 0; if (animationFrameset != "") { frameset = animation.GetFrameset(animationFrameset); frDuration = animation.GetDuration(frameset); frCount = animation.GetFrameCount(frameset); } else { frameset = null; frDuration = animation.duration; frCount = animation.frameCount; } if (startAtRandomFrame) time = (frDuration / frCount) * (Mathf.Floor(frCount * Random.value)); else { if (startFrame != -1) { time = (frDuration / frCount) * startFrame; if (endFrame != -1) endTime = (frDuration / frCount) * (endFrame + 1) - 0.001f; } else time = 0; } waiting = false; if (onAnimationStart != null) onAnimationStart(this); if (!CallBack("onAnimationStart", new object[] { this })) CallBack("OnAnimationStart", new object[] { this }); } else waitTime += Time.deltaTime; } if (!waiting) UpdateFrame(); } else { if (animationPreview < 0) animationPreview = 0; else if (animationPreview > 100) animationPreview = 100; if (!Application.isPlaying && animation != null && animation.isReady) { if (animationFrameset != "" && (frameset == null || (frameset != null && frameset.name.ToLower() != animationFrameset.ToLower()))) { frameset = animation.GetFrameset(animationFrameset); frCount = animation.GetFrameCount(frameset); } frDuration = animation.GetDuration(frameset); if (frameset != null && frameset.name == "") frameset = null; time = ((frDuration / 100) * animationPreview); if (time == frDuration) time -= 0.001f; if (time != _time) { UpdateFrame(); _time = time; } } else if (animation != null && animation.isReady) { if (spriteContainer == null) spriteContainer = animation.GetFrame(0, 1, null).container; } } base.Update(); }
void EditorPreview() { if (animationPreview < 0) animationPreview = 0; else if (animationPreview > 100) animationPreview = 100; if (!Application.isPlaying && animation != null && animation.isReady) { if (animationFrameset != "" && (frameset == null || (frameset != null && framesetName != animationFramesetLower))) { frameset = animation.GetFrameset(animationFrameset); frCount = animation.GetFrameCount(frameset); frDuration = animation.GetDuration(frameset); System.Array.Resize<OTAnimation.Frame>(ref frames,0); } else { frCount = animation.frameCount; frDuration = animation.duration; } frDurationDelta = frDuration/frCount; if (frames.Length == 0) { System.Array.Resize<OTAnimation.Frame>(ref frames,frCount); // cache the animation frames for quicker lookup for (int i=0; i<frCount; i++) frames[i] = animation.GetFrame(i * frDurationDelta, direction, frameset); } frDuration = animation.GetDuration(frameset); if (frameset != null && frameset.name == "") frameset = null; time = ((frDuration / 100) * animationPreview); if (time == frDuration) time -= 0.001f; if (time != _time) { UpdateFrame(); _time = time; } } else if (animation != null && animation.isReady) { if (spriteContainer == null) spriteContainer = animation.GetFrame(0, 1, null).container; } }
/// <exclude /> public float GetDuration(OTAnimationFrameset frameset) { if (frameset != null) { return (frameset.singleDuration != 0) ? frameset.singleDuration : frameset.frameCount / fps; } else return duration; }
public OTAnimationFramesetCheck(OTAnimationFrameset fs) { this.fs = fs; Assign(); }
private void generateSprite() { // Next thing is to create the animation that our animating sprite will use cardToFront = OT.CreateObject(OTObjectType.Animation).GetComponent<OTAnimation>(); // This animation will use only one frameset with all animating star frames. OTAnimationFrameset frameset2 = new OTAnimationFrameset(); frameset2.container = this.atlas; frameset2.startFrame = int.Parse(this.getID())+CardBehaviour.offset; frameset2.endFrame = int.Parse(this.getID())+CardBehaviour.offset; // Assign this frameset to the animation. // HINT : by asigning more than one frameset it is possible to create an animation that // will span across mutiple framesets // HINT : Because it is possible (and very easy) to play a specific frameset of an animation // One could pack a lot of animations into one animation object. cardToFront.framesets = new OTAnimationFrameset[] { this.initialFrameSet , frameset2 }; // Set the duration of this animation // HINT : By using the OTAnimationSprite.speed setting one can speed up or slow down a // running animation without changing the OTAnimation.fps or .duration setting. cardToFront.duration = 0.2f; // Lets give our animation a name cardToFront.name = "card-animation"; // To finally get the animatiing star on screen we will create our animation sprite object card = (OTAnimatingSprite)GetComponent(typeof(OTAnimatingSprite)); card.playOnStart = false; card.startAtRandomFrame = false; card.animation = cardToFront; card.position = (new Vector2(this.location.getX() - 400, this.location.getY() - 405)); card.depth = -3; //La llevo para adelante en la pantalla }
float starTime = 0; // star creation wait time #endregion Fields #region Methods // Create all objects fo r the star stage by code void AnimatingGreenStarStage() { // To create a scrolling background, first create a filled sprite object back = OT.CreateObject(OTObjectType.FilledSprite).GetComponent<OTFilledSprite>(); // Set the image to the tile texture back.image = whiteTile; // Set material reference to 'custom' blue material back.materialReference = "blue"; // Set size to match the screen resolution so it will fill the entire screen back.size = new Vector2(Screen.width,Screen.height); // Set the display depth all the way back so everything else will come on top back.depth = 1000; // Set fill image size to 50 x 50 pixels back.fillSize = new Vector2(50, 50); // Set scroll speed so we will scroll horizontally 20 px / second back.scrollSpeed = new Vector2(20, 0); // To create the animating star we first have to create the sprite sheet object that will // hold our texture/animation frames OTSpriteSheet sheet = OT.CreateObject(OTObjectType.SpriteSheet).GetComponent<OTSpriteSheet>(); // Assign texture sheet.texture = greenStarsAnimation; // Specify how many columns and rows we have (frames) sheet.framesXY = new Vector2(25, 3); // Because we have some overhead space to the right and bottom of our texture we have to // specify the original texture size and the original frame size so that the right texture // scale and offsetting can be calculated. sheet.sheetSize = new Vector2(2048, 256); sheet.frameSize = new Vector2(80, 80); // Next thing is to create the animation that our animating sprite will use OTAnimation animation = OT.CreateObject(OTObjectType.Animation).GetComponent<OTAnimation>(); // This animation will use only one frameset with all animating star frames. OTAnimationFrameset frameset = new OTAnimationFrameset(); // Link up the sprite sheet to this animation's frameset frameset.container = sheet; // Frameset animation will start at frame index 0 frameset.startFrame = 0; // Frameset animation will end at frame index 69 frameset.endFrame = 69; // Assign this frameset to the animation. // HINT : by asigning more than one frameset it is possible to create an animation that will span // across mutiple framesets // HINT : Because it is possible (and very easy) to play a specific frameset of an animation // One could pack a lot of animations into one animation object. animation.framesets = new OTAnimationFrameset[] { frameset }; // Set the duration of this animation // HINT : By using the OTAnimationSprite.speed setting one can speed up or slow down a // running animation without changing the OTAnimation.fps or .duration setting. animation.duration = .95f; // Lets give our animation a name animation.name = "star-animation"; // To finally get the animatiing star on screen we will create our animation sprite object star = OT.CreateObject(OTObjectType.AnimatingSprite).GetComponent<OTAnimatingSprite>(); // Link up the animation star.animation = animation; // Lets start at a random frame star.startAtRandomFrame = true; // Lets auto-start this animation star.playOnStart = true; // INFO : This animation 'star' will be center (0,0) positioned and act as a prototype // to create more moveing and animating (additive) 'stars'. }
void CheckEditorSettings() { if (frameCount == 0 && framesets.Length > 0 && !dirtyAnimation) { dirtyAnimation = true; } if (framesets.Length > 0) { if (_framesetSize != framesets.Length) { _framesetSize = framesets.Length; dirtyAnimation = true; } int _frameCount = 0; for (int f = 0; f < framesets.Length; f++) { OTAnimationFrameset fs = framesets[f]; if (fs.container != null) { if (f <= _framesets.Count - 1) { dirtyAnimation = _framesets[f].isChanged; _framesets[f].Assign(); } else { _framesets.Add(new OTAnimationFramesetCheck(fs)); dirtyAnimation = true; } if (fs.container != null) { fs._containerName = fs.container.name; } if (fs.container.isReady) { if (fs.startFrame < 0) { fs.startFrame = 0; } else if (fs.startFrame >= fs.container.frameCount) { fs.startFrame = fs.container.frameCount - 1; } if (fs.endFrame < 0) { fs.endFrame = 0; } else if (fs.endFrame >= fs.container.frameCount) { fs.endFrame = fs.container.frameCount - 1; } _frameCount += fs.frameCount; } } else { if (fs._containerName == "") { fs.startFrame = -1; fs.endFrame = -1; } } if (fs.playCount < 1) { fs.playCount = 1; } } if (frames != null) { if (_frameCount != frames.Length) { dirtyAnimation = true; } } while (framesets.Length < _framesets.Count) { _framesets.RemoveAt(_framesets.Count - 1); } } }
/// <summary> /// Retrieve the animation frame that is active at a specific time. /// </summary> /// <param name="time">Animation time in seconds.</param> /// <param name="direction">Animation direction, 1 = forward, -1 = backward</param> /// <param name="frameset">The animation frameset of which a frame is requested</param> /// <returns>Retrieved animation frame.</returns> public Frame GetFrame(float time, int direction, OTAnimationFrameset frameset) { if (frames.Length == 0) { return new Frame(); } else { if (frameset != null) { return frames[frameset.startIndex+GetIndex(time, direction, frameset)]; } else return frames[GetIndex(time, direction, null)]; } }
// Update is called once per frame void Update() { if (!OT.isValid || !Ready()) { return; } if (!registered || !Application.isPlaying) { RegisterAnimation(); } if (!Application.isPlaying) { CheckEditorSettings(); } else { if (OT.dirtyChecks && framesets.Length > 0) { if (_framesetSize != framesets.Length) { _framesetSize = framesets.Length; dirtyAnimation = true; } } } if (dirtyAnimation) { bool isOk = true; for (int f = 0; f < framesets.Length; f++) { OTAnimationFrameset fs = framesets[f]; if (fs.container == null && fs._containerName != "") { OTContainer c = OT.ContainerByName(fs._containerName); if (c != null && c.isReady) { fs.container = c; } else { isOk = false; break; } } } if (isOk) { frames = GetFrames(); dirtyAnimation = false; if (_duration == _duration_) { _duration = (float)frames.Length / _fps; _duration_ = _duration; } } } if (!Application.isPlaying || OT.dirtyChecks) { if (_duration > 0) { if (_duration_ != _duration) { _duration_ = _duration; _fps = (float)frames.Length / _duration; _fps_ = _fps; } } if (_fps > 0) { if (_fps_ != _fps) { _fps_ = _fps; _duration = (float)frames.Length / _fps; _duration_ = _duration; } } } }
int GetIndex(float time, int direction, OTAnimationFrameset frameset) { int index = 0; int fc = GetFrameCount(frameset); index = (int)Mathf.Floor((float)fc * (time / GetDuration(frameset))); while (index > fc - 1) index -= fc; if (direction == -1) index = fc - 1 - index; return index; }