예제 #1
0
    void Reset()
    {
        if (this.RequirementsCheck())
        {
            this.SVGFile = null;
            this.ScaleAdaption = SVGBackgroundScaleType.Horizontal;
            this.Size = 256;
            this.ClearColor = new Color(1, 1, 1, 0);
            this.GenerateOnStart = true;

            this.Sliced = false;
            this.SlicedWidth = 256;
            this.SlicedHeight = 256;

            this.m_SvgDoc = null;
            this.m_Texture = null;
            this.m_Sprite = null;
            this.DestroyAll(true);
        }
    }
    private void DrawInspector(SVGBackgroundBehaviour svgBackground)
    {
        SVGBackgroundScaleType scaleAdaption = SVGBackgroundScaleType.Vertical;
        int       size         = 256;
        int       slicedWidth  = 256;
        int       slicedHeight = 256;
        bool      needUpdate   = false;
        bool      fullUpdate   = false;
        TextAsset svgFile      = EditorGUILayout.ObjectField("SVG file", svgBackground.SVGFile, typeof(TextAsset), true) as TextAsset;
        bool      sliced       = EditorGUILayout.Toggle(new GUIContent("Sliced", "Check if you want to slice the background in order to fit specified width/height"), svgBackground.Sliced);

        if (sliced)
        {
            slicedWidth  = EditorGUILayout.IntField(new GUIContent("Width", "Sliced width, in pixels"), svgBackground.SlicedWidth);
            slicedHeight = EditorGUILayout.IntField(new GUIContent("Height", "Sliced height, in pixels"), svgBackground.SlicedHeight);
        }
        else
        {
            scaleAdaption = (SVGBackgroundScaleType)EditorGUILayout.EnumPopup("Scale adaption", svgBackground.ScaleAdaption);
            size          = EditorGUILayout.IntField(new GUIContent("Size", "Size in pixels"), svgBackground.Size);
        }
        Color clearColor      = EditorGUILayout.ColorField("Clear color", svgBackground.ClearColor);
        bool  generateOnStart = EditorGUILayout.Toggle(new GUIContent("Generate on Start()", "Generate the background texture/sprite on Start()"), svgBackground.GenerateOnStart);
        bool  fastUpload      = EditorGUILayout.Toggle(new GUIContent("Fast upload", "Use the fast native method (OpenGL/DirectX) to upload the texture to the GPU"), svgBackground.FastUpload);

        // show dimensions in pixel and world units
        EditorGUILayout.LabelField("Width (pixel unit)", svgBackground.PixelWidth.ToString());
        EditorGUILayout.LabelField("Height (pixel units)", svgBackground.PixelHeight.ToString());
        EditorGUILayout.LabelField("Width (world units)", svgBackground.WorldWidth.ToString());
        EditorGUILayout.LabelField("Height (world units)", svgBackground.WorldHeight.ToString());

        // update svg file, if needed
        if (svgFile != svgBackground.SVGFile)
        {
            svgBackground.SVGFile = svgFile;
            SVGUtils.MarkSceneDirty();
            needUpdate = true;
            // in this case we must destroy the current document and load the new one
            fullUpdate = true;
        }

        if (sliced != svgBackground.Sliced)
        {
            svgBackground.Sliced = sliced;
            SVGUtils.MarkSceneDirty();
            needUpdate = true;
        }

        if (sliced)
        {
            // update sliced width (in pixels), if needed
            if (slicedWidth != svgBackground.SlicedWidth)
            {
                svgBackground.SlicedWidth = slicedWidth;
                SVGUtils.MarkSceneDirty();
                needUpdate = true;
            }
            // update sliced height (in pixels), if needed
            if (slicedHeight != svgBackground.SlicedHeight)
            {
                svgBackground.SlicedHeight = slicedHeight;
                SVGUtils.MarkSceneDirty();
                needUpdate = true;
            }
        }
        else
        {
            // update scale adaption, if needed
            if (scaleAdaption != svgBackground.ScaleAdaption)
            {
                svgBackground.ScaleAdaption = scaleAdaption;
                SVGUtils.MarkSceneDirty();
                needUpdate = true;
            }
            // update size (in pixels), if needed
            if (size != svgBackground.Size)
            {
                svgBackground.Size = size;
                SVGUtils.MarkSceneDirty();
                needUpdate = true;
            }
        }
        // update clear color, if needed
        if (clearColor != svgBackground.ClearColor)
        {
            svgBackground.ClearColor = clearColor;
            SVGUtils.MarkSceneDirty();
            needUpdate = true;
        }
        // update "update on start" flag, if needed
        if (generateOnStart != svgBackground.GenerateOnStart)
        {
            svgBackground.GenerateOnStart = generateOnStart;
            SVGUtils.MarkSceneDirty();
        }
        // update "fast upload" flag, if needed
        if (fastUpload != svgBackground.FastUpload)
        {
            svgBackground.FastUpload = fastUpload;
            SVGUtils.MarkSceneDirty();
        }
        // update the background, if needed
        if (needUpdate)
        {
            svgBackground.UpdateBackground(fullUpdate);
        }
    }