예제 #1
0
        protected static void RebuildSeperateRGBandAlphaNGUIAtlas(string assetPath)
        {
            try
            {
                EditorUtility.DisplayProgressBar("设置NGUI图集", string.Format("正在进行 {0}", assetPath), 1);
                string pngFile    = Path.ChangeExtension(assetPath, "png");
                string prefabFile = Path.ChangeExtension(assetPath, "prefab");
                string matFile    = Path.ChangeExtension(assetPath, "mat");

                GameObject prefabAsset = GEditorNGUILoader.LoadAtlasPrefab(prefabFile);
                Material   matAsset    = GEditorNGUILoader.LoadETCMaterial(matFile);
                if (matAsset == null || prefabAsset == null)
                {
                    Debug.LogError(string.Format("AssetPath: {0}  Material或者预制体为空", assetPath));
                    return;
                }
                UIAtlas uiAtlas = prefabAsset.GetComponent <UIAtlas>();
                if (uiAtlas == null)
                {
                    uiAtlas = prefabAsset.AddComponent <UIAtlas>();
                }

                // 配置图集参数

                Texture2D _mainTex  = GEditorNGUILoader.LoadTexture2D(pngFile.Replace(".png", "_RGB.png"));
                Texture2D _alphaTex = GEditorNGUILoader.LoadTexture2D(pngFile.Replace(".png", "_Alpha.png"));

                TextAsset dataAsset = AssetDatabase.LoadAssetAtPath <TextAsset>(assetPath) as TextAsset;
                if (_mainTex == null || _alphaTex == null || dataAsset == null)
                {
                    Debug.LogError(string.Format("AssetPath: {0}  图集所需图片或者配置文件不存在", assetPath));
                    return;
                }
                matAsset.SetTexture("_MainTex", _mainTex);
                matAsset.SetTexture("_MainTex_A", _alphaTex);
                uiAtlas.spriteMaterial = matAsset;
                NGUIJson.LoadSpriteData(uiAtlas, dataAsset);
                uiAtlas.MarkAsChanged();
                EditorUtility.SetDirty(uiAtlas);
                AssetDatabase.SaveAssets();
            }
            catch (System.Exception ex)
            {
                Debug.LogError("Error " + ex.ToString());
            }
            finally
            {
                EditorUtility.ClearProgressBar();
            }
        }
예제 #2
0
        public static void DoImportBitmapFont(string fntPath)
        {
            if (!IsFnt(fntPath))
            {
                return;
            }
            try
            {
                EditorUtility.DisplayProgressBar("Build Bitmap Font", string.Format("正在进行 {0}", fntPath), 1);
                string pngPath    = Path.ChangeExtension(fntPath, "png");
                string prefabPath = Path.ChangeExtension(fntPath, "prefab");
                string matPath    = Path.ChangeExtension(fntPath, "mat");

                GameObject prefabAsset = GEditorNGUILoader.LoadAtlasPrefab(prefabPath);
                Material   matAsset    = GEditorNGUILoader.LoadTransparentMaterial(matPath);
                UIFont     mUIFont     = prefabAsset.GetComponent <UIFont>();
                if (mUIFont == null)
                {
                    mUIFont = prefabAsset.AddComponent <UIFont>();
                }
                if (matAsset == null || prefabAsset == null)
                {
                    Debug.LogError(string.Format("Build Bitmap Font -> AssetPath: {0}  Material或者预制体为空", fntPath));
                    return;
                }
                // 配置图集参数
                Texture2D pngAsset = GEditorNGUILoader.LoadTexture2D(pngPath);
                TextAsset data     = AssetDatabase.LoadAssetAtPath <TextAsset>(fntPath) as TextAsset;
                if (pngAsset == null || data == null)
                {
                    Debug.LogError(string.Format("Build Bitmap Font -> AssetPath: {0}  配置文件缺失", fntPath));
                    return;
                }
                BMFontReader.Load(mUIFont.bmFont, NGUITools.GetHierarchy(mUIFont.gameObject), data.bytes);
                matAsset.SetTexture("_MainTex", pngAsset);
                mUIFont.material = matAsset;
                mUIFont.MarkAsChanged();
                EditorUtility.SetDirty(mUIFont);
                AssetDatabase.SaveAssets();
            }
            catch (System.Exception ex)
            {
                EditorUtility.DisplayDialog("异常", ex.ToString(), "确定");
            }
            finally
            {
                EditorUtility.ClearProgressBar();
            }
        }