Ejemplo n.º 1
0
        protected bool TypeGUI()
        {
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(m_Type, new GUIContent("Image Type"));

            ++EditorGUI.indentLevel;
            {
                SVGImage.Type typeEnum = (SVGImage.Type)m_Type.enumValueIndex;

                bool showSlicedOrTiled = (!m_Type.hasMultipleDifferentValues && (typeEnum == SVGImage.Type.Sliced));
                if (showSlicedOrTiled && targets.Length > 1)
                {
                    showSlicedOrTiled = targets.Select(obj => obj as SVGImage).All(img => img.hasBorder);
                }

                SVGImage image = target as SVGImage;
                if (EditorGUILayout.BeginFadeGroup(m_ShowSliced.faded))
                {
                    if (image.vectorGraphics != null && !image.hasBorder)
                    {
                        EditorGUILayout.HelpBox("This Image doesn't have a border.", MessageType.Warning);
                    }
                }
                EditorGUILayout.EndFadeGroup();
            }
            --EditorGUI.indentLevel;

            return(EditorGUI.EndChangeCheck());
        }
Ejemplo n.º 2
0
        void SetShowNativeSize(bool instant)
        {
            SVGImage.Type type           = (SVGImage.Type)m_Type.enumValueIndex;
            bool          showNativeSize = (type == SVGImage.Type.Simple);

            SetShowNativeSize(showNativeSize, instant);
        }
Ejemplo n.º 3
0
        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);
        }