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; }
private PlayerData SavePlayerData(Player player) { PlayerData playerData = new PlayerData (); playerData.currentScene = Application.loadedLevel; playerData.currentSceneName = Application.loadedLevelName; playerData.previousScene = KickStarter.sceneChanger.previousScene; playerData.previousSceneName = KickStarter.sceneChanger.previousSceneName; playerData.playerUpLock = KickStarter.playerInput.isUpLocked; playerData.playerDownLock = KickStarter.playerInput.isDownLocked; playerData.playerLeftlock = KickStarter.playerInput.isLeftLocked; playerData.playerRightLock = KickStarter.playerInput.isRightLocked; playerData.playerRunLock = (int) KickStarter.playerInput.runLock; playerData.playerFreeAimLock = KickStarter.playerInput.freeAimLock; KickStarter.runtimeInventory.RemoveRecipes (); playerData.inventoryData = CreateInventoryData (KickStarter.runtimeInventory.localItems); if (player == null) { playerData.playerPortraitGraphic = ""; playerData.playerID = KickStarter.settingsManager.GetEmptyPlayerID (); return playerData; } playerData.playerID = player.ID; playerData.playerLocX = player.transform.position.x; playerData.playerLocY = player.transform.position.y; playerData.playerLocZ = player.transform.position.z; playerData.playerRotY = player.transform.eulerAngles.y; playerData.playerWalkSpeed = player.walkSpeedScale; playerData.playerRunSpeed = player.runSpeedScale; // Animation clips if (player.animationEngine == AnimationEngine.Sprites2DToolkit || player.animationEngine == AnimationEngine.SpritesUnity) { playerData.playerIdleAnim = player.idleAnimSprite; playerData.playerWalkAnim = player.walkAnimSprite; playerData.playerRunAnim = player.runAnimSprite; playerData.playerTalkAnim = player.talkAnimSprite; } else if (player.animationEngine == AnimationEngine.Legacy) { playerData.playerIdleAnim = AssetLoader. GetAssetInstanceID (player.idleAnim); playerData.playerWalkAnim = AssetLoader. GetAssetInstanceID (player.walkAnim); playerData.playerRunAnim = AssetLoader. GetAssetInstanceID (player.runAnim); playerData.playerTalkAnim = AssetLoader. GetAssetInstanceID (player.talkAnim); } else if (player.animationEngine == AnimationEngine.Mecanim) { playerData.playerWalkAnim = player.moveSpeedParameter; playerData.playerTalkAnim = player.talkParameter; playerData.playerRunAnim = player.turnParameter; } // Sound playerData.playerWalkSound = AssetLoader. GetAssetInstanceID (player.walkSound); playerData.playerRunSound = AssetLoader. GetAssetInstanceID (player.runSound); // Portrait graphic playerData.playerPortraitGraphic = AssetLoader. GetAssetInstanceID (player.portraitIcon.texture); playerData.playerSpeechLabel = player.speechLabel; // Rendering playerData.playerLockDirection = player.lockDirection; playerData.playerLockScale = player.lockScale; if (player.spriteChild && player.spriteChild.GetComponent <FollowSortingMap>()) { playerData.playerLockSorting = player.spriteChild.GetComponent <FollowSortingMap>().lockSorting; } else if (player.GetComponent <FollowSortingMap>()) { playerData.playerLockSorting = player.GetComponent <FollowSortingMap>().lockSorting; } else { playerData.playerLockSorting = false; } playerData.playerSpriteDirection = player.spriteDirection; playerData.playerSpriteScale = player.spriteScale; if (player.spriteChild && player.spriteChild.GetComponent <Renderer>()) { playerData.playerSortingOrder = player.spriteChild.GetComponent <Renderer>().sortingOrder; playerData.playerSortingLayer = player.spriteChild.GetComponent <Renderer>().sortingLayerName; } else if (player.GetComponent <Renderer>()) { playerData.playerSortingOrder = player.GetComponent <Renderer>().sortingOrder; playerData.playerSortingLayer = player.GetComponent <Renderer>().sortingLayerName; } playerData.playerActivePath = 0; playerData.lastPlayerActivePath = 0; if (player.GetPath (true)) { playerData.playerTargetNode = player.GetTargetNode (true); playerData.playerPrevNode = player.GetPrevNode (true); playerData.playerIsRunning = player.isRunning; playerData.playerPathAffectY = player.activePath.affectY; if (player.GetComponent <Paths>() && player.GetPath (true) == player.GetComponent <Paths>()) { playerData.playerPathData = Serializer.CreatePathData (player.GetComponent <Paths>()); playerData.playerLockedPath = false; } else { playerData.playerPathData = ""; playerData.playerActivePath = Serializer.GetConstantID (player.GetPath (true).gameObject); playerData.playerLockedPath = player.lockedPath; } } if (player.GetPath (false)) { playerData.lastPlayerTargetNode = player.GetTargetNode (false); playerData.lastPlayerPrevNode = player.GetPrevNode (false); playerData.lastPlayerActivePath = Serializer.GetConstantID (player.GetPath (false).gameObject); } playerData.playerIgnoreGravity = player.ignoreGravity; // Head target playerData.playerLockHotspotHeadTurning = player.lockHotspotHeadTurning; if (player.headFacing == HeadFacing.Manual) { playerData.isHeadTurning = true; playerData.headTargetX = player.headTurnTarget.x; playerData.headTargetY = player.headTurnTarget.y; playerData.headTargetZ = player.headTurnTarget.z; } else { playerData.isHeadTurning = false; playerData.headTargetX = 0f; playerData.headTargetY = 0f; playerData.headTargetZ = 0f; } // Camera MainCamera mainCamera = KickStarter.mainCamera; if (mainCamera.attachedCamera) { playerData.gameCamera = Serializer.GetConstantID (mainCamera.attachedCamera.gameObject); } if (mainCamera.lastNavCamera) { playerData.lastNavCamera = Serializer.GetConstantID (mainCamera.lastNavCamera.gameObject); } if (mainCamera.lastNavCamera2) { playerData.lastNavCamera2 = Serializer.GetConstantID (mainCamera.lastNavCamera2.gameObject); } mainCamera.StopShaking (); playerData.mainCameraLocX = mainCamera.transform.position.x; playerData.mainCameraLocY = mainCamera.transform.position.y; playerData.mainCameraLocZ = mainCamera.transform.position.z; playerData.mainCameraRotX = mainCamera.transform.eulerAngles.x; playerData.mainCameraRotY = mainCamera.transform.eulerAngles.y; playerData.mainCameraRotZ = mainCamera.transform.eulerAngles.z; playerData.isSplitScreen = mainCamera.isSplitScreen; if (mainCamera.isSplitScreen) { playerData.isTopLeftSplit = mainCamera.isTopLeftSplit; playerData.splitAmountMain = mainCamera.splitAmountMain; playerData.splitAmountOther = mainCamera.splitAmountOther; if (mainCamera.splitOrientation == MenuOrientation.Vertical) { playerData.splitIsVertical = true; } else { playerData.splitIsVertical = false; } if (mainCamera.splitCamera && mainCamera.splitCamera.GetComponent <ConstantID>()) { playerData.splitCameraID = mainCamera.splitCamera.GetComponent <ConstantID>().constantID; } else { playerData.splitCameraID = 0; } } return playerData; }
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(); } } }