private void CreateAnimation() { if (animationController == null) { animationController = new AnimationController(); } animationController.ClearAnimations(); animationController.AddResetAction(() => proxy.SetValue(BlendShapePreset.Blink, 0.0f)); animationController.AddWait(null, () => BlinkTimeMin + Random.value * (BlinkTimeMax - BlinkTimeMin)); animationController.AddAnimation(CloseAnimationTime, 0.0f, 1.0f, v => proxy.SetValue(BlendShapePreset.Blink, v)); animationController.AddWait(ClosingTime); animationController.AddAnimation(OpenAnimationTime, 1.0f, 0.0f, v => proxy.SetValue(BlendShapePreset.Blink, v)); }
// Get the AnimationController to do the animation of the Cube and the Map. public void OnRotate(InputAction.CallbackContext context, CubeAxis axis, CubeSlices slices) { if (context.phase != InputActionPhase.Started) { return; } AnimationSpecification animationSpecification; animationSpecification.cubeAxis = axis; animationSpecification.cubeSlices = slices; if (Keyboard.current.leftShiftKey.isPressed) { animationSpecification.rotationDirection = RotationDirection.reverse; } else { animationSpecification.rotationDirection = RotationDirection.normal; } if (Keyboard.current.leftCtrlKey.isPressed) { animationSpecification.moveType = MoveType.doubleMove; } else { animationSpecification.moveType = MoveType.singleMove; } animationController.AddAnimation(animationSpecification); }
public void SetHandAngle(bool LeftEnable, bool RightEnable, List <int> angles, float animationTime) { if (leftAnimationController == null) { leftAnimationController = new AnimationController(); } if (rightAnimationController == null) { rightAnimationController = new AnimationController(); } var startEulers = GetHandEulerAngles(); var endEulers = CalcHandEulerAngles(angles); if (LeftEnable) { leftAnimationController.StopAnimations(); leftAnimationController.ClearAnimations(); leftAnimationController.AddAnimation(animationTime, 0.0f, 1.0f, v => SetHandEulerAngles(true, false, eulersLerp(startEulers, endEulers, v))); doLeftAnimation = true; } if (RightEnable) { rightAnimationController.StopAnimations(); rightAnimationController.ClearAnimations(); rightAnimationController.AddAnimation(animationTime, 0.0f, 1.0f, v => SetHandEulerAngles(false, true, eulersLerp(startEulers, endEulers, v))); doRightAnimation = true; } }
/* * void WalkingState(bool state) * { * if (isWalking && !state) * { * isWalking = false; * if (animator) * { * animator.AnimationData = idle; * animator.Play(); * } * } * else if (!isWalking && state) * { * isWalking = true; * if (animator) * { * animator.AnimationData = walk; * animator.Play(); * } * } * * } * */ void CreateAnimationController() { animator = Node.GetComponent <Animator>(); var idle = new AnimationNode(ResourcesManager.LoadAsset <Animation>(@"Assets\Animations\02.vmd")); var walk = new AnimationNode(ResourcesManager.LoadAsset <Animation>(@"Assets\Animations\walk001.vmd")); var sitDown = new AnimationNode(ResourcesManager.LoadAsset <Animation>(@"Assets\Animations\SitDownMumi.vmd")); var sitIdle = new AnimationNode(ResourcesManager.LoadAsset <Animation>(@"Assets\Animations\SitIdleMumi.vmd")); var standUp = new AnimationNode(ResourcesManager.LoadAsset <Animation>(@"Assets\Animations\StandUpMumi.vmd")); idle.Name = "Idle"; walk.Name = "Walk"; sitDown.Name = "Sitdown"; sitIdle.Name = "Sit Idle"; standUp.Name = "Standup"; sitDown.Repeat = false; standUp.Repeat = false; sitDown.NextAnimation = sitIdle; standUp.NextAnimation = idle; AnimController = new AnimationController(idle); var idleWalkTransit = new AnimationTransition((anim) => anim.GetFloat("speed") > 0, walk); var walkIdleTransit = new AnimationTransition((anim) => anim.GetFloat("speed") == 0, idle); var idleSitTransit = new AnimationTransition((anim) => anim.GetBool("sit"), sitDown); sitIdle.Transitions.Add(new AnimationTransition((anim) => !anim.GetBool("sit"), standUp)); idle.Transitions.Add(idleWalkTransit); idle.Transitions.Add(idleSitTransit); walk.Transitions.Add(walkIdleTransit); AnimController.AddAnimation(idle); AnimController.AddAnimation(walk); AnimController.AddAnimation(sitDown); AnimController.AddAnimation(sitIdle); AnimController.AddAnimation(standUp); animator.Controller = AnimController; }
void Start() { Respawn(); birdState = new ByteField(objectName, "birdstate", 0); pX = new SingleField(objectName, "position x", 0); pY = new SingleField(objectName, "position y", 0); pZ = new SingleField(objectName, "position z", 0); vX = new SingleField(objectName, "velocity x", 0); vY = new SingleField(objectName, "velocity y", 0); vZ = new SingleField(objectName, "velocity z", 0); rYaw = new SingleField(objectName, "rotation yaw", 0); rPitch = new SingleField(objectName, "rotation pitch", 0); rRoll = new SingleField(objectName, "rotation roll", 0); time = new SingleField(objectName, "time", 0); animationController.AddAnimation(flap); animationController.AddAnimation(soar); animationController.AddAnimation(noise); animationController.PlayAnimation(soar); animationController.PlayAnimation(noise); }
private void RenderCurrentAnimationSettings() { if (AnimController == null) { if (ImGui.Button("Create Controller")) { AnimController = new AnimationController(Animation); AnimController.AddAnimation(new AnimationNode("Default") { EndingFrame = Animation.EndingFrame, StartingFrame = Animation.StartingFrame, LoopType = Animation.LoopType }); } int frameTime = Animation.TimeBetweenFrames; if (ImGui.InputInt("MS Between Frames", ref frameTime)) { Animation.TimeBetweenFrames = frameTime; Animation.Reset(); } ImGui.Text("Starting and ending frames are 0 indexed and inclusive."); int startingFrame = Animation.StartingFrame; if (ImGui.InputInt("Starting Frame", ref startingFrame)) { Animation.StartingFrame = startingFrame; Animation.Reset(); } int endingFrame = Animation.EndingFrame; if (ImGui.InputInt("Ending Frame", ref endingFrame)) { Animation.EndingFrame = endingFrame; Animation.Reset(); } var loopType = (int) Animation.LoopType; if (ImGui.Combo("Loop Type", ref loopType, string.Join('\0', Enum.GetNames(typeof(AnimationLoopType))))) { Animation.LoopType = (AnimationLoopType) loopType; Animation.Reset(); } } else { ImGui.Text("Animations"); ImGui.PushID("animList"); foreach (AnimationNode n in AnimController.Animations.Values) { bool activeOverlay = _overlayAnimation == n; ImGui.PushID(n.Name); if (n == AnimController.CurrentAnimation) { ImGui.Text(n.Name); } else { if (ImGui.Button(n.Name)) AnimController.SetAnimation(n.Name); } ImGui.SameLine(); ImGui.Text($"({n.StartingFrame}-{n.EndingFrame})"); ImGui.SameLine(); if (ImGui.Checkbox("Overlay", ref activeOverlay)) _overlayAnimation = activeOverlay ? n : null; ImGui.PopID(); } bool enableShortcuts = !ImGui.IsAnyItemActive(); if (ImGui.Button("(C)reate") || enableShortcuts && Engine.Host.IsKeyDown(Key.C) && AnimController.Animations.All(x => x.Key != "NewAnim")) { var newNode = new AnimationNode("NewAnim"); AnimController.AddAnimation(newNode); AnimController.SetAnimation(newNode.Name); } ImGui.SameLine(); if (AnimController.CurrentAnimation == null) { ImGui.PopID(); return; } if (ImGui.Button("Remove")) AnimController.RemoveAnimation(AnimController.CurrentAnimation.Name); ImGui.SameLine(); if (ImGui.Button("(R)ename") || enableShortcuts && Engine.Host.IsKeyDown(Key.R)) { var newName = new StringInputModal(s => { AnimController.CurrentAnimation.Name = s; AnimController.Reindex(); }, $"New name for {AnimController.CurrentAnimation.Name}"); Parent.AddWindow(newName); } ImGui.PopID(); AnimationNode cur = AnimController.CurrentAnimation; var modified = false; int frameTime = cur.TimeBetweenFrames; if (ImGui.InputInt("MS Between Frames", ref frameTime)) { cur.TimeBetweenFrames = frameTime; modified = true; } ImGui.Text("Starting and ending frames are 0 indexed and inclusive."); int startingFrame = cur.StartingFrame; if (ImGui.InputInt("Starting Frame", ref startingFrame)) { cur.StartingFrame = startingFrame; modified = true; } int endingFrame = cur.EndingFrame; if (ImGui.InputInt("Ending Frame", ref endingFrame)) { cur.EndingFrame = endingFrame; modified = true; } var loopType = (int) cur.LoopType; if (ImGui.Combo("Loop Type", ref loopType, string.Join('\0', Enum.GetNames(typeof(AnimationLoopType))))) { cur.LoopType = (AnimationLoopType) loopType; modified = true; } if (modified) AnimController.SetAnimation(cur.Name, true); } }
private void btnAnimate_Click(object sender, EventArgs e) { if (lstValues.SelectedIndices.Count != 1) { return; } using (Form frmAnimate = new Form()) { frmAnimate.Text = "Animate value"; frmAnimate.FormBorderStyle = FormBorderStyle.FixedToolWindow; frmAnimate.StartPosition = FormStartPosition.CenterParent; Type controlType = pnlContainer.Controls.Cast <Control>().First().GetType(); Control ctrlStart = (Control)Activator.CreateInstance(controlType); Control ctrlEnd = (Control)Activator.CreateInstance(controlType); ctrlStart.Location = new Point(0, 0); ctrlEnd.Location = new Point(0, ctrlStart.Height + 10); Button btnOk = new Button() { Text = "Ok", Width = 32, Height = 23 }; btnOk.Location = new Point(frmAnimate.Width - btnOk.Width - 80, ctrlStart.Height + ctrlEnd.Height + 20); btnOk.Click += (s, f) => { frmAnimate.DialogResult = DialogResult.OK; frmAnimate.Close(); }; frmAnimate.Controls.Add(btnOk); frmAnimate.Width = ctrlStart.Width + 20; frmAnimate.Height = ctrlStart.Height + ctrlEnd.Height + 85; frmAnimate.Controls.Add(ctrlStart); frmAnimate.Controls.Add(ctrlEnd); if (frmAnimate.ShowDialog() != DialogResult.OK) { return; } if (_animator == null) { _animator = new AnimationController(_generator); btnResetAnimations.Visible = true; } if (ctrlStart is ctrlFloatController) { float from = ((ctrlFloatController)ctrlStart).Value; float to = ((ctrlFloatController)ctrlEnd).Value; _animator.AddAnimation(lstValues.SelectedItems[0].Tag as FieldInfo, from, to); lstValues.SelectedItems[0].SubItems[1].Text = from + " - " + to; } else if (ctrlStart is ctrlIntController) { int from = ((ctrlIntController)ctrlStart).Value; int to = ((ctrlIntController)ctrlEnd).Value; _animator.AddAnimation(lstValues.SelectedItems[0].Tag as FieldInfo, from, to); lstValues.SelectedItems[0].SubItems[1].Text = from + " - " + to; } lstValues.SelectedItems[0].ForeColor = Color.Brown; } }
private void RenderCurrentAnimationSettings() { if (_animController == null) { if (ImGui.Button("Create Controller")) { _animController = new AnimationController(_animation); _animController.AddAnimation(new AnimationNode("Default") { EndingFrame = _animation.EndingFrame, StartingFrame = _animation.StartingFrame, LoopType = _animation.LoopType }); } int frameTime = _animation.TimeBetweenFrames; ImGui.InputInt("MS Between Frames", ref frameTime); if (frameTime != _animation.TimeBetweenFrames) { _animation.TimeBetweenFrames = frameTime; } int startingFrame = _animation.StartingFrame; ImGui.InputInt("Starting Frame", ref startingFrame); if (startingFrame != _animation.StartingFrame) { _animation.StartingFrame = startingFrame; } int endingFrame = _animation.EndingFrame; ImGui.InputInt("Ending Frame", ref endingFrame); if (endingFrame != _animation.EndingFrame) { _animation.EndingFrame = endingFrame; } var loopType = (int)_animation.LoopType; ImGui.Combo("Loop Type", ref loopType, string.Join('\0', Enum.GetNames(typeof(AnimationLoopType)))); if ((AnimationLoopType)loopType != _animation.LoopType) { _animation.LoopType = (AnimationLoopType)loopType; _animation.Reset(); } } else { ImGui.Text("Animations"); ImGui.PushID("animList"); foreach (AnimationNode n in _animController.Animations.Values) { if (n == _animController.CurrentAnimation) { ImGui.Text(n.Name); } else { if (ImGui.Button(n.Name)) { _animController.SetAnimation(n.Name); } } } if (ImGui.Button("Create") && _animController.Animations.All(x => x.Key != "NewAnim")) { var newNode = new AnimationNode("NewAnim"); _animController.AddAnimation(newNode); } ImGui.SameLine(); if (_animController.CurrentAnimation == null) { ImGui.PopID(); return; } if (ImGui.Button("Remove")) { _animController.RemoveAnimation(_animController.CurrentAnimation.Name); } ImGui.SameLine(); if (ImGui.Button("Rename")) { var newName = new StringInputModal(s => { _animController.CurrentAnimation.Name = s; _animController.Reindex(); }, $"New name for {_animController.CurrentAnimation.Name}"); Parent.AddWindow(newName); } ImGui.PopID(); AnimationNode cur = _animController.CurrentAnimation; var modified = false; int frameTime = cur.TimeBetweenFrames; ImGui.InputInt("MS Between Frames", ref frameTime); if (frameTime != cur.TimeBetweenFrames) { cur.TimeBetweenFrames = frameTime; modified = true; } int startingFrame = cur.StartingFrame; ImGui.InputInt("Starting Frame", ref startingFrame); if (startingFrame != cur.StartingFrame) { cur.StartingFrame = startingFrame; modified = true; } int endingFrame = cur.EndingFrame; ImGui.InputInt("Ending Frame", ref endingFrame); if (endingFrame != cur.EndingFrame) { cur.EndingFrame = endingFrame; modified = true; } var loopType = (int)cur.LoopType; ImGui.Combo("Loop Type", ref loopType, string.Join('\0', Enum.GetNames(typeof(AnimationLoopType)))); if ((AnimationLoopType)loopType != cur.LoopType) { cur.LoopType = (AnimationLoopType)loopType; modified = true; } if (modified) { _animController.SetAnimation(cur.Name); } } }