Beispiel #1
0
        public void ChangeScene(string sceneName, int sceneNumber, bool saveRoomData)
        {
            bool useLoadingScreen = false;
            if (KickStarter.settingsManager != null && KickStarter.settingsManager.useLoadingScreen)
            {
                useLoadingScreen = true;
            }

            KickStarter.mainCamera.FadeOut (0f);

            if (KickStarter.player)
            {
                KickStarter.player.Halt ();

                if (KickStarter.settingsManager.movementMethod == MovementMethod.UltimateFPS)
                {
                    UltimateFPSIntegration.SetCameraEnabled (false, true);
                }
            }

            Sound[] sounds = FindObjectsOfType (typeof (Sound)) as Sound[];
            foreach (Sound sound in sounds)
            {
                if (sound.canDestroy)
                {
                    if (sound.GetComponent <RememberSound>())
                    {
                        DestroyImmediate (sound.GetComponent <RememberSound>());
                    }
                    DestroyImmediate (sound);
                }
            }

            KickStarter.playerMenus.ClearParents ();
            KickStarter.dialog.KillDialog (true, true);

            if (saveRoomData)
            {
                KickStarter.levelStorage.StoreCurrentLevelData ();
                previousScene = Application.loadedLevel;
                previousSceneName = Application.loadedLevelName;
            }

            KickStarter.stateHandler.gameState = GameState.Normal;
            playerOnTransition = KickStarter.player;

            LoadLevel (sceneName, sceneNumber, useLoadingScreen);
        }
Beispiel #2
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.playerSwitching == PlayerSwitching.Allow && !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 ();
                }
            }
        }
        /**
         * The default Constructor.
         * An array of ID numbers is required, to ensure it's own ID is unique.
         */
        public PlayerPrefab(int[] idArray)
        {
            ID = 0;
            playerOb = null;

            if (idArray.Length > 0)
            {
                isDefault = false;

                foreach (int _id in idArray)
                {
                    if (ID == _id)
                        ID ++;
                }
            }
            else
            {
                isDefault = true;
            }
        }
		private void Awake ()
		{
			// Test for key imports
			References references = (References) Resources.Load (Resource.references);
			if (references)
			{
				SceneManager sceneManager = AdvGame.GetReferences ().sceneManager;
				SettingsManager settingsManager = AdvGame.GetReferences ().settingsManager;
				ActionsManager actionsManager = AdvGame.GetReferences ().actionsManager;
				InventoryManager inventoryManager = AdvGame.GetReferences ().inventoryManager;
				VariablesManager variablesManager = AdvGame.GetReferences ().variablesManager;
				SpeechManager speechManager = AdvGame.GetReferences ().speechManager;
				CursorManager cursorManager = AdvGame.GetReferences ().cursorManager;
				MenuManager menuManager = AdvGame.GetReferences ().menuManager;
				
				if (sceneManager == null)
				{
					Debug.LogError ("No Scene Manager found - please set one using the Adventure Creator Kit wizard");
				}
				
				if (settingsManager == null)
				{
					Debug.LogError ("No Settings Manager found - please set one using the Adventure Creator Kit wizard");
				}
				else
				{
					if (settingsManager.IsInLoadingScene ())
					{
						Debug.Log ("Bypassing regular AC startup because the current scene is the 'Loading' scene.");
						return;
					}
					if (!GameObject.FindGameObjectWithTag (Tags.player))
					{
						KickStarter.ResetPlayer (settingsManager.GetDefaultPlayer (), settingsManager.GetDefaultPlayerID (), false, Quaternion.identity);
					}
					else
					{
						KickStarter.playerPrefab = GameObject.FindWithTag (Tags.player).GetComponent <Player>();
					}

					Physics.IgnoreLayerCollision (LayerMask.NameToLayer(settingsManager.navMeshLayer), LayerMask.NameToLayer(settingsManager.hotspotLayer));
					Physics.IgnoreLayerCollision (LayerMask.NameToLayer(settingsManager.navMeshLayer), LayerMask.NameToLayer(settingsManager.deactivatedLayer));
					Physics.IgnoreLayerCollision (LayerMask.NameToLayer(settingsManager.navMeshLayer), LayerMask.NameToLayer(settingsManager.backgroundImageLayer));

					Physics2D.IgnoreLayerCollision (LayerMask.NameToLayer(settingsManager.navMeshLayer), LayerMask.NameToLayer(settingsManager.hotspotLayer));
					Physics2D.IgnoreLayerCollision (LayerMask.NameToLayer(settingsManager.navMeshLayer), LayerMask.NameToLayer(settingsManager.deactivatedLayer));
					Physics2D.IgnoreLayerCollision (LayerMask.NameToLayer(settingsManager.navMeshLayer), LayerMask.NameToLayer(settingsManager.backgroundImageLayer));
				}
				
				if (actionsManager == null)
				{
					Debug.LogError ("No Actions Manager found - please set one using the main Adventure Creator window");
				}
				
				if (inventoryManager == null)
				{
					Debug.LogError ("No Inventory Manager found - please set one using the main Adventure Creator window");
				}
				
				if (variablesManager == null)
				{
					Debug.LogError ("No Variables Manager found - please set one using the main Adventure Creator window");
				}
				
				if (speechManager == null)
				{
					Debug.LogError ("No Speech Manager found - please set one using the main Adventure Creator window");
				}

				if (cursorManager == null)
				{
					Debug.LogError ("No Cursor Manager found - please set one using the main Adventure Creator window");
				}

				if (menuManager == null)
				{
					Debug.LogError ("No Menu Manager found - please set one using the main Adventure Creator window");
				}
				
				if (GameObject.FindWithTag (Tags.player) == null)
				{
					Debug.LogWarning ("No Player found - please set one using the Settings Manager, tagging it as Player and placing it in a Resources folder");
				}
				
			}
			else
			{
				Debug.LogError ("No References object found. Please set one using the main Adventure Creator window");
			}

			if (!GameObject.FindGameObjectWithTag (Tags.persistentEngine))
			{
				try
				{
					GameObject persistentEngine = (GameObject) Instantiate (Resources.Load (Resource.persistentEngine));
					persistentEngine.name = AdvGame.GetName (Resource.persistentEngine);
				}
				catch {}
			}

			if (GameObject.FindWithTag (Tags.persistentEngine) == null)
			{
				Debug.LogError ("No PersistentEngine prefab found - please place one in the Resources directory, and tag it as PersistentEngine");
			}
			else
			{
				GameObject persistentEngine = GameObject.FindWithTag (Tags.persistentEngine);
				
				if (persistentEngine.GetComponent <Options>() == null)
				{
					Debug.LogError (persistentEngine.name + " has no Options component attached.");
				}
				if (persistentEngine.GetComponent <RuntimeInventory>() == null)
				{
					Debug.LogError (persistentEngine.name + " has no RuntimeInventory component attached.");
				}
				if (persistentEngine.GetComponent <RuntimeVariables>() == null)
				{
					Debug.LogError (persistentEngine.name + " has no RuntimeVariables component attached.");
				}
				if (persistentEngine.GetComponent <PlayerMenus>() == null)
				{
					Debug.LogError (persistentEngine.name + " has no PlayerMenus component attached.");
				}
				if (persistentEngine.GetComponent <StateHandler>() == null)
				{
					Debug.LogError (persistentEngine.name + " has no StateHandler component attached.");
				}
				if (persistentEngine.GetComponent <SceneChanger>() == null)
				{
					Debug.LogError (persistentEngine.name + " has no SceneChanger component attached.");
				}
				if (persistentEngine.GetComponent <SaveSystem>() == null)
				{
					Debug.LogError (persistentEngine.name + " has no SaveSystem component attached.");
				}
				if (persistentEngine.GetComponent <LevelStorage>() == null)
				{
					Debug.LogError (persistentEngine.name + " has no LevelStorage component attached.");
				}
			}
			
			if (GameObject.FindWithTag (Tags.mainCamera) == null)
			{
				Debug.LogError ("No MainCamera found - please click 'Organise room objects' in the Scene Manager to create one.");
			}
			else
			{
				if (GameObject.FindWithTag (Tags.mainCamera).GetComponent <MainCamera>() == null)
				{
					Debug.LogError ("MainCamera has no MainCamera component.");
				}
			}
			
			if (this.tag == Tags.gameEngine)
			{
				if (this.GetComponent <MenuSystem>() == null)
				{
					Debug.LogError (this.name + " has no MenuSystem component attached.");
				}
				if (this.GetComponent <Dialog>() == null)
				{
					Debug.LogError (this.name + " has no Dialog component attached.");
				}
				if (this.GetComponent <PlayerInput>() == null)
				{
					Debug.LogError (this.name + " has no PlayerInput component attached.");
				}
				if (this.GetComponent <PlayerInteraction>() == null)
				{
					Debug.LogError (this.name + " has no PlayerInteraction component attached.");
				}
				if (this.GetComponent <PlayerMovement>() == null)
				{
					Debug.LogError (this.name + " has no PlayerMovement component attached.");
				}
				if
					(this.GetComponent <PlayerCursor>() == null)
				{
					Debug.LogError (this.name + " has no PlayerCursor component attached.");
				}
				if (this.GetComponent <SceneSettings>() == null)
				{
					Debug.LogError (this.name + " has no SceneSettings component attached.");
				}
				else
				{
					if (this.GetComponent <SceneSettings>().navigationMethod == AC_NavigationMethod.meshCollider && this.GetComponent <SceneSettings>().navMesh == null)
					{
						Debug.LogWarning ("No NavMesh set.  Characters will not be able to PathFind until one is defined - please choose one using the Scene Manager.");
					}
					
					if (this.GetComponent <SceneSettings>().defaultPlayerStart == null)
					{
						Debug.LogWarning ("No default PlayerStart set.  The game may not be able to begin if one is not defined - please choose one using the Scene Manager.");
					}
				}
				if (this.GetComponent <NavigationManager>() == null)
				{
					Debug.LogError (this.name + " has no NavigationManager component attached.");
				}
				if (this.GetComponent <ActionListManager>() == null)
				{
					Debug.LogError (this.name + " has no ActionListManager component attached.");
				}
			}
		}
Beispiel #5
0
        private void CreatePlayersGUI()
        {
            playerSwitching = (PlayerSwitching) EditorGUILayout.EnumPopup ("Player switching:", playerSwitching);
            if (playerSwitching == PlayerSwitching.DoNotAllow)
            {
                player = (Player) EditorGUILayout.ObjectField ("Player:", player, typeof (Player), false);
            }
            else
            {
                shareInventory = EditorGUILayout.Toggle ("Share same Inventory?", shareInventory);

                foreach (PlayerPrefab _player in players)
                {
                    EditorGUILayout.BeginHorizontal ();

                    _player.playerOb = (Player) EditorGUILayout.ObjectField ("Player " + _player.ID + ":", _player.playerOb, typeof (Player), false);

                    if (_player.isDefault)
                    {
                        GUILayout.Label ("DEFAULT", EditorStyles.boldLabel, GUILayout.Width (80f));
                    }
                    else
                    {
                        if (GUILayout.Button ("Make default", GUILayout.Width (80f)))
                        {
                            SetDefaultPlayer (_player);
                        }
                    }

                    if (GUILayout.Button (deleteContent, EditorStyles.miniButtonRight, buttonWidth))
                    {
                        Undo.RecordObject (this, "Delete player reference");
                        players.Remove (_player);
                        break;
                    }

                    EditorGUILayout.EndHorizontal ();
                }

                if (GUILayout.Button("Add new player"))
                {
                    Undo.RecordObject (this, "Add player");

                    PlayerPrefab newPlayer = new PlayerPrefab (GetPlayerIDArray ());
                    players.Add (newPlayer);
                }
            }
        }
Beispiel #6
0
        /**
         * <summary>Unsets the values of all script variables, so that they can be re-assigned to the correct scene if multiple scenes are open.</summary>
         */
        public void ClearVariables()
        {
            playerPrefab = null;
            mainCameraPrefab = null;
            persistentEnginePrefab = null;
            gameEnginePrefab = null;

            // Managers
            sceneManagerPrefab = null;
            settingsManagerPrefab = null;
            actionsManagerPrefab = null;
            variablesManagerPrefab = null;
            inventoryManagerPrefab = null;
            speechManagerPrefab = null;
            cursorManagerPrefab = null;
            menuManagerPrefab = null;

            // PersistentEngine components
            optionsComponent = null;
            runtimeInventoryComponent = null;
            runtimeVariablesComponent = null;
            playerMenusComponent = null;
            stateHandlerComponent = null;
            sceneChangerComponent = null;
            saveSystemComponent = null;
            levelStorageComponent = null;
            runtimeLanguagesComponent = null;

            // GameEngine components
            menuSystemComponent = null;
            dialogComponent = null;
            playerInputComponent = null;
            playerInteractionComponent = null;
            playerMovementComponent = null;
            playerCursorComponent = null;
            playerQTEComponent = null;
            sceneSettingsComponent = null;
            navigationManagerComponent = null;
            actionListManagerComponent = null;
            localVariablesComponent = null;
            menuPreviewComponent = null;

            SetGameEngine ();
        }
Beispiel #7
0
        private void PrepareSceneForExit(bool isInstant, bool saveRoomData)
        {
            if (isInstant)
            {
                KickStarter.mainCamera.FadeOut (0f);

                if (KickStarter.player)
                {
                    KickStarter.player.Halt ();
                }

                KickStarter.stateHandler.gameState = GameState.Normal;
            }

            Sound[] sounds = FindObjectsOfType (typeof (Sound)) as Sound[];
            foreach (Sound sound in sounds)
            {
                sound.TryDestroy ();
            }
            KickStarter.stateHandler.GatherObjects ();

            KickStarter.playerMenus.ClearParents ();
            if (KickStarter.dialog)
            {
                KickStarter.dialog.KillDialog (true, true);
            }

            if (saveRoomData)
            {
                KickStarter.levelStorage.StoreCurrentLevelData ();
                previousSceneInfo = new SceneInfo ();
            }

            playerOnTransition = KickStarter.player;
        }
Beispiel #8
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;
        }
Beispiel #9
0
        private PlayerData SavePlayerData(Player player)
        {
            PlayerData playerData = new PlayerData ();

            playerData.currentScene = UnityVersionHandler.GetCurrentSceneNumber ();
            playerData.currentSceneName = UnityVersionHandler.GetCurrentSceneName ();

            playerData.previousScene = KickStarter.sceneChanger.previousSceneInfo.number;
            playerData.previousSceneName = KickStarter.sceneChanger.previousSceneInfo.name;

            playerData = KickStarter.playerInput.SavePlayerData (playerData);

            KickStarter.runtimeInventory.RemoveRecipes ();
            playerData.inventoryData = CreateInventoryData (KickStarter.runtimeInventory.localItems);

            // 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;
                }
            }

            if (player == null)
            {
                playerData.playerPortraitGraphic = "";
                playerData.playerID = KickStarter.settingsManager.GetEmptyPlayerID ();
                return playerData;
            }

            playerData = player.SavePlayerData (playerData);

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

            player.LoadPlayerData (playerData);
        }
Beispiel #11
0
        /**
         * Ends all skippable ActionLists.
         * This is triggered when the user presses the "EndCutscene" Input button.
         */
        public void EndCutscene()
        {
            if (!IsInSkippableCutscene())
            {
                return;
            }

            if (AdvGame.GetReferences().settingsManager.blackOutWhenSkipping)
            {
                KickStarter.mainCamera.HideScene();
            }

            // Stop all non-looping sound
            Sound[] sounds = FindObjectsOfType(typeof(Sound)) as Sound[];
            foreach (Sound sound in sounds)
            {
                if (sound.GetComponent <AudioSource>())
                {
                    if (sound.soundType != SoundType.Music && !sound.GetComponent <AudioSource>().loop)
                    {
                        sound.Stop();
                    }
                }
            }

            // Set correct Player prefab before skipping
            if (KickStarter.settingsManager.playerSwitching == PlayerSwitching.Allow)
            {
                if (KickStarter.player != null && !noPlayerOnStartQueue && playerIDOnStartQueue != KickStarter.player.ID && playerIDOnStartQueue >= 0)
                {
                    Player playerToRevertTo = KickStarter.settingsManager.GetPlayer(playerIDOnStartQueue);
                    KickStarter.ResetPlayer(playerToRevertTo, playerIDOnStartQueue, true, Quaternion.identity, false, true);
                }
                else if (KickStarter.player != null && noPlayerOnStartQueue)
                {
                    KickStarter.ResetPlayer(null, KickStarter.settingsManager.GetEmptyPlayerID(), true, Quaternion.identity, false, true);
                }
                else if (KickStarter.player == null && !noPlayerOnStartQueue && playerIDOnStartQueue >= 0)
                {
                    Player playerToRevertTo = KickStarter.settingsManager.GetPlayer(playerIDOnStartQueue);
                    KickStarter.ResetPlayer(playerToRevertTo, playerIDOnStartQueue, true, Quaternion.identity, false, true);
                }
            }

            for (int i = 0; i < activeLists.Count; i++)
            {
                if (!activeLists[i].inSkipQueue && activeLists[i].actionList.IsSkippable())
                {
                    // Kill, but do isolated, to bypass setting GameState etc
                    activeLists[i].Reset(true);
                }
                else
                {
                    activeLists[i].Skip();
                }
            }

            for (int i = 0; i < KickStarter.actionListAssetManager.activeLists.Count; i++)
            {
                if (!KickStarter.actionListAssetManager.activeLists[i].inSkipQueue && KickStarter.actionListAssetManager.activeLists[i].actionList.IsSkippable())
                {
                    // Kill, but do isolated, to bypass setting GameState etc
                    KickStarter.actionListAssetManager.activeLists[i].Reset(true);
                }
                else
                {
                    KickStarter.actionListAssetManager.activeLists[i].Skip();
                }
            }
        }
        private void PrepareSceneForExit(bool isInstant, bool saveRoomData)
        {
            if (isInstant)
            {
                KickStarter.mainCamera.FadeOut (0f);

                if (KickStarter.player)
                {
                    KickStarter.player.Halt ();

                    if (KickStarter.settingsManager.movementMethod == MovementMethod.UltimateFPS)
                    {
                        UltimateFPSIntegration.SetCameraEnabled (false, true);
                    }
                }

                KickStarter.stateHandler.gameState = GameState.Normal;
            }

            Sound[] sounds = FindObjectsOfType (typeof (Sound)) as Sound[];
            foreach (Sound sound in sounds)
            {
                sound.TryDestroy ();
            }
            KickStarter.stateHandler.GatherObjects ();

            KickStarter.playerMenus.ClearParents ();
            if (KickStarter.dialog)
            {
                KickStarter.dialog.KillDialog (true, true);
            }

            if (saveRoomData)
            {
                KickStarter.levelStorage.StoreCurrentLevelData ();
                previousSceneInfo = new SceneInfo (Application.loadedLevelName, Application.loadedLevel);
            }

            playerOnTransition = KickStarter.player;
        }
        private void Start()
        {
            #if !UltimateFPSIsPresent

            ACDebug.LogWarning ("'UltimateFPSIsPresent' must be listed in your Unity Player Setting's 'Scripting define symbols' for AC's UFPS integration to work.");
            return;

            #else

            // Assign the UFPS components, and report warnings if they are not present
            fpCamera = GetComponentInChildren <vp_FPCamera>();
            fpController = GetComponentInChildren <vp_FPController>();
            fpInput = GetComponentInChildren <vp_FPInput>();
            _audioListener = GetComponentInChildren <AudioListener>();

            if (fpController == null)
            {
                ACDebug.LogWarning ("Cannot find UFPS script 'vp_FPController' anywhere on '" + gameObject.name + "'.");
            }
            if (fpInput == null)
            {
                ACDebug.LogWarning ("Cannot find UFPS script 'vp_FPInput' anywhere on '" + gameObject.name + "'.");
            }
            if (fpCamera == null)
            {
                ACDebug.LogWarning ("Cannot find UFPS script 'vp_FPCamera' anywhere on '" + gameObject.name + "'.");
            }
            if (KickStarter.settingsManager != null && KickStarter.settingsManager.movementMethod != MovementMethod.FirstPerson)
            {
                ACDebug.Log ("The Ultimate FPS integration script requires the Settings Manager's 'Movement method' is set to 'First Person'");
            }

            // Tell the AC Player component that we'l be controlling movement/rotation manually during Cutscenes
            player = GetComponent <Player>();
            player.FirstPersonCamera = fpCamera.transform;
            player.SetAnimEngine (AnimationEngine.Custom);
            player.motionControl = MotionControl.Manual;

            // Assign a short delay whenever we load a saved game, to prevent firing when click
            if (KickStarter.saveSystem)
            {
                KickStarter.saveSystem.SetGameplayReturnTime (0.1f);
            }

            // Fixes gun sounds from not always playing
            AudioListener.pause = false;

            #endif
        }
Beispiel #14
0
        private void Awake()
        {
            // Test for key imports
            References references = (References) Resources.Load (Resource.references);
            if (references)
            {
                SceneManager sceneManager = AdvGame.GetReferences ().sceneManager;
                SettingsManager settingsManager = AdvGame.GetReferences ().settingsManager;
                ActionsManager actionsManager = AdvGame.GetReferences ().actionsManager;
                InventoryManager inventoryManager = AdvGame.GetReferences ().inventoryManager;
                VariablesManager variablesManager = AdvGame.GetReferences ().variablesManager;
                SpeechManager speechManager = AdvGame.GetReferences ().speechManager;
                CursorManager cursorManager = AdvGame.GetReferences ().cursorManager;
                MenuManager menuManager = AdvGame.GetReferences ().menuManager;

                if (sceneManager == null)
                {
                    Debug.LogError ("No Scene Manager found - please set one using the Adventure Creator Kit wizard");
                }

                if (settingsManager == null)
                {
                    Debug.LogError ("No Settings Manager found - please set one using the Adventure Creator Kit wizard");
                }
                else
                {
                    if (settingsManager.IsInLoadingScene ())
                    {
                        Debug.Log ("Bypassing regular AC startup because the current scene is the 'Loading' scene.");
                        return;
                    }
                    if (!GameObject.FindGameObjectWithTag (Tags.player))
                    {
                        KickStarter.ResetPlayer (settingsManager.GetDefaultPlayer (), settingsManager.GetDefaultPlayerID (), false, Quaternion.identity);
                    }
                    else
                    {
                        KickStarter.playerPrefab = GameObject.FindWithTag (Tags.player).GetComponent <Player>();

                        if (sceneChanger != null && sceneChanger.GetPlayerOnTransition () != null && settingsManager.playerSwitching == PlayerSwitching.DoNotAllow)
                        {
                            // Replace "prefab" player with a local one if one exists
                            GameObject[] playerObs = GameObject.FindGameObjectsWithTag (Tags.player);
                            foreach (GameObject playerOb in playerObs)
                            {
                                if (playerOb.GetComponent <Player>() && sceneChanger.GetPlayerOnTransition () != playerOb.GetComponent <Player>())
                                {
                                    KickStarter.sceneChanger.DestroyOldPlayer ();
                                    KickStarter.playerPrefab = playerOb.GetComponent <Player>();
                                    break;
                                }
                            }
                        }
                    }
                }

                if (actionsManager == null)
                {
                    Debug.LogError ("No Actions Manager found - please set one using the main Adventure Creator window");
                }

                if (inventoryManager == null)
                {
                    Debug.LogError ("No Inventory Manager found - please set one using the main Adventure Creator window");
                }

                if (variablesManager == null)
                {
                    Debug.LogError ("No Variables Manager found - please set one using the main Adventure Creator window");
                }

                if (speechManager == null)
                {
                    Debug.LogError ("No Speech Manager found - please set one using the main Adventure Creator window");
                }

                if (cursorManager == null)
                {
                    Debug.LogError ("No Cursor Manager found - please set one using the main Adventure Creator window");
                }

                if (menuManager == null)
                {
                    Debug.LogError ("No Menu Manager found - please set one using the main Adventure Creator window");
                }

                if (GameObject.FindWithTag (Tags.player) == null && KickStarter.settingsManager.movementMethod != MovementMethod.None)
                {
                    Debug.LogWarning ("No Player found - please set one using the Settings Manager, tagging it as Player and placing it in a Resources folder");
                }

            }
            else
            {
                Debug.LogError ("No References object found. Please set one using the main Adventure Creator window");
            }

            if (persistentEnginePrefab == null)
            {
                try
                {
                    persistentEnginePrefab = (GameObject) Instantiate (Resources.Load (Resource.persistentEngine));
                    persistentEnginePrefab.name = AdvGame.GetName (Resource.persistentEngine);
                }
                catch {}
            }

            if (persistentEnginePrefab == null)
            {
                Debug.LogError ("No PersistentEngine prefab found - please place one in the Resources directory, and tag it as PersistentEngine");
            }
            else
            {
                if (persistentEnginePrefab.GetComponent <Options>() == null)
                {
                    Debug.LogError (persistentEnginePrefab.name + " has no Options component attached.");
                }
                if (persistentEnginePrefab.GetComponent <RuntimeInventory>() == null)
                {
                    Debug.LogError (persistentEnginePrefab.name + " has no RuntimeInventory component attached.");
                }
                if (persistentEnginePrefab.GetComponent <RuntimeVariables>() == null)
                {
                    Debug.LogError (persistentEnginePrefab.name + " has no RuntimeVariables component attached.");
                }
                if (persistentEnginePrefab.GetComponent <PlayerMenus>() == null)
                {
                    Debug.LogError (persistentEnginePrefab.name + " has no PlayerMenus component attached.");
                }
                if (persistentEnginePrefab.GetComponent <StateHandler>() == null)
                {
                    Debug.LogError (persistentEnginePrefab.name + " has no StateHandler component attached.");
                }
                if (persistentEnginePrefab.GetComponent <SceneChanger>() == null)
                {
                    Debug.LogError (persistentEnginePrefab.name + " has no SceneChanger component attached.");
                }
                if (persistentEnginePrefab.GetComponent <SaveSystem>() == null)
                {
                    Debug.LogError (persistentEnginePrefab.name + " has no SaveSystem component attached.");
                }
                if (persistentEnginePrefab.GetComponent <LevelStorage>() == null)
                {
                    Debug.LogError (persistentEnginePrefab.name + " has no LevelStorage component attached.");
                }
            }

            if (GameObject.FindWithTag (Tags.mainCamera) == null)
            {
                Debug.LogError ("No MainCamera found - please click 'Organise room objects' in the Scene Manager to create one.");
            }
            else
            {
                if (GameObject.FindWithTag (Tags.mainCamera).GetComponent <MainCamera>() == null &&
                    GameObject.FindWithTag (Tags.mainCamera).GetComponentInParent <MainCamera>() == null)
                {
                    Debug.LogError ("MainCamera has no MainCamera component.");
                }
            }

            if (this.GetComponent <MenuSystem>() == null)
            {
                Debug.LogError (this.name + " has no MenuSystem component attached.");
            }
            if (this.GetComponent <Dialog>() == null)
            {
                Debug.LogError (this.name + " has no Dialog component attached.");
            }
            if (this.GetComponent <PlayerInput>() == null)
            {
                Debug.LogError (this.name + " has no PlayerInput component attached.");
            }
            if (this.GetComponent <PlayerInteraction>() == null)
            {
                Debug.LogError (this.name + " has no PlayerInteraction component attached.");
            }
            if (this.GetComponent <PlayerMovement>() == null)
            {
                Debug.LogError (this.name + " has no PlayerMovement component attached.");
            }
            if (this.GetComponent <PlayerCursor>() == null)
            {
                Debug.LogError (this.name + " has no PlayerCursor component attached.");
            }
            if (this.GetComponent <PlayerQTE>() == null)
            {
                Debug.LogError (this.name + " has no PlayerQTE component attached.");
            }
            if (this.GetComponent <SceneSettings>() == null)
            {
                Debug.LogError (this.name + " has no SceneSettings component attached.");
            }
            else
            {
                if (this.GetComponent <SceneSettings>().navigationMethod == AC_NavigationMethod.meshCollider && this.GetComponent <SceneSettings>().navMesh == null)
                {
                    // No NavMesh, are there Characters in the scene?
                    AC.Char[] allChars = GameObject.FindObjectsOfType (typeof(AC.Char)) as AC.Char[];
                    if (allChars.Length > 0)
                    {
                        Debug.LogWarning ("No NavMesh set. Characters will not be able to PathFind until one is defined - please choose one using the Scene Manager.");
                    }
                }

                if (this.GetComponent <SceneSettings>().defaultPlayerStart == null)
                {
                    Debug.LogWarning ("No default PlayerStart set.  The game may not be able to begin if one is not defined - please choose one using the Scene Manager.");
                }
            }
            if (this.GetComponent <NavigationManager>() == null)
            {
                Debug.LogError (this.name + " has no NavigationManager component attached.");
            }
            if (this.GetComponent <ActionListManager>() == null)
            {
                Debug.LogError (this.name + " has no ActionListManager component attached.");
            }
        }
Beispiel #15
0
 public static void AssignLocalPlayer()
 {
     SetPersistentEngine ();
     if (sceneChanger != null && sceneChanger.GetPlayerOnTransition () != null)
     {
         // Replace "prefab" player with a local one if one exists
         GameObject[] playerObs = GameObject.FindGameObjectsWithTag (Tags.player);
         foreach (GameObject playerOb in playerObs)
         {
             if (playerOb.GetComponent <Player>() && sceneChanger.GetPlayerOnTransition () != playerOb.GetComponent <Player>())
             {
                 KickStarter.sceneChanger.DestroyOldPlayer ();
                 KickStarter.playerPrefab = playerOb.GetComponent <Player>();
                 KickStarter.playerPrefab.ID = -1;
                 break;
             }
         }
         KickStarter.stateHandler.GatherObjects (true);
     }
 }
Beispiel #16
0
 private void OnLevelWasLoaded()
 {
     if (GameObject.FindWithTag (Tags.player) && GameObject.FindWithTag (Tags.player).GetComponent <Player>())
     {
         KickStarter.playerPrefab = GameObject.FindWithTag (Tags.player).GetComponent <Player>();
     }
 }
Beispiel #17
0
        /**
         * <summary>Removes the current Player from the scene, and re-instantiates the correct Player prefab.</summary>
         * <param name = "ref_player">The new Player prefab to instantiate</param>
         * <param name = "ID">The ID number to assign the new Player</param>
         * <param name = "resetReferences">If True, then any references to the Player prefab in other AC scripts will be updated</param>
         * <param name = "_rotation">The new Player's rotation</param>
         * <param name = "keepInventory">If True, then the inventory items of the previous player (if there is one) will be transferred onto the new one, replacing any items held by the new one.</param>
         */
        public static void ResetPlayer(Player ref_player, int ID, bool resetReferences, Quaternion _rotation, bool keepInventory = false)
        {
            // Delete current player(s)
            if (GameObject.FindGameObjectsWithTag (Tags.player) != null)
            {
                foreach (GameObject playerOb in GameObject.FindGameObjectsWithTag (Tags.player))
                {
                    if (playerOb != null)
                    {
                        if (playerOb.GetComponent <Player>())
                        {
                            playerOb.GetComponent <Player>().ReleaseHeldObjects ();
                        }
                        DestroyImmediate (playerOb);
                    }
                }
            }

            // 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.playerSwitching == PlayerSwitching.Allow && !settingsManager.shareInventory)
                    {
                        if (!keepInventory)
                        {
                            KickStarter.runtimeInventory.localItems.Clear ();
                        }
                    }

                    if (KickStarter.saveSystem != null && KickStarter.saveSystem.DoesPlayerDataExist (ID, false))
                    {
                        bool loadNewInventory = !settingsManager.shareInventory;
                        if (settingsManager.playerSwitching == PlayerSwitching.DoNotAllow || (!settingsManager.shareInventory && keepInventory))
                        {
                            loadNewInventory = false;
                        }
                        saveSystem.AssignPlayerData (ID, loadNewInventory);
                    }

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

                newPlayer.Initialise ();
            }

            // Reset player references
            if (resetReferences)
            {
                KickStarter.playerMovement.AssignFPCamera ();
                KickStarter.stateHandler.IgnoreNavMeshCollisions ();
                KickStarter.stateHandler.GatherObjects (false);
                KickStarter.stateHandler.UpdateAllMaxVolumes ();
                _Camera[] cameras = FindObjectsOfType (typeof (_Camera)) as _Camera[];
                foreach (_Camera camera in cameras)
                {
                    camera.ResetTarget ();
                }
            }
        }
Beispiel #18
0
        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;
        }
Beispiel #19
0
		public override float Run ()
		{
			if (KickStarter.settingsManager.playerSwitching == PlayerSwitching.Allow)
			{
				PlayerPrefab newPlayerPrefab = KickStarter.settingsManager.GetPlayerPrefab (playerID);

				if (newPlayerPrefab != null)
				{
					if (KickStarter.player != null && KickStarter.player.ID == playerID)
					{
						Log ("Cannot switch player - already controlling the desired prefab.");
						return 0f;
					}
					
					if (newPlayerPrefab.playerOb != null)
					{
						KickStarter.saveSystem.SaveCurrentPlayerData ();
						
						Vector3 oldPlayerPosition = Vector3.zero;
						Quaternion oldPlayerRotation = new Quaternion ();
						Vector3 oldPlayerScale = Vector3.one;

						PlayerData oldPlayerData = new PlayerData ();
						NPCData oldNPCData = new NPCData ();
						bool recordedOldPlayerData = false;
						bool recordedOldNPCData = false;

						if (KickStarter.player != null)
						{
							oldPlayerPosition = KickStarter.player.transform.position;
							oldPlayerRotation = KickStarter.player.TransformRotation;
							oldPlayerScale = KickStarter.player.transform.localScale;

							oldPlayerData = KickStarter.player.SavePlayerData (oldPlayerData);
							recordedOldPlayerData = true;
						}

						if (newPlayerPosition != NewPlayerPosition.ReplaceCurrentPlayer)
						{
							if (oldPlayer == OldPlayer.ReplaceWithAssociatedNPC &&
								(runtimeOldPlayerNPC == null || !runtimeOldPlayerNPC.gameObject.activeInHierarchy) &&
								KickStarter.player.associatedNPCPrefab != null)
							{
								GameObject newObject = (GameObject) Instantiate (KickStarter.player.associatedNPCPrefab.gameObject);
								newObject.name = KickStarter.player.associatedNPCPrefab.gameObject.name;
								runtimeOldPlayerNPC = newObject.GetComponent <NPC>();
							}

							if ((oldPlayer == OldPlayer.ReplaceWithNPC || oldPlayer == OldPlayer.ReplaceWithAssociatedNPC) &&
								runtimeOldPlayerNPC != null && runtimeOldPlayerNPC.gameObject.activeInHierarchy)
							{
								runtimeOldPlayerNPC.Teleport (oldPlayerPosition);
								runtimeOldPlayerNPC.SetRotation (oldPlayerRotation);
								runtimeOldPlayerNPC.transform.localScale = oldPlayerScale;

								if (recordedOldPlayerData)
								{
									ApplyRenderData (runtimeOldPlayerNPC, oldPlayerData);
								}

								// Force the rotation / sprite child to update
								runtimeOldPlayerNPC._Update ();
							}
						}

						if (runtimeNewPlayerNPC == null || newPlayerPosition == NewPlayerPosition.ReplaceAssociatedNPC)
						{
							// Try to find from associated NPC prefab

							if (newPlayerPrefab.playerOb.associatedNPCPrefab != null)
							{
								ConstantID prefabID = newPlayerPrefab.playerOb.associatedNPCPrefab.GetComponent <ConstantID>();
								if (prefabID != null && prefabID.constantID != 0)
								{
									newPlayerNPC_ID = prefabID.constantID;
									runtimeNewPlayerNPC = AssignFile <NPC> (prefabID.constantID, null);
								}
							}
						}

						Quaternion newRotation = Quaternion.identity;
						if (newPlayerPosition == NewPlayerPosition.ReplaceCurrentPlayer)
						{
							newRotation = oldPlayerRotation;
						}
						else if (newPlayerPosition == NewPlayerPosition.ReplaceNPC && runtimeNewPlayerNPC != null)
						{
							newRotation = runtimeNewPlayerNPC.TransformRotation;
						}
						else if (newPlayerPosition == NewPlayerPosition.AppearAtMarker && runtimeNewPlayerMarker != null)
						{
							newRotation = runtimeNewPlayerMarker.transform.rotation;
						}

						if (runtimeNewPlayerNPC != null)
						{
							oldNPCData = runtimeNewPlayerNPC.SaveData (oldNPCData);
						}

						bool replacesOldPlayer = newPlayerPosition == NewPlayerPosition.ReplaceCurrentPlayer &&
												 (!restorePreviousData || !KickStarter.saveSystem.DoesPlayerDataExist (playerID, true));
						KickStarter.ResetPlayer (newPlayerPrefab.playerOb, playerID, true, newRotation, keepInventory, false, replacesOldPlayer, alwaysSnapCamera);
						Player newPlayer = KickStarter.player;
						PlayerMenus.ResetInventoryBoxes ();

						if (replacesOldPlayer && recordedOldPlayerData)
						{
							ApplyRenderData (newPlayer, oldPlayerData);
						}

						if (restorePreviousData && KickStarter.saveSystem.DoesPlayerDataExist (playerID, true))
						{
							int sceneToLoad = KickStarter.saveSystem.GetPlayerScene (playerID);
							if (sceneToLoad >= 0 && sceneToLoad != UnityVersionHandler.GetCurrentSceneNumber ())
							{
								KickStarter.saveSystem.loadingGame = LoadingGame.JustSwitchingPlayer;
								KickStarter.sceneChanger.ChangeScene (new SceneInfo (string.Empty, sceneToLoad), true, false);
							}
							else
							{
								// Same scene
								if (runtimeNewPlayerNPC != null)
								{
									newPlayer.RepositionToTransform (runtimeNewPlayerNPC.transform);
									runtimeNewPlayerNPC.HideFromView (newPlayer);
								}	
							}
						}
						else
						{
							// No data to restore

							if (newPlayerPosition == NewPlayerPosition.ReplaceCurrentPlayer)
							{
								newPlayer.Teleport (oldPlayerPosition);
								newPlayer.SetRotation (oldPlayerRotation);
								newPlayer.transform.localScale = oldPlayerScale;
							}
							else if (newPlayerPosition == NewPlayerPosition.ReplaceNPC || newPlayerPosition == NewPlayerPosition.ReplaceAssociatedNPC)
							{
								if (runtimeNewPlayerNPC != null)
								{
									newPlayer.RepositionToTransform (runtimeNewPlayerNPC.transform);
									runtimeNewPlayerNPC.HideFromView (newPlayer);

									if (recordedOldNPCData)
									{
										ApplyRenderData (newPlayer, oldNPCData);
									}
								}
							}
							else if (newPlayerPosition == NewPlayerPosition.AppearAtMarker)
							{
								if (runtimeNewPlayerMarker)
								{
									newPlayer.RepositionToTransform (runtimeNewPlayerMarker.transform);
								}
							}
							else if (newPlayerPosition == NewPlayerPosition.AppearInOtherScene)
							{
								if (chooseNewSceneBy == ChooseSceneBy.Name && newPlayerSceneName == UnityVersionHandler.GetCurrentSceneName () ||
									(chooseNewSceneBy == ChooseSceneBy.Number && newPlayerScene == UnityVersionHandler.GetCurrentSceneNumber ()))
								{
									// Already in correct scene
									if (runtimeNewPlayerNPC && runtimeNewPlayerNPC.gameObject.activeInHierarchy)
									{
										newPlayer.RepositionToTransform (runtimeNewPlayerNPC.transform);
										runtimeNewPlayerNPC.HideFromView (newPlayer);
									}
								}
								else
								{
									KickStarter.sceneChanger.ChangeScene (new SceneInfo (chooseNewSceneBy, newPlayerSceneName, newPlayerScene), true, false, true);
								}
							}
						}
						
						if (KickStarter.mainCamera.attachedCamera && alwaysSnapCamera)
						{
							KickStarter.mainCamera.attachedCamera.MoveCameraInstant ();
						}
						
						AssetLoader.UnloadAssets ();
					}
					else
					{
						LogWarning ("Cannot switch player - no player prefabs is defined.");
					}
				}
			}
			
			return 0f;
		}