/// <summary> /// Stretches or compresses all frames of the animation to fit a new frame count. /// </summary> public void Resize(int newFrameCount) { KeyframeEntry kfe = null; float ratio = (float)newFrameCount / (float)FrameCount; foreach (SRT0EntryNode n in Children) { foreach (SRT0TextureNode e in n.Children) { KeyframeCollection newCollection = new KeyframeCollection(5, newFrameCount + (Loop ? 1 : 0), 1, 1); for (int x = 0; x < FrameCount; x++) { int newFrame = (int)((float)x * ratio + 0.5f); float frameRatio = newFrame == 0 ? 0 : (float)x / (float)newFrame; for (int i = 0; i < 5; i++) { if ((kfe = e.GetKeyframe(i, x)) != null) { newCollection.SetFrameValue(i, newFrame, kfe._value)._tangent = kfe._tangent * (float.IsNaN(frameRatio) ? 1 : frameRatio); } } } e._keyframes = newCollection; } } FrameCount = newFrameCount; }
// Sets an animation for this instance with a frame timer public void SetAnimation(string[] spriteNames, float frametime) { Vector2 pivot = img.GetComponent <RectTransform>().pivot; Keyframe[] kfArray = new Keyframe[spriteNames.Length]; for (int i = 0; i < spriteNames.Length; i++) { kfArray[i] = new Keyframe(SpriteRegistry.Get(spriteNames[i]), spriteNames[i].ToLower()); } if (keyframes == null) { if (img.GetComponent <KeyframeCollection>()) { keyframes = img.GetComponent <KeyframeCollection>(); keyframes.enabled = true; } else { keyframes = img.AddComponent <KeyframeCollection>(); keyframes.spr = this; } } else { keyframes.enabled = true; } keyframes.loop = loop; keyframes.Set(kfArray, frametime); UpdateAnimation(); img.GetComponent <RectTransform>().pivot = pivot; }
protected ScriptResource(string name, string source, KeyframeCollection keyframes, ScriptResourceOrigin origin) { Name = name; Source = source; Origin = origin; Keyframes = keyframes; }
private static BoneAnim Chr0Entry2BoneAnim(CHR0EntryNode entry) { BoneAnim boneAnim = new BoneAnim(); boneAnim.Name = entry.Name; if (entry.UseModelTranslate) { boneAnim.FlagsBase |= BoneAnimFlagsBase.Translate; } if (entry.UseModelRotate) { boneAnim.FlagsBase |= BoneAnimFlagsBase.Rotate; } if (entry.UseModelScale) { boneAnim.FlagsBase |= BoneAnimFlagsBase.Scale; } var baseData = new BoneAnimData(); baseData.Translate = new Vector3F(); baseData.Rotate = new Vector4F(); baseData.Scale = new Vector3F(); baseData.Flags = 0; boneAnim.BaseData = baseData; boneAnim.BeginBaseTranslate = 0; boneAnim.BeginRotate = 0; boneAnim.BeginTranslate = 0; boneAnim.FlagsTransform = 0; KeyframeCollection c = entry.Keyframes; for (int index = 0; index < 9; index++) { } if (entry.UseModelTranslate) { boneAnim.FlagsCurve |= BoneAnimFlagsCurve.TranslateX; } if (entry.UseModelRotate) { boneAnim.FlagsBase |= BoneAnimFlagsBase.Rotate; } if (entry.UseModelScale) { boneAnim.FlagsBase |= BoneAnimFlagsBase.Scale; } return(boneAnim); }
public override bool OnInitialize() { if (_name == null) { _name = (_indirect ? "Ind" : "") + "Texture" + _textureIndex; } _code = Header->Code; _keyframes = null; return(false); }
protected override bool OnInitialize() { _keyframes = null; if (_parent is CHR0Node) { _numFrames = ((CHR0Node)_parent)._numFrames; } if ((_name == null) && (Header->_stringOffset != 0)) { _name = Header->ResourceString; } return(false); }
protected override bool OnInitialize() { if (_name == null) { _name = "Texture" + _textureIndex; } _flags = Header->Code; _keyframes = null; if (_parent is SRT0EntryNode && _parent._parent is SRT0Node) { _numFrames = ((SRT0Node)_parent._parent).FrameCount; } return(false); }
public override bool OnInitialize() { if (_name == null) { _name = (_indirect ? "Ind" : "") + "Texture" + _textureIndex; } _flags = Header->Code; _keyframes = null; if (Parent is SRT0EntryNode && Parent.Parent is SRT0Node) { _numFrames = ((SRT0Node)Parent.Parent).FrameCount; } return(false); }
public void SetAnimation(string[] spriteNames, float frametime) { Keyframe[] kfArray = new Keyframe[spriteNames.Length]; for (int i = 0; i < spriteNames.Length; i++) { kfArray[i] = new Keyframe(SpriteRegistry.Get(spriteNames[i])); } if (keyframes == null) { keyframes = img.gameObject.AddComponent <KeyframeCollection>(); keyframes.spr = this; } else { keyframes.enabled = true; } keyframes.Set(kfArray, frametime); }
public override bool OnInitialize() { _keyframes = null; if ((_name == null) && (Header->_stringOffset != 0)) { _name = Header->ResourceString; } _code = Header->Code; _useModelScale = _code.UseModelScale; _useModelRotate = _code.UseModelRot; _useModelTranslate = _code.UseModelTrans; _scaleCompApply = _code.ScaleCompApply; _scaleCompParent = _code.ScaleCompParent; _classicScaleOff = _code.ClassicScaleOff; return(false); }
/// <summary> /// Stretches or compresses all frames of the animation to fit a new frame count. /// </summary> public void Resize(int newFrameCount) { KeyframeEntry kfe = null; float ratio = (float)newFrameCount / (float)FrameCount; foreach (CHR0EntryNode e in Children) { KeyframeCollection newCollection = new KeyframeCollection(newFrameCount); for (int x = 0; x < FrameCount; x++) { int newFrame = (int)((float)x * ratio + 0.5f); float frameRatio = newFrame == 0 ? 0 : (float)x / (float)newFrame; for (int i = 0x10; i < 0x19; i++) { if ((kfe = e.GetKeyframe((KeyFrameMode)i, x)) != null) { newCollection.SetFrameValue((KeyFrameMode)i, newFrame, kfe._value)._tangent = kfe._tangent * (float.IsNaN(frameRatio) ? 1 : frameRatio); } } } e._keyframes = newCollection; } FrameCount = newFrameCount; }
// Sets an animation for this instance with a frame timer public void SetAnimation(string[] spriteNames, float frametime, string prefix = "") { if (spriteNames == null) { throw new CYFException("sprite.SetAnimation: The first argument (list of images) is nil.\n\nSee the documentation for proper usage."); } if (spriteNames.Length == 0) { throw new CYFException("sprite.SetAnimation: No sequence of animations was provided (animation table is empty)."); } if (frametime < 0) { throw new CYFException("sprite.SetAnimation: An animation can not have negative speed!"); } if (frametime == 0) { throw new CYFException("sprite.SetAnimation: An animation can not play at 0 frames per second!"); } if (prefix != "") { while (prefix.StartsWith("/")) { prefix = prefix.Substring(1); } if (!prefix.EndsWith("/")) { prefix += "/"; } for (int i = 0; i < spriteNames.Length; i++) { spriteNames[i] = prefix + spriteNames[i]; } } Vector2 pivot = img.GetComponent <RectTransform>().pivot; Keyframe[] kfArray = new Keyframe[spriteNames.Length]; for (int i = 0; i < spriteNames.Length; i++) { // at least one sprite in the sequence was unable to be loaded if (SpriteRegistry.Get(spriteNames[i]) == null) { throw new CYFException("sprite.SetAnimation: Failed to load sprite with the name \"" + spriteNames[i] + "\". Are you sure it is spelled correctly?"); } kfArray[i] = new Keyframe(SpriteRegistry.Get(spriteNames[i]), spriteNames[i].ToLower()); } if (keyframes == null) { if (img.GetComponent <KeyframeCollection>()) { keyframes = img.GetComponent <KeyframeCollection>(); keyframes.enabled = true; } else { keyframes = img.AddComponent <KeyframeCollection>(); keyframes.spr = this; } } else { keyframes.enabled = true; } keyframes.loop = loop; keyframes.Set(kfArray, frametime); UpdateAnimation(); img.GetComponent <RectTransform>().pivot = pivot; }