ScriptObject创建工具

using UnityEngine;
using System.Collections;
using UnityEditor;
using System.Reflection;

public class ScriptObjectCreator : EditorWindow
{
    public string scriptName;
    public string fieldName;

    public static void GetData()
    {
        string stringholderpath = "Assets/bonenames.asset";
        TestScriptObject a = AssetDatabase.LoadAssetAtPath(stringholderpath, typeof(TestScriptObject)) as TestScriptObject;
        Debug.LogError(a.test[0]);
    }
    [MenuItem("tools/CreateScriptObject")]
    public static void GetWindow()
    {
        EditorWindow.GetWindow("CreatorWindow");
    }
    void OnGUI()
    {
        EditorGUILayout.BeginVertical();
        scriptName = EditorGUILayout.TextField(scriptName, GUILayout.Width(250));
        fieldName = EditorGUILayout.TextField(fieldName, GUILayout.Width(250));
        if (GUILayout.Button(new GUIContent("确定")))
        {
            Assembly assembly = Assembly.GetExecutingAssembly();
            System.Type[] types = assembly.GetTypes();
            System.Type instanceType = null;
            foreach (var a in types)
            {
                if(a.ToString() == scriptName)
                {
                    instanceType = (System.Type)a;
                    break;
                }
            }

            ScriptableObject temp = ScriptableObject.CreateInstance(instanceType);
            string stringholderpath = "Assets/"+ fieldName + ".asset";
            AssetDatabase.CreateAsset(temp, stringholderpath);
        }
        EditorGUILayout.EndVertical();
    }
}

你可能感兴趣的:(ScriptObject创建工具)