public ImageProperty(ImageProperty other)
        {
            m_ImageColor       = other.m_ImageColor;
            m_ImageType        = other.m_ImageType;
            m_IsPreserveAspect = other.m_IsPreserveAspect;
            m_FillMethod       = other.m_FillMethod;

            switch (other.m_FillMethod)
            {
            case Image.FillMethod.Radial180:
                m_fillOrigin180 = other.m_fillOrigin180;
                break;

            case Image.FillMethod.Radial360:
                m_fillOrigin360 = other.m_fillOrigin360;
                break;

            case Image.FillMethod.Radial90:
                m_fillOrigin90 = other.m_fillOrigin90;
                break;

            case Image.FillMethod.Horizontal:
                m_fillOriginHorizontal = other.m_fillOriginHorizontal;
                break;

            case Image.FillMethod.Vertical:
                m_fillOriginVertical = other.m_fillOriginVertical;
                break;
            }
            m_FillAmount = other.m_FillAmount;
        }
Example #2
0
        /// <summary>
        /// Radial fill an image over time.
        /// </summary>
        /// <param name="image">The image to fill</param>
        /// <param name="duration">Over how long should it be filled</param>
        /// <param name="fillMethod">Fill method used. (Default: Radial360)</param>
        public void RadialFillOverTime(Image image, float duration, Image.FillMethod fillMethod = Image.FillMethod.Radial360)
        {
            image.type       = Image.Type.Filled;
            image.fillMethod = fillMethod;

            StartCoroutine(RadialFillRoutine(image, duration));
        }
Example #3
0
        /// <summary>
        /// Fills an Image and sets it type to fill if it is not yet fill
        /// </summary>
        /// <param name="img">The Image to fill</param>
        /// <param name="fillIn">Fill In or Out?</param>
        /// <param name="duration">The Amount of time in seconds the filling will take</param>
        /// <param name="method">The Fill Method</param>
        /// <param name="clockwise">Fill clockwise?</param>
        /// <param name="deactivate">Should the GameObject be deactivated when done?</param>
        /// <param name="finished">Callback for when the Fading is finished</param>
        /// <param name="progressMapping">Function for mapping the progress, takes one float argument between 0 and 1 and should return a float between 0 and 1</param>
        /// <returns></returns>
        private static IEnumerator FillImage(Image img, bool fillIn, float duration, Image.FillMethod method, bool clockwise, bool deactivate, Action finished, Func <float, float> progressMapping)
        {
            if (img.type != Image.Type.Filled)
            {
                img.type = Image.Type.Filled;
            }
            img.fillMethod    = method;
            img.fillClockwise = clockwise;

            float progress = 0.0f;

            while (progress < 1.0f)
            {
                float mappedProgress = progressMapping?.Invoke(progress) ?? progress;

                img.fillAmount = fillIn ? mappedProgress : 1 - mappedProgress;
                yield return(null);

                progress += Time.deltaTime / duration;
            }

            img.fillAmount = fillIn ? 1 : 0;

            finished?.Invoke();

            if (deactivate)
            {
                img.gameObject.SetActive(false);
            }
        }
        public void CloneFromImage(Image image)
        {
            this.m_ImageColor       = image.color;
            this.m_IsPreserveAspect = image.preserveAspect;
            this.m_ImageType        = image.type;

            this.m_FillMethod = image.fillMethod;
            this.m_FillAmount = image.fillAmount;

            switch (image.fillMethod)
            {
            case Image.FillMethod.Radial180:
                this.m_fillOrigin180 = (Image.Origin180)image.fillOrigin;
                break;

            case Image.FillMethod.Radial360:
                this.m_fillOrigin360 = (Image.Origin360)image.fillOrigin;
                break;

            case Image.FillMethod.Radial90:
                this.m_fillOrigin90 = (Image.Origin90)image.fillOrigin;
                break;

            case Image.FillMethod.Horizontal:
                this.m_fillOriginHorizontal = (Image.OriginHorizontal)image.fillOrigin;
                break;

            case Image.FillMethod.Vertical:
                this.m_fillOriginVertical = (Image.OriginVertical)image.fillOrigin;
                break;
            }
        }
Example #5
0
        private void Awake()
        {
            m_originalSize = (this.transform as RectTransform).sizeDelta;   //原尺寸
            m_size         = m_originalSize;

            KImage image = GetComponentInChildren <KImage>();

            m_fillMethod   = image.fillMethod;
            m_slicedFilled = image.slicedFilled;
        }
        void Awake()
        {
            var image = GetComponent <Image>();

            if (image)
            {
                if (ImageType != image.type)
                {
                    ImageType = image.type;
                }
                if (ImageType == Image.Type.Simple || ImageType == Image.Type.Filled)
                {
                    if (PreserveAspect != image.preserveAspect)
                    {
                        PreserveAspect = image.preserveAspect;
                    }
                }
                else
                {
                    if (FillCenter != image.fillCenter)
                    {
                        FillCenter = image.fillCenter;
                    }
                }
                if (ImageType == Image.Type.Filled)
                {
                    if (FillMethod != image.fillMethod)
                    {
                        FillMethod = image.fillMethod;
                    }
                    if (FillOrigin != image.fillOrigin)
                    {
                        FillOrigin = image.fillOrigin;
                    }
                    if (FillAmount != image.fillAmount)
                    {
                        FillAmount = image.fillAmount;
                    }
                    if (FillClockwise != image.fillClockwise)
                    {
                        FillClockwise = image.fillClockwise;
                    }
                }
            }
#if UNITY_EDITOR && !USE_CLIENT_RES_MANAGER
            _TargetRawImage = null;
            _TargetImage    = null;
            if (Application.isPlaying)
            {
                _TargetRawImage = GetComponent <RawImage>();
                _TargetImage    = image;
            }
#endif
        }
Example #7
0
 protected override void Collect(Image img)
 {
     sprite         = img.sprite;
     imageType      = img.type;
     fillAmount     = img.fillAmount;
     fillCenter     = img.fillCenter;
     fillClockwise  = img.fillClockwise;
     fillMethod     = img.fillMethod;
     fillOrigin     = img.fillOrigin;
     useSpriteMesh  = img.useSpriteMesh;
     preserveAspect = img.preserveAspect;
     maskable       = img.maskable;
 }
        protected override void ReadFromImpl(object obj)
        {
            base.ReadFromImpl(obj);
            Image uo = (Image)obj;

            sprite         = ToID(uo.sprite);
            overrideSprite = ToID(uo.overrideSprite);
            type           = uo.type;
            preserveAspect = uo.preserveAspect;
            fillCenter     = uo.fillCenter;
            fillMethod     = uo.fillMethod;
            fillAmount     = uo.fillAmount;
            fillClockwise  = uo.fillClockwise;
            fillOrigin     = uo.fillOrigin;
            alphaHitTestMinimumThreshold = uo.alphaHitTestMinimumThreshold;
            useSpriteMesh = uo.useSpriteMesh;
        }
Example #9
0
    private static int set_fillMethod(IntPtr L)
    {
        object obj = null;
        int    result;

        try
        {
            obj = ToLua.ToObject(L, 1);
            Image            image      = (Image)obj;
            Image.FillMethod fillMethod = (Image.FillMethod)((int)ToLua.CheckObject(L, 2, typeof(Image.FillMethod)));
            image.fillMethod = fillMethod;
            result           = 0;
        }
        catch (Exception ex)
        {
            result = LuaDLL.toluaL_exception(L, ex, (obj != null) ? ex.Message : "attempt to index fillMethod on a nil value");
        }
        return(result);
    }
Example #10
0
    private static int get_fillMethod(IntPtr L)
    {
        object obj = null;
        int    result;

        try
        {
            obj = ToLua.ToObject(L, 1);
            Image            image      = (Image)obj;
            Image.FillMethod fillMethod = image.fillMethod;
            ToLua.Push(L, fillMethod);
            result = 1;
        }
        catch (Exception ex)
        {
            result = LuaDLL.toluaL_exception(L, ex, (obj != null) ? ex.Message : "attempt to index fillMethod on a nil value");
        }
        return(result);
    }
Example #11
0
        /// <summary>
        /// Draws the Fill Origin property.
        /// </summary>
        /// <returns>The new position.</returns>
        /// <param name="position">Position.</param>
        /// <param name="fillMethod">Fill method.</param>
        /// <param name="fillOrigin">Fill origin.</param>
        protected Rect DrawFillOrigin(Rect position, Image.FillMethod fillMethod, SerializedProperty fillOrigin)
        {
            var height      = EditorGUI.GetPropertyHeight(fillOrigin, new GUIContent(Labels[fillOrigin.name]));
            var indent      = Indent * IndentLevel;
            var label_width = EditorGUIUtility.labelWidth - indent;
            var label_rect  = new Rect(position.x + indent, position.y, label_width, height);

            EditorGUI.SelectableLabel(label_rect, Labels[fillOrigin.name]);

            var rect = new Rect(position.x + indent + label_width, position.y, position.width - indent - label_width, height);

            switch (fillMethod)
            {
            case Image.FillMethod.Horizontal:
                fillOrigin.intValue = (int)(Image.OriginHorizontal)EditorGUI.EnumPopup(rect, GUIContent.none, (Image.OriginHorizontal)fillOrigin.intValue);
                break;

            case Image.FillMethod.Vertical:
                fillOrigin.intValue = (int)(Image.OriginVertical)EditorGUI.EnumPopup(rect, GUIContent.none, (Image.OriginVertical)fillOrigin.intValue);
                break;

            case Image.FillMethod.Radial90:
                fillOrigin.intValue = (int)(Image.Origin90)EditorGUI.EnumPopup(rect, GUIContent.none, (Image.Origin90)fillOrigin.intValue);
                break;

            case Image.FillMethod.Radial180:
                fillOrigin.intValue = (int)(Image.Origin180)EditorGUI.EnumPopup(rect, GUIContent.none, (Image.Origin180)fillOrigin.intValue);
                break;

            case Image.FillMethod.Radial360:
                fillOrigin.intValue = (int)(Image.Origin360)EditorGUI.EnumPopup(rect, GUIContent.none, (Image.Origin360)fillOrigin.intValue);
                break;
            }

            position.y += rect.height + EmptySpace;

            return(position);
        }
Example #12
0
    // Full setup
    public void InitTransition(TransitionTypes.FadeTypes incFadeType, Image.FillMethod incTransitionType, float speed)
    {
        fadeType = incFadeType;

        transitionImage.fillMethod = incTransitionType;
        transitionSpeed            = speed;

        switch (fadeType)
        {
        case TransitionTypes.FadeTypes.fadeIn:
            transitionImage.color      = fadeEndColor;
            transitionImage.fillAmount = 1.0f;
            StartCoroutine(SelfDestruct(1 / transitionSpeed));
            break;

        case TransitionTypes.FadeTypes.fadeOut:
            transitionImage.color      = fadeStartColor;
            transitionImage.fillAmount = 0.0f;

            break;
        }

        transitioning = true;
    }
Example #13
0
        public static void GenerateFilledSprite(VertexHelper toFill, bool preserveAspect, Canvas canvas,
                                                RectTransform rectTransform, Sprite activeSprite, Color32 color, Image.FillMethod fillMethod,
                                                float fillAmount, int fillOrigin, bool fillClockwise, float falloffDistance)
        {
            toFill.Clear();

            if (fillAmount < 0.001f)
            {
                return;
            }

            Vector4 v    = GetDrawingDimensions(preserveAspect, activeSprite, canvas, rectTransform);
            Vector2 size = new Vector2(v.z - v.x, v.w - v.y);

            Vector4 outer = activeSprite != null
                ? Sprites.DataUtility.GetOuterUV(activeSprite)
                : new Vector4(0, 0, 1, 1);

            UIVertex uiv = UIVertex.simpleVert;

            uiv.color = color;

            float tx0 = outer.x;
            float ty0 = outer.y;
            float tx1 = outer.z;
            float ty1 = outer.w;

            // Horizontal and vertical filled sprites are simple -- just end the Image prematurely
            if (fillMethod == Image.FillMethod.Horizontal || fillMethod == Image.FillMethod.Vertical)
            {
                if (fillMethod == Image.FillMethod.Horizontal)
                {
                    float fill = (tx1 - tx0) * fillAmount;

                    if (fillOrigin == 1)
                    {
                        v.x = v.z - (v.z - v.x) * fillAmount;
                        tx0 = tx1 - fill;
                    }
                    else
                    {
                        v.z = v.x + (v.z - v.x) * fillAmount;
                        tx1 = tx0 + fill;
                    }
                }
                else if (fillMethod == Image.FillMethod.Vertical)
                {
                    float fill = (ty1 - ty0) * fillAmount;

                    if (fillOrigin == 1)
                    {
                        v.y = v.w - (v.w - v.y) * fillAmount;
                        ty0 = ty1 - fill;
                    }
                    else
                    {
                        v.w = v.y + (v.w - v.y) * fillAmount;
                        ty1 = ty0 + fill;
                    }
                }
            }

            SXy[0] = new Vector2(v.x, v.y);
            SXy[1] = new Vector2(v.x, v.w);
            SXy[2] = new Vector2(v.z, v.w);
            SXy[3] = new Vector2(v.z, v.y);

            SUv[0] = new Vector2(tx0, ty0);
            SUv[1] = new Vector2(tx0, ty1);
            SUv[2] = new Vector2(tx1, ty1);
            SUv[3] = new Vector2(tx1, ty0);


            {
                if (fillAmount < 1f && fillMethod != Image.FillMethod.Horizontal &&
                    fillMethod != Image.FillMethod.Vertical)
                {
                    if (fillMethod == Image.FillMethod.Radial90)
                    {
                        if (RadialCut(SXy, SUv, fillAmount, fillClockwise, fillOrigin))
                        {
                            AddQuad(toFill, SXy, color, SUv, size);
                        }
                    }
                    else if (fillMethod == Image.FillMethod.Radial180)
                    {
                        for (int side = 0; side < 2; ++side)
                        {
                            float fx0, fx1, fy0, fy1;
                            int   even = fillOrigin > 1 ? 1 : 0;

                            if (fillOrigin == 0 || fillOrigin == 2)
                            {
                                fy0 = 0f;
                                fy1 = 1f;
                                if (side == even)
                                {
                                    fx0 = 0f;
                                    fx1 = 0.5f;
                                }
                                else
                                {
                                    fx0 = 0.5f;
                                    fx1 = 1f;
                                }
                            }
                            else
                            {
                                fx0 = 0f;
                                fx1 = 1f;
                                if (side == even)
                                {
                                    fy0 = 0.5f;
                                    fy1 = 1f;
                                }
                                else
                                {
                                    fy0 = 0f;
                                    fy1 = 0.5f;
                                }
                            }

                            SXy[0].x = Mathf.Lerp(v.x, v.z, fx0);
                            SXy[1].x = SXy[0].x;
                            SXy[2].x = Mathf.Lerp(v.x, v.z, fx1);
                            SXy[3].x = SXy[2].x;

                            SXy[0].y = Mathf.Lerp(v.y, v.w, fy0);
                            SXy[1].y = Mathf.Lerp(v.y, v.w, fy1);
                            SXy[2].y = SXy[1].y;
                            SXy[3].y = SXy[0].y;

                            SUv[0].x = Mathf.Lerp(tx0, tx1, fx0);
                            SUv[1].x = SUv[0].x;
                            SUv[2].x = Mathf.Lerp(tx0, tx1, fx1);
                            SUv[3].x = SUv[2].x;

                            SUv[0].y = Mathf.Lerp(ty0, ty1, fy0);
                            SUv[1].y = Mathf.Lerp(ty0, ty1, fy1);
                            SUv[2].y = SUv[1].y;
                            SUv[3].y = SUv[0].y;

                            float val = fillClockwise ? fillAmount * 2f - side : fillAmount * 2f - (1 - side);

                            if (RadialCut(SXy, SUv, Mathf.Clamp01(val), fillClockwise,
                                          ((side + fillOrigin + 3) % 4)))
                            {
                                AddQuad(toFill, SXy, color, SUv, size);
                            }
                        }
                    }
                    else if (fillMethod == Image.FillMethod.Radial360)
                    {
                        for (int corner = 0; corner < 4; ++corner)
                        {
                            float fx0, fx1, fy0, fy1;

                            if (corner < 2)
                            {
                                fx0 = 0f;
                                fx1 = 0.5f;
                            }
                            else
                            {
                                fx0 = 0.5f;
                                fx1 = 1f;
                            }

                            if (corner == 0 || corner == 3)
                            {
                                fy0 = 0f;
                                fy1 = 0.5f;
                            }
                            else
                            {
                                fy0 = 0.5f;
                                fy1 = 1f;
                            }

                            SXy[0].x = Mathf.Lerp(v.x, v.z, fx0);
                            SXy[1].x = SXy[0].x;
                            SXy[2].x = Mathf.Lerp(v.x, v.z, fx1);
                            SXy[3].x = SXy[2].x;

                            SXy[0].y = Mathf.Lerp(v.y, v.w, fy0);
                            SXy[1].y = Mathf.Lerp(v.y, v.w, fy1);
                            SXy[2].y = SXy[1].y;
                            SXy[3].y = SXy[0].y;

                            SUv[0].x = Mathf.Lerp(tx0, tx1, fx0);
                            SUv[1].x = SUv[0].x;
                            SUv[2].x = Mathf.Lerp(tx0, tx1, fx1);
                            SUv[3].x = SUv[2].x;

                            SUv[0].y = Mathf.Lerp(ty0, ty1, fy0);
                            SUv[1].y = Mathf.Lerp(ty0, ty1, fy1);
                            SUv[2].y = SUv[1].y;
                            SUv[3].y = SUv[0].y;

                            float val = fillClockwise
                                ? fillAmount * 4f - ((corner + fillOrigin) % 4)
                                : fillAmount * 4f - (3 - ((corner + fillOrigin) % 4));

                            if (RadialCut(SXy, SUv, Mathf.Clamp01(val), fillClockwise, ((corner + 2) % 4)))
                            {
                                AddQuad(toFill, SXy, color, SUv, size);
                            }
                        }
                    }
                }
                else
                {
                    AddQuad(toFill, SXy, color, SUv, size);
                }
            }
        }
Example #14
0
        public static ProgressBar Show(string bgPath, string fgPath, Action onFinished = null, Image.FillMethod fillMethod = Image.FillMethod.Horizontal, bool leftFill = true)
        {
            if (barGo != null)
            {
                GameObject.DestroyImmediate(barGo);
            }

            barGo          = null;
            curProgressBar = null;
            var tempGo = Instantiate(ResourceManager.LoadGameObjectAssets(PrefabResourceName));

            barGo = tempGo;
            GameObject.DontDestroyOnLoad(barGo);
            curProgressBar          = tempGo.GetComponent <ProgressBar>();
            curProgressBar.onFinish = onFinished;

            curProgressBar.progressBg.sprite = UR.Load <Sprite>(bgPath) as Sprite;
            curProgressBar.progressBg.SetNativeSize();
            curProgressBar.progress.sprite = UR.Load <Sprite>(fgPath) as Sprite;
            curProgressBar.progress.SetNativeSize();

            curProgressBar.progress.type       = Image.Type.Filled;
            curProgressBar.progress.fillMethod = fillMethod;
            curProgressBar.progress.fillOrigin = leftFill ? 0 : 1;
            curProgressBar.progress.fillAmount = 0;
            return(curProgressBar);
        }
Example #15
0
 public static ProgressBar Show(Action onFinished = null, Image.FillMethod fillMethod = Image.FillMethod.Horizontal, bool leftFill = true)
 {
     return(Show(DefaultBgPath, DefaultFgPath, onFinished, fillMethod, leftFill));;
 }
Example #16
0
    private static GameObject CreateMaskTemplate(string name, RectTransform target, Sprite img, Image.FillMethod fillMethod, Image.Type type = Image.Type.Filled)
    {
        var mask_m = new GameObject(name + "template", typeof(RectTransform), typeof(Mask), typeof(Image));

        mask_m.transform.SetParent(target.parent);
        mask_m.GetComponent <Image>().type           = type;
        mask_m.GetComponent <Image>().fillMethod     = fillMethod;
        mask_m.GetComponent <Image>().sprite         = img;
        mask_m.GetComponent <Mask>().showMaskGraphic = false;
        return(mask_m);
    }
 public void SetImageSetting(Image.FillMethod fillMethod = Image.FillMethod.Horizontal, int fillOrigin = (int)Image.OriginHorizontal.Left)
 {
     overlayImage.fillMethod = fillMethod;
     overlayImage.fillOrigin = fillOrigin;
 }
Example #18
0
        /// <summary>
        /// Fills an Image and sets it type to fill if it is not yet fill
        /// </summary>
        /// <param name="img">The Image to fill</param>
        /// <param name="fillIn">Fill In or Out?</param>
        /// <param name="duration">The Amount of time in seconds the filling will take</param>
        /// <param name="manageActive">If true the gameobject is activated or deactivated automatically</param>
        /// <param name="method">The Fill Method</param>
        /// <param name="clockwise">Fill clockwise?</param>
        /// <param name="finished">Callback for when the Fading is finished</param>
        /// <param name="progressMapping">Function for mapping the progress, takes one float argument between 0 and 1 and should return a float between 0 and 1</param>
        /// <returns></returns>
        public static Coroutine Fill(this Image img, bool fillIn, float duration, bool manageActive, Image.FillMethod method, bool clockwise, Func <float, float> progressMapping,
                                     Action finished = null)
        {
            if (manageActive && fillIn)
            {
                img.gameObject.SetActive(true);
            }

            CoroutineHost.StopTrackedCoroutine(img, COROUTINE_TAG);
            return(CoroutineHost.StartTrackedCoroutine(FillImage(img, fillIn, duration, method, clockwise, manageActive && !fillIn, finished, progressMapping), img, COROUTINE_TAG));
        }
Example #19
0
 // Метод заполнения
 public void set_fill_meth(Image.FillMethod meth)
 {
     image.fillMethod = meth;
 }
 public void ChangeFillType(Image.FillMethod fillmethod)
 {
     ProgressImage.fillMethod = fillmethod;
 }