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<ImageMergeWindow> ();
        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<Texture> 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<Renderer> ().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");
    }
  */
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值