public override void ShowGUI(List<ActionParameter> parameters) { npcToMoveParameterID = Action.ChooseParameterGUI ("NPC to affect:", parameters, npcToMoveParameterID, ParameterType.GameObject); if (npcToMoveParameterID >= 0) { npcToMoveID = 0; npcToMove = null; } else { npcToMove = (NPC) EditorGUILayout.ObjectField ("NPC to affect:", npcToMove, typeof(NPC), true); npcToMoveID = FieldToID <NPC> (npcToMove, npcToMoveID); npcToMove = IDToField <NPC> (npcToMove, npcToMoveID, false); } followType = (FollowType) EditorGUILayout.EnumPopup ("Follow type:", followType); if (followType == FollowType.StartFollowing) { followPlayer = EditorGUILayout.Toggle ("Follow Player?", followPlayer); if (!followPlayer) { charToFollowParameterID = Action.ChooseParameterGUI ("Character to follow:", parameters, charToFollowParameterID, ParameterType.GameObject); if (charToFollowParameterID >= 0) { charToFollowID = 0; charToFollow = null; } else { charToFollow = (Char) EditorGUILayout.ObjectField ("Character to follow:", charToFollow, typeof(Char), true); if (charToFollow && charToFollow == (Char) npcToMove) { charToFollow = null; Debug.LogWarning ("An NPC cannot follow themselves!"); } else { charToFollowID = FieldToID <Char> (charToFollow, charToFollowID); charToFollow = IDToField <Char> (charToFollow, charToFollowID, false); } } } updateFrequency = EditorGUILayout.FloatField ("Update frequency (s):", updateFrequency); if (updateFrequency == 0f || updateFrequency < 0f) { EditorGUILayout.HelpBox ("Update frequency must be greater than zero.", MessageType.Warning); } followDistance = EditorGUILayout.FloatField ("Minimum distance:", followDistance); if (followDistance <= 0f) { EditorGUILayout.HelpBox ("Minimum distance must be greater than zero.", MessageType.Warning); } followDistanceMax = EditorGUILayout.FloatField ("Maximum distance:", followDistanceMax); if (followDistanceMax <= 0f || followDistanceMax < followDistance) { EditorGUILayout.HelpBox ("Maximum distance must be greater than minimum distance.", MessageType.Warning); } } AfterRunningOption (); }
public override void AssignValues(List<ActionParameter> parameters) { npcToMove = AssignFile <NPC> (parameters, npcToMoveParameterID, npcToMoveID, npcToMove); charToFollow = AssignFile <Char> (parameters, charToFollowParameterID, charToFollowID, charToFollow); }
public override void ShowGUI() { if (!settingsManager) { settingsManager = AdvGame.GetReferences ().settingsManager; } if (!settingsManager) { return; } if (settingsManager.playerSwitching == PlayerSwitching.DoNotAllow) { EditorGUILayout.HelpBox ("This Action requires Player Switching to be allowed, as set in the Settings Manager.", MessageType.Info); return; } // Create a string List of the field's names (for the PopUp box) List<string> labelList = new List<string>(); int i = 0; playerNumber = -1; if (settingsManager.players.Count > 0) { foreach (PlayerPrefab playerPrefab in settingsManager.players) { if (playerPrefab.playerOb != null) { labelList.Add (playerPrefab.playerOb.name); } else { labelList.Add ("(Undefined prefab)"); } // If a player has been removed, make sure selected player is still valid if (playerPrefab.ID == playerID) { playerNumber = i; } i++; } if (playerNumber == -1) { // Wasn't found (item was possibly deleted), so revert to zero ACDebug.LogWarning ("Previously chosen Player no longer exists!"); playerNumber = 0; playerID = 0; } playerNumber = EditorGUILayout.Popup ("New Player:", playerNumber, labelList.ToArray()); playerID = settingsManager.players[playerNumber].ID; if (AdvGame.GetReferences ().settingsManager == null || !AdvGame.GetReferences ().settingsManager.shareInventory) { keepInventory = EditorGUILayout.Toggle ("Transfer inventory?", keepInventory); } restorePreviousData = EditorGUILayout.Toggle ("Restore position?", restorePreviousData); if (restorePreviousData) { EditorGUILayout.LabelField ("If first time in game:", EditorStyles.boldLabel); } newPlayerPosition = (NewPlayerPosition) EditorGUILayout.EnumPopup ("New Player position:", newPlayerPosition); if (newPlayerPosition == NewPlayerPosition.ReplaceNPC) { newPlayerNPC = (NPC) EditorGUILayout.ObjectField ("NPC to be replaced:", newPlayerNPC, typeof (NPC), true); newPlayerNPC_ID = FieldToID <NPC> (newPlayerNPC, newPlayerNPC_ID); newPlayerNPC = IDToField <NPC> (newPlayerNPC, newPlayerNPC_ID, false); } else if (newPlayerPosition == NewPlayerPosition.AppearAtMarker) { newPlayerMarker = (Marker) EditorGUILayout.ObjectField ("Marker to appear at:", newPlayerMarker, typeof (Marker), true); newPlayerMarker_ID = FieldToID <Marker> (newPlayerMarker, newPlayerMarker_ID); newPlayerMarker = IDToField <Marker> (newPlayerMarker, newPlayerMarker_ID, false); } else if (newPlayerPosition == NewPlayerPosition.AppearInOtherScene) { chooseNewSceneBy = (ChooseSceneBy) EditorGUILayout.EnumPopup ("Choose scene by:", chooseNewSceneBy); if (chooseNewSceneBy == ChooseSceneBy.Name) { newPlayerSceneName = EditorGUILayout.TextField ("Scene to appear in:", newPlayerSceneName); } else { newPlayerScene = EditorGUILayout.IntField ("Scene to appear in:", newPlayerScene); } } if (newPlayerPosition == NewPlayerPosition.ReplaceNPC || newPlayerPosition == NewPlayerPosition.AppearAtMarker) { EditorGUILayout.Space (); oldPlayer = (OldPlayer) EditorGUILayout.EnumPopup ("Old Player", oldPlayer); if (oldPlayer == OldPlayer.ReplaceWithNPC) { oldPlayerNPC = (NPC) EditorGUILayout.ObjectField ("NPC to replace old Player:", oldPlayerNPC, typeof (NPC), true); oldPlayerNPC_ID = FieldToID <NPC> (oldPlayerNPC, oldPlayerNPC_ID); oldPlayerNPC = IDToField <NPC> (oldPlayerNPC, oldPlayerNPC_ID, false); } } } else { EditorGUILayout.LabelField ("No players exist!"); playerID = -1; playerNumber = -1; } EditorGUILayout.Space (); AfterRunningOption (); }
public override void AssignValues() { oldPlayerNPC = AssignFile <NPC> (oldPlayerNPC_ID, oldPlayerNPC); newPlayerNPC = AssignFile <NPC> (newPlayerNPC_ID, newPlayerNPC); newPlayerMarker = AssignFile <Marker> (newPlayerMarker_ID, newPlayerMarker); }
override public void ShowGUI(List <ActionParameter> parameters) { npcToMoveParameterID = Action.ChooseParameterGUI("NPC to affect:", parameters, npcToMoveParameterID, ParameterType.GameObject); if (npcToMoveParameterID >= 0) { npcToMoveID = 0; npcToMove = null; } else { npcToMove = (NPC)EditorGUILayout.ObjectField("NPC to affect:", npcToMove, typeof(NPC), true); npcToMoveID = FieldToID <NPC> (npcToMove, npcToMoveID); npcToMove = IDToField <NPC> (npcToMove, npcToMoveID, false); } followType = (FollowType)EditorGUILayout.EnumPopup("Follow type:", followType); if (followType == FollowType.StartFollowing) { followPlayer = EditorGUILayout.Toggle("Follow Player?", followPlayer); if (!followPlayer) { charToFollowParameterID = Action.ChooseParameterGUI("Character to follow:", parameters, charToFollowParameterID, ParameterType.GameObject); if (charToFollowParameterID >= 0) { charToFollowID = 0; charToFollow = null; } else { charToFollow = (Char)EditorGUILayout.ObjectField("Character to follow:", charToFollow, typeof(Char), true); if (charToFollow && charToFollow == (Char)npcToMove) { ACDebug.LogWarning("An NPC cannot follow themselves!", charToFollow); charToFollow = null; } else { charToFollowID = FieldToID <Char> (charToFollow, charToFollowID); charToFollow = IDToField <Char> (charToFollow, charToFollowID, false); } } } randomDirection = EditorGUILayout.Toggle("Randomise position?", randomDirection); updateFrequency = EditorGUILayout.FloatField("Update frequency (s):", updateFrequency); if (updateFrequency <= 0f) { EditorGUILayout.HelpBox("Update frequency must be greater than zero.", MessageType.Warning); } followDistance = EditorGUILayout.FloatField("Minimum distance:", followDistance); if (followDistance <= 0f) { EditorGUILayout.HelpBox("Minimum distance must be greater than zero.", MessageType.Warning); } followDistanceMax = EditorGUILayout.FloatField("Maximum distance:", followDistanceMax); if (followDistanceMax <= 0f || followDistanceMax < followDistance) { EditorGUILayout.HelpBox("Maximum distance must be greater than minimum distance.", MessageType.Warning); } if (followPlayer) { faceWhenIdle = EditorGUILayout.Toggle("Faces Player when idle?", faceWhenIdle); } else { faceWhenIdle = EditorGUILayout.Toggle("Faces character when idle?", faceWhenIdle); } } AfterRunningOption(); }
override public void AssignValues(List <ActionParameter> parameters) { runtimeNpcToMove = AssignFile <NPC> (parameters, npcToMoveParameterID, npcToMoveID, npcToMove); runtimeCharToFollow = AssignFile <Char> (parameters, charToFollowParameterID, charToFollowID, charToFollow); }
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; }
public override void ShowGUI (List<ActionParameter> parameters) { if (settingsManager == null) { settingsManager = AdvGame.GetReferences ().settingsManager; } if (settingsManager == null) { return; } if (settingsManager.playerSwitching == PlayerSwitching.DoNotAllow) { EditorGUILayout.HelpBox ("This Action requires Player Switching to be allowed, as set in the Settings Manager.", MessageType.Info); return; } if (settingsManager.players.Count > 0) { playerIDParameterID = Action.ChooseParameterGUI ("New Player ID:", parameters, playerIDParameterID, ParameterType.Integer); if (playerIDParameterID == -1) { // Create a string List of the field's names (for the PopUp box) List<string> labelList = new List<string>(); int i = 0; int playerNumber = -1; foreach (PlayerPrefab playerPrefab in settingsManager.players) { if (playerPrefab.playerOb != null) { labelList.Add (playerPrefab.playerOb.name); } else { labelList.Add ("(Undefined prefab)"); } // If a player has been removed, make sure selected player is still valid if (playerPrefab.ID == playerID) { playerNumber = i; } i++; } if (playerNumber == -1) { // Wasn't found (item was possibly deleted), so revert to zero ACDebug.LogWarning ("Previously chosen Player no longer exists!"); playerNumber = 0; playerID = 0; } playerNumber = EditorGUILayout.Popup ("New Player:", playerNumber, labelList.ToArray()); playerID = settingsManager.players[playerNumber].ID; } if (AdvGame.GetReferences ().settingsManager == null || !AdvGame.GetReferences ().settingsManager.shareInventory) { keepInventory = EditorGUILayout.Toggle ("Transfer inventory?", keepInventory); } restorePreviousData = EditorGUILayout.Toggle ("Restore position?", restorePreviousData); if (restorePreviousData) { EditorGUILayout.BeginVertical (CustomStyles.thinBox); EditorGUILayout.LabelField ("If first time in game:", EditorStyles.boldLabel); } newPlayerPosition = (NewPlayerPosition) EditorGUILayout.EnumPopup ("New Player position:", newPlayerPosition); if (newPlayerPosition == NewPlayerPosition.ReplaceNPC) { newPlayerNPC = (NPC) EditorGUILayout.ObjectField ("NPC to be replaced:", newPlayerNPC, typeof (NPC), true); newPlayerNPC_ID = FieldToID <NPC> (newPlayerNPC, newPlayerNPC_ID); newPlayerNPC = IDToField <NPC> (newPlayerNPC, newPlayerNPC_ID, false); } else if (newPlayerPosition == NewPlayerPosition.AppearAtMarker) { newPlayerMarker = (Marker) EditorGUILayout.ObjectField ("Marker to appear at:", newPlayerMarker, typeof (Marker), true); newPlayerMarker_ID = FieldToID <Marker> (newPlayerMarker, newPlayerMarker_ID); newPlayerMarker = IDToField <Marker> (newPlayerMarker, newPlayerMarker_ID, false); } else if (newPlayerPosition == NewPlayerPosition.AppearInOtherScene) { chooseNewSceneBy = (ChooseSceneBy) EditorGUILayout.EnumPopup ("Choose scene by:", chooseNewSceneBy); if (chooseNewSceneBy == ChooseSceneBy.Name) { newPlayerSceneName = EditorGUILayout.TextField ("Scene to appear in:", newPlayerSceneName); } else { newPlayerScene = EditorGUILayout.IntField ("Scene to appear in:", newPlayerScene); } newPlayerNPC = (NPC) EditorGUILayout.ObjectField ("NPC to be replaced:", newPlayerNPC, typeof (NPC), true); newPlayerNPC_ID = FieldToID <NPC> (newPlayerNPC, newPlayerNPC_ID); newPlayerNPC = IDToField <NPC> (newPlayerNPC, newPlayerNPC_ID, false); EditorGUILayout.HelpBox ("If the Player has an Associated NPC defined, it will be used if none is defined here.", MessageType.Info); } else if (newPlayerPosition == NewPlayerPosition.ReplaceAssociatedNPC) { EditorGUILayout.HelpBox ("A Player's 'Associated NPC' is defined in the Player Inspector.", MessageType.Info); } if (restorePreviousData) { EditorGUILayout.EndVertical (); } if (newPlayerPosition == NewPlayerPosition.ReplaceNPC || newPlayerPosition == NewPlayerPosition.AppearAtMarker || newPlayerPosition == NewPlayerPosition.AppearInOtherScene || newPlayerPosition == NewPlayerPosition.ReplaceAssociatedNPC) { EditorGUILayout.Space (); oldPlayer = (OldPlayer) EditorGUILayout.EnumPopup ("Old Player:", oldPlayer); if (oldPlayer == OldPlayer.ReplaceWithNPC) { oldPlayerNPC = (NPC) EditorGUILayout.ObjectField ("NPC to replace old Player:", oldPlayerNPC, typeof (NPC), true); oldPlayerNPC_ID = FieldToID <NPC> (oldPlayerNPC, oldPlayerNPC_ID); oldPlayerNPC = IDToField <NPC> (oldPlayerNPC, oldPlayerNPC_ID, false); EditorGUILayout.HelpBox ("This NPC must be already be present in the scene - either within the scene file itself, or spawned at runtime with the 'Object: Add or remove' Action.", MessageType.Info); } else if (oldPlayer == OldPlayer.ReplaceWithAssociatedNPC) { EditorGUILayout.HelpBox ("A Player's 'Associated NPC' is defined in the Player Inspector.", MessageType.Info); } } } else { EditorGUILayout.LabelField ("No players exist!"); playerID = -1; } alwaysSnapCamera = EditorGUILayout.Toggle ("Snap camera if shared?", alwaysSnapCamera); EditorGUILayout.Space (); AfterRunningOption (); }
public override void LoadNPCData(NPCData npcData, NPC npc) { npc.moveSpeedParameter = npcData.walkAnim; npc.talkParameter = npcData.talkAnim; npc.turnParameter = npcData.runAnim;; }