private T CreateSoundtrackEngine <T> (string resourceName) where T : Soundtrack { GameObject soundtrackOb = (GameObject)Instantiate(Resources.Load(resourceName)); if (soundtrackOb != null) { soundtrackOb.name = AdvGame.GetName(resourceName); return(soundtrackOb.GetComponent <T>()); } else { ACDebug.LogError("Cannot find " + resourceName + " prefab in /AdventureCreator/Resources - did you import AC completely?"); return(null); } }
private static bool SetPersistentEngine() { if (persistentEnginePrefab == null) { StateHandler stateHandler = UnityVersionHandler.GetKickStarterComponent <StateHandler>(); if (stateHandler) { persistentEnginePrefab = stateHandler.gameObject; } else { GameObject newPersistentEngine = null; try { newPersistentEngine = (GameObject)Instantiate(Resources.Load(Resource.persistentEngine)); newPersistentEngine.name = AdvGame.GetName(Resource.persistentEngine); } catch (System.Exception e) { ACDebug.LogWarning("Could not create PersistentEngine - make sure " + Resource.persistentEngine + ", prefab is present in a Resources folder. Exception: " + e); } if (newPersistentEngine) { #if UNITY_EDITOR if (!TestPersistentEngine(newPersistentEngine)) { return(false); } #endif persistentEnginePrefab = newPersistentEngine; stateHandler = persistentEnginePrefab.GetComponent <StateHandler>(); stateHandler.Initialise(); return(true); } } } if (stateHandler) { stateHandler.RegisterInitialConstantIDs(); } return(true); }
private void CreateMusicEngine() { if (music == null) { GameObject musicOb = (GameObject)Instantiate(Resources.Load(Resource.musicEngine)); if (musicOb != null) { musicOb.name = AdvGame.GetName(Resource.musicEngine); if (GameObject.Find("_Sound") && GameObject.Find("_Sound").transform.parent == null) { musicOb.transform.parent = GameObject.Find("_Sound").transform; } music = musicOb.GetComponent <Music>(); } else { ACDebug.LogError("Cannot find MusicEngine prefab in /AdventureCreator/Resources - did you import AC completely?"); } GatherObjects(); } }
private static void SetPersistentEngine() { if (persistentEnginePrefab == null) { StateHandler stateHandler = UnityVersionHandler.GetKickStarterComponent <StateHandler>(); if (stateHandler != null) { persistentEnginePrefab = stateHandler.gameObject; } else { try { persistentEnginePrefab = (GameObject)Instantiate(Resources.Load(Resource.persistentEngine)); persistentEnginePrefab.name = AdvGame.GetName(Resource.persistentEngine); } catch { } stateHandler = persistentEnginePrefab.GetComponent <StateHandler>(); stateHandler.OnAwake(); } } }
public static GameObject AddPrefab(string folderName, string prefabName, bool canCreateMultiple, bool selectAfter, bool putInFolder) { if (canCreateMultiple || !GameObject.Find(AdvGame.GetName(prefabName))) { string fileName = assetFolder + folderName + Path.DirectorySeparatorChar.ToString() + prefabName + ".prefab"; GameObject newOb = (GameObject)PrefabUtility.InstantiatePrefab(AssetDatabase.LoadAssetAtPath(fileName, typeof(GameObject))); newOb.name = "Temp"; if (folderName != "" && putInFolder) { if (!PutInFolder(newOb, "_" + prefabName + "s")) { string newName = "_" + prefabName; if (newName.Contains("2D")) { newName = newName.Substring(0, newName.IndexOf("2D")); if (!PutInFolder(newOb, newName + "s")) { PutInFolder(newOb, newName); } else { PutInFolder(newOb, newName); } } else if (newName.Contains("2.5D")) { newName = newName.Substring(0, newName.IndexOf("2.5D")); if (!PutInFolder(newOb, newName + "s")) { PutInFolder(newOb, newName); } else { PutInFolder(newOb, newName); } } else if (newName.Contains("Animated")) { newName = newName.Substring(0, newName.IndexOf("Animated")); if (!PutInFolder(newOb, newName + "s")) { PutInFolder(newOb, newName); } else { PutInFolder(newOb, newName); } } else if (newName.Contains("ThirdPerson")) { newName = newName.Substring(0, newName.IndexOf("ThirdPerson")); if (!PutInFolder(newOb, newName + "s")) { PutInFolder(newOb, newName); } else { PutInFolder(newOb, newName); } } else { PutInFolder(newOb, newName); } } } if (newOb.GetComponent <GameCamera2D>()) { newOb.GetComponent <GameCamera2D>().SetCorrectRotation(); } RenameObject(newOb, prefabName); Undo.RegisterCreatedObjectUndo(newOb, "Created " + newOb.name); // Select the object if (selectAfter) { Selection.activeObject = newOb; } return(newOb); } return(null); }
public static void RenameObject(GameObject ob, string resourceName) { ob.name = AdvGame.GetName(resourceName); }
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) { 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."); } }