Skip to content

Instantly share code, notes, and snippets.

@SiarheiPilat
Last active October 6, 2020 08:20
Show Gist options
  • Save SiarheiPilat/28db660d72196bda5c7989d4379922d2 to your computer and use it in GitHub Desktop.
Save SiarheiPilat/28db660d72196bda5c7989d4379922d2 to your computer and use it in GitHub Desktop.
Editor script to create a whole bunch of scriptable objects from a list of comma-separated names or selected game objects in the scene.
using UnityEditor;
using UnityEngine;
public class ScriptableObjectMassCreator : EditorWindow
{
public string str;
public bool FromText;
public bool SplitComma;
[MenuItem("Window/Scriptable Object Mass Creator")]
static void Init()
{
ScriptableObjectMassCreator window = (ScriptableObjectMassCreator)GetWindow(typeof(ScriptableObjectMassCreator));
window.minSize = new Vector2(405.0f, 550.0f);
window.Show();
}
void OnGUI()
{
FromText = EditorGUILayout.Toggle("From text", FromText);
if (FromText)
{
str = GUILayout.TextArea(str, GUILayout.ExpandWidth(true), GUILayout.Height(500.0f));
}
else
{
if(Selection.transforms.Length > 0)
{
str = "";
for (int i = 0; i < Selection.transforms.Length; i++)
{
str = str + Selection.transforms[i].gameObject.name + "\n";
}
str = GUILayout.TextArea(str, GUILayout.ExpandWidth(true), GUILayout.Height(500.0f));
}
}
if (GUI.Button(new Rect(5, 510, 400, 40), "Create"))
{
MassCreate();
}
}
void MassCreate()
{
string[] names;
if (SplitComma)
{
names = str.Split(',');
}
else
{
names = str.Split('\n');
}
for (int i = 0; i < names.Length; i++)
{
if (names[i] == "") return;
names[i] = names[i].Trim();
var obj = CreateInstance(typeof(/* your so type here */));
AssetDatabase.CreateAsset(obj, "Assets/" + names[i] + ".asset");
}
AssetDatabase.Refresh();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment