public override void OnInspectorGUI() { base.OnInspectorGUI(); serializedObject.Update(); EditorGUILayout.PropertyField(m_UICamera); if (!EditorApplication.isPlaying) { EditorGUILayout.HelpBox("Available during runtime only.", MessageType.Info); } else { EditorGUILayout.LabelField("UIPackage All Count", UIPackage.GetPackages().Count.ToString()); FGuiComponent fGuiComponent = (FGuiComponent)target; EditorGUILayout.BeginVertical("box"); { foreach (KeyValuePair <string, int> valuePair in fGuiComponent.FguiRef) { EditorGUILayout.LabelField(Utility.Text.Format("{0} RefCount:{1}", valuePair.Key, valuePair.Value)); } } EditorGUILayout.EndVertical(); } Repaint(); serializedObject.ApplyModifiedProperties(); }
public static void LoadPackages() { if (Application.isPlaying || _loaded) { return; } #if !UNITY_5 EditorApplication.update -= EditorApplication_Update; EditorApplication.update += EditorApplication_Update; #endif _loaded = true; UIPackage.RemoveAllPackages(); FontManager.Clear(); NTexture.DisposeEmpty(); string[] ids = AssetDatabase.FindAssets("@sprites t:textAsset"); int cnt = ids.Length; for (int i = 0; i < cnt; i++) { string assetPath = AssetDatabase.GUIDToAssetPath(ids[i]); int pos = assetPath.LastIndexOf("@"); if (pos == -1) { continue; } assetPath = assetPath.Substring(0, pos); if (AssetDatabase.AssetPathToGUID(assetPath) != null) { UIPackage.AddPackage(assetPath, (string name, string extension, System.Type type) => { return(AssetDatabase.LoadAssetAtPath(name + extension, type)); } ); } } List <UIPackage> pkgs = UIPackage.GetPackages(); pkgs.Sort(CompareUIPackage); cnt = pkgs.Count; packagesPopupContents = new GUIContent[cnt + 1]; for (int i = 0; i < cnt; i++) { packagesPopupContents[i] = new GUIContent(pkgs[i].name); } packagesPopupContents[cnt] = new GUIContent("Please Select"); UIConfig.ClearResourceRefs(); UIConfig[] configs = GameObject.FindObjectsOfType <UIConfig>(); foreach (UIConfig config in configs) { config.Load(); } EMRenderSupport.Reload(); }
public static void LoadPackages() { if (Application.isPlaying || _loaded) { return; } EditorApplication.update -= EditorApplication_Update; EditorApplication.update += EditorApplication_Update; _loaded = true; UIPackage.RemoveAllPackages(); FontManager.Clear(); NTexture.DisposeEmpty(); UIObjectFactory.Clear(); string[] ids = AssetDatabase.FindAssets("_fui t:textAsset"); int cnt = ids.Length; for (int i = 0; i < cnt; i++) { string assetPath = AssetDatabase.GUIDToAssetPath(ids[i]); int pos = assetPath.LastIndexOf("_fui"); if (pos == -1) { continue; } assetPath = assetPath.Substring(0, pos); if (AssetDatabase.AssetPathToGUID(assetPath) != null) { UIPackage.AddPackage(assetPath, (string name, string extension, System.Type type, out DestroyMethod destroyMethod) => { destroyMethod = DestroyMethod.Unload; return(AssetDatabase.LoadAssetAtPath(name + extension, type)); } ); } } List <UIPackage> pkgs = UIPackage.GetPackages(); pkgs.Sort(CompareUIPackage); cnt = pkgs.Count; packagesPopupContents = new GUIContent[cnt + 1]; for (int i = 0; i < cnt; i++) { packagesPopupContents[i] = new GUIContent(pkgs[i].name); } packagesPopupContents[cnt] = new GUIContent("Please Select"); EMRenderSupport.Reload(); }
public static void UnLoadAllUI() { List <UIPackage> pkgs = UIPackage.GetPackages(); if (null != pkgs) { foreach (UIPackage pkg in pkgs) { pkg.UnloadAssets(); } } UIPackage.RemoveAllPackages(); }
/// <summary> /// 删除FGUIPackage的引用 /// </summary> public void RemoveRef(string packageName) { int refCout; if (!m_FguiRef.TryGetValue(packageName, out refCout)) { throw new GameFrameworkException(Utility.Text.Format("{0} is not exit", packageName)); } m_FguiRef[packageName]--; if (m_FguiRef[packageName] <= 0 && UIPackage.GetPackages().Count != 0) { m_FguiRef.Remove(packageName); UIPackage.RemovePackage(packageName); } }
// Use this for initialization void Start() { UIPackage.AddPackage("TestUI"); GComponent com = UIPackage.CreateObject("TestUI", "RoomMgrPanel").asCom; GRoot.inst.AddChild(com); GObject com1 = com.GetChild("PlayerInfo"); if (com1 == null) { Debug.LogError("没有找到子物体"); return; } com1.onClick.Add(OnClick); Debug.Log(UIPackage.GetPackages().Count); }
private static void HandleAllDataTables() { EditorToolSet.LoadPackages(); var packages = UIPackage.GetPackages(); foreach (var package in packages) { var items = package.GetItems(); foreach (var item in items) { if (item.type == PackageItemType.Component && item.name.Contains("Panel") && !item.name.Contains("Frame")) { GenerateCode(package.name, item.name); } } } Debug.Log("GenerateUICode Finish"); }
public override void OnInspectorGUI() { serializedObject.Update(); #if (UNITY_5 || UNITY_5_3_OR_NEWER) DrawPropertiesExcluding(serializedObject, propertyToExclude); #endif UIConfig config = (UIConfig)target; EditorGUILayout.BeginHorizontal(); EditorGUI.BeginChangeCheck(); itemsFoldout = EditorGUILayout.Foldout(itemsFoldout, "Config Items"); if (EditorGUI.EndChangeCheck()) { EditorPrefs.SetBool("itemsFoldOut", itemsFoldout); } EditorGUILayout.EndHorizontal(); bool modified = false; if (itemsFoldout) { Undo.RecordObject(config, "Items"); int len = config.Items.Count; EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Add"); UIConfig.ConfigKey selectedKey = (UIConfig.ConfigKey)EditorGUILayout.EnumPopup((System.Enum)UIConfig.ConfigKey.PleaseSelect); if (selectedKey != UIConfig.ConfigKey.PleaseSelect) { int index = (int)selectedKey; if (index > len - 1) { for (int i = len; i < index; i++) { config.Items.Add(new UIConfig.ConfigValue()); } UIConfig.ConfigValue value = new UIConfig.ConfigValue(); value.valid = true; UIConfig.SetDefaultValue(selectedKey, value); config.Items.Add(value); } else { UIConfig.ConfigValue value = config.Items[index]; if (value == null) { value = new UIConfig.ConfigValue(); value.valid = true; UIConfig.SetDefaultValue(selectedKey, value); config.Items[index] = value; } else if (!value.valid) { value.valid = true; UIConfig.SetDefaultValue(selectedKey, value); } } } EditorGUILayout.EndHorizontal(); for (int i = 0; i < len; i++) { UIConfig.ConfigValue value = config.Items[i]; if (value == null || !value.valid) { continue; } EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(((UIConfig.ConfigKey)i).ToString()); switch ((UIConfig.ConfigKey)i) { case UIConfig.ConfigKey.ClickDragSensitivity: case UIConfig.ConfigKey.DefaultComboBoxVisibleItemCount: case UIConfig.ConfigKey.DefaultScrollStep: case UIConfig.ConfigKey.TouchDragSensitivity: case UIConfig.ConfigKey.TouchScrollSensitivity: case UIConfig.ConfigKey.InputCaretSize: value.i = EditorGUILayout.IntField(value.i); break; case UIConfig.ConfigKey.ButtonSound: case UIConfig.ConfigKey.GlobalModalWaiting: case UIConfig.ConfigKey.HorizontalScrollBar: case UIConfig.ConfigKey.LoaderErrorSign: case UIConfig.ConfigKey.PopupMenu: case UIConfig.ConfigKey.PopupMenu_seperator: case UIConfig.ConfigKey.TooltipsWin: case UIConfig.ConfigKey.VerticalScrollBar: case UIConfig.ConfigKey.WindowModalWaiting: case UIConfig.ConfigKey.DefaultFont: value.s = EditorGUILayout.TextField(value.s); break; case UIConfig.ConfigKey.DefaultScrollBounceEffect: case UIConfig.ConfigKey.DefaultScrollTouchEffect: case UIConfig.ConfigKey.RenderingTextBrighterOnDesktop: case UIConfig.ConfigKey.AllowSoftnessOnTopOrLeftSide: case UIConfig.ConfigKey.DepthSupportForPaintingMode: value.b = EditorGUILayout.Toggle(value.b); break; case UIConfig.ConfigKey.EnhancedTextOutlineEffect: EditorGUI.BeginChangeCheck(); value.b = EditorGUILayout.Toggle(value.b); if (EditorGUI.EndChangeCheck()) { modified = true; } break; case UIConfig.ConfigKey.ButtonSoundVolumeScale: value.f = EditorGUILayout.Slider(value.f, 0, 1); break; case UIConfig.ConfigKey.ModalLayerColor: case UIConfig.ConfigKey.InputHighlightColor: value.c = EditorGUILayout.ColorField(value.c); break; case UIConfig.ConfigKey.RichTextRowVerticalAlign: EditorGUI.BeginChangeCheck(); value.i = EditorGUILayout.EnumPopup((VertAlignType)value.i).GetHashCode(); if (EditorGUI.EndChangeCheck()) { modified = true; } break; case UIConfig.ConfigKey.Branch: EditorGUI.BeginChangeCheck(); value.s = EditorGUILayout.TextField(value.s); if (EditorGUI.EndChangeCheck()) { modified = true; } break; } if (GUILayout.Button(new GUIContent("X", "Delete Item"), EditorStyles.miniButtonRight, GUILayout.Width(30))) { config.Items[i].Reset(); UIConfig.SetDefaultValue((UIConfig.ConfigKey)i, config.Items[i]); modified = true; } EditorGUILayout.EndHorizontal(); } } EditorGUILayout.BeginHorizontal(); EditorGUI.BeginChangeCheck(); packagesFoldOut = EditorGUILayout.Foldout(packagesFoldOut, "Preload Packages"); if (EditorGUI.EndChangeCheck()) { EditorPrefs.SetBool("packagesFoldOut", packagesFoldOut); } EditorGUILayout.EndHorizontal(); if (packagesFoldOut) { Undo.RecordObject(config, "PreloadPackages"); EditorToolSet.LoadPackages(); if (EditorToolSet.packagesPopupContents != null) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Add"); int selected = EditorGUILayout.Popup(EditorToolSet.packagesPopupContents.Length - 1, EditorToolSet.packagesPopupContents); EditorGUILayout.EndHorizontal(); if (selected != EditorToolSet.packagesPopupContents.Length - 1) { UIPackage pkg = UIPackage.GetPackages()[selected]; string tmp = pkg.assetPath.ToLower(); int pos = tmp.LastIndexOf("resources/"); if (pos != -1) { string packagePath = pkg.assetPath.Substring(pos + 10); if (config.PreloadPackages.IndexOf(packagePath) == -1) { config.PreloadPackages.Add(packagePath); } errorState = 0; } else { errorState = 10; } } } if (errorState > 0) { errorState--; EditorGUILayout.HelpBox("Package is not in resources folder.", MessageType.Warning); } int cnt = config.PreloadPackages.Count; int pi = 0; while (pi < cnt) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("" + pi + "."); config.PreloadPackages[pi] = EditorGUILayout.TextField(config.PreloadPackages[pi]); if (GUILayout.Button(new GUIContent("X", "Delete Item"), EditorStyles.miniButtonRight, GUILayout.Width(30))) { config.PreloadPackages.RemoveAt(pi); cnt--; } else { pi++; } EditorGUILayout.EndHorizontal(); } } else { errorState = 0; } if (serializedObject.ApplyModifiedProperties() || modified) { (target as UIConfig).ApplyModifiedProperties(); } }
void OnGUI() { if (itemStyle == null) { itemStyle = new GUIStyle(GUI.skin.GetStyle("IN Toggle")); itemStyle.normal.background = null; itemStyle.onNormal.background = GUI.skin.GetStyle("ObjectPickerResultsEven").active.background; itemStyle.focused.background = null; itemStyle.onFocused.background = null; itemStyle.hover.background = null; itemStyle.onHover.background = null; itemStyle.active.background = null; itemStyle.onActive.background = null; itemStyle.margin.top = 0; itemStyle.margin.bottom = 0; } EditorGUILayout.BeginHorizontal(); //package list start------ EditorGUILayout.BeginHorizontal(); GUILayout.Space(5); EditorGUILayout.BeginVertical(); GUILayout.Space(10); EditorGUILayout.LabelField("Packages", (GUIStyle)"OL Title", GUILayout.Width(300)); EditorGUILayout.BeginHorizontal(); GUILayout.Space(4); scrollPos1 = EditorGUILayout.BeginScrollView(scrollPos1, (GUIStyle)"CN Box", GUILayout.Height(300), GUILayout.Width(300)); EditorToolSet.LoadPackages(); List <UIPackage> pkgs = UIPackage.GetPackages(); int cnt = pkgs.Count; if (cnt == 0) { selectedPackage = -1; selectedPackageName = null; } else { for (int i = 0; i < cnt; i++) { EditorGUILayout.BeginHorizontal(); GUILayout.Space(4); if (GUILayout.Toggle(selectedPackageName == pkgs[i].name, pkgs[i].name, itemStyle, GUILayout.ExpandWidth(true))) { selectedPackage = i; selectedPackageName = pkgs[i].name; } EditorGUILayout.EndHorizontal(); } } EditorGUILayout.EndScrollView(); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); //package list end------ //component list start------ EditorGUILayout.BeginHorizontal(); GUILayout.Space(5); EditorGUILayout.BeginVertical(); GUILayout.Space(10); EditorGUILayout.LabelField("Components", (GUIStyle)"OL Title", GUILayout.Width(220)); EditorGUILayout.BeginHorizontal(); GUILayout.Space(4); scrollPos2 = EditorGUILayout.BeginScrollView(scrollPos2, (GUIStyle)"CN Box", GUILayout.Height(300), GUILayout.Width(220)); if (selectedPackage >= 0) { List <PackageItem> items = pkgs[selectedPackage].GetItems(); int i = 0; foreach (PackageItem pi in items) { if (pi.type == PackageItemType.Component && pi.exported) { EditorGUILayout.BeginHorizontal(); GUILayout.Space(4); if (GUILayout.Toggle(selectedComponentName == pi.name, pi.name, itemStyle, GUILayout.ExpandWidth(true))) { selectedComponentName = pi.name; } i++; EditorGUILayout.EndHorizontal(); } } } EditorGUILayout.EndScrollView(); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); //component list end------ GUILayout.Space(10); EditorGUILayout.EndHorizontal(); GUILayout.Space(20); //buttons start--- EditorGUILayout.BeginHorizontal(); GUILayout.Space(210); if (GUILayout.Button("Cancel", GUILayout.Width(100))) { this.Close(); } GUILayout.Space(20); if (GUILayout.Button("OK", GUILayout.Width(100)) && selectedPackage >= 0) { UIPackage selectedPkg = pkgs[selectedPackage]; string tmp = selectedPkg.assetPath.ToLower(); string packagePath; int pos = tmp.LastIndexOf("resources/"); if (pos != -1) { packagePath = selectedPkg.assetPath.Substring(pos + 10); } else { packagePath = null; } bool isPrefab = PrefabUtility.GetPrefabType(Selection.activeGameObject) == PrefabType.Prefab; Selection.activeGameObject.SendMessage("OnUpdateSource", new object[] { selectedPkg.name, packagePath, selectedComponentName, !isPrefab }, SendMessageOptions.DontRequireReceiver); #if UNITY_5_3_OR_NEWER EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); #elif UNITY_5 EditorApplication.MarkSceneDirty(); #else EditorUtility.SetDirty(Selection.activeGameObject); #endif this.Close(); } EditorGUILayout.EndHorizontal(); }
void OnGUI() { if (itemStyle == null) { itemStyle = new GUIStyle(GUI.skin.GetStyle("Tag MenuItem")); } EditorGUILayout.BeginHorizontal(); //package list start------ EditorGUILayout.BeginHorizontal(); GUILayout.Space(5); EditorGUILayout.BeginVertical(); GUILayout.Space(10); EditorGUILayout.LabelField("Packages", (GUIStyle)"OL Title", GUILayout.Width(300)); GUILayout.Space(5); EditorGUILayout.BeginHorizontal(); GUILayout.Space(4); scrollPos1 = EditorGUILayout.BeginScrollView(scrollPos1, (GUIStyle)"CN Box", GUILayout.Height(300), GUILayout.Width(300)); EditorToolSet.LoadPackages(); List <UIPackage> pkgs = UIPackage.GetPackages(); int cnt = pkgs.Count; if (cnt == 0) { selectedPackage = -1; selectedPackageName = null; } else { for (int i = 0; i < cnt; i++) { EditorGUILayout.BeginHorizontal(); if (GUILayout.Toggle(selectedPackageName == pkgs[i].name, pkgs[i].name, itemStyle, GUILayout.ExpandWidth(true))) { selectedPackage = i; selectedPackageName = pkgs[i].name; } EditorGUILayout.EndHorizontal(); } } EditorGUILayout.EndScrollView(); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); //package list end------ //component list start------ EditorGUILayout.BeginHorizontal(); GUILayout.Space(5); EditorGUILayout.BeginVertical(); GUILayout.Space(10); EditorGUILayout.LabelField("Components", (GUIStyle)"OL Title", GUILayout.Width(220)); GUILayout.Space(5); EditorGUILayout.BeginHorizontal(); GUILayout.Space(4); scrollPos2 = EditorGUILayout.BeginScrollView(scrollPos2, (GUIStyle)"CN Box", GUILayout.Height(300), GUILayout.Width(220)); if (selectedPackage >= 0) { List <PackageItem> items = pkgs[selectedPackage].GetItems(); int i = 0; foreach (PackageItem pi in items) { if (pi.type == PackageItemType.Component && pi.exported) { EditorGUILayout.BeginHorizontal(); if (GUILayout.Toggle(selectedComponentName == pi.name, pi.name, itemStyle, GUILayout.ExpandWidth(true))) { selectedComponentName = pi.name; } i++; EditorGUILayout.EndHorizontal(); } } } EditorGUILayout.EndScrollView(); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); //component list end------ GUILayout.Space(10); EditorGUILayout.EndHorizontal(); GUILayout.Space(20); //buttons start--- EditorGUILayout.BeginHorizontal(); GUILayout.Space(180); if (GUILayout.Button("Refresh", GUILayout.Width(100))) { EditorToolSet.ReloadPackages(); } GUILayout.Space(20); if (GUILayout.Button("OK", GUILayout.Width(100)) && selectedPackage >= 0) { UIPackage selectedPkg = pkgs[selectedPackage]; string tmp = selectedPkg.assetPath.ToLower(); string packagePath; int pos = tmp.LastIndexOf("/resources/"); if (pos != -1) { packagePath = selectedPkg.assetPath.Substring(pos + 11); } else { pos = tmp.IndexOf("resources/"); if (pos == 0) { packagePath = selectedPkg.assetPath.Substring(pos + 10); } else { packagePath = selectedPkg.assetPath; } } if (Selection.activeGameObject != null) { #if UNITY_2018_3_OR_NEWER bool isPrefab = PrefabUtility.GetPrefabAssetType(Selection.activeGameObject) != PrefabAssetType.NotAPrefab; #else bool isPrefab = PrefabUtility.GetPrefabType(Selection.activeGameObject) == PrefabType.Prefab; #endif Selection.activeGameObject.SendMessage("OnUpdateSource", new object[] { selectedPkg.name, packagePath, selectedComponentName, !isPrefab }, SendMessageOptions.DontRequireReceiver); } #if UNITY_2018_3_OR_NEWER PrefabStage prefabStage = PrefabStageUtility.GetCurrentPrefabStage(); if (prefabStage != null) { EditorSceneManager.MarkSceneDirty(prefabStage.scene); } else { ApplyChange(); } #else ApplyChange(); #endif this.Close(); } EditorGUILayout.EndHorizontal(); }