Beispiel #1
0
        private void ReturnPlayerData(PlayerData playerData, Player player)
        {
            if (player == null)
            {
                return;
            }

            player.Teleport (new Vector3 (playerData.playerLocX, playerData.playerLocY, playerData.playerLocZ));
            player.SetRotation (playerData.playerRotY);
            //player.SetLookDirection (Vector3.zero, true);

            player.walkSpeedScale = playerData.playerWalkSpeed;
            player.runSpeedScale = playerData.playerRunSpeed;

            // Animation clips
            if (player.animationEngine == AnimationEngine.Sprites2DToolkit || player.animationEngine == AnimationEngine.SpritesUnity)
            {
                player.idleAnimSprite = playerData.playerIdleAnim;
                player.walkAnimSprite = playerData.playerWalkAnim;
                player.talkAnimSprite = playerData.playerTalkAnim;
                player.runAnimSprite = playerData.playerRunAnim;
            }
            else if (player.animationEngine == AnimationEngine.Legacy)
            {
                player.idleAnim = AssetLoader.RetrieveAsset <AnimationClip> (player.idleAnim, playerData.playerIdleAnim);
                player.walkAnim = AssetLoader.RetrieveAsset <AnimationClip> (player.walkAnim, playerData.playerWalkAnim);
                player.talkAnim = AssetLoader.RetrieveAsset <AnimationClip> (player.talkAnim, playerData.playerTalkAnim);
                player.runAnim = AssetLoader.RetrieveAsset <AnimationClip> (player.runAnim, playerData.playerRunAnim);
            }
            else if (player.animationEngine == AnimationEngine.Mecanim)
            {
                player.moveSpeedParameter = playerData.playerWalkAnim;
                player.talkParameter = playerData.playerTalkAnim;
                player.turnParameter = playerData.playerRunAnim;
            }

            // Sound
            player.walkSound = AssetLoader.RetrieveAsset (player.walkSound, playerData.playerWalkSound);
            player.runSound = AssetLoader.RetrieveAsset (player.runSound, playerData.playerRunSound);

            // Portrait graphic
            player.portraitIcon.texture = AssetLoader.RetrieveAsset (player.portraitIcon.texture, playerData.playerPortraitGraphic);
            player.speechLabel = playerData.playerSpeechLabel;

            // Rendering
            player.lockDirection = playerData.playerLockDirection;
            player.lockScale = playerData.playerLockScale;
            if (player.spriteChild && player.spriteChild.GetComponent <FollowSortingMap>())
            {
                player.spriteChild.GetComponent <FollowSortingMap>().lockSorting = playerData.playerLockSorting;
            }
            else if (player.GetComponent <FollowSortingMap>())
            {
                player.GetComponent <FollowSortingMap>().lockSorting = playerData.playerLockSorting;
            }
            else
            {
                player.ReleaseSorting ();
            }

            if (playerData.playerLockDirection)
            {
                player.spriteDirection = playerData.playerSpriteDirection;
            }
            if (playerData.playerLockScale)
            {
                player.spriteScale = playerData.playerSpriteScale;
            }
            if (playerData.playerLockSorting)
            {
                if (player.spriteChild && player.spriteChild.GetComponent <Renderer>())
                {
                    player.spriteChild.GetComponent <Renderer>().sortingOrder = playerData.playerSortingOrder;
                    player.spriteChild.GetComponent <Renderer>().sortingLayerName = playerData.playerSortingLayer;
                }
                else if (player.GetComponent <Renderer>())
                {
                    player.GetComponent <Renderer>().sortingOrder = playerData.playerSortingOrder;
                    player.GetComponent <Renderer>().sortingLayerName = playerData.playerSortingLayer;
                }
            }

            // Active path
            player.Halt ();
            player.ForceIdle ();

            if (playerData.playerPathData != null && playerData.playerPathData != "" && player.GetComponent <Paths>())
            {
                Paths savedPath = player.GetComponent <Paths>();
                savedPath = Serializer.RestorePathData (savedPath, playerData.playerPathData);
                player.SetPath (savedPath, playerData.playerTargetNode, playerData.playerPrevNode, playerData.playerPathAffectY);
                player.isRunning = playerData.playerIsRunning;
                player.lockedPath = false;
            }
            else if (playerData.playerActivePath != 0)
            {
                Paths savedPath = Serializer.returnComponent <Paths> (playerData.playerActivePath);
                if (savedPath)
                {
                    player.lockedPath = playerData.playerLockedPath;

                    if (player.lockedPath)
                    {
                        player.SetLockedPath (savedPath);
                    }
                    else
                    {
                        player.SetPath (savedPath, playerData.playerTargetNode, playerData.playerPrevNode);
                    }
                }
            }

            // Previous path
            if (playerData.lastPlayerActivePath != 0)
            {
                Paths savedPath = Serializer.returnComponent <Paths> (playerData.lastPlayerActivePath);
                if (savedPath)
                {
                    player.SetLastPath (savedPath, playerData.lastPlayerTargetNode, playerData.lastPlayerPrevNode);
                }
            }

            // Head target
            player.lockHotspotHeadTurning = playerData.playerLockHotspotHeadTurning;
            if (playerData.isHeadTurning)
            {
                player.SetHeadTurnTarget (new Vector3 (playerData.headTargetX, playerData.headTargetY, playerData.headTargetZ), true);
            }
            else
            {
                player.ClearHeadTurnTarget (true);
            }

            player.ignoreGravity = playerData.playerIgnoreGravity;
        }