public float GetDeathTiming() { var motionId = RoAnimationHelper.GetMotionIdForSprite(Type, SpriteMotion.Dead); var time = SpriteData.Actions[motionId].Delay; var frames = SpriteData.Actions[motionId].Frames.Length; return((time * frames) / 1000f); }
public void ChangeMotion(SpriteMotion nextMotion, bool forceUpdate = false) { //Debug.Log($"{name} state {State} change motion from {CurrentMotion} to {nextMotion}"); if (CurrentMotion == nextMotion && !forceUpdate) { return; } CurrentMotion = nextMotion; currentFrame = 0; if (!isInitialized) { return; } var action = RoAnimationHelper.GetMotionIdForSprite(Type, nextMotion); if (action < 0 || action > SpriteData.Actions.Length) { action = 0; } ChangeAction(action); isPaused = false; isDirty = true; if (Type == SpriteType.Player) { if (CurrentMotion == SpriteMotion.Idle || CurrentMotion == SpriteMotion.Sit) { currentFrame = (int)HeadFacing; UpdateSpriteFrame(); isPaused = true; } else { HeadFacing = HeadFacing.Center; } } if (Shadow != null) { if (CurrentMotion == SpriteMotion.Sit || CurrentMotion == SpriteMotion.Dead) { Shadow.SetActive(false); } else { Shadow.SetActive(true); } } }
public static void BuildSpriteAttackTiming() { var guids = AssetDatabase.FindAssets("t:RoSpriteData", new[] { "Assets/Sprites" }); var output = new List <string>(); for (var i = 0; i < guids.Length; i++) { var path = AssetDatabase.GUIDToAssetPath(guids[i]); var asset = AssetDatabase.LoadAssetAtPath <RoSpriteData>(path); if (asset.Type != SpriteType.Monster && asset.Type != SpriteType.Monster2 && asset.Type != SpriteType.Pet) { continue; } var actionId = RoAnimationHelper.GetMotionIdForSprite(asset.Type, SpriteMotion.Attack1); if (actionId == -1) { actionId = RoAnimationHelper.GetMotionIdForSprite(asset.Type, SpriteMotion.Attack2); } if (actionId == -1) { continue; } var frames = asset.Actions[actionId].Frames; var found = false; for (var j = 0; j < frames.Length; j++) { if (frames[j].IsAttackFrame) { var time = j * asset.Actions[actionId].Delay; output.Add($"{asset.Name}:{time}"); found = true; break; } } if (found) { continue; } } File.WriteAllLines(@"Assets/Sprites/AttackTiming.txt", output); }
public void AdvanceFrame() { if (!isPaused) { currentFrame++; } if (currentFrame > maxFrame) { var nextMotion = RoAnimationHelper.GetMotionForState(State); if (nextMotion != CurrentMotion) { ChangeMotion(nextMotion); } else { if (State != SpriteState.Dead) { currentFrame = 0; } else { currentFrame = maxFrame; isPaused = true; } } } if (currentFrameTime < 0) { currentFrameTime += (float)currentAction.Delay / 1000f * AnimSpeed; } if (!isPaused) { isDirty = true; } }