private void OnEnable() { targetChunkData = target as LevelChunkData; numberOfLinesProperty = serializedObject.FindProperty("numberOfLines"); numberOfColumns = targetChunkData.GetNumberOfColumn; prefabLibrary = targetChunkData.GetPrefabLibrary; ComposePrefabsDictionary(); if (prefabsDictionnary.ContainsKey(100)) { currentBrushType = LevelChunkBrushType.Obstacle; SetCurrentBrushIndex(100); } else if (prefabsDictionnary.ContainsKey(200)) { currentBrushType = LevelChunkBrushType.Enemy; SetCurrentBrushIndex(200); } }
private void Awake() { prefabsLibrary = Resources.Load("Level Prefabs Library") as LevelPrefabsLibrary; UpdateGridSize(); }
public void AssignPoolValuesWithLibrary() { foreach (EnemyPool pool in enemiesPools) { pool.DestroyPoolParent(); pool.DestroyPoolObjects(); } foreach (ObstaclePool pool in obstaclesPools) { pool.DestroyPoolParent(); pool.DestroyPoolObjects(); } foreach (ProjectilePool pool in projectilesPools) { pool.DestroyPoolParent(); pool.DestroyPoolObjects(); } enemiesPools = new List <EnemyPool>(); obstaclesPools = new List <ObstaclePool>(); projectilesPools = new List <ProjectilePool>(); LevelPrefabsLibrary levelPrefabsLibrary = Resources.Load("Level Prefabs Library") as LevelPrefabsLibrary; if (levelPrefabsLibrary == null) { Debug.LogError("Library Not Found"); return; } List <LevelPrefabInformations> enemiesInformations = levelPrefabsLibrary.GetEnemyPrefabInformations; for (int i = 0; i < enemiesInformations.Count; i++) { LevelPrefabInformations info = enemiesInformations[i]; if (info.elementPrefab == null) { continue; } EnemyPool newEnemyPool = new EnemyPool(); int index = 200 + i; newEnemyPool.elementLibraryIndex = index; newEnemyPool.enemyPrefab = info.elementPrefab.GetComponent <EnemySpaceShipScript>(); newEnemyPool.instantiatedObjects = new List <EnemySpaceShipScript>(); newEnemyPool.numberOfElements = 20; GameObject parent = new GameObject(); parent.name = info.elementName + " Pool"; parent.transform.parent = poolsParent; newEnemyPool.poolParent = parent.transform; enemiesPools.Add(newEnemyPool); } List <LevelPrefabInformations> obstaclesInformations = levelPrefabsLibrary.GetObstaclePrefabInformations; for (int i = 0; i < obstaclesInformations.Count; i++) { LevelPrefabInformations info = obstaclesInformations[i]; if (info.elementPrefab == null) { continue; } ObstaclePool newObstaclePool = new ObstaclePool(); int index = 100 + i; newObstaclePool.elementLibraryIndex = index; newObstaclePool.obstaclePrefab = info.elementPrefab.GetComponent <Obstacle>(); newObstaclePool.instantiatedObjects = new List <Obstacle>(); newObstaclePool.numberOfElements = 20; GameObject parent = new GameObject(); parent.name = info.elementName + " Pool"; parent.transform.parent = poolsParent; newObstaclePool.poolParent = parent.transform; obstaclesPools.Add(newObstaclePool); } List <LevelPrefabInformations> projectileInformations = levelPrefabsLibrary.GetProjectilePrefabInformations; for (int i = 0; i < projectileInformations.Count; i++) { LevelPrefabInformations info = projectileInformations[i]; if (info.elementPrefab == null) { continue; } ProjectilePool newProjectilePool = new ProjectilePool(); int index = 300 + i; newProjectilePool.elementLibraryIndex = index; newProjectilePool.projectilePrefab = info.elementPrefab.GetComponent <ProjectileScript>(); newProjectilePool.projectilePrefab.SetPoolingIndex(index); #if UNITY_EDITOR UnityEditor.EditorUtility.SetDirty(newProjectilePool.projectilePrefab); #endif newProjectilePool.instantiatedObjects = new List <ProjectileScript>(); newProjectilePool.numberOfElements = 20; GameObject parent = new GameObject(); parent.name = info.elementName + " Pool"; parent.transform.parent = poolsParent; newProjectilePool.poolParent = parent.transform; projectilesPools.Add(newProjectilePool); } #if UNITY_EDITOR UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(gameObject.scene); #endif }
private void OnGUI() { EditorStaticMethods.ShowFolderAndAskIfCreateNew(ref selectedFolderRef, ref createFolder); float oldWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth *= 1.5f; GUILayout.Space(8); GUILayout.Label("Enemy Parameters", EditorStyles.boldLabel); EditorGUI.BeginChangeCheck(); newEnemyName = EditorGUILayout.TextField("New Enemy Name", newEnemyName); if (EditorGUI.EndChangeCheck()) { newWeaponName = newEnemyName + " Weapon"; } enemyCreationParameters.enemyIdentifyingColor = EditorGUILayout.ColorField("Enemy Identifying Color", enemyCreationParameters.enemyIdentifyingColor); enemyCreationParameters.lifeAmount = EditorGUILayout.IntField("Life Amount", enemyCreationParameters.lifeAmount); enemyCreationParameters.aimingType = (EnemyAimingType)EditorGUILayout.EnumPopup(new GUIContent("Aiming Type"), enemyCreationParameters.aimingType); GUILayout.Space(8); GUILayout.Label("Linked Weapon", EditorStyles.boldLabel); EditorGUI.BeginChangeCheck(); createLinkedWeaponParameters = EditorGUILayout.Toggle("Create Linked Weapon Parameters", createLinkedWeaponParameters); if (EditorGUI.EndChangeCheck()) { newWeaponName = newEnemyName + " Weapon"; } if (createLinkedWeaponParameters) { EditorGUI.indentLevel++; GUILayout.BeginVertical("box"); WeaponSetCreationWindow.ShowWeaponSetCreationParameters(selectedFolderRef, ref newWeaponName, false, ref createLinkedWeaponObject, ref newWeaponCreationParameters); EditorGUI.indentLevel--; GUILayout.EndVertical(); } GUILayout.Space(16); if (selectedFolderRef != null) { if (GUILayout.Button("Create the new Enemy : \"" + newEnemyName + "\" !")) { string finalFolderPath = selectedFolderRef.GetFolderPath(); if (createFolder) { string folderCreationPath = finalFolderPath; finalFolderPath = AssetDatabase.GenerateUniqueAssetPath(finalFolderPath + "/" + newEnemyName + " Set"); AssetDatabase.CreateFolder(folderCreationPath, newEnemyName + " Set"); } EnemySpaceShipScript newEnemyTempObj = EnemyCreationParameters.ComposeEnemy(enemyCreationParameters, newEnemyName); EnemySpaceShipScript newEnemyPrefab = EditorStaticMethods.CreateEnemyPrefabInFolder(finalFolderPath, newEnemyTempObj); if (newEnemyPrefab == null) { Debug.LogError("Couldn't create enemy Set"); return; } WeaponScript newWeaponPrefab = null; if (createLinkedWeaponObject) { WeaponScript newWeapon = WeaponCreationParameters.ComposeWeapon(newWeaponCreationParameters, newWeaponName); newWeaponPrefab = EditorStaticMethods.CreateWeaponObjectInFolder(finalFolderPath, newWeapon); } WeaponParameters newWeaponParameters = null; if (newWeaponPrefab != null) { newWeaponParameters = EditorStaticMethods.CreateWeaponSetInFolder(finalFolderPath, newWeaponName, newWeaponPrefab); } else { newWeaponParameters = EditorStaticMethods.CreateWeaponSetInFolder(finalFolderPath, newWeaponName); } newEnemyPrefab.GetShootingSystem.SetWeaponParameters(newWeaponParameters); Selection.activeObject = newEnemyPrefab; EditorGUIUtility.PingObject(newEnemyPrefab); #region Library //LevelPrefabsLibrary enemiesLibrary = AssetDatabase.LoadAssetAtPath("Assets/Resources/Level Prefabs Library.asset", typeof(LevelPrefabsLibrary)) as LevelPrefabsLibrary; ScriptableObject library = Resources.Load("Level Prefabs Library") as ScriptableObject; LevelPrefabsLibrary prefabsLibrary = library as LevelPrefabsLibrary; if (prefabsLibrary == null) { Debug.LogError("Library Not Found"); return; } prefabsLibrary.AddEnemyPrefabInformations(newEnemyPrefab.gameObject, enemyCreationParameters.enemyIdentifyingColor); EditorUtility.SetDirty(prefabsLibrary); #endregion } } EditorGUIUtility.labelWidth = oldWidth; }
void DebugLibraryElement(object index) { LevelPrefabsLibrary.DebugPrefabInformations(targetLibrary.GetEnemyPrefabInformations[(int)index]); }
private void OnEnable() { targetLibrary = target as LevelPrefabsLibrary; }