Exemplo n.º 1
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();
                }
            }
        }