public static EnemySpaceShipScript ComposeEnemy(EnemyCreationParameters weaponCreationParameters, string enemyName)
    {
        GameObject baseEnemyPrefab = AssetDatabase.LoadAssetAtPath("Assets/Enemies/BaseEnemyPrefab.prefab", typeof(GameObject)) as GameObject;

        if (baseEnemyPrefab == null)
        {
            Debug.LogError("BASE ENEMY PREFAB NOT FOUND : Make sure to have a \"BaseEnemyPrefab\" prefab in the \"Enemies\" folder");
            return(null);
        }

        GameObject newEnemyObject = Object.Instantiate(baseEnemyPrefab);

        newEnemyObject.name = enemyName;

        EnemySpaceShipScript enemyComponent = newEnemyObject.GetComponent <EnemySpaceShipScript>();

        if (enemyComponent == null)
        {
            Debug.LogError("No EnemySpaceShipScript affected on the found object");
            return(null);
        }

        enemyComponent.GetRelatedDamageableComponent.SetMaxLifeAmount(weaponCreationParameters.lifeAmount);
        enemyComponent.SetAimingType(weaponCreationParameters.aimingType);

        return(enemyComponent);
    }
Ejemplo n.º 2
0
    public void ReturnEnemyInPool(EnemySpaceShipScript enemy)
    {
        int enemyIndex = enemy.GetPoolingIndex;

        if (enemiesPoolsDictionnary.ContainsKey(enemyIndex))
        {
            enemiesPoolsDictionnary[enemyIndex].Enqueue(enemy);
        }
    }
    public static EnemySpaceShipScript CreateEnemyPrefabInFolder(string folderPath, EnemySpaceShipScript enemy)
    {
        string     enemyPath = AssetDatabase.GenerateUniqueAssetPath(folderPath + "/" + enemy.name + ".prefab");
        GameObject prefab    = PrefabUtility.SaveAsPrefabAsset(enemy.gameObject, enemyPath);

        EditorUtility.SetDirty(prefab);
        Object.DestroyImmediate(enemy.gameObject);

        return(prefab.GetComponent <EnemySpaceShipScript>());
    }
Ejemplo n.º 4
0
    public void GeneratePoolsObjects()
    {
        foreach (EnemyPool enemyPool in enemiesPools)
        {
            enemyPool.DestroyPoolObjects();

            for (int i = 0; i < enemyPool.numberOfElements; i++)
            {
                EnemySpaceShipScript newEnemy = Instantiate(enemyPool.enemyPrefab, enemyPool.poolParent);
                newEnemy.SetUpOnPoolInstantiation(enemyPool.elementLibraryIndex);
                enemyPool.instantiatedObjects.Add(newEnemy);
            }
        }

        foreach (ObstaclePool obstaclePool in obstaclesPools)
        {
            obstaclePool.DestroyPoolObjects();

            for (int i = 0; i < obstaclePool.numberOfElements; i++)
            {
                Obstacle newObstacle = Instantiate(obstaclePool.obstaclePrefab, obstaclePool.poolParent);
                newObstacle.SetUpOnPoolInstantiation(obstaclePool.elementLibraryIndex);
                obstaclePool.instantiatedObjects.Add(newObstacle);
            }
        }

        foreach (ProjectilePool projectilePool in projectilesPools)
        {
            projectilePool.DestroyPoolObjects();

            for (int i = 0; i < projectilePool.numberOfElements; i++)
            {
                ProjectileScript newProjectile = Instantiate(projectilePool.projectilePrefab, projectilePool.poolParent);
                newProjectile.SetUpOnPoolInstantiation(projectilePool.elementLibraryIndex);
                projectilePool.instantiatedObjects.Add(newProjectile);
            }
        }

#if UNITY_EDITOR
        UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(gameObject.scene);
#endif
    }
Ejemplo n.º 5
0
    public EnemySpaceShipScript GetEnemyFromPool(int enemyIndex)
    {
        EnemySpaceShipScript enemy = null;

        if (enemiesPoolsDictionnary.ContainsKey(enemyIndex))
        {
            if (enemiesPoolsDictionnary[enemyIndex].Count > 0)
            {
                enemy = enemiesPoolsDictionnary[enemyIndex].Dequeue();
            }
        }

        // BONUS : Gérer le manque de ressources (instantiation de nouveaux éléments)

        if (enemy != null)
        {
            enemy.ResetPoolableObject();
        }

        return(enemy);
    }
    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;
    }