Beispiel #1
0
        public static string Generate(string jsonName, InputParam param_)
        {
            JsonData data = KAssetManager.GetUIJsonData(jsonName);

            //1.创建canvas
            GameObject root = new GameObject("Canvas_" + jsonName);

            root.layer = LayerMask.NameToLayer("UI");
            AddCanvas(root, jsonName);  //canvas组件

            //2.构建go
            ComponentCreator creator = ComponentCreatorFactory.GetTypeCreator("Container");
            GameObject       panel   = creator.Create(data, root); //创建对象

            AddPanelToRoot(panel, root);

            //3.执行builder
            //AddPanelBuilder(root);
            //RemoveAllBuildHelper(panel);

            //4.创建预制
            GenPrefabs(root, param_.isBuildAssetbundle);

            return(string.Empty);
        }
Beispiel #2
0
 private void AddMask(GameObject go, JsonData data)
 {
     if (HasParam(data, PARAM_CLIP_EFFECT))
     {
         go.AddComponent <ClipMask>();
     }
     if (HasParam(data, PARAM_MASK_STENCIL))
     {
         var    mask  = go.AddComponent <Mask>();
         KImage image = go.AddComponent <KImage>();
         string link  = (string)(data["normal"]["link"]);
         image.sprite = KAssetManager.GetSprite(link);
         //image.material = KAssetManager.GetEtcMaterialByLink(link);
         //image.color = new Color(0, 0, 0, 0);
         Vector4 border = image.sprite.border;
         if (border.x > 0 || border.y > 0 || border.z > 0 || border.w > 0)
         {
             image.type = Image.Type.Sliced;
         }
         mask.showMaskGraphic = false;
     }
     else
     {
         go.AddComponent <KImageNoTex>();  //RectMask2D还需要一张白图接受点击事件,否则scrollview不法拖动
         go.AddComponent <RectMask2D>();
     }
 }
Beispiel #3
0
        //显示当前Batch的所有Assets
        void ShowBatchAssets()
        {
            if (_batchIndice == 0)
            {
                return;
            }

            string        batchName     = _batchNames[_batchIndice];
            List <string> batchChildren = _batch2chlidren[batchName];

            JsonAsset[] newJsonAssets  = new JsonAsset[batchChildren.Count];
            int[]       newJsonIndices = new int[batchChildren.Count];
            for (int i = 0; i < batchChildren.Count; i++)
            {
                JsonAsset asset = KAssetManager.GetJson(KAssetManager.FOLDER_JSON + "/" + batchChildren[i] + ".json");
                if (asset != null)
                {
                    int indexInArr = Array.IndexOf <string>(_popupJsonNames, GetMenuItemLabel(batchChildren[i]));
                    newJsonAssets[i]  = asset;
                    newJsonIndices[i] = indexInArr;
                }
                else
                {
                    newJsonAssets[i]  = null;
                    newJsonIndices[i] = 0;
                }
            }
            _jsonAssets  = newJsonAssets;
            _jsonIndices = newJsonIndices;
        }
Beispiel #4
0
        public static void Generate(string jsonName, InputParam inputParam_)
        {
            Initialize();

            _isHighQuality = inputParam_.isHighQuality;

            _atlasName = AtlasBatchSetting.GetBatchedAtlasName(jsonName);   //获取实际的图集名称

            //WriteBatchedReadme(_atlasName, jsonName);   //提醒图集已经移到partxx

            List <string> batchedAtlasNameList = AtlasBatchSetting.GetBatchedAtlasNameList(jsonName);    //收集此图集包含的所有json名称

            for (int i = 0; i < batchedAtlasNameList.Count; i++)
            {
                string name = batchedAtlasNameList[i];
                if (batchedAtlasNameList.Count == 1 || i > 0)   //如果多于一个,跳过第一个,因为那个是目标图集,不是界面
                {
                    JsonData jsonData = KAssetManager.GetUIJsonData(name);
                    ProcessJson(jsonData);  //处理所有该图集需要用到的json, 不只是该界面的json
                }
            }

            //处理散图
            ProcessTextureDataList();

            if (_uniqueTextureDataList.Count > 0)
            {
                //需要生成图集
                GenerateAtlas();
            }
            else
            {
                Debug.Log("面板资源都在公共图集中~~~~");
            }
        }
Beispiel #5
0
        //-------∽-★-∽------∽-★-∽--------∽-★-∽Batch相关∽-★-∽--------∽-★-∽------∽-★-∽--------//

        //初始化打包图集设置
        void InitBatchSetting()
        {
            JsonAsset jsonAsset = KAssetManager.GetJson(KAssetManager.AtlasBatchSettingPath);

            if (jsonAsset == null)
            {
                //没找到BatchSetting
                _batchNames  = new string[] { "请选择图集名称" };
                _batchIndice = 0;
                return;
            }

            JsonData data    = jsonAsset.GetJsonData();
            JsonData setting = data["setting"];

            _batchNames     = new string[setting.Count + 1];
            _batchNames[0]  = "请选择图集名称";
            _batchIndice    = 0;
            _batch2chlidren = new Dictionary <string, List <string> >();

            int i = 1;

            foreach (JsonData part in setting)
            {
                string partname = part[0].ToString();
                _batchNames[i]            = partname;
                _batch2chlidren[partname] = new List <string>();
                for (int j = 1; j < part.Count; j++)
                {
                    _batch2chlidren[partname].Add(part[j].ToString());
                }

                ++i;
            }
        }
Beispiel #6
0
        /// <summary>
        /// 处理所有散图
        /// </summary>
        static void ProcessTextureDataList()
        {
            foreach (LinkTextureData textureData in _uniqueTextureDataList)
            {
                string texturePath = KAssetManager.GetTexturePath(textureData.link);    //散图在Assets下的路径(External模式下是用mklink超链过来)
                //string texturePath = KAssetManager.EnsureTextureInAssets(textureData.link);

                TextureImporterUtil.CreateReadableTextureImporter(texturePath);         //处理散图
                AssetDatabase.ImportAsset(texturePath, ImportAssetOptions.ForceUpdate); //重新import一次

                Texture2D texture = KAssetManager.GetTextureInAssets(textureData.link); //获取图片资源
                if (textureData.IsScale9Grid == true)
                {
                    //根据九宫格生成图片的最小尺寸
                    texture = Scale9GridTextureProcessor.Process(texture, textureData.top, textureData.right, textureData.bottom, textureData.left);
                }

                Rect    rect;
                Vector4 padding;
                texture                   = TextureAlphaKicker.Kick(texture, out rect, out padding); //优化掉四周的透明像素,减少图片尺寸
                texture                   = TextureClamper.Clamp(texture);                           //四周补2像素
                textureData.texture       = texture;
                textureData.spritePadding = padding;
            }
        }
Beispiel #7
0
        void ShowJsonAssets()
        {
            scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Width(500), GUILayout.Height(400));

            if (_jsonAssets != null)
            {
                for (int i = 0; i < _jsonAssets.Length; i++)
                {
                    GUILayout.Space(5);
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Json文件:", GUILayout.Width(70));
                    JsonAsset json = _jsonAssets[i];
                    if (json == null)
                    {
                        GUI.contentColor = COLOR_RED;
                    }

                    //
                    //拖动输入框, json放在外部了,不用支持拖放
                    //TextAsset jsonAsset = EditorGUILayout.ObjectField(_jsonAssets[i], typeof(TextAsset), false, GUILayout.Width(200)) as TextAsset;
                    //int jsonIndex = EditorGUILayout.Popup(_jsonIndices[i], _jsonNames, GUILayout.Width(120));
                    //if (jsonAsset != _jsonAssets[i])
                    //{
                    //    _jsonIndices[i] = Array.IndexOf<string>(_jsonNames, GetMenuItemLabel(jsonAsset.name));
                    //    _jsonAssets[i] = jsonAsset;
                    //}
                    //else if (jsonIndex != _jsonIndices[i])
                    //{
                    //    _jsonAssets[i] = AssetDatabase.LoadAssetAtPath(KAssetManager.FOLDER_JSON + "/" + _jsonNames[jsonIndex].Substring(2) + ".json", typeof(TextAsset)) as TextAsset;
                    //    _jsonIndices[i] = jsonIndex;
                    //}

                    GUILayout.TextArea(json != null ? json.name : _popupJsonNames[0], GUILayout.Width(200));
                    int jsonIndex = EditorGUILayout.Popup(_jsonIndices[i], _popupJsonNames, GUILayout.Width(120));
                    if (jsonIndex != _jsonIndices[i])
                    {
                        if (jsonIndex == 0)
                        {
                            //删除此项
                            _jsonAssets[i]  = null;
                            _jsonIndices[i] = 0;
                        }
                        else
                        {
                            string name = _popupJsonNames[jsonIndex].Substring(2); //去掉"A/"
                            _jsonAssets[i]  = KAssetManager.GetUIJson(name);
                            _jsonIndices[i] = jsonIndex;                           //记录选中序号
                        }
                    }

                    GUI.contentColor = Color.white;
                    GUILayout.EndHorizontal();
                }
            }

            EditorGUILayout.EndScrollView();
        }
Beispiel #8
0
        static void PrepareAtlasFolders(string atlasName)
        {
            List <string> names = AtlasBatchSetting.GetBatchedAtlasNameList(atlasName);

            for (int i = 0; i < names.Count; i++)
            {
                KAssetManager.CreateAtlasFolder(names[i]);
            }
        }
Beispiel #9
0
        static void GenerateAtlas()
        {
            _atlas = new Texture2D(ATLAS_MAX_SIZE, ATLAS_MAX_SIZE);
            Rect[] rects = _atlas.PackTextures(GetPackTextures(), 0, ATLAS_MAX_SIZE, false);    //pack!

            string atlasPath      = KAssetManager.GetAtlasPath(_atlasName);
            string alphaAtlasPath = KAssetManager.GetAlphaAtlasPath(_atlasName);
            string folderPath     = mg.org.FileUtility.GetFolderFromFullPath(atlasPath);

            mg.org.FileUtility.EnsureDirectory(folderPath);        //创建文件夹

            _atlas = AtlasOptimizer.Optimize(_atlas, rects, true); //优化图集
            AtlasWriter.Write(_atlas, atlasPath);                  //保存图集
            LogAtlasSize(_atlas, _atlasName);

            // 暂时不采用分开的纹理格式, 删除ALPHA贴图
            AssetDatabase.DeleteAsset(alphaAtlasPath);

            bool isTurecolor = AtlasQualitySetting.Contains(_atlasName);

            //if(isTurecolor)
            //{
            //    AssetDatabase.DeleteAsset(alphaAtlasPath);
            //}
            //else
            //{
            //    //EtcGeneratorWrapper.Execute(atlasPath, _isHighQuality);
            //    ImageChannelSpliterWrapper.Execute(atlasPath, _isHighQuality);
            //    AssetDatabase.ImportAsset(alphaAtlasPath, ImportAssetOptions.ForceUpdate);
            //    TextureImporterUtil.CreateEtcAlphaChannelImporter(alphaAtlasPath);
            //    AssetDatabase.ImportAsset(alphaAtlasPath, ImportAssetOptions.ForceUpdate);
            //}

            try
            {
                AssetDatabase.ImportAsset(atlasPath, ImportAssetOptions.ForceUpdate);
            }
            catch (System.Exception e)
            {
                Debug.Log("ImportAssetError:" + atlasPath);
            }

            isTurecolor = false;    //都用压缩格式
            TextureImporterFormat format = isTurecolor ? TextureImporterFormat.ARGB32 : TextureImporterFormat.AutomaticCompressed;

            TextureImporterUtil.CreateMultipleSpriteImporter(atlasPath, rects, GetPackTextureNames(), GetSpriteBorders(), _atlas.width, _atlas.height, format, ATLAS_MAX_SIZE);
            AssetDatabase.ImportAsset(atlasPath, ImportAssetOptions.ForceUpdate);
            //记录所有图片的边距数据
            AtlasSpritePaddingHelper.WriteSpritePaddingRecord(_uniqueTextureDataList, KAssetManager.GetAtlasSpritePaddingRecordPath(_atlasName));
            //暂时不采用分开的纹理格式

            //采用替换内置材质的方式
            //EtcMaterialCreator.CreateWithoutAlpha(EtcMaterialCreator.PSD4UGUI_ONE_TEX_SHADER, atlasPath);
        }
Beispiel #10
0
        public static void Initialize()
        {
            JsonAsset jsonAsset = KAssetManager.GetJson(KAssetManager.AtlasQualitySettingPath);

            if (jsonAsset != null)
            {
                Dictionary <string, List <string> > dict = JsonMapper.ToObject <Dictionary <string, List <string> > >(jsonAsset.text);
                _highQualityAtlasList = dict["highQuality"];
            }
            else
            {
                _highQualityAtlasList = new List <string>();
            }
        }
        private static void LoadAtlasSpritePaddingRecord(string atlasName)
        {
            string    path      = KAssetManager.GetAtlasSpritePaddingRecordPath(atlasName);
            TextAsset jsonAsset = AssetDatabase.LoadAssetAtPath <TextAsset>(path);

            if (jsonAsset != null)
            {
                Dictionary <string, int[]> record = JsonMapper.ToObject <Dictionary <string, int[]> >(jsonAsset.text);
                _atlasSpritePaddingRecordDict.Add(atlasName, record);
            }
            else
            {
                _atlasSpritePaddingRecordDict.Add(atlasName, new Dictionary <string, int[]>());
            }
        }
Beispiel #12
0
        void Initialize()
        {
            KAssetManager.Initialize();

            _jsonAssets     = new JsonAsset[1];
            _jsonIndices    = new int[1];
            _popupJsonNames = new string[] { "选择Json文件" };

            _constructError = string.Empty;
            _error          = string.Empty;

            _inputParam = new InputParam();

            RefreshJsonNames();  //初始化json列表
            InitBatchSetting();
        }
Beispiel #13
0
        private static HashSet <string> _atlasNameSet; //在某次运行中已经生成的Atlas集合,避免重复生成Atlas

        public static void Initialize()
        {
            _batchSetting = new List <List <string> >();
            _atlasNameSet = new HashSet <string>();

            JsonAsset jsonAsset = KAssetManager.GetJson(KAssetManager.AtlasBatchSettingPath);

            if (jsonAsset == null)
            {
                Debug.LogWarning("未找到图集合并设置 " + KAssetManager.AtlasBatchSettingPath);
            }
            else
            {
                Dictionary <string, List <List <string> > > dict = JsonMapper.ToObject <Dictionary <string, List <List <string> > > >(jsonAsset.text);
                _batchSetting = dict["setting"];
                for (int i = 0; i < _batchSetting.Count; ++i)
                {
                    _batchSetting[i] = ListUtil.RemoveRepeat(_batchSetting[i]); //剔除重复项
                }
            }
        }
Beispiel #14
0
        //保存readme
        static void WriteBatchedReadme(string atlasName, string jsonName)
        {
            string path = KAssetManager.AtlasFolder + "/" + jsonName + "/readme.txt";

            if (atlasName == jsonName)
            {
                AssetDatabase.DeleteAsset(path);
                return;
            }

            AssetDatabase.DeleteAsset(KAssetManager.GetAtlasPath(jsonName));
            AssetDatabase.DeleteAsset(KAssetManager.GetAlphaAtlasPath(jsonName));
            AssetDatabase.DeleteAsset(KAssetManager.GetEtcMaterialPath(jsonName));

            //合并到别的图集,删除原来的文件夹
            KAssetManager.DeleteAtlasFolder(jsonName);

            //不导出readme了
            //string content = string.Format(BATCHED_TEMPLATE, jsonName, atlasName);
            //File.WriteAllText(Application.dataPath.Replace("Assets", "") + path, content, System.Text.Encoding.Unicode);
            //AssetDatabase.ImportAsset(path);
        }
Beispiel #15
0
        protected virtual void AddTextComponent(GameObject go, JsonData stateData)
        {
            KText text = go.AddComponent <KText>();

            text.supportRichText = true;
            JsonData formatData = stateData["format"];

            text.color    = GetColor((string)formatData["color"], 100);
            text.font     = KAssetManager.GetFont((string)formatData["font"]);
            text.fontSize = (int)formatData["size"];
            text.text     = (string)stateData["content"];
            text.material = KAssetManager.GetFontMaterial();
            if (text.text == "{0}")
            {
                text.text = "?";
            }
            //单行文本默认值,超出文本范围不显示
            text.horizontalOverflow = HorizontalWrapMode.Overflow;  //改为自动增长
            text.verticalOverflow   = VerticalWrapMode.Truncate;
            //多行文本垂直方向超出范围仍然显示
            float h = 0.0f;

            if (stateData["height"].IsInt)
            {
                h = (float)(int)stateData["height"];
            }
            else
            {
                h = (float)(double)stateData["height"];
            }
            bool isMutilple = IsMutilpleLine(h, (int)formatData["size"]); //多行

            if (isMutilple)
            {
                text.horizontalOverflow = HorizontalWrapMode.Wrap;
                text.verticalOverflow   = VerticalWrapMode.Overflow;
            }
            else//单行,检查overflow是否设置
            {
                if (HasParam(stateData, PATTERN_OVERFLOW) == true)
                {
                    text.horizontalOverflow = HorizontalWrapMode.Overflow;  //水平多行
                }
                else if (HasParam(stateData, PATTERN_WRAP) == true)
                {
                    text.horizontalOverflow = HorizontalWrapMode.Wrap;  //超出文本范围不显示
                }

                if (HasParam(stateData, PATTERN_OVERFLOW_V) == true)
                {
                    text.verticalOverflow = VerticalWrapMode.Overflow;      //垂直多行
                    //如果直接指定垂直方向overflow,那横向将自动设为换行
                    text.horizontalOverflow = HorizontalWrapMode.Wrap;
                }
            }
            if (stateData.Keys.Contains("langId") == true)  //语言包,暂时没用
            {
                text.langId = (int)stateData["langId"];
            }
            text.alignment = TextAnchor.UpperLeft;  //文本对齐方式
            if (stateData.Keys.Contains(PATTERN_ALIGNMENT) == true)
            {
                string alignment = (string)stateData[PATTERN_ALIGNMENT];
                text.alignment = (TextAnchor)Enum.Parse(typeof(TextAnchor), alignment, true);
            }
            text.lineSpacing = 1.0f;
            if (stateData.Keys.Contains("lineSpacing") == true)   //行距
            {
                text.lineSpacing = float.Parse((string)stateData["lineSpacing"]);
            }
            text.resizeTextForBestFit = GetBestFitParam(stateData); //缩放文本框来适应文本框
            int bold = (int)formatData["bold"];                     //粗体

            text.fontStyle = (bold == 1) ? FontStyle.Bold : FontStyle.Normal;
            text.fontStyle = GetFontStyleParam(stateData); //覆盖了上面。。
            AddUnderline(go, stateData);                   //添加下划线
            AddGradientEffect(go, stateData);
            AddStrokeEffect(go, stateData);                //添加描边
            AddShadowEffect(go, stateData);                //添加阴影
            if (isMutilple == false)
            {
                SetPreferredSize(go);
            }
            if (go.name == STATE_DISABLE)
            {
                text.grey = true;   //置灰
            }
        }
Beispiel #16
0
        //-------∽-★-∽------∽-★-∽--------∽-★-∽RawImage∽-★-∽--------∽-★-∽------∽-★-∽--------//

        void AddRawImageComponent(GameObject go)
        {
            var rawimage = go.AddComponent <RawImage>();

            rawimage.material = KAssetManager.GetMaterial("Assets/Resources/Materials/UI_OneChannel.mat");
        }
Beispiel #17
0
        protected virtual void AddImageComponent(GameObject go, JsonData stateData)
        {
            KImage image = null;

            if (HasParam(stateData, NO_TEX) == true)     //纯色
            {
                image      = go.AddComponent <KImageNoTex>();
                image.type = Image.Type.Simple;
            }
            else if (HasParam(stateData, PATTERN_SCALE_9_GRID) == true) //九宫格
            {
                image = AddScale9GridImage(go);
            }
            else if (HasParam(stateData, PATTERN_UV) == true)    //渐变
            {
                image = AddUvImage(go, stateData);
            }
            else
            {
                image      = go.AddComponent <KImage>();
                image.type = Image.Type.Simple;
            }

            string link = (string)stateData["link"];    //资源路径

            if (HasParam(stateData, NO_TEX) == false)
            {
                image.sprite = KAssetManager.GetSprite(link);
                //if (LinkTextureData.GetAtlasName(link) != image.sprite.texture.name)      //引用其他part的图片,暂时不需要
                //{
                //    link = image.sprite.texture.name + "." + LinkTextureData.GetTextureName(link);
                //    link = link.Replace("UI_", "");
                //}

                image.spritePadding = AtlasSpritePaddingHelper.GetAtlasSpritePadding(link);
            }

            if (go.name.Contains(SHARED_ANCHOR) || link.Contains(SHARED_ANCHOR))
            {
                //icon用
                image.color = new Color(1.0f, 1.0f, 1.0f, 1.0f);
                var sc        = GetSolidFillColor(stateData);
                var blendMode = GetSolidFillMode(stateData);
                if (blendMode == "normal")
                {
                    image.overlayColor = sc;
                }
                else if (blendMode == "multiply")
                {
                    image.color        = sc;
                    image.overlayColor = new Color(1.0f, 1.0f, 1.0f, 0.0f);
                }
            }
            else if (HasParam(stateData, NO_TEX))
            {
                //纯色
                image.sprite = null;
                //image.material = KAssetManager.GetNoTexMaterial();
                image.color = GetSolidFillColor(stateData); //配置颜色
                if (GetAlpha(stateData) > 0.03)
                {
                    var comNoTex = (KImageNoTex)image;
                    comNoTex.NeedColor = true;
                }
            }
            else
            {
                //image.material = KAssetManager.GetEtcMaterialByLink(link);  //设置为ui对应的材质球
                var sc        = GetSolidFillColor(stateData);
                var blendMode = GetSolidFillMode(stateData);
                if (blendMode == "normal")
                {
                    image.overlayColor = sc;
                }
                else if (blendMode == "multiply")
                {
                    image.color        = sc;
                    image.overlayColor = new Color(1.0f, 1.0f, 1.0f, 0.0f);
                }
                //image.color = new Color(1.0f, 1.0f, 1.0f, 0.0f);
            }

            image.alpha    = GetAlpha(stateData);    //透明度
            image.rotation = GetRotation(stateData); //ImageType为Simple时
            image.Initialize();
        }