void OnDisable() { if(unappliedChanges) { string assetPaths = ""; if(serializedObject.isEditingMultipleObjects) { for(int i = 0; i < assets.Length; i++) { assetPaths += "'"+AssetDatabase.GetAssetPath(assets[i])+"'\n"; } } else { assetPaths = AssetDatabase.GetAssetPath(asset); } if(EditorUtility.DisplayDialog("Unapplied import settings", "Unapplied import settings for "+assetPaths, "Apply", "Revert")) { ApplyChanges(); } else { RevertChanges(); } unappliedChanges = false; } Instance = null; }
void OnDestroy() { if (this.m_PreviewUtility != null) { this.m_PreviewUtility.Cleanup(); this.m_PreviewUtility = null; } Instance = null; }
void OnEnable() { Instance = this; asset = (SVGAsset)serializedObject.targetObject; anchorPositionContent = new GUIContent[anchorPosition.Length]; for(int i = 0; i < anchorPosition.Length; i++) { anchorPositionContent[i] = new GUIContent(anchorPosition[i]); } if(serializedObject.isEditingMultipleObjects) { assets = new SVGAsset[serializedObject.targetObjects.Length]; for(int i = 0; i < serializedObject.targetObjects.Length; i++) { assets[i] = (SVGAsset)serializedObject.targetObjects[i]; } } filesValid = true; if(serializedObject.isEditingMultipleObjects) { for(int i = 0; i < assets.Length; i++) { if(string.IsNullOrEmpty(assets[i].svgFile)) filesValid = false; } } else { if(string.IsNullOrEmpty(asset.svgFile)) filesValid = false; } format = serializedObject.FindProperty("_format"); useGradients = serializedObject.FindProperty("_useGradients"); antialiasing = serializedObject.FindProperty("_antialiasing"); meshCompression = serializedObject.FindProperty("_meshCompression"); scale = serializedObject.FindProperty("_scale"); vpm = serializedObject.FindProperty("_vpm"); depthOffset = serializedObject.FindProperty("_depthOffset"); compressDepth = serializedObject.FindProperty("_compressDepth"); customPivotPoint = serializedObject.FindProperty("_customPivotPoint"); pivotPoint = serializedObject.FindProperty("_pivotPoint"); //border = serializedObject.FindProperty("_border"); generateCollider = serializedObject.FindProperty("_generateCollider"); keepSVGFile = serializedObject.FindProperty("_keepSVGFile"); useLayers = serializedObject.FindProperty("_useLayers"); ignoreSVGCanvas = serializedObject.FindProperty("_ignoreSVGCanvas"); optimizeMesh = serializedObject.FindProperty("_optimizeMesh"); generateNormals = serializedObject.FindProperty("_generateNormals"); generateTangents = serializedObject.FindProperty("_generateTangents"); CreateSnapshot(); unappliedChanges = false; }
public override void OnInspectorGUI() { Instance = this; if (filesValid) { OnFilesValid(); } else { EditorGUILayout.HelpBox("File is invalid or corrupted!", MessageType.Error); } }
private void DoPivotFields(Rect fieldLocation) { EditorGUI.BeginChangeCheck(); bool customPivotPoint = svgAsset.customPivotPoint; bool sliceMesh = svgAsset.sliceMesh; Vector2 pivotPoint = svgAsset.pivotPoint; fieldLocation.x = 5f; fieldLocation.y += 18f; fieldLocation.width = 414f; customPivotPoint = EditorGUI.Toggle(fieldLocation, new GUIContent("Custom Pivot", "Choose the predefined pivot point or the custom pivot point."), customPivotPoint); fieldLocation.y += 18f; sliceMesh = EditorGUI.Toggle(fieldLocation, new GUIContent("Slice Mesh", "For reducing scaling artefacts slice mesh."), sliceMesh); fieldLocation.y += 18f; if (customPivotPoint) { EditorGUILayout.BeginHorizontal(); pivotPoint = EditorGUI.Vector2Field(fieldLocation, new GUIContent("Pivot", "The location of the SVG Asset center point in the original Rect, specified in percents."), pivotPoint); EditorGUILayout.EndHorizontal(); } else { Vector2 pivotPointVector = pivotPoint; int selectedIndex = SVGAssetEditor.GetPivotPointIndex(pivotPointVector); selectedIndex = EditorGUI.Popup(fieldLocation, new GUIContent("Pivot", "The location of the SVG Asset center point in the original Rect, specified in percents."), selectedIndex, SVGAssetEditor.anchorPositionContent); pivotPoint = SVGAssetEditor.GetPivotPoint(selectedIndex); } if (EditorGUI.EndChangeCheck()) { typeof(SVGAsset).GetField("_customPivotPoint", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(svgAsset, customPivotPoint); typeof(SVGAsset).GetField("_pivotPoint", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(svgAsset, pivotPoint); typeof(SVGAsset).GetField("_sliceMesh", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(svgAsset, sliceMesh); if (SVGAssetEditor.Instance != null) { SVGAssetEditor.Instance.unappliedChanges = true; } } }
private void DoApplyRevertGUI() { if (GUILayout.Button("Revert", EditorStyles.toolbarButton, new GUILayoutOption[0])) { SVGAssetEditor assetEditor = SVGAssetEditor.Instance; if (assetEditor != null) { assetEditor.RevertChanges(); } UpdateOriginalPivotPoint(); } if (GUILayout.Button("Apply", EditorStyles.toolbarButton, new GUILayoutOption[0])) { SVGAssetEditor assetEditor = SVGAssetEditor.Instance; if (assetEditor != null) { assetEditor.ApplyChanges(); } UpdateOriginalPivotPoint(); } }
void OnEnable() { Instance = this; asset = (SVGAsset)serializedObject.targetObject; anchorPositionContent = new GUIContent[anchorPosition.Length]; for(int i = 0; i < anchorPosition.Length; i++) { anchorPositionContent[i] = new GUIContent(anchorPosition[i]); } if(serializedObject.isEditingMultipleObjects) { assets = new SVGAsset[serializedObject.targetObjects.Length]; for(int i = 0; i < serializedObject.targetObjects.Length; i++) { assets[i] = (SVGAsset)serializedObject.targetObjects[i]; } } filesValid = true; if(serializedObject.isEditingMultipleObjects) { for(int i = 0; i < assets.Length; i++) { if(string.IsNullOrEmpty(assets[i].svgFile)) filesValid = false; } } else { if(string.IsNullOrEmpty(asset.svgFile)) filesValid = false; } format = serializedObject.FindProperty("_format"); useGradients = serializedObject.FindProperty("_useGradients"); antialiasing = serializedObject.FindProperty("_antialiasing"); antialiasingWidth = serializedObject.FindProperty("_antialiasingWidth"); meshCompression = serializedObject.FindProperty("_meshCompression"); scale = serializedObject.FindProperty("_scale"); vpm = serializedObject.FindProperty("_vpm"); depthOffset = serializedObject.FindProperty("_depthOffset"); compressDepth = serializedObject.FindProperty("_compressDepth"); customPivotPoint = serializedObject.FindProperty("_customPivotPoint"); pivotPoint = serializedObject.FindProperty("_pivotPoint"); //border = serializedObject.FindProperty("_border"); generateCollider = serializedObject.FindProperty("_generateCollider"); keepSVGFile = serializedObject.FindProperty("_keepSVGFile"); ignoreSVGCanvas = serializedObject.FindProperty("_ignoreSVGCanvas"); optimizeMesh = serializedObject.FindProperty("_optimizeMesh"); generateNormals = serializedObject.FindProperty("_generateNormals"); generateTangents = serializedObject.FindProperty("_generateTangents"); CreateSnapshot(); unappliedChanges = false; }
protected bool VectorGUI() { bool changed = false; EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(m_VectorGraphics, m_VectorContent); if (EditorGUI.EndChangeCheck()) { MethodInfo Refresh = typeof(SVGImage).GetMethod("Refresh", BindingFlags.NonPublic | BindingFlags.Instance); Refresh.Invoke(target, null); changed = true; SVGImage.Type oldType = (SVGImage.Type)m_Type.enumValueIndex; SVGAsset vectorGraphics = m_VectorGraphics.objectReferenceValue as SVGAsset; if (vectorGraphics != null) { if (vectorGraphics.border.SqrMagnitude() > 0) { m_Type.enumValueIndex = (int)SVGImage.Type.Sliced; } else if (oldType == SVGImage.Type.Sliced) { m_Type.enumValueIndex = (int)SVGImage.Type.Simple; } } } #if DEBUG_MATERIALS EditorGUILayout.ObjectField("Default Material", image.defaultMaterialTest, typeof(Material), true); EditorGUILayout.ObjectField("Mask Material", image.maskMaterialTest, typeof(Material), true); EditorGUILayout.ObjectField("Current Material", image.currenttMaterialTest, typeof(Material), true); EditorGUILayout.ObjectField("Render Material", image.renderMaterialTest, typeof(Material), true); EditorGUILayout.ObjectField("Canvas Render Material", image.canvasRenderer.GetMaterial(), typeof(Material), true); #endif SVGAsset newVectorGraphics = m_VectorGraphics.objectReferenceValue as SVGAsset; if (newVectorGraphics) { if (newVectorGraphics.format != SVGAssetFormat.uGUI) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.HelpBox("Vector Graphics Asset must be set to uGUI format", MessageType.Error); if (GUILayout.Button("Apply")) { FieldInfo _editor_format = typeof(SVGAsset).GetField("_format", BindingFlags.NonPublic | BindingFlags.Instance); _editor_format.SetValue(newVectorGraphics, (int)SVGAssetFormat.uGUI); MethodInfo _editor_ApplyChanges = typeof(SVGAsset).GetMethod("_editor_ApplyChanges", BindingFlags.NonPublic | BindingFlags.Instance); _editor_ApplyChanges.Invoke(newVectorGraphics, new object[] { false }); SVGAssetEditor.UpdateInstances(new SVGAsset[] { newVectorGraphics }); changed = true; } EditorGUILayout.EndHorizontal(); } else { #if UNITY_4_6 || UNITY_4_7 || UNITY_4_8 || UNITY_4_9 || UNITY_4_6 || UNITY_5_0 || UNITY_5_1 int vertexCount = newVectorGraphics.uiVertexCount; int percent = Mathf.RoundToInt(((float)vertexCount / 65534f) * 100f); if (vertexCount > 128) { GUIContent infoContent = new GUIContent("Asset takes " + percent + "% of this Canvas, " + vertexCount + " vertices" + "\nUI Canvas has limit of 65,534 vertices in total."); EditorStyles s_Current = (EditorStyles)typeof(EditorStyles).GetField("s_Current", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null); GUIStyle helpBoxStyle = (GUIStyle)typeof(EditorStyles).GetField("m_HelpBox", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(s_Current); Rect helpRect = GUILayoutUtility.GetRect(infoContent, helpBoxStyle); EditorGUI.ProgressBar(helpRect, percent * 0.01f, ""); EditorGUI.HelpBox(helpRect, infoContent.text, MessageType.Warning); } #endif } } return(changed); }