コード例 #1
0
        private void EnableAnimation(string animationName, bool?enabled)
        {
            if (enabled.HasValue)
            {
                var animation = GetUnityAnimationComponent();
                if (animation)
                {
                    if (animation[animationName] != null)
                    {
                        var animState  = animation[animationName];
                        var wasEnabled = animState.enabled;
                        if (wasEnabled != enabled.Value)
                        {
                            animation[animationName].enabled = enabled.Value;
                            // NOTE: animationData.Enabled will be set in the next call to Update()

                            // When stopping an animation, send an update to the app letting it know the final animation state.
                            if (!enabled.Value && (AttachedActor.App.IsAuthoritativePeer || AttachedActor.App.OperatingModel == OperatingModel.ServerAuthoritative))
                            {
                                // FUTURE: Add additional animatable properties as support for them is added (light color, etc).
                                AttachedActor.SendActorUpdate(ActorComponentType.Transform);
                            }
                        }
                        animation[animationName].weight = enabled.Value ? 1.0f : 0.0f;
                    }
                }
            }
        }
コード例 #2
0
        private void EnableAnimation(string animationName, bool?enabled)
        {
            if (enabled.HasValue)
            {
                var animationPlayer = GetGodotAnimationPlayer(animationName);
                if (animationPlayer != null)
                {
                    var animation  = animationPlayer.GetAnimation(animationName);
                    var wasEnabled = animationPlayer.PlaybackActive;
                    if (wasEnabled != enabled.Value)
                    {
                        animationPlayer.PlaybackActive = enabled.Value;
                        // NOTE: animationData.Enabled will be set in the next call to Update()

                        // When stopping an animation, send an update to the app letting it know the final animation state.
                        if (!enabled.Value && (AttachedActor.App.IsAuthoritativePeer || AttachedActor.App.OperatingModel == OperatingModel.ServerAuthoritative))
                        {
                            // FUTURE: Add additional animatable properties as support for them is added (light color, etc).
                            AttachedActor.SendActorUpdate(ActorComponentType.Transform);
                        }
                    }
                    if (enabled.Value)
                    {
                        animationPlayer.Play();
                    }
                }
            }
        }
コード例 #3
0
        public override void _Process(float delta)
        {
            // Check for changes to an animation's enabled state and notify the server when a change is detected.
            if (_animationPlayers.Count == 0)
            {
                return;
            }

            foreach (var animationPlayer in _animationPlayers.Values)
            {
                if (!GetAnimationData(animationPlayer.Name, out AnimationData animationData) ||
                    animationData.Managed ||
                    animationData.Enabled == animationPlayer.PlaybackActive
                    )
                {
                    continue;
                }

                animationData.Enabled = animationPlayer.PlaybackActive;

                // Let the app know this animation (or interpolation) changed state.
                NotifySetAnimationStateEvent(
                    animationPlayer.Name,
                    animationTime: null,
                    animationSpeed: null,
                    animationEnabled: animationData.Enabled);

                // If the animation stopped, sync the actor's final transform.
                if (!animationData.Enabled)
                {
                    AttachedActor.SynchronizeApp(ActorComponentType.Transform);
                }

                // If this was an internal one-shot animation (aka an interpolation), remove it.
                if (!animationData.Enabled && animationData.IsInternal)
                {
                    _animationData.Remove(animationPlayer.Name);
                    GD.Print(animationPlayer.Name);
                    this.RemoveChild(animationPlayer);
                    animationPlayer.QueueFree();
                    _animationPlayers.Remove(animationPlayer.Name);
                }
            }
        }
コード例 #4
0
        private void Update()
        {
            // Check for changes to an animation's enabled state and notify the server when a change is detected.
            var animation = GetUnityAnimationComponent();

            if (animation == null)
            {
                return;
            }

            foreach (AnimationState animationState in animation)
            {
                if (!GetAnimationData(animationState.name, out AnimationData animationData) ||
                    animationData.Managed ||
                    animationData.Enabled == animationState.enabled
                    )
                {
                    continue;
                }

                animationData.Enabled = animationState.enabled;

                // Let the app know this animation (or interpolation) changed state.
                NotifySetAnimationStateEvent(
                    animationState.name,
                    animationTime: null,
                    animationSpeed: null,
                    animationEnabled: animationData.Enabled);

                // If the animation stopped, sync the actor's final transform.
                if (!animationData.Enabled)
                {
                    AttachedActor.SynchronizeApp(ActorComponentType.Transform);
                }

                // If this was an internal one-shot animation (aka an interpolation), remove it.
                if (!animationData.Enabled && animationData.IsInternal)
                {
                    _animationData.Remove(animationState.name);
                    animation.RemoveClip(animationState.clip);
                }
            }
        }