public override void OnInspectorGUI() { var instance = target as LocalizeAtlasRequest; Initialize(); var update = false; var folderGuids = instance.FolderGuids.ToList(); var removeTarget = new List <string>(); using (new EditorGUILayout.HorizontalScope()) { GUILayout.Space(8f); if (GUILayout.Button(toolbarPlusIcon, GUILayout.Width(30f), GUILayout.Height(16f))) { folderGuids.Add(null); update = true; } } var scrollViewLayoutOption = new List <GUILayoutOption>(); if (5 < folderGuids.Count) { scrollViewLayoutOption.Add(GUILayout.MaxHeight(120f)); } using (var scrollView = new EditorGUILayout.ScrollViewScope(scrollPosition, scrollViewLayoutOption.ToArray())) { for (var i = 0; i < folderGuids.Count; i++) { var folderGuid = folderGuids[i]; UnityEngine.Object folder = null; if (!string.IsNullOrEmpty(folderGuid)) { var assetPath = AssetDatabase.GUIDToAssetPath(folderGuid); folder = AssetDatabase.LoadMainAssetAtPath(assetPath); } using (new EditorGUILayout.HorizontalScope()) { var layoutOption = new GUILayoutOption[] { GUILayout.Height(16f), GUILayout.ExpandWidth(true), }; EditorGUI.BeginChangeCheck(); folder = EditorGUILayout.ObjectField(folder, typeof(UnityEngine.Object), false, layoutOption); if (EditorGUI.EndChangeCheck()) { // フォルダだけ登録可能. if (UnityEditorUtility.IsFolder(folder) || folder == null) { folderGuids[i] = folder == null ? string.Empty : UnityEditorUtility.GetAssetGUID(folder); update = true; } } if (GUILayout.Button(toolbarMinusIcon, EditorStyles.miniButton, GUILayout.Width(25f))) { removeTarget.Add(folderGuid); } } GUILayout.Space(2f); } scrollPosition = scrollView.scrollPosition; } if (removeTarget.Any()) { foreach (var info in removeTarget) { folderGuids.Remove(info); } update = true; } if (update) { Reflection.SetPrivateField(instance, "folderGuids", folderGuids.ToArray()); } }
private void DrawContents() { var labelBackgroundColor = new Color(0.2f, 0.8f, 0.5f, 0.8f); EditorLayoutTools.DrawLabelWithBackground("ShaderVariantCollection", labelBackgroundColor, EditorLayoutTools.LabelColor); EditorGUI.BeginChangeCheck(); shaderVariantCollection = EditorLayoutTools.ObjectField(shaderVariantCollection, false); if (EditorGUI.EndChangeCheck()) { targetFolder = null; shaderInfos.Clear(); scrollPosition = Vector2.zero; } GUILayout.Space(2f); EditorLayoutTools.DrawLabelWithBackground("TargetFolder", labelBackgroundColor, EditorLayoutTools.LabelColor); EditorGUI.BeginChangeCheck(); targetFolder = EditorLayoutTools.ObjectField(targetFolder, false); if (EditorGUI.EndChangeCheck()) { if (!UnityEditorUtility.IsFolder(targetFolder)) { targetFolder = null; } shaderInfos.Clear(); scrollPosition = Vector2.zero; } GUILayout.Space(2f); if (shaderVariantCollection != null) { if (shaderInfos.IsEmpty()) { EditorGUILayout.HelpBox("Please search shader.", MessageType.Info); } else { using (new EditorGUILayout.HorizontalScope()) { EditorLayoutTools.DrawLabelWithBackground("Shaders", labelBackgroundColor, EditorLayoutTools.LabelColor); assetViewMode = (AssetViewMode)EditorGUILayout.EnumPopup(assetViewMode, GUILayout.Width(60f)); } using (new EditorGUILayout.HorizontalScope()) { if (GUILayout.Button("add all", GUILayout.Width(120f))) { shaderInfos.ForEach(x => x.add = true); } if (GUILayout.Button("remove all", GUILayout.Width(120f))) { shaderInfos.ForEach(x => x.add = false); } GUILayout.FlexibleSpace(); } using (var scrollViewScope = new EditorGUILayout.ScrollViewScope(scrollPosition)) { using (new ContentsScope()) { foreach (var shaderInfo in shaderInfos) { using (new EditorGUILayout.HorizontalScope()) { shaderInfo.add = EditorGUILayout.Toggle(shaderInfo.add, GUILayout.Width(20f)); switch (assetViewMode) { case AssetViewMode.Asset: EditorLayoutTools.ObjectField(shaderInfo.shader, false, GUILayout.Height(15f)); break; case AssetViewMode.Path: EditorGUILayout.SelectableLabel(shaderInfo.assetPath, GUILayout.Height(15f)); break; } } GUILayout.Space(2f); } } scrollPosition = scrollViewScope.scrollPosition; } } GUILayout.Space(2f); GUILayout.FlexibleSpace(); using (new EditorGUILayout.HorizontalScope()) { GUILayout.FlexibleSpace(); if (GUILayout.Button("Search", GUILayout.Width(150f))) { BuildShaderInfos(); } GUILayout.Space(20f); using (new DisableScope(shaderInfos.IsEmpty())) { if (GUILayout.Button("Update", GUILayout.Width(150f))) { ApplyShaderVariantCollection(); } } GUILayout.FlexibleSpace(); } } else { EditorGUILayout.HelpBox("Select shaderVariant file.", MessageType.Info); } }
public override void OnInspectorGUI() { Initialize(); InitializeStyle(); var instance = target as LocalizeSpriteAsset; var removeInfos = new List <LocalizeSpriteAsset.FolderInfo>(); var update = false; GUILayout.Space(4f); using (new EditorGUILayout.HorizontalScope()) { GUILayout.FlexibleSpace(); if (GUILayout.Button(toolbarPlusIcon, GUILayout.Width(50f), GUILayout.Height(16f))) { var info = new LocalizeSpriteAsset.FolderInfo(); folderInfos.Add(info); update = true; } GUILayout.Space(8f); } var swapTargets = new List <Tuple <int, int> >(); using (var scrollView = new EditorGUILayout.ScrollViewScope(scrollPosition, GUILayout.ExpandWidth(true))) { for (var i = 0; i < folderInfos.Count; i++) { var info = folderInfos[i]; using (new ContentsScope()) { using (new EditorGUILayout.HorizontalScope()) { EditorGUI.BeginChangeCheck(); var index = EditorGUILayout.DelayedIntField("Index", i, inputFieldStyle, GUILayout.Height(16f), GUILayout.ExpandWidth(true)); if (EditorGUI.EndChangeCheck()) { if (0 <= index && index < folderInfos.Count) { swapTargets.Add(Tuple.Create(i, index)); } } GUILayout.FlexibleSpace(); if (GUILayout.Button(toolbarMinusIcon, EditorStyles.miniButton, GUILayout.Width(35f))) { removeInfos.Add(info); } } GUILayout.Space(2f); UnityEngine.Object folder = null; if (!string.IsNullOrEmpty(info.guid)) { var assetPath = AssetDatabase.GUIDToAssetPath(info.guid); folder = AssetDatabase.LoadMainAssetAtPath(assetPath); } var layoutOption = new GUILayoutOption[] { GUILayout.Height(16f), GUILayout.ExpandWidth(true), }; EditorGUI.BeginChangeCheck(); folder = EditorGUILayout.ObjectField("Atlas Folder", folder, typeof(UnityEngine.Object), false, layoutOption); GUILayout.Space(2f); info.description = EditorGUILayout.DelayedTextField("Description", info.description, inputFieldStyle, layoutOption); if (EditorGUI.EndChangeCheck()) { // フォルダだけ登録可能. if (UnityEditorUtility.IsFolder(folder) || folder == null) { info.guid = folder == null ? string.Empty : UnityEditorUtility.GetAssetGUID(folder); } update = true; } } GUILayout.Space(4f); } scrollPosition = scrollView.scrollPosition; } if (swapTargets.Any()) { foreach (var swapTarget in swapTargets) { folderInfos = folderInfos.Swap(swapTarget.Item1, swapTarget.Item2).ToList(); } update = true; } if (removeInfos.Any()) { foreach (var info in removeInfos) { folderInfos.Remove(info); } update = true; } if (update) { var infos = folderInfos .Select(x => { var info = x.DeepCopy(); info.description = info.description.Encrypt(cryptoKey); return(info); }) .ToArray(); Reflection.SetPrivateField(instance, "infos", infos); isChanged = true; } }