Ejemplo n.º 1
0
        private void PlayStandardAnim(AnimationClip clip, bool doLoop, bool reverse)
        {
            if (character == null)
            {
                return;
            }

            Animation animation = null;

            if (character.spriteChild && character.spriteChild.GetComponent <Animation>())
            {
                animation = character.spriteChild.GetComponent <Animation>();
            }
            if (character.GetComponent <Animation>())
            {
                animation = character.GetComponent <Animation>();
            }

            if (animation != null)
            {
                if (clip != null && animation[clip.name] != null)
                {
                    if (!animation [clip.name].enabled)
                    {
                        if (doLoop)
                        {
                            AdvGame.PlayAnimClip(animation, AdvGame.GetAnimLayerInt(AnimLayer.Base), clip, AnimationBlendMode.Blend, WrapMode.Loop, character.animCrossfadeSpeed, null, reverse);
                        }
                        else
                        {
                            AdvGame.PlayAnimClip(animation, AdvGame.GetAnimLayerInt(AnimLayer.Base), clip, AnimationBlendMode.Blend, WrapMode.Once, character.animCrossfadeSpeed, null, reverse);
                        }
                    }
                }
                else
                {
                    if (doLoop)
                    {
                        AdvGame.PlayAnimClip(animation, AdvGame.GetAnimLayerInt(AnimLayer.Base), clip, AnimationBlendMode.Blend, WrapMode.Loop, character.animCrossfadeSpeed, null, reverse);
                    }
                    else
                    {
                        AdvGame.PlayAnimClip(animation, AdvGame.GetAnimLayerInt(AnimLayer.Base), clip, AnimationBlendMode.Blend, WrapMode.Once, character.animCrossfadeSpeed, null, reverse);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public override void ActionSpeechRun(ActionSpeech action)
        {
            if (action.Speaker != null && action.Speaker.talkingAnimation == TalkingAnimation.CustomFace && (action.headClip || action.mouthClip))
            {
                AdvGame.CleanUnusedClips(action.Speaker.GetAnimation());

                if (action.headClip)
                {
                    AdvGame.PlayAnimClip(action.Speaker.GetAnimation(), AdvGame.GetAnimLayerInt(AnimLayer.Head), action.headClip, AnimationBlendMode.Additive, WrapMode.Once, 0f, action.Speaker.neckBone, false);
                }

                if (action.mouthClip)
                {
                    AdvGame.PlayAnimClip(action.Speaker.GetAnimation(), AdvGame.GetAnimLayerInt(AnimLayer.Mouth), action.mouthClip, AnimationBlendMode.Additive, WrapMode.Once, 0f, action.Speaker.neckBone, false);
                }
            }
        }
Ejemplo n.º 3
0
        /**
         * Initialises the Player's animation.
         */
        public void Initialise()
        {
            if (GetAnimation())
            {
                // Hack: Force idle of Legacy characters
                AdvGame.PlayAnimClip(GetAnimation(), AdvGame.GetAnimLayerInt(AnimLayer.Base), idleAnim, AnimationBlendMode.Blend, WrapMode.Loop, 0f, null, false);
            }
            else if (spriteChild)
            {
                // Hack: update 2D sprites
                InitSpriteChild();
            }
            UpdateScale();

            GetAnimEngine().TurnHead(Vector2.zero);
            GetAnimEngine().PlayIdle();
        }
Ejemplo n.º 4
0
        /**
         * Plays the AnimationClip "clip" if animatedCameraType = AnimatedCameraType.PlayWhenActive.
         */
        public void PlayClip()
        {
            if (GetComponent <Animation>() == null)
            {
                ACDebug.LogError("Cannot play animation on " + this.name + " - no Animation component is attached.");
                return;
            }

            if (clip && animatedCameraType == AnimatedCameraType.PlayWhenActive)
            {
                WrapMode wrapMode = WrapMode.Once;
                if (loopClip)
                {
                    wrapMode = WrapMode.Loop;
                }
                AdvGame.PlayAnimClip(GetComponent <Animation>(), 0, clip, AnimationBlendMode.Blend, wrapMode, 0f, null, false);
            }
        }
Ejemplo n.º 5
0
 /**
  * Initialises the Player's animation.
  */
 public void Initialise()
 {
     if (GetAnimation())
     {
         // Hack: Force idle of Legacy characters
         AdvGame.PlayAnimClip(GetAnimation(), AdvGame.GetAnimLayerInt(AnimLayer.Base), idleAnim, AnimationBlendMode.Blend, WrapMode.Loop, 0f, null, false);
     }
     else if (spriteChild)
     {
         // Hack: update 2D sprites
         if (spriteChild.GetComponent <FollowSortingMap>())
         {
             KickStarter.sceneSettings.UpdateAllSortingMaps();
         }
         UpdateSpriteChild(KickStarter.settingsManager.IsTopDown(), KickStarter.settingsManager.IsUnity2D());
     }
     GetAnimEngine().PlayIdle();
 }
Ejemplo n.º 6
0
        private void PlayStandardAnim(AnimationClip clip, bool doLoop, bool reverse)
        {
            if (character == null)
            {
                return;
            }

            Animation animation = character.GetAnimation();

            if (animation != null)
            {
                AnimationState animationState = animation[NonAllocAnimationClipName(clip)];
                if (clip != null && animationState != null)
                {
                    if (!animationState.enabled)
                    {
                        if (doLoop)
                        {
                            AdvGame.PlayAnimClip(animation, AdvGame.GetAnimLayerInt(AnimLayer.Base), clip, AnimationBlendMode.Blend, WrapMode.Loop, character.animCrossfadeSpeed, null, reverse);
                        }
                        else
                        {
                            AdvGame.PlayAnimClip(animation, AdvGame.GetAnimLayerInt(AnimLayer.Base), clip, AnimationBlendMode.Blend, WrapMode.Once, character.animCrossfadeSpeed, null, reverse);
                        }
                    }
                }
                else
                {
                    if (doLoop)
                    {
                        AdvGame.PlayAnimClip(animation, AdvGame.GetAnimLayerInt(AnimLayer.Base), clip, AnimationBlendMode.Blend, WrapMode.Loop, character.animCrossfadeSpeed, null, reverse);
                    }
                    else
                    {
                        AdvGame.PlayAnimClip(animation, AdvGame.GetAnimLayerInt(AnimLayer.Base), clip, AnimationBlendMode.Blend, WrapMode.Once, character.animCrossfadeSpeed, null, reverse);
                    }
                }
            }
        }
Ejemplo n.º 7
0
        public override float ActionAnimRun(ActionAnim action)
        {
            if (!action.isRunning)
            {
                action.isRunning = true;

                if (action.method == AnimMethod.PlayCustom && action.runtimeAnim != null && action.clip != null)
                {
                    AdvGame.CleanUnusedClips(action.runtimeAnim);

                    WrapMode wrap = WrapMode.Once;
                    if (action.playMode == AnimPlayMode.PlayOnceAndClamp)
                    {
                        wrap = WrapMode.ClampForever;
                    }
                    else if (action.playMode == AnimPlayMode.Loop)
                    {
                        wrap = WrapMode.Loop;
                    }

                    AdvGame.PlayAnimClip(action.runtimeAnim, 0, action.clip, action.blendMode, wrap, action.fadeTime, null, false);
                }

                else if (action.method == AnimMethod.StopCustom && action.runtimeAnim && action.clip)
                {
                    AdvGame.CleanUnusedClips(action.runtimeAnim);
                    action.runtimeAnim.Blend(action.clip.name, 0f, action.fadeTime);
                }

                else if (action.method == AnimMethod.BlendShape && action.shapeKey > -1)
                {
                    if (action.runtimeShapeObject != null)
                    {
                        action.runtimeShapeObject.Change(action.shapeKey, action.shapeValue, action.fadeTime);

                        if (action.willWait)
                        {
                            return(action.fadeTime);
                        }
                    }
                }

                if (action.willWait)
                {
                    return(action.defaultPauseTime);
                }
            }
            else
            {
                if (action.method == AnimMethod.PlayCustom && action.runtimeAnim && action.clip)
                {
                    if (!action.runtimeAnim.IsPlaying(action.clip.name))
                    {
                        action.isRunning = false;
                        return(0f);
                    }
                    else
                    {
                        return(action.defaultPauseTime);
                    }
                }
                else if (action.method == AnimMethod.BlendShape && action.runtimeShapeObject != null)
                {
                    action.isRunning = false;
                    return(0f);
                }
            }

            return(0f);
        }
Ejemplo n.º 8
0
        public override float ActionCharAnimRun(ActionCharAnim action)
        {
            if (character == null)
            {
                return(0f);
            }

            Animation animation = character.GetAnimation();

            if (!action.isRunning)
            {
                action.isRunning = true;

                if (action.method == ActionCharAnim.AnimMethodChar.PlayCustom && action.clip)
                {
                    AdvGame.CleanUnusedClips(animation);

                    WrapMode  wrap            = WrapMode.Once;
                    Transform mixingTransform = null;

                    if (action.layer == AnimLayer.Base)
                    {
                        character.charState = CharState.Custom;
                        action.blendMode    = AnimationBlendMode.Blend;
                        action.playMode     = (AnimPlayMode)action.playModeBase;
                    }
                    else if (action.layer == AnimLayer.UpperBody)
                    {
                        mixingTransform = character.upperBodyBone;
                    }
                    else if (action.layer == AnimLayer.LeftArm)
                    {
                        mixingTransform = character.leftArmBone;
                    }
                    else if (action.layer == AnimLayer.RightArm)
                    {
                        mixingTransform = character.rightArmBone;
                    }
                    else if (action.layer == AnimLayer.Neck || action.layer == AnimLayer.Head || action.layer == AnimLayer.Face || action.layer == AnimLayer.Mouth)
                    {
                        mixingTransform = character.neckBone;
                    }

                    if (action.playMode == AnimPlayMode.PlayOnceAndClamp)
                    {
                        wrap = WrapMode.ClampForever;
                    }
                    else if (action.playMode == AnimPlayMode.Loop)
                    {
                        wrap = WrapMode.Loop;
                    }

                    AdvGame.PlayAnimClip(animation, AdvGame.GetAnimLayerInt(action.layer), action.clip, action.blendMode, wrap, action.fadeTime, mixingTransform, false);
                }

                else if (action.method == ActionCharAnim.AnimMethodChar.StopCustom && action.clip)
                {
                    if (action.clip != character.idleAnim && action.clip != character.walkAnim)
                    {
                        animation.Blend(action.clip.name, 0f, action.fadeTime);
                    }
                }

                else if (action.method == ActionCharAnim.AnimMethodChar.ResetToIdle)
                {
                    character.ResetBaseClips();

                    character.charState = CharState.Idle;
                    AdvGame.CleanUnusedClips(animation);
                }

                else if (action.method == ActionCharAnim.AnimMethodChar.SetStandard)
                {
                    if (action.clip != null)
                    {
                        if (action.standard == AnimStandard.Idle)
                        {
                            character.idleAnim = action.clip;
                        }
                        else if (action.standard == AnimStandard.Walk)
                        {
                            character.walkAnim = action.clip;
                        }
                        else if (action.standard == AnimStandard.Run)
                        {
                            character.runAnim = action.clip;
                        }
                        else if (action.standard == AnimStandard.Talk)
                        {
                            character.talkAnim = action.clip;
                        }
                    }

                    if (action.changeSpeed)
                    {
                        if (action.standard == AnimStandard.Walk)
                        {
                            character.walkSpeedScale = action.newSpeed;
                        }
                        else if (action.standard == AnimStandard.Run)
                        {
                            character.runSpeedScale = action.newSpeed;
                        }
                    }

                    if (action.changeSound)
                    {
                        if (action.standard == AnimStandard.Walk)
                        {
                            if (action.newSound != null)
                            {
                                character.walkSound = action.newSound;
                            }
                            else
                            {
                                character.walkSound = null;
                            }
                        }
                        else if (action.standard == AnimStandard.Run)
                        {
                            if (action.newSound != null)
                            {
                                character.runSound = action.newSound;
                            }
                            else
                            {
                                character.runSound = null;
                            }
                        }
                    }
                }

                if (action.willWait && action.clip)
                {
                    if (action.method == ActionCharAnim.AnimMethodChar.PlayCustom)
                    {
                        return(action.defaultPauseTime);
                    }
                    else if (action.method == ActionCharAnim.AnimMethodChar.StopCustom)
                    {
                        return(action.fadeTime);
                    }
                }
            }

            else
            {
                if (character.GetAnimation()[action.clip.name] && character.GetAnimation()[action.clip.name].normalizedTime < 1f && character.GetAnimation().IsPlaying(action.clip.name))
                {
                    return(action.defaultPauseTime);
                }
                else
                {
                    action.isRunning = false;

                    if (action.playMode == AnimPlayMode.PlayOnce)
                    {
                        character.GetAnimation().Blend(action.clip.name, 0f, action.fadeTime);

                        if (action.layer == AnimLayer.Base && action.method == ActionCharAnim.AnimMethodChar.PlayCustom)
                        {
                            character.charState = CharState.Idle;
                            character.ResetBaseClips();
                        }
                    }

                    AdvGame.CleanUnusedClips(animation);

                    return(0f);
                }
            }

            return(0f);
        }
Ejemplo n.º 9
0
        public static void ResetPlayer(Player ref_player, int ID, bool resetReferences, Quaternion _rotation)
        {
            // Delete current player
            if (GameObject.FindWithTag(Tags.player))
            {
                DestroyImmediate(GameObject.FindWithTag(Tags.player));
            }

            // Load new player
            if (ref_player)
            {
                SettingsManager settingsManager = AdvGame.GetReferences().settingsManager;

                Player newPlayer = (Player)Instantiate(ref_player, Vector3.zero, _rotation);
                newPlayer.ID   = ID;
                newPlayer.name = ref_player.name;
                playerPrefab   = newPlayer;
                DontDestroyOnLoad(newPlayer);

                if (KickStarter.runtimeInventory)
                {
                    KickStarter.runtimeInventory.SetNull();
                    KickStarter.runtimeInventory.RemoveRecipes();

                    // Clear inventory
                    if (!settingsManager.shareInventory)
                    {
                        KickStarter.runtimeInventory.localItems.Clear();
                    }

                    if (KickStarter.saveSystem != null && KickStarter.saveSystem.DoesPlayerDataExist(ID, false))
                    {
                        saveSystem.AssignPlayerData(ID, !settingsManager.shareInventory);
                    }

                    // Menus
                    foreach (AC.Menu menu in PlayerMenus.GetMenus())
                    {
                        foreach (MenuElement element in menu.elements)
                        {
                            if (element is MenuInventoryBox)
                            {
                                MenuInventoryBox invBox = (MenuInventoryBox)element;
                                invBox.ResetOffset();
                            }
                        }
                    }
                }

                if (newPlayer.GetComponent <Animation>())
                {
                    // Hack: Force idle of Legacy characters
                    AdvGame.PlayAnimClip(newPlayer.GetComponent <Animation>(), AdvGame.GetAnimLayerInt(AnimLayer.Base), newPlayer.idleAnim, AnimationBlendMode.Blend, WrapMode.Loop, 0f, null, false);
                }
                else if (newPlayer.spriteChild)
                {
                    // Hack: update 2D sprites
                    if (newPlayer.spriteChild.GetComponent <FollowSortingMap>())
                    {
                        newPlayer.spriteChild.GetComponent <FollowSortingMap>().UpdateSortingMap();
                    }
                    newPlayer.UpdateSpriteChild(settingsManager.IsTopDown(), settingsManager.IsUnity2D());
                }
                newPlayer.animEngine.PlayIdle();
            }

            // Reset player references
            if (resetReferences)
            {
                KickStarter.sceneSettings.ResetPlayerReference();
                KickStarter.playerMovement.AssignFPCamera();
                KickStarter.stateHandler.IgnoreNavMeshCollisions();
                KickStarter.stateHandler.GatherObjects(false);
                _Camera[] cameras = FindObjectsOfType(typeof(_Camera)) as _Camera[];
                foreach (_Camera camera in cameras)
                {
                    camera.ResetTarget();
                }
            }
        }