This commit is contained in:
2025-05-16 23:31:59 +08:00
parent 9e4fef3f1e
commit d891e3f0ee
1198 changed files with 274242 additions and 1558 deletions

View File

@@ -0,0 +1,721 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
namespace RapidIcon_1_7_2
{
[Serializable]
public class IconEditor
{
//---PUBLIC---//
//Textures
public Texture2D previewBackgroundImage;
public Texture2D scrollAreaBackgroundImage;
public Texture2D scaleLinkOnImage;
public Texture2D scaleLinkOffImage;
public Texture2D separatorTex;
//Icon resolution
public Vector2Int renderResolution;
public Vector2Int renderSize;
public int resMultiplyerIndex;
public float[] resMultiplyers = new float[] { 0.25f, 0.5f, 1f };
//Icons
public Icon currentIcon;
public IconSet currentIconSet;
public bool updateFlag;
//Tabs
public bool linkScale;
public MaterialEditor materialEditor;
public Material mat;
public ReorderableList reorderableList;
public string lastPresetPath;
public string[] tabNames = new string[] { "Object", "Hierarchy", "Camera", "Lighting", "Animation", "Post-Processing", "Export" };
//RapidIcon Window Elements/Settings
public RapidIconWindow window;
public AssetGrid assetGrid;
public ReorderableListCallbacks reorderableListCallbacks;
public bool fullscreen;
public float fullWidth;
public float sepWidth;
public float oldMinWidth;
//Other
public bool replaceAll;
//---INTERNAL---//
//Preview zoom/resolution
int zoomScaleIndex;
float[] zoomScales = new float[] { 0.25f, 0.5f, 0.75f, 1f, 1.25f, 1.5f, 2f, 3f, 1f };
string[] zoomScalesStrings = new string[] { "25%", "50%", "75%", "100%", "125%", "150%", "200%", "300%", "Scale to Fit (num %)" };
string[] resMultiplyersStrings = new string[] { "Quarter", "Half", "Full" };
int zoomFitByWidthHeight; //0: height, 1: width
//Preview GUI
Vector2 previewScrollPos;
GUIStyle renderStyle;
GUIStyle scrollStyle;
Vector2 previewAreaSize;
Rect previewRect;
DraggableSeparator previewDraggableSeparator;
//Tabs
Vector2 controlsScrollPos;
public int tab;
//Icons
int currentIconIndex;
bool updateAllFlag;
//Other
bool undoHold;
bool sceneChangeUpdate = false;
public IconEditor(AssetGrid grid, RapidIconWindow w)
{
//---Initialise IconEditor---//
//Set RapidIcon elements
CheckAndSetWindow(w);
assetGrid = grid;
//Render resolution/style
renderResolution = new Vector2Int(256, 256);
renderSize = new Vector2Int(256, 256);
renderStyle = new GUIStyle();
renderStyle.stretchWidth = true;
renderStyle.stretchHeight = true;
renderStyle.stretchHeight = true;
renderStyle.stretchWidth = true;
//Set preview zoom/resolution setting
zoomScaleIndex = 8;
resMultiplyerIndex = 2;
//Create colour textures
scrollAreaBackgroundImage = Utils.CreateColourTexture(4, 4, new Color32(50, 50, 50, 255));
if (EditorGUIUtility.isProSkin)
separatorTex = Utils.CreateColourTexture(2, 2, new Color32(31, 31, 31, 255));
else
separatorTex = Utils.CreateColourTexture(2, 2, new Color32(153, 153, 153, 255));
//Load textures
previewBackgroundImage = (Texture2D)AssetDatabase.LoadMainAssetAtPath(assetGrid.rapidIconRootFolder + "Editor/UI/previewGrid.png");
scaleLinkOnImage = (Texture2D)AssetDatabase.LoadMainAssetAtPath(assetGrid.rapidIconRootFolder + "Editor/UI/linkOn.png");
scaleLinkOffImage = (Texture2D)AssetDatabase.LoadMainAssetAtPath(assetGrid.rapidIconRootFolder + "Editor/UI/linkOff.png");
//Create horizontal separator
previewDraggableSeparator = new DraggableSeparator(SeparatorTypes.Horizontal);
//Set bools
linkScale = true;
replaceAll = false;
//Create material editor
mat = new Material(Shader.Find("RapidIcon/ImgShader"));
materialEditor = (MaterialEditor)Editor.CreateEditor(mat);
//Create reorderable list for post-processing shaders
List<Material> blankList = new List<Material>();
reorderableList = new ReorderableList(blankList, typeof(Material), true, true, true, true);
reorderableListCallbacks = new ReorderableListCallbacks(this);
reorderableList.drawElementCallback = reorderableListCallbacks.DrawListItems;
reorderableList.drawHeaderCallback = reorderableListCallbacks.DrawHeader;
reorderableList.onSelectCallback = reorderableListCallbacks.SelectShader;
reorderableList.onAddCallback = reorderableListCallbacks.AddShader;
reorderableList.onRemoveCallback = reorderableListCallbacks.RemoveShader;
reorderableList.onReorderCallback = reorderableListCallbacks.ShadersReorded;
//Configure undo
undoHold = false;
Undo.undoRedoPerformed += OnUndo;
}
public void Draw(float width, RapidIconWindow w)
{
//---Check variables are set---//
CheckAndSetWindow(w);
//---On first update of new scene---//
if (!sceneChangeUpdate)
{
foreach (IconSet iconSet in assetGrid.objectIconSets.Values)
{
foreach (Icon icon in iconSet.icons)
{
if (icon.iconSettings.postProcessingMaterials.Count > 0 && icon.iconSettings.postProcessingMaterials[0] == null)
{
if (iconSet.saveData)
{
//---Load the MatInfo if icon has been saved---//
icon.LoadMatInfo();
}
else
{
//---Reset the icon if not saved---//
ObjectPathPair obj = new ObjectPathPair(iconSet.assetObject, iconSet.assetPath);
IconSet newIconSet = assetGrid.CreateIconSet(obj);
//----------TODO----------//
//Utils.CopyIconSettings(newIcon, currentIcon, -1);
//Utils.UpdateIcon(currentIcon, this);
}
//---Update all icons---//
updateAllFlag = true;
sceneChangeUpdate = true;
}
}
}
}
//---If icon(s) selected---//
if (assetGrid.selectedIconSets.Count > 0)
{
//---Get the currently selected icon---//
currentIconIndex = Mathf.Clamp(currentIconIndex, 0, assetGrid.selectedIconSets.Count - 1);
currentIconSet = assetGrid.selectedIconSets[currentIconIndex];
currentIcon = currentIconSet.GetCurrentIcon();
//---Check if the object asscoiated with the icon has been deleted---//
if (currentIconSet.assetObject == null)
{
//---Flag as deleted and remove from selection---//
currentIconSet.deleted = true;
assetGrid.selectedIconSets.Remove(currentIconSet);
//---If other icon(s) still selected, update currentIcon - otherwise return---//
if (assetGrid.selectedIconSets.Count > 0)
{
if (currentIconIndex > assetGrid.selectedIconSets.Count - 1)
currentIconIndex = assetGrid.selectedIconSets.Count - 1;
currentIconSet = assetGrid.selectedIconSets[currentIconIndex];
currentIcon = currentIconSet.GetCurrentIcon();
}
else
return;
}
//---Create a GUI area, prevents buggy behaviour when moving left separator---//
Rect r = new Rect(window.rightSeparator.rect);
if (fullscreen)
{
r.x = 0;
r.width = window.position.width;
}
else
{
r.width = width;
}
GUILayout.BeginArea(r);
GUILayout.BeginVertical();
//---Update icons if flag set---//
if (updateFlag)
{
Utils.UpdateIcon(currentIcon, this);
updateFlag = false;
}
if (updateAllFlag)
{
assetGrid.RefreshAllIcons();
updateAllFlag = false;
}
//---Check current icon has a full render---//
Utils.CheckCurrentIconRender(this);
//---Draw the icon preview---//
DrawPreview();
GUILayout.Space(2);
//---Draw the preview zoom/resolution controls---//
DrawPreviewResAndZoom();
//---Draw the draggable separator---//
previewDraggableSeparator.Draw(100, window.position.height - 100, window);
GUILayout.Space(8);
//---Draw the icon selector---//
DrawIconSelecter();
//---Draw the tab selector---//
tab = GUILayout.Toolbar(tab, tabNames);
sepWidth = width - 50;
//---Draw the tabs---//
DrawTabs(width);
//---Check mouse inputs to rotate/zoom the preview---//
CheckMouseMovement();
//---End GUI elements---//
GUILayout.EndVertical();
GUILayout.EndArea();
}
else if (Event.current.type == EventType.Layout || Event.current.type == EventType.Repaint)
{
GUILayout.BeginVertical();
GUILayout.FlexibleSpace();
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
GUILayout.Label("No Icons Selected");
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GUILayout.FlexibleSpace();
GUILayout.EndVertical();
}
}
public void SaveData()
{
//---Save the separator---//
previewDraggableSeparator.SaveData("RapidIconSepPosPreview");
//---Add the icons to be saved to list---//
IconSetData iconSetData = new IconSetData();
foreach (KeyValuePair<UnityEngine.Object, IconSet> iconSet in assetGrid.objectIconSets)
{
if (iconSet.Value.saveData)
iconSetData.iconSets.Add(iconSet.Value);
}
//---Save the icon data---//
Utils.SaveIconSetData(iconSetData);
//---Save the preview zoom/resolution settings and current tab---//
EditorPrefs.SetInt(PlayerSettings.productName + "RapidIconPreviewResIdx", resMultiplyerIndex);
EditorPrefs.SetInt(PlayerSettings.productName + "RapidIconPreviewZoomIdx", zoomScaleIndex);
EditorPrefs.SetInt(PlayerSettings.productName + "RapidIconEditorTab", tab);
//---Save the window position and width if fullscreen mode set---//
if (fullscreen)
{
EditorPrefs.SetFloat(PlayerSettings.productName + "RapidIconWindowPosX", window.position.xMax - (fullWidth + window.position.width));
EditorPrefs.SetFloat(PlayerSettings.productName + "RapidIconWindowPosY", window.position.y);
EditorPrefs.SetFloat(PlayerSettings.productName + "RapidIconWindowWidth", fullWidth + window.position.width);
}
else
{
EditorPrefs.SetFloat(PlayerSettings.productName + "RapidIconWindowPosX", -1);
EditorPrefs.SetFloat(PlayerSettings.productName + "RapidIconWindowPosY", -1);
EditorPrefs.SetFloat(PlayerSettings.productName + "RapidIconWindowWidth", -1);
}
}
public void LoadData()
{
//---Load icon data---//
IconSetData iconData = new IconSetData();
iconData = Utils.LoadIconSetData();
assetGrid.objectIconSets = new Dictionary<UnityEngine.Object, IconSet>();
if (iconData != null)
{
foreach (IconSet iconSet in iconData.iconSets)
{
if (iconSet.assetObject != null)
assetGrid.objectIconSets.Add(iconSet.assetObject, iconSet);
}
}
//---Load the draggable separator data---//
previewDraggableSeparator.LoadData("RapidIconSepPosPreview", 650);
//---Load the preview zoom/resolution settings---//
resMultiplyerIndex = EditorPrefs.GetInt(PlayerSettings.productName + "RapidIconPreviewResIdx", -1);
zoomScaleIndex = EditorPrefs.GetInt(PlayerSettings.productName + "RapidIconPreviewZoomIdx", -1);
if (resMultiplyerIndex == -1)
resMultiplyerIndex = 2;
if (zoomScaleIndex == -1)
zoomScaleIndex = 8;
//---Load the current tab---//
tab = EditorPrefs.GetInt(PlayerSettings.productName + "RapidIconEditorTab", 0);
}
void OnUndo()
{
//---Need to update icon after undo---//
updateFlag = true;
//---Create new material editor---//
if (materialEditor == null)
{
reorderableList.index = reorderableList.count - 1;
materialEditor = (MaterialEditor)Editor.CreateEditor((UnityEngine.Object)reorderableList.list[reorderableList.index]);
}
//---Load materials---//
if (assetGrid.visibleIconSets != null)
{
foreach (IconSet iconSet in assetGrid.visibleIconSets)
{
foreach (Icon icon in iconSet.icons)
{
if (icon.iconSettings.matInfo != null && icon.iconSettings.matInfo.Count > 0)
icon.LoadMatInfo();
}
}
}
}
void CheckAndSetWindow(RapidIconWindow w)
{
if (!window)
window = w;
}
void DrawIconSelecter()
{
GUILayout.BeginHorizontal();
//---Draw previous icon select button---//
if (GUILayout.Button("←", GUILayout.Width(50)) && currentIconIndex > 0)
currentIconIndex--;
//---Draw dropdown list of selected assets---//
int idx = 0;
string[] iconNames = new string[assetGrid.selectedIconSets.Count];
foreach (IconSet iconSet in assetGrid.selectedIconSets)
{
string name = iconSet.assetName;
for (int i = 1; i <= 128; i++)
{
if (!iconNames.Contains(name))
break;
name = iconSet.assetName + " (" + i + ")";
}
iconNames[idx++] = (name);
}
currentIconIndex = EditorGUILayout.Popup(currentIconIndex, iconNames);
//---Draw next icon select button---//
if (GUILayout.Button("→", GUILayout.Width(50)) && currentIconIndex < assetGrid.selectedIconSets.Count - 1)
currentIconIndex++;
GUILayout.EndHorizontal();
//---Sub icon selector---//
GUILayout.BeginHorizontal();
idx = 0;
string[] subIconNames = new string[currentIconSet.icons.Count];
foreach (Icon icon in currentIconSet.icons)
{
string name = icon.iconSettings.exportName;
for (int i = 1; i <= 128; i++)
{
if (!subIconNames.Contains(name))
break;
name = icon.iconSettings.exportName + " (" + i + ")";
}
subIconNames[idx++] = (name);
}
float tmp = EditorGUIUtility.labelWidth;
EditorGUIUtility.labelWidth = 75;
currentIconSet.iconIndex = EditorGUILayout.Popup("Icon Variant", currentIconSet.iconIndex, subIconNames);
EditorGUIUtility.labelWidth = tmp;
if (GUILayout.Button("+", GUILayout.Width(20)))
{
Icon newIcon = currentIconSet.AddDefaultIcon(assetGrid, new ObjectPathPair { path = currentIconSet.assetPath, UnityEngine_object = currentIconSet.assetObject });
currentIconSet.iconIndex = currentIconSet.icons.Count - 1;
newIcon.iconSettings.exportName += " (" + currentIconSet.iconIndex + ")";
currentIconSet.saveData = true;
updateFlag = true;
}
GUI.enabled = currentIconSet.icons.Count > 1;
if (GUILayout.Button("-", GUILayout.Width(20)))
{
currentIconSet.icons.Remove(currentIcon);
currentIconSet.iconIndex = currentIconSet.icons.Count - 1;
currentIconSet.saveData = true;
updateFlag = true;
}
GUI.enabled = true;
GUILayout.EndHorizontal();
}
void CheckMouseMovement()
{
//---Detect right mouse button down---//
if (Event.current.button == 1 && Event.current.type == EventType.Layout)
{
//---Check if the mouse is over the preview render---//
if (previewRect.Contains(Event.current.mousePosition))
{
//---Record the object for undo, but only once until hold released---//
if (!undoHold)
{
Undo.RecordObject(currentIcon, "Camera Rotation");
undoHold = true;
}
//---Get rotation from mouse x movement---//
Quaternion camTurnAngle = Quaternion.AngleAxis(Event.current.delta.x * 0.2f, Vector3.up);
//---Combine with rotation from mouse y movement---//
Vector3 axis = Quaternion.LookRotation(currentIcon.iconSettings.cameraTarget - currentIcon.iconSettings.cameraPosition) * Vector3.right;
camTurnAngle *= Quaternion.AngleAxis(Event.current.delta.y * 0.2f, axis);
//---Rotate the camera by moving it---//
currentIcon.iconSettings.cameraPosition = camTurnAngle * currentIcon.iconSettings.cameraPosition;
//---Flag the icon to be saved and updated---//
currentIconSet.saveData = true;
updateFlag = true;
window.Repaint();
}
}
//---Detect scroll wheel movement---//
else if (Event.current.type == EventType.ScrollWheel)
{
//---Check if the mouse is over the preview render---//
if (previewRect.Contains(Event.current.mousePosition))
{
//---Record the object for undo, but only once until hold released---//
if (!undoHold)
{
Undo.RecordObject(currentIcon, "Camera Zoom");
undoHold = true;
}
//---Zoom the camra---//
if (Mathf.Sign(Event.current.delta.y) == 1)
currentIcon.iconSettings.camerasScaleFactor /= 1.1f;
else
currentIcon.iconSettings.camerasScaleFactor *= 1.1f;
//---Flag the icon to be saved and updated---//
currentIconSet.saveData = true;
updateFlag = true;
window.Repaint();
}
}
//--If no mouse inputs then release undo hold---//
else if (undoHold)
undoHold = false;
}
void DrawPreview()
{
//---Setup scroll style if null---//
if (scrollStyle == null)
{
scrollStyle = new GUIStyle(GUI.skin.scrollView);
scrollStyle.margin.left = 1;
scrollStyle.normal.background = scrollAreaBackgroundImage;
}
//---Begin GUI elements---//
previewScrollPos = GUILayout.BeginScrollView(previewScrollPos, scrollStyle, GUILayout.Height(previewDraggableSeparator.value));
GUILayout.FlexibleSpace();
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
//---Get the render rect---//
Rect renderRect = GUILayoutUtility.GetRect(renderSize.x, renderSize.y);
renderRect.size -= new Vector2(12, 12);
renderRect.center += new Vector2(6, 6);
//---Draw the background checkerboard texture---//
GUI.DrawTextureWithTexCoords(renderRect, previewBackgroundImage, new Rect(0, 0, renderRect.width / 32, renderRect.height / 32));
//---Draw the icon render---//
GUI.DrawTexture(renderRect, currentIcon.fullRender);
//---End GUI elements---//
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GUILayout.FlexibleSpace();
GUILayout.EndScrollView();
if (Event.current.type == EventType.Repaint)
{
//---Get difference in pixels between export resolution and preview window resolution---//
previewRect = GUILayoutUtility.GetLastRect();
previewAreaSize = previewRect.size;
Vector2 delta = currentIcon.iconSettings.exportResolution - previewRect.size;
//---Normalise the delta to the export resolution---//
delta.x /= currentIcon.iconSettings.exportResolution.x;
delta.y /= currentIcon.iconSettings.exportResolution.y;
//---If export resolution is bigger than preview window (x and y)---//
if (delta.x > 0 && delta.y > 0)
{
//---If normalised delta is larger in y---//
if (Mathf.Abs(delta.x) < Mathf.Abs(delta.y))
zoomFitByWidthHeight = 0; //fit by height
else
zoomFitByWidthHeight = 1; //fit by width
}
//---If export resolution is smaller than preview window (x and y)---//
else if (delta.x <= 0 && delta.y <= 0)
{
//---If normalised delta is larger in x---//
if (Mathf.Abs(delta.x) < Mathf.Abs(delta.y))
zoomFitByWidthHeight = 1; //fit by width
else
zoomFitByWidthHeight = 0; //fit by height
}
//---If export resolution is bigger than preview window (y only)---//
else if (delta.y > 0)
zoomFitByWidthHeight = 0; //fit by height
//---If export resolution is bigger than preview window (x only)---//
else if (delta.x > 0)
zoomFitByWidthHeight = 1; //fit by width
}
}
void DrawPreviewResAndZoom()
{
//---Begin GUI elements---//
EditorGUI.BeginChangeCheck();
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
//---Calculate zoom scale for 'Zoom to Fit'---//
switch (zoomFitByWidthHeight)
{
case 0: //fit by height
zoomScales[8] = previewAreaSize.y / (float)(currentIcon.iconSettings.exportResolution.y);
break;
case 1: //fit by width
zoomScales[8] = previewAreaSize.x / (float)(currentIcon.iconSettings.exportResolution.x);
break;
}
//---Set this zoom scale to 1 if not icons selected---//
if (assetGrid.selectedIconSets.Count == 0)
zoomScales[8] = 1;
//---Set the string for the zoom option---//
string s = "Scale to Fit (" + (100f * (float)zoomScales[8]).ToString("f1") + "%)";
zoomScalesStrings[8] = s;
//---Draw preview resolution selection dropdown---//
GUILayout.Label("Preview Resolution", GUILayout.Width(115));
resMultiplyerIndex = EditorGUILayout.Popup(resMultiplyerIndex, resMultiplyersStrings, GUILayout.Width(70));
renderResolution = Utils.MutiplyVector2IntByFloat(currentIcon.iconSettings.exportResolution, resMultiplyers[resMultiplyerIndex]);
//---If preview resolution changed then update the icon---//
if (EditorGUI.EndChangeCheck())
{
currentIconSet = assetGrid.selectedIconSets[currentIconIndex];
currentIcon = currentIconSet.GetCurrentIcon();
if (currentIcon != null)
{
updateFlag = true;
}
}
//---Draw the preview zoom selection dropdown---//
GUILayout.Space(32);
GUILayout.Label("Zoom", GUILayout.Width(40));
zoomScaleIndex = EditorGUILayout.Popup(zoomScaleIndex, zoomScalesStrings, GUILayout.Width(150));
renderSize = Utils.MutiplyVector2IntByFloat(currentIcon.iconSettings.exportResolution, zoomScales[zoomScaleIndex]);
//---End GUI elements---//
GUILayout.EndHorizontal();
}
void DrawTabs(float width)
{
//---Begin scroll view---//
controlsScrollPos = GUILayout.BeginScrollView(controlsScrollPos, GUILayout.Height(window.position.height - previewDraggableSeparator.value - 98));
//---Draw the controls for the selected tab---//
switch (tab)
{
case 0:
Tabs.DrawObjectControls(this);
break;
case 1:
Tabs.DrawHierarchyControls(this);
break;
case 2:
Tabs.DrawCameraControls(this);
break;
case 3:
Tabs.DrawLightingControls(this);
break;
case 4:
Tabs.DrawAnimationControls(this);
break;
case 5:
Tabs.DrawPostProcessingControls(this);
break;
case 6:
Tabs.DrawExportControls(this);
break;
}
//---If any tab other than export/hierarchy tab---//
if (tab != 1 && tab != 6)
{
//---Draw button to apply settings to all selected icons---//
GUILayout.Space(12);
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
if (GUILayout.Button("Copy to Other Icons", GUILayout.Width(200)))
{
CopyWindow.Init(this);
}
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
}
//---Draw button to reset this icon's settings---//
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
if (GUILayout.Button("Reset Icon(s)", GUILayout.Width(200)))
{
ResetWindow.Init(this);
}
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
//---End scroll view---//
GUILayout.EndScrollView();
//---Draw fullscreen toggle button---//
if (GUILayout.Button(fullscreen ? "<" : ">", GUILayout.Width(20)))
{
//---Toggle fullscreen---//
fullscreen = !fullscreen;
//---Set window position and size---//
if (fullscreen)
{
fullWidth = window.position.width - width;
oldMinWidth = window.minSize.x;
window.minSize = new Vector2(400, window.minSize.y);
window.position = new Rect(window.position.xMax - width, window.position.y, width, window.position.height);
}
else
{
window.position = new Rect(window.position.xMax - (fullWidth + window.position.width), window.position.y, fullWidth + window.position.width, window.position.height);
window.minSize = new Vector2(oldMinWidth, window.minSize.y);
}
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 18af1c8019c04c147852c58dd6f9894a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,209 @@
using System;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
namespace RapidIcon_1_7_2
{
public class ReorderableListCallbacks
{
private IconEditor iconEditor;
public ReorderableListCallbacks(IconEditor iconEditor)
{
this.iconEditor = iconEditor;
}
private ReorderableListCallbacks()
{ }
public void DrawHeader(Rect rect)
{
//---Title label---//
EditorGUI.LabelField(rect, "Shaders");
//---Fullscreen check---//
float sw2 = iconEditor.sepWidth;
if (iconEditor.fullscreen)
sw2 += iconEditor.fullWidth;
rect.width = 100;
rect.x = sw2 - 154;
//---Draw Save preset button---//
if (GUI.Button(rect, "Save Preset"))
{
//---Get save path---//
string savePath = EditorUtility.SaveFilePanel("Save Preset", iconEditor.lastPresetPath == "" ? Application.dataPath : iconEditor.lastPresetPath, "PostProcessingPreset", "rippp");
//---If savepath is not empty then save preset---//
if (savePath != "")
{
//---Convert data to JSON string---//
iconEditor.currentIcon.SaveMatInfo();
string data = JsonUtility.ToJson(iconEditor.currentIcon);
//int pos = data.IndexOf("\"matInfo\":");
//data = "{\"iconSettings\":{" + data.Substring(pos);
//---Save bytes---//
File.WriteAllBytes(savePath, System.Text.Encoding.ASCII.GetBytes(data));
//---Store path as last preset path---//
iconEditor.lastPresetPath = savePath;
}
}
//---Draw Load Preset button---//
rect.x += 102;
if (GUI.Button(rect, "Load Preset"))
{
//---Get open path---//
string openPath = EditorUtility.OpenFilePanel("Open Preset", iconEditor.lastPresetPath == "" ? Application.dataPath : iconEditor.lastPresetPath, "rippp");
//---If open path is not empty then load the preset---//
if (openPath != "")
{
//---Read bytes and get JSON string---//
Byte[] bytes = File.ReadAllBytes(openPath);
iconEditor.lastPresetPath = openPath;
string data = System.Text.Encoding.ASCII.GetString(bytes);
//---Convert to icon from JSON---//
Icon tmp = JsonUtility.FromJson<Icon>(data);
//---Load mat info---//
iconEditor.currentIconSet.saveData = true;
iconEditor.currentIcon.iconSettings.matInfo = new List<Icon.MaterialInfo>(tmp.iconSettings.matInfo);
iconEditor.currentIcon.LoadMatInfo();
//---Update icon---//
Utils.UpdateIcon(iconEditor.currentIcon, iconEditor);
//---Update reorderable list---//
iconEditor.reorderableList.list = iconEditor.currentIcon.iconSettings.postProcessingMaterials;
iconEditor.reorderableList.index = 0;
//---Create new material editor---//
Editor.DestroyImmediate(iconEditor.materialEditor);
iconEditor.materialEditor = (MaterialEditor)Editor.CreateEditor((UnityEngine.Object)iconEditor.reorderableList.list[iconEditor.reorderableList.index]);
}
}
}
public void DrawListItems(Rect rect, int index, bool isActive, bool isFocused)
{
//---If index within bounds of the list---//
if (index >= 0 && index < iconEditor.reorderableList.list.Count)
{
//---Check and fix editor---//
if (iconEditor.materialEditor == null)
{
Editor.DestroyImmediate(iconEditor.materialEditor);
iconEditor.materialEditor = (MaterialEditor)Editor.CreateEditor((UnityEngine.Object)iconEditor.reorderableList.list[iconEditor.reorderableList.index]);
}
//---Check and fix materials---//
if (iconEditor.currentIcon.iconSettings.postProcessingMaterials[index] == null)
{
iconEditor.currentIcon.LoadMatInfo();
}
//---Check for fullscreen---//
float sw2 = iconEditor.sepWidth;
if (iconEditor.fullscreen)
sw2 += iconEditor.fullWidth;
//---Get widths of elements in list item - layer toggle, layer name, layer shader---//
float[] widths = new float[] { 16, (sw2 - 150) / 2, (sw2 + 100) / 2 };
//---Prevent error, close window if material toggles is null - reopening window should fix---//
if (iconEditor.currentIcon.iconSettings.materialToggles == null)
{
iconEditor.window.Close();
return;
}
//---Draw text field for layer name, this is draw first before the change check as changing the layer name doesn't need to update the icon---//
GUI.enabled = iconEditor.currentIcon.iconSettings.materialToggles[iconEditor.currentIcon.iconSettings.postProcessingMaterials[index]];
iconEditor.currentIcon.iconSettings.materialDisplayNames[iconEditor.currentIcon.iconSettings.postProcessingMaterials[index]] = EditorGUI.TextField(new Rect(rect.x + widths[0] + 4, rect.y + 3, widths[1], EditorGUIUtility.singleLineHeight), iconEditor.currentIcon.iconSettings.materialDisplayNames[iconEditor.currentIcon.iconSettings.postProcessingMaterials[index]]);
//---Draw the layer toggle---//
GUI.enabled = true;
EditorGUI.BeginChangeCheck();
iconEditor.currentIcon.iconSettings.materialToggles[iconEditor.currentIcon.iconSettings.postProcessingMaterials[index]] = EditorGUI.Toggle(new Rect(rect.x, rect.y + 3, widths[0], EditorGUIUtility.singleLineHeight), iconEditor.currentIcon.iconSettings.materialToggles[iconEditor.currentIcon.iconSettings.postProcessingMaterials[index]]);
//---Draw the shader selection field---//
GUI.enabled = iconEditor.currentIcon.iconSettings.materialToggles[iconEditor.currentIcon.iconSettings.postProcessingMaterials[index]];
iconEditor.currentIcon.iconSettings.postProcessingMaterials[index].shader = (Shader)EditorGUI.ObjectField(new Rect(rect.x + widths[0] + widths[1] + 8, rect.y + 3, widths[2], EditorGUIUtility.singleLineHeight), iconEditor.currentIcon.iconSettings.postProcessingMaterials[index].shader, typeof(Shader), true);
GUI.enabled = true;
//---If layer toggles/shaders changed then update the icon---//
if (EditorGUI.EndChangeCheck())
{
iconEditor.updateFlag = true;
Editor.DestroyImmediate(iconEditor.materialEditor);
iconEditor.materialEditor = (MaterialEditor)Editor.CreateEditor((UnityEngine.Object)iconEditor.reorderableList.list[iconEditor.reorderableList.index]);
}
}
}
public void SelectShader(ReorderableList l)
{
//---If selected shader changes, create a new material editor---//
Editor.DestroyImmediate(iconEditor.materialEditor);
iconEditor.materialEditor = (MaterialEditor)Editor.CreateEditor((UnityEngine.Object)iconEditor.reorderableList.list[iconEditor.reorderableList.index]);
}
public void AddShader(ReorderableList l)
{
//---Record object for undo---//
Undo.RecordObject(iconEditor.currentIcon, "Add New Shader");
//---Create new material with default shader---//
Material m = new Material(Shader.Find("RapidIcon/ObjectRender"));
//---Add the new material to the list and select it---//
l.list.Add(m);
l.index = l.list.Count - 1;
//---Add the material display name and toggle to the current icon---//
iconEditor.currentIcon.iconSettings.materialDisplayNames.Add(m, "Shader " + l.list.Count);
iconEditor.currentIcon.iconSettings.materialToggles.Add(m, true);
//---Create a new material editor---//
Editor.DestroyImmediate(iconEditor.materialEditor);
iconEditor.materialEditor = (MaterialEditor)Editor.CreateEditor((UnityEngine.Object)iconEditor.reorderableList.list[iconEditor.reorderableList.index]);
//---Update and save the current icon---//
iconEditor.currentIconSet.saveData = true;
iconEditor.updateFlag = true;
}
public void RemoveShader(ReorderableList l)
{
//---Record object for undo---//
Undo.RecordObject(iconEditor.currentIcon, "Remove Shader");
//---Remove the material from the list---//
l.list.Remove(l.list[l.index]);
l.index = (int)Mathf.Clamp(l.index, 0, l.list.Count - 1);
//---Create a new material editor, if any materials left in the list---//
Editor.DestroyImmediate(iconEditor.materialEditor);
if (l.list.Count > 0)
iconEditor.materialEditor = (MaterialEditor)Editor.CreateEditor((UnityEngine.Object)iconEditor.reorderableList.list[iconEditor.reorderableList.index]);
//---Update and save the current icon---//
iconEditor.currentIconSet.saveData = true;
iconEditor.updateFlag = true;
}
public void ShadersReorded(ReorderableList l)
{
//---Update and save the current icon if the list is reordered---//
iconEditor.currentIconSet.saveData = true;
iconEditor.updateFlag = true;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1395b5f87121a87409bf19e220e7d467
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,660 @@
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
namespace RapidIcon_1_7_2
{
public static class Tabs
{
public static void DrawObjectControls(IconEditor iconEditor)
{
//---Begin change check---//
EditorGUI.BeginChangeCheck();
//---Draw position field---//
GUI.enabled = !iconEditor.currentIcon.iconSettings.autoPosition;
Vector3 tmpObjPos = EditorGUILayout.Vector3Field("Position", iconEditor.currentIcon.iconSettings.objectPosition);
Rect posR = GUILayoutUtility.GetLastRect();
posR.x += 50;
posR.height = 18;
posR.width = 50;
GUI.enabled = true;
//---Draw auto button for position---//
bool tmpAutoPos = GUI.Toggle(posR, iconEditor.currentIcon.iconSettings.autoPosition, "Auto", GUI.skin.button);
//---Draw object rotation and scale fields---//
Vector3 tmpObjRot = EditorGUILayout.Vector3Field("Rotation", iconEditor.currentIcon.iconSettings.objectRotation);
Vector3 tmpObjScale = EditorGUILayout.Vector3Field("Scale", iconEditor.currentIcon.iconSettings.objectScale);
//---Draw link scale toggle---//
Rect r = GUILayoutUtility.GetLastRect();
r.position += new Vector2(40, 0);
if (GUI.Button(r, iconEditor.linkScale ? iconEditor.scaleLinkOnImage : iconEditor.scaleLinkOffImage, GUIStyle.none))
{
iconEditor.linkScale = !iconEditor.linkScale;
}
//---If any fields changed---//
if (EditorGUI.EndChangeCheck())
{
//---Record object for undo---//
Undo.RecordObject(iconEditor.currentIcon, "Edit Icon Object");
//---Apply position and rotation---//
iconEditor.currentIcon.iconSettings.objectPosition = tmpObjPos;
iconEditor.currentIcon.iconSettings.objectRotation = tmpObjRot;
if (tmpAutoPos && !iconEditor.currentIcon.iconSettings.autoPosition)
{
iconEditor.currentIcon.iconSettings.objectPosition = Utils.GetObjectAutoOffset(iconEditor.currentIcon, Utils.GetObjectBounds(iconEditor.currentIconSet));
}
iconEditor.currentIcon.iconSettings.autoPosition = tmpAutoPos;
//---If link scale disabled, apply scale---//
if (!iconEditor.linkScale)
{
iconEditor.currentIcon.iconSettings.objectScale = tmpObjScale;
}
else
{
//---If link scale enabled, detect which axis changed and apply to all axes---//
if (tmpObjScale.x != iconEditor.currentIcon.iconSettings.objectScale.x)
{
iconEditor.currentIcon.iconSettings.objectScale = tmpObjScale.x * Vector3.one;
}
else if (tmpObjScale.y != iconEditor.currentIcon.iconSettings.objectScale.y)
{
iconEditor.currentIcon.iconSettings.objectScale = tmpObjScale.y * Vector3.one;
}
else if (tmpObjScale.z != iconEditor.currentIcon.iconSettings.objectScale.z)
{
iconEditor.currentIcon.iconSettings.objectScale = tmpObjScale.z * Vector3.one;
}
}
//---Save and update icon---//
iconEditor.currentIconSet.saveData = true;
iconEditor.updateFlag = true;
}
}
public static void DrawHierarchyControls(IconEditor iconEditor)
{
GUILayout.BeginHorizontal();
GUILayout.Label("Object Hierarchy");
if (GUILayout.Button("Enable All"))
{
List<string> keys = iconEditor.currentIcon.iconSettings.subObjectEnables.Keys.ToList();
foreach (string s in keys)
iconEditor.currentIcon.iconSettings.subObjectEnables[s] = true;
iconEditor.updateFlag = true;
iconEditor.currentIconSet.saveData = true;
}
if (GUILayout.Button("Disable All"))
{
List<string> keys = iconEditor.currentIcon.iconSettings.subObjectEnables.Keys.ToList();
foreach (string s in keys)
iconEditor.currentIcon.iconSettings.subObjectEnables[s] = false;
iconEditor.updateFlag = true;
iconEditor.currentIconSet.saveData = true;
}
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GameObject obj = (GameObject)iconEditor.currentIconSet.assetObject;
Rect r = GUILayoutUtility.GetRect(new GUIContent(obj.name), GUI.skin.label);
bool active = iconEditor.currentIcon.iconSettings.subObjectEnables["/0"];
EditorGUI.BeginChangeCheck();
bool tmpToggle = GUI.Toggle(r, active, obj.name);
if (EditorGUI.EndChangeCheck())
{
iconEditor.currentIcon.iconSettings.subObjectEnables["/0"] = tmpToggle;
iconEditor.updateFlag = true;
iconEditor.currentIconSet.saveData = true;
}
DrawChildObjects(iconEditor, obj, 0, 0, "/0", !tmpToggle);
}
private static void DrawChildObjects(IconEditor iconEditor, GameObject obj, int depth, int childIdx, string path, bool parentDisabled)
{
for (int i = 0; i < obj.transform.childCount; i++)
{
GameObject child = obj.transform.GetChild(i).gameObject;
Rect r = GUILayoutUtility.GetRect(new GUIContent(child.name), GUI.skin.label);
r.x += (depth + 1) * 16;
string newPath = path + "/" + i;
bool active = iconEditor.currentIcon.iconSettings.subObjectEnables[newPath];
if (parentDisabled)
{
active = false;
GUI.enabled = false;
}
EditorGUI.BeginChangeCheck();
bool tmpToggle = GUI.Toggle(r, active, child.name);
if (EditorGUI.EndChangeCheck())
{
iconEditor.currentIcon.iconSettings.subObjectEnables[newPath] = tmpToggle;
iconEditor.updateFlag = true;
iconEditor.currentIconSet.saveData = true;
}
GUI.enabled = true;
DrawChildObjects(iconEditor, child, depth + 1, i, newPath, !tmpToggle);
}
}
public static void DrawCameraControls(IconEditor iconEditor)
{
//---Begin change check---//
EditorGUI.BeginChangeCheck();
//---Draw camera position field---//
Vector3 tmpCamPos = EditorGUILayout.Vector3Field("Position", iconEditor.currentIcon.iconSettings.cameraPosition);
//---Draw camera point of focus field---//
GUILayout.Space(8);
float tmpWdith = EditorGUIUtility.labelWidth;
EditorGUIUtility.labelWidth = 80;
Vector3 tmpCamTgt = iconEditor.currentIcon.iconSettings.cameraTarget;
tmpCamTgt = EditorGUILayout.Vector3Field("Point of Focus", iconEditor.currentIcon.iconSettings.cameraTarget);
//---Draw camera projection mode field---//
GUILayout.Space(8);
string[] listOptions = { "Perspective", "Orthographic" };
EditorGUIUtility.labelWidth = 80;
int tmpOrtho = EditorGUILayout.Popup("Projection", iconEditor.currentIcon.iconSettings.cameraOrtho ? 1 : 0, listOptions);
//---Temporary variables for undo---//
float tmpCamSize = iconEditor.currentIcon.iconSettings.cameraSize;
float tmpScaleFactor = iconEditor.currentIcon.iconSettings.camerasScaleFactor;
float tmpCamFov = iconEditor.currentIcon.iconSettings.cameraFov;
bool tmpCamAuto = iconEditor.currentIcon.iconSettings.autoScale;
//---If projection mode is ortho---//
if (tmpOrtho == 1)
{
GUILayout.BeginHorizontal();
GUI.enabled = !iconEditor.currentIcon.iconSettings.autoScale;
//---Draw camera size field---//
tmpCamSize = EditorGUILayout.FloatField("Size", iconEditor.currentIcon.iconSettings.cameraSize);
GUI.enabled = true;
//---Draw auto button---//
GUIStyle s = new GUIStyle(GUI.skin.button);
s.fixedWidth = 50;
tmpCamAuto = GUILayout.Toggle(iconEditor.currentIcon.iconSettings.autoScale, "Auto", s);
GUILayout.EndHorizontal();
}
else
{
//---Draw FOV field---//
tmpCamFov = EditorGUILayout.FloatField("Field of View", iconEditor.currentIcon.iconSettings.cameraFov);
}
//---Draw scale factor field---//
tmpScaleFactor = EditorGUILayout.FloatField("Scale Factor", iconEditor.currentIcon.iconSettings.camerasScaleFactor);
//---If perspective projection mode---//
EditorGUIUtility.labelWidth = tmpWdith;
//---If any field changed---//
if (EditorGUI.EndChangeCheck())
{
//---Record object for undo---//
Undo.RecordObject(iconEditor.currentIcon, "Edit Icon Camera");
//---Apply camera position, point of focus, and projection mode---//
iconEditor.currentIcon.iconSettings.cameraPosition = tmpCamPos;
iconEditor.currentIcon.iconSettings.cameraTarget = tmpCamTgt;
iconEditor.currentIcon.iconSettings.cameraOrtho = tmpOrtho == 1 ? true : false;
//---Apply size, fov, and scale factor---//
iconEditor.currentIcon.iconSettings.cameraSize = tmpCamSize;
iconEditor.currentIcon.iconSettings.cameraFov = tmpCamFov;
iconEditor.currentIcon.iconSettings.camerasScaleFactor = tmpScaleFactor;
//---Auto scale---//
if (tmpCamAuto && !iconEditor.currentIcon.iconSettings.autoScale)
{
iconEditor.currentIcon.iconSettings.cameraSize = Utils.GetCameraAuto(iconEditor.currentIcon, Utils.GetObjectBounds(iconEditor.currentIconSet));
}
iconEditor.currentIcon.iconSettings.autoScale = tmpCamAuto;
//---Save and update icon---//
iconEditor.currentIconSet.saveData = true;
iconEditor.updateFlag = true;
}
}
private static void ApplyScaleFactor(Icon icon, IconEditor iconEditor)
{
//---If not current icon then apply the scale factor---//
if (icon != iconEditor.currentIcon)
{
icon.iconSettings.camerasScaleFactor = iconEditor.currentIcon.iconSettings.camerasScaleFactor;
icon.iconSettings.perspLastScale = iconEditor.currentIcon.iconSettings.perspLastScale;
icon.parentIconSet.saveData = true;
Utils.UpdateIcon(icon, iconEditor);
}
}
public static void DrawLightingControls(IconEditor iconEditor)
{
//---Begin change check---//
EditorGUI.BeginChangeCheck();
//---Draw ambient light field---///
Color tmpAmbLight = EditorGUILayout.ColorField("Ambient Light Colour", iconEditor.currentIcon.iconSettings.ambientLightColour);
//---Draw diretional light fields---//
EditorGUILayout.Space(4);
EditorGUILayout.LabelField("Directional Light");
Color tmpLightColour = EditorGUILayout.ColorField("Colour", iconEditor.currentIcon.iconSettings.lightColour);
Vector3 tmpLightDir = EditorGUILayout.Vector3Field("Rotation", iconEditor.currentIcon.iconSettings.lightDir);
float tmpLightIntensity = EditorGUILayout.FloatField("Intensity", iconEditor.currentIcon.iconSettings.lightIntensity);
//---If any fields have changed---//
if (EditorGUI.EndChangeCheck())
{
//---Record object for undo---//
Undo.RecordObject(iconEditor.currentIcon, "Edit Icon Lighting");
//---Apply settings---//
iconEditor.currentIcon.iconSettings.ambientLightColour = tmpAmbLight;
iconEditor.currentIcon.iconSettings.lightColour = tmpLightColour;
iconEditor.currentIcon.iconSettings.lightDir = tmpLightDir;
iconEditor.currentIcon.iconSettings.lightIntensity = tmpLightIntensity;
//---Update and save icon---//
iconEditor.currentIconSet.saveData = true;
iconEditor.updateFlag = true;
}
}
public static void DrawAnimationControls(IconEditor iconEditor)
{
//---Begin change check---//
EditorGUI.BeginChangeCheck();
//---Draw animation clip field---//
AnimationClip c = (AnimationClip)EditorGUILayout.ObjectField("Animation Clip", iconEditor.currentIcon.iconSettings.animationClip, typeof(AnimationClip), false);
//---Draw animation offset field---//
Rect r = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight);
float offset = EditorGUI.Slider(r, "Animation Offset", iconEditor.currentIcon.iconSettings.animationOffset, 0, 1);
//---If any fields have changed---//
if (EditorGUI.EndChangeCheck())
{
//---Record object for undo---//
Undo.RecordObject(iconEditor.currentIcon, "Edit Icon Animations");
//---Apply settings---//
iconEditor.currentIcon.iconSettings.animationClip = c;
iconEditor.currentIcon.iconSettings.animationOffset = offset;
//---Update and save icon---//
iconEditor.updateFlag = true;
iconEditor.currentIconSet.saveData = true;
}
}
public static void DrawPostProcessingControls(IconEditor iconEditor)
{
//---Begin change check---//
EditorGUI.BeginChangeCheck();
//---Draw filter mode field---//
FilterMode tmpFilterMode = (FilterMode)EditorGUILayout.EnumPopup("Filter Mode", iconEditor.currentIcon.iconSettings.filterMode);
//---If filter mode changed---//
if (EditorGUI.EndChangeCheck())
{
//---Record object for undo---//
//---Apply sttings, update icon---//
Undo.RecordObject(iconEditor.currentIcon, "Change Filter Mode");
iconEditor.currentIcon.iconSettings.filterMode = tmpFilterMode;
iconEditor.updateFlag = true;
}
//---Draw reorderable list---//
iconEditor.reorderableList.list = iconEditor.currentIcon.iconSettings.postProcessingMaterials;
iconEditor.reorderableList.index = (int)Mathf.Clamp(iconEditor.reorderableList.index, 0, iconEditor.reorderableList.list.Count - 1);
GUILayout.Space(2);
iconEditor.reorderableList.DoLayoutList();
//---Begin change check---//
EditorGUI.BeginChangeCheck();
if (iconEditor.reorderableList.list.Count > 0)
{
//---Draw shader settings label---//
string shaderName = iconEditor.currentIcon.iconSettings.postProcessingMaterials[iconEditor.reorderableList.index].shader.name;
GUILayout.Label("Shader Settings (" + shaderName + ")");
GUILayout.BeginVertical(GUI.skin.box);
//---If not the default render shader---//
if (shaderName != "RapidIcon/ObjectRender")
{
//---Get the material properties---//
UnityEngine.Object[] obj = new UnityEngine.Object[1];
obj[0] = (UnityEngine.Object)iconEditor.reorderableList.list[iconEditor.reorderableList.index];
MaterialProperty[] props = MaterialEditor.GetMaterialProperties(obj);
//---If the shader doesn't have a custom GUI---//
if (iconEditor.materialEditor.customShaderGUI == null)
{
//---Draw the properties fields---//
foreach (MaterialProperty prop in props)
{
if (iconEditor.materialEditor == null)
{
Debug.LogWarning("null editor!!!");
continue;
}
if (prop.name != "_MainTex" && prop.flags != MaterialProperty.PropFlags.HideInInspector)
{
iconEditor.materialEditor.ShaderProperty(prop, prop.displayName);
}
}
}
else
//---If the shader does have a custom GUI---//
{
//---Get list of all properties---//
List<MaterialProperty> list = new List<MaterialProperty>(props);
//---Remove the property from list if it is _MainTex---//
foreach (MaterialProperty prop in list)
{
if (prop.name == "_MainTex")
{
list.Remove(prop);
break;
}
}
//---Draw the custom GUI---//
props = list.ToArray();
iconEditor.materialEditor.customShaderGUI.OnGUI(iconEditor.materialEditor, props);
}
}
//---If the default render shader---//
else
{
//---Begine change check---//
EditorGUI.BeginChangeCheck();
//---Draw fix alpha edges toggle---//
IconSettings.FixEdgesModes tmpFixEdges = (IconSettings.FixEdgesModes)EditorGUILayout.EnumPopup("Edge Fix Mode", iconEditor.currentIcon.iconSettings.fixEdgesMode);
//---If toggle changed---//
if (EditorGUI.EndChangeCheck())
{
//---Record object for undo and apply---//
Undo.RecordObject(iconEditor.currentIcon, "Toggle Icon Premultiplied Alpha");
iconEditor.currentIcon.iconSettings.fixEdgesMode = tmpFixEdges;
//---Update and save icon---//
iconEditor.currentIconSet.saveData = true;
iconEditor.updateFlag = true;
}
}
GUILayout.EndVertical();
}
//---If any fields changed---//
if (EditorGUI.EndChangeCheck())
{
//---Save material info and update icon---//
iconEditor.currentIcon.SaveMatInfo();
iconEditor.updateFlag = true;
}
}
public static void DrawExportControls(IconEditor iconEditor)
{
//---Begin change check---//
EditorGUI.BeginChangeCheck();
//---Draw export resolution field, limit to 8x8 - 2048x2048---//
Vector2Int tmpExportRes = EditorGUILayout.Vector2IntField("Export Resolution", iconEditor.currentIcon.iconSettings.exportResolution);
tmpExportRes.x = (int)Mathf.Clamp(tmpExportRes.x, 8, 2048);
tmpExportRes.y = (int)Mathf.Clamp(tmpExportRes.y, 8, 2048);
//---If resolution fields change---//
if (EditorGUI.EndChangeCheck())
{
//---Record object for undo---//
Undo.RecordObject(iconEditor.currentIcon, "Edit Icon Export Resolution");
//---Apply settings---//
iconEditor.currentIcon.iconSettings.exportResolution.x = (int)Mathf.Clamp(tmpExportRes.x, 8, 2048);
iconEditor.currentIcon.iconSettings.exportResolution.y = (int)Mathf.Clamp(tmpExportRes.y, 8, 2048);
//---Save and update icon---//
iconEditor.currentIconSet.saveData = true;
iconEditor.updateFlag = true;
}
//---Begin new change check---//
EditorGUI.BeginChangeCheck();
GUILayout.Space(2);
GUILayout.BeginHorizontal();
//---Add forward slash to end of export path if missing---//
if (iconEditor.currentIcon.iconSettings.exportFolderPath[iconEditor.currentIcon.iconSettings.exportFolderPath.Length - 1] != '/')
iconEditor.currentIcon.iconSettings.exportFolderPath += "/";
//---Draw export folder field---//
float tmpWdith = EditorGUIUtility.labelWidth;
EditorGUIUtility.labelWidth = 80;
iconEditor.currentIcon.iconSettings.exportFolderPath = EditorGUILayout.TextField("Export Folder", iconEditor.currentIcon.iconSettings.exportFolderPath);
//---If export path is blank, change it to default Export folder---//
string tmpFolder = iconEditor.currentIcon.iconSettings.exportFolderPath;
if (tmpFolder == "")
{
string[] split = AssetDatabase.GUIDToAssetPath(AssetDatabase.FindAssets("RapidIconWindow")[0]).Split('/');
string rapidIconRootFolder = "";
for (int i = 0; i < split.Length - 3; i++)
rapidIconRootFolder += split[i] + "/";
iconEditor.currentIcon.iconSettings.exportFolderPath = rapidIconRootFolder + "Exports/";
}
//---Draw button to open file explorer to select export folder---//
EditorGUIUtility.labelWidth = tmpWdith;
if (GUILayout.Button("Browse", GUILayout.Width(100)))
{
string folder = EditorUtility.OpenFolderPanel("Export Folder", iconEditor.currentIcon.iconSettings.exportFolderPath, "");
if (folder != "")
{
string dataPath = Application.dataPath;
dataPath = dataPath.Substring(0, dataPath.LastIndexOf('/') + 1);
folder = folder.Replace(dataPath, "");
iconEditor.currentIcon.iconSettings.exportFolderPath = folder;
}
}
GUILayout.EndHorizontal();
//---Draw export path prefix/suffix fields---//
tmpWdith = EditorGUIUtility.labelWidth;
EditorGUIUtility.labelWidth = 80;
string exportPrefix = EditorGUILayout.TextField("Export Prefix", iconEditor.currentIcon.iconSettings.exportPrefix);
string exportSuffix = EditorGUILayout.TextField("Export Suffix", iconEditor.currentIcon.iconSettings.exportSuffix);
//---If any fields changes---//
if (EditorGUI.EndChangeCheck())
{
//---Record object for undo---//
Undo.RecordObject(iconEditor.currentIcon, "Edit Icon Export Path");
//---Apply settings---//
iconEditor.currentIcon.iconSettings.exportResolution = tmpExportRes;
iconEditor.currentIcon.iconSettings.exportPrefix = exportPrefix;
iconEditor.currentIcon.iconSettings.exportSuffix = exportSuffix;
iconEditor.currentIconSet.saveData = true;
}
//---Add button apply to all selected icons---//
if (GUILayout.Button("Copy to Other Icons"))
CopyWindow.Init(iconEditor);
//---Draw a separator---//
GUILayout.Space(12);
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
Rect r = GUILayoutUtility.GetRect(iconEditor.sepWidth, 1);
if (iconEditor.separatorTex == null)
{
if (EditorGUIUtility.isProSkin)
iconEditor.separatorTex = Utils.CreateColourTexture(2, 2, new Color32(31, 31, 31, 255));
else
iconEditor.separatorTex = Utils.CreateColourTexture(2, 2, new Color32(153, 153, 153, 255));
}
GUI.DrawTexture(r, iconEditor.separatorTex);
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GUILayout.Space(12);
//---Begin change check---//
EditorGUI.BeginChangeCheck();
//---Draw export name field---//
string exportName = EditorGUILayout.TextField("Export Name", iconEditor.currentIcon.iconSettings.exportName);
//---Draw label showing full name with prefix/suffix---//
EditorGUIUtility.labelWidth = tmpWdith;
GUILayout.Label("Full Export Name: " + iconEditor.currentIcon.iconSettings.exportPrefix + iconEditor.currentIcon.iconSettings.exportName + iconEditor.currentIcon.iconSettings.exportSuffix + ".png");
//---If fields changesd, and export name is valid---//
if (EditorGUI.EndChangeCheck())
{
if (exportName.Length > 0)
{
//---Record object for undo---//
Undo.RecordObject(iconEditor.currentIcon, "Edit Icon Export Name");
//---Apply and save---//
iconEditor.currentIcon.iconSettings.exportName = exportName;
iconEditor.currentIconSet.saveData = true;
}
}
//---Draw button to export icon---//
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
if (GUILayout.Button("Export Icon", GUILayout.Width(160)))
{
int result = EditorUtility.DisplayDialogComplex("Export Icon", "Export All Variants?", "All Variants", "Cancel", "Currently Selected Variant");
//---Export icon---//
if (result != 1)
{
if (result == 2)
{
Utils.ExportIcon(iconEditor.currentIcon, false, iconEditor);
Utils.FinishExportIcon(iconEditor.currentIcon);
}
else
{
//---Start asset editing---//
AssetDatabase.StartAssetEditing();
foreach (Icon icon in iconEditor.currentIconSet.icons)
{
Utils.ExportIcon(icon, iconEditor.currentIconSet.icons.Count > 1 ? true : false, iconEditor);
}
AssetDatabase.StopAssetEditing();
Utils.FinishExportIconSet(iconEditor.currentIconSet);
}
//---Reset replaceAll---//
iconEditor.replaceAll = false;
}
}
//---Draw button to export all selected icons---//
if (GUILayout.Button("Export Selected Icons", GUILayout.Width(160)))
{
int result = EditorUtility.DisplayDialogComplex("Export Icon", "Export All Variants?", "All Variants", "Cancel", "Currently Selected Variant");
if (result != 1)
{
//---Loop through all selected icons---//
int index = 1;
List<string> exportPaths = new List<string>();
foreach (IconSet iconSet in iconEditor.assetGrid.selectedIconSets)
{
if (result == 2)
{
Icon icon = iconSet.GetCurrentIcon();
//--Show progress bar---//
EditorUtility.DisplayProgressBar("Exporting Icons (" + index + "/" + iconEditor.assetGrid.selectedIconSets.Count + ")", iconSet.assetPath, ((float)index++ / iconEditor.assetGrid.selectedIconSets.Count));
//---Export icon---//
Utils.ExportIcon(icon, iconEditor.assetGrid.selectedIconSets.Count > 1 ? true : false, iconEditor);
//---Stop asset editing and finish export---//
Utils.FinishExportIcon(icon);
}
else
{
//--Show progress bar---//
EditorUtility.DisplayProgressBar("Exporting Icons (" + index + "/" + iconEditor.assetGrid.selectedIconSets.Count + ")", iconSet.assetPath, ((float)index++ / iconEditor.assetGrid.selectedIconSets.Count));
//---Start asset editing---//
AssetDatabase.StartAssetEditing();
foreach (Icon icon in iconSet.icons)
{
//---Export icon---//
Utils.ExportIcon(icon, iconEditor.assetGrid.selectedIconSets.Count > 1 || iconSet.icons.Count > 1 ? true : false, iconEditor);
}
//---Stop asset editing and finish export---//
AssetDatabase.StopAssetEditing();
Utils.FinishExportIconSet(iconSet);
}
}
//---Clear progress bar---//
EditorUtility.ClearProgressBar();
//---Reset replaceAll---//
iconEditor.replaceAll = false;
}
}
GUILayout.EndHorizontal();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 43277a6de4118d145a17df3c98e17ffd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: