Unity 编译器扩展 -参考

创建预制件

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

public class ImageMergeWindow :EditorWindow  {

    [MenuItem("Window/S_ImageMerge")]
    static void S_ImageMerge()
    {
        ImageMergeWindow window = EditorWindow.GetWindow ();
        window.autoRepaintOnSceneChange = true;
        window.Show ();
    //    EditorApplication.hierarchyWindowChanged += hierarchyWindowChanged;
    //    EditorApplication.projectWindowChanged += projectWindowChanged;

    }
//    static void  projectWindowChanged()
//    {
//        Debug.Log ("和下面的update方法一样 projectWindowChanged 26次什么鬼");
//    }
//
//
//    static void  hierarchyWindowChanged()
//    {
//        Debug.Log ("和下面的update方法一样 hierarchyWindowChanged");
//    }

    private int row;
    private int list;

    private List textures;
    private GameObject parentObj;


    int num;
    Texture texture;
    void OnGUI()
    {
        EditorGUILayout.BeginHorizontal ();
        EditorGUILayout.LabelField ("行:",GUILayout.Width(20));
        row = EditorGUILayout.IntField (row,GUILayout.Width(30));
        EditorGUILayout.LabelField ("列:",GUILayout.Width(20));
        list = EditorGUILayout.IntField ( list,GUILayout.Width(30));
        EditorGUILayout.EndHorizontal ();
    
        //Debug.Log ("走了几次" + num++);
        for (int i = 0; i < 4; i++) {
            EditorGUILayout.BeginHorizontal();
            for (int j = 0; j < 3; j++) {
                texture =    EditorGUILayout.ObjectField ("", texture, typeof(Texture), true, GUILayout.Width (70)) as Texture;
                //Debug.Log ("为什么走了这么多遍?" + num++ +"TextureCount"+textures.Count);
            }
            EditorGUILayout.EndHorizontal ();
        }
    

        if (GUILayout.Button ("创建")) {
        //    Debug.Log ("创建..."+ textures.Count);

            if (parentObj == null) {
                parentObj = new GameObject ();
                parentObj.name = "Production" + num++;
            }

            GameObject subObj = GameObject.CreatePrimitive (PrimitiveType.Quad);
            subObj.transform.Rotate (0, 180, 0);
            subObj.GetComponent ().sharedMaterial.mainTexture =texture;
            subObj.transform.SetParent (parentObj.transform);
            PrefabUtility.CreatePrefab ("Assets/Prefabs/"+ parentObj.name + ".prefab", parentObj);

        }
    }



    /*
    void OnInspectorUpdate()
    {
        //Debug.Log ("这个方法刷新一直走....");
    }

    void OnHierarchyChange() {
        Debug.Log("点击创建的时候才走OnHierarchyChange");
    }
    void OnProjectChange() {
        //Debug.Log("OnProjectChange");
    }

    void OnSelectionChange()
    {
        Debug.Log ("选中物体才会走OnSelectionChange");
    }
  */
}


你可能感兴趣的:(Unity 编译器扩展 -参考)