public void Copy(TFormatterSetting srcSetting) { standaloneDefault = srcSetting.standaloneDefault; androidDefault = srcSetting.androidDefault; iosDefault = srcSetting.iosDefault; formatList.Clear(); for (int i = 0; i < srcSetting.formatList.Count; i++) { formatList.Add((FormatPathPair)srcSetting.formatList[i].Clone()); } }
public object Clone() { TFormatterSetting ts = (TFormatterSetting)MemberwiseClone(); ts.formatList = new List <FormatPathPair>(); for (int i = 0; i < formatList.Count; i++) { ts.formatList.Add((FormatPathPair)formatList[i].Clone()); } return(ts); }
public static void FormatAll(bool showTip = true) { bool success = true; reimportList.Clear(); TFormatterSetting tfs = AssetDatabase.LoadAssetAtPath <TFormatterSetting>(settingPath); List <FormatPathPair> ctf = tfs.formatList; AllApplyFormat(ctf); CombineParentPath(reimportList); for (int i = 0; i < reimportList.Count; i++) { string path = reimportList[i]; if (Directory.Exists(path)) { if (EditorUtility.DisplayCancelableProgressBar("TextureFormatter", string.Format("Reimporting {0}", path), (i + 1) / reimportList.Count)) { success = false; break; } ; AssetDatabase.ImportAsset(reimportList[i], ImportAssetOptions.ImportRecursive); } else { if (EditorUtility.DisplayCancelableProgressBar("TextureFormatter", string.Format("Reimporting {0}", path), (i + 1) / reimportList.Count)) { success = false; break; } ; AssetDatabase.ImportAsset(reimportList[i]); } } EditorUtility.ClearProgressBar(); if (success) { if (showTip) { EditorUtility.DisplayDialog("TextureFormatter", "资源格式化完成!", "确定"); } else { Debug.Log("资源格式化完成!"); } } else { Debug.LogWarning("资源格式化中断"); } }
void OnGUI() { try { scrollPos = GUILayout.BeginScrollView(scrollPos); GUILayout.Label("默认格式:"); setting.standaloneDefault = (TextureImporterFormat)EditorGUILayout.EnumPopup("StandAlone", (StandAloneCompress)setting.standaloneDefault); setting.androidDefault = (TextureImporterFormat)EditorGUILayout.EnumPopup("Android", (AndroidCompress)setting.androidDefault); setting.iosDefault = (TextureImporterFormat)EditorGUILayout.EnumPopup("IOS", (IosCompress)setting.iosDefault); GUILayout.BeginHorizontal(); GUILayout.Label("平台设置选择:"); toolBar = GUILayout.Toolbar(toolBar, platforms); GUILayout.EndHorizontal(); if (toolBar != editPlatform) { editPlatform = toolBar; OnPlatformChange(); } for (int i = 0; i < curtf.Count; i++) { FormatPathPair fpp = curtf[i]; ItemState its = stateList[i]; TextureFormat tf = fpp.GetFormatByPlatform(editPlatform); GUILayout.BeginVertical("box"); GUILayout.BeginHorizontal(); GUI.backgroundColor = Color.red; if (GUILayout.Button("X", GUILayout.MaxWidth(20))) { curtf.RemoveAt(i); stateList.RemoveAt(i); return; } GUI.backgroundColor = Color.white; if (its.rename) { fpp.name = GUILayout.TextField(fpp.name, GUILayout.MaxWidth(100)); GUI.backgroundColor = Color.yellow; if (GUILayout.Button("R", GUILayout.MaxWidth(20))) { its.rename = false; } GUI.backgroundColor = Color.white; } else { Rect rect = EditorGUILayout.BeginHorizontal("Button", GUILayout.MaxWidth(120)); if (GUI.Button(rect, GUIContent.none)) { its.expand = !its.expand; } GUILayout.Label(its.expand ? "-" : "+"); GUILayout.Label(fpp.name); GUILayout.Label(""); EditorGUILayout.EndHorizontal(); GUI.backgroundColor = Color.yellow; if (GUILayout.Button("R", GUILayout.MaxWidth(20))) { its.rename = true; } GUI.backgroundColor = Color.white; } fpp.iType = (ImporterType)EditorGUILayout.EnumPopup(fpp.iType); if (fpp.iType == ImporterType.Texture) { tf.format = (TextureImporterFormat)EditorGUILayout.EnumPopup(TextureFormat.GetPlatformEnum(editPlatform, (int)tf.format)); } GUI.backgroundColor = Color.blue; if (GUILayout.Button("Apply", GUILayout.MaxWidth(43))) { List <FormatPathPair> applyList = new List <FormatPathPair>(); applyList.Add(fpp); Format(applyList, (TFormatterPlatform)editPlatform); return; } GUI.backgroundColor = Color.white; GUILayout.EndHorizontal(); if (its.expand) { switch (fpp.iType) { case ImporterType.Texture: DrawTextureSettingItem(tf, fpp); break; case ImporterType.Model: DrawModelSettingItem(tf, fpp); break; case ImporterType.Audio: DrawAudioSettingItem(tf, fpp); break; } } GUILayout.EndVertical(); } GUILayout.Label("", GUILayout.Height(20)); GUILayout.BeginArea(new Rect(0, position.height - 20 + scrollPos.y, position.width, 20)); GUILayout.BeginHorizontal(); if (GUILayout.Button("添加自定义配置")) { GUILayout.EndHorizontal(); if (scrollPos.y == 0) { GUILayout.EndArea(); } GUILayout.EndScrollView(); for (int i = 0; i < stateList.Count; i++) { stateList[i].expand = false; } int newIndex = 1; while (!CheckIndexAvailable(newIndex, curtf)) { newIndex++; } FormatPathPair fpp = new FormatPathPair(newIndex); curtf.Add(fpp); ItemState its = new ItemState(); its.expand = true; stateList.Add(its); return; } if (GUILayout.Button("保存配置到磁盘")) { GUILayout.EndHorizontal(); if (scrollPos.y == 0) { GUILayout.EndArea(); } GUILayout.EndScrollView(); EditorUtility.SetDirty(setting); AssetDatabase.SaveAssets(); tmp_setting = (TFormatterSetting)setting.Clone(); EditorUtility.DisplayDialog("TextureFormatter", "配置保存成功!", "确定"); return; } if (GUILayout.Button("回滚至磁盘版本")) { GUILayout.EndHorizontal(); if (scrollPos.y == 0) { GUILayout.EndArea(); } GUILayout.EndScrollView(); setting.Copy(tmp_setting); return; } if (GUILayout.Button("应用当前平台配置")) { GUILayout.EndHorizontal(); if (scrollPos.y == 0) { GUILayout.EndArea(); } GUILayout.EndScrollView(); Format(setting.formatList, (TFormatterPlatform)editPlatform); return; } if (GUILayout.Button("应用全平台配置")) { GUILayout.EndHorizontal(); if (scrollPos.y == 0) { GUILayout.EndArea(); } GUILayout.EndScrollView(); FormatAll(); return; } GUILayout.EndHorizontal(); GUILayout.EndArea(); GUILayout.EndScrollView(); } catch (Exception e) { Debug.Log(e); Close(); } }