private void CreateAnimationClipFile(DirectionAnimation directionAnimation, Direction direction, string targetFolder) { var name = direction + "_" + directionAnimation.name; AnimationClip animClip = new AnimationClip(); animClip.frameRate = directionAnimation.framerate; // FPS animClip.wrapMode = WrapMode.Loop; EditorCurveBinding spriteBinding = new EditorCurveBinding(); spriteBinding.type = typeof(SpriteRenderer); spriteBinding.path = ""; spriteBinding.propertyName = "m_Sprite"; ObjectReferenceKeyframe[] spriteKeyFrames = new ObjectReferenceKeyframe[directionAnimation.frames]; for (int i = 0; i < directionAnimation.frames; i++) { spriteKeyFrames[i] = new ObjectReferenceKeyframe(); spriteKeyFrames[i].time = i; spriteKeyFrames[i].value = newSprites[currentAnimIndex + i]; } currentAnimIndex += directionAnimation.frames; AnimationUtility.SetObjectReferenceCurve(animClip, spriteBinding, spriteKeyFrames); AssetDatabase.CreateAsset(animClip, targetFolder + "/" + name + ".anim"); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); Debug.Log("Trying to create : " + targetFolder + "/" + name + ".anim"); }
protected override void SetStateInternal(BinaryActuatorState newState, params IParameter[] parameters) { if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } BinaryActuatorState oldState = GetStateInternal(); var animationParameter = parameters.SingleOrDefault(p => p is AnimateParameter) as AnimateParameter; if (animationParameter != null) { var directionAnimation = new DirectionAnimation(_timer); directionAnimation.WithActuator(this); directionAnimation.WithTargetState(newState); if (animationParameter.Reverse) { directionAnimation.WithReversed(); } directionAnimation.Start(); OnStateChanged(oldState, newState); return; } // Set the state of the actuators without a commit to ensure that the state is applied at once without a delay. foreach (var actuator in Actuators) { actuator.SetState(newState, new DoNotCommitStateParameter()); } bool commit = !parameters.Any(p => p is DoNotCommitStateParameter); if (commit) { foreach (var actuator in Actuators) { actuator.SetState(newState); } } OnStateChanged(newState, GetStateInternal()); }