public static WeaponScript ComposeWeapon(WeaponCreationParameters weaponCreationParameters, string weaponName) { GameObject newWeaponObject = new GameObject(); newWeaponObject.name = weaponName; WeaponScript weaponComponent = newWeaponObject.AddComponent <WeaponScript>(); List <ShootOriginScript> origins = new List <ShootOriginScript>(); for (int i = 0; i < weaponCreationParameters.numberOfShootOrigins; i++) { GameObject newOriginObject = new GameObject(); newOriginObject.name = "Shoot Origin " + (i + 1); newOriginObject.transform.parent = newWeaponObject.transform; newOriginObject.transform.localPosition = Vector3.zero; newOriginObject.transform.localRotation = Quaternion.identity; ShootOriginScript shootOriginComponent = newOriginObject.AddComponent <ShootOriginScript>(); float xPos = (-weaponCreationParameters.lateralDistanceBetweenEachOrigin * (weaponCreationParameters.numberOfShootOrigins - 1)) / 2 + i * weaponCreationParameters.lateralDistanceBetweenEachOrigin; newOriginObject.transform.localPosition = new Vector3(xPos, 0, 0); float zAngle = (weaponCreationParameters.angleBetweenEachOrigin * (weaponCreationParameters.numberOfShootOrigins - 1)) / 2 - i * weaponCreationParameters.angleBetweenEachOrigin; newOriginObject.transform.localRotation = Quaternion.Euler(0, 0, zAngle); origins.Add(shootOriginComponent); } weaponComponent.SetShootOrigins(origins); return(weaponComponent); }
private void OnGUI() { EditorStaticMethods.ShowFolderAndAskIfCreateNew(ref selectedFolderRef, ref createFolder); GUILayout.Space(12); float oldWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth *= 1.5f; ShowWeaponSetCreationParameters(selectedFolderRef, ref newWeaponName, createFolder, ref createLinkedObject, ref newWeaponCreationParameters); EditorGUIUtility.labelWidth = oldWidth; if (selectedFolderRef != null) { if (GUILayout.Button("Create the new Weapon : \"" + newWeaponName + "\" !")) { string finalFolderPath = selectedFolderRef.GetFolderPath(); if (createFolder) { string folderCreationPath = finalFolderPath; finalFolderPath = AssetDatabase.GenerateUniqueAssetPath(finalFolderPath + "/" + newWeaponName + " Set"); Debug.Log("Create Folder \"" + newWeaponName + "Set" + "\" in \"" + folderCreationPath + "\""); AssetDatabase.CreateFolder(folderCreationPath, newWeaponName + " Set"); } WeaponScript newWeaponPrefab = null; if (createLinkedObject) { 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); } if (newWeaponPrefab != null) { Selection.activeObject = newWeaponPrefab; EditorGUIUtility.PingObject(newWeaponPrefab); // PrefabUtility.LoadPrefabContents(AssetDatabase.GetAssetPath(newWeaponPrefab.GetInstanceID())); } else if (newWeaponParameters != null) { Selection.activeObject = newWeaponParameters; EditorGUIUtility.PingObject(newWeaponParameters); } } } }
public static void ShowWeaponSetCreationParameters(DefaultAsset selectedFolderRef, ref string newWeaponName, bool createFolder, ref bool createLinkedObject, ref WeaponCreationParameters weaponCreationParameters) { EditorGUILayout.LabelField("Weapon Name", EditorStyles.boldLabel); newWeaponName = EditorGUILayout.TextField("New Weapon Name", newWeaponName); GUILayout.Space(12); EditorGUILayout.LabelField("Weapon Object", EditorStyles.boldLabel); createLinkedObject = EditorGUILayout.Toggle("Create Weapon Object", createLinkedObject); if (createLinkedObject) { weaponCreationParameters.numberOfShootOrigins = EditorGUILayout.IntField("Number of Shoot Origin", weaponCreationParameters.numberOfShootOrigins); weaponCreationParameters.lateralDistanceBetweenEachOrigin = EditorGUILayout.FloatField("Lateral Distance between each Origin", weaponCreationParameters.lateralDistanceBetweenEachOrigin); weaponCreationParameters.angleBetweenEachOrigin = EditorGUILayout.FloatField("Angle between each Origin", weaponCreationParameters.angleBetweenEachOrigin); } GUILayout.Space(12); }
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; }