Exemple #1
0
        public static bool TrySetSprite(this Graphic graphic, SpriteCache sc)
        {
            if (!sc)
            {
                return(false);
            }

            if (graphic is Image)
            {
                var img = (Image)graphic;
                if (img.sprite != sc)
                {
                    img.sprite = sc;
                }
                return(true);
            }
            else if (graphic is RawImage)
            {
                var imgRaw = (RawImage)graphic;
                UIExtension.OnSetSprite(imgRaw, sc);
                return(true);
            }

            return(false);
        }
Exemple #2
0
        public static void SetSpriteWithOffset(this RawImage imgRaw, SpriteCache sc, Rect offset)
        {
            if (!imgRaw)
            {
                return;
            }

            if (!sc)
            {
                return;
            }

            UIExtension.OnSetSpriteWithOffset(imgRaw, sc, offset);
        }
Exemple #3
0
        public static void SetSprite(this RawImage imgRaw, SpriteCache sc)
        {
            if (!imgRaw)
            {
                return;
            }

            if (!sc)
            {
                return;
            }

            UIExtension.OnSetSprite(imgRaw, sc);
        }
Exemple #4
0
        public static RectCulling CreateSampleObject(Transform parent)
        {
            RectCulling component = UIExtension.CreateUIObject <RectCulling>("RectCulling", parent, Vector3.zero, new Vector2(100, 100));

            component.cullRectTrans = component.GetComponent <RectTransform>();
            component.list          = new List <CullData>();

            var imgVisibled = UIExtension.CreateUIObject <Image>("Visibled", component.CachedTransform, new Vector3(0, 0), new Vector2(30, 30));

            component.list.Add(new CullData(component, imgVisibled.rectTransform));
            var imgInvisibled = UIExtension.CreateUIObject <Image>("Invisibled", component.CachedTransform, new Vector3(-150, 0), new Vector2(30, 30));

            component.list.Add(new CullData(component, imgInvisibled.rectTransform));
            component.EditorSetting();
            component.LateUpdate();
            return(component);
        }
Exemple #5
0
        public static NumberBox CreateSampleObject(Transform parent)
        {
            var rectTransform = UnityExtension.CreateObject <RectTransform>("NumberBox", parent);
            var component     = rectTransform.gameObject.AddComponent <NumberBox>();

            component.CachedRectTransform.sizeDelta = new Vector2(100, 100);
            component.EditorResetAlignBase(UnityExtension.CreateObject <RectTransform>("Align", component.CachedRectTransform));
            component.EditorResetElements(new List <UICache>());
            for (int n = 0; n < 3; ++n)
            {
                Image img = UIExtension.CreateUIObject <Image>(n.ToString(), component.AlignBase, Vector3.zero, new Vector2(20, 20));
                component.Elements.Add(new UICache(img.gameObject));
            }
            component.Align = ALIGN.LeftOrBottom;
            component.EditorSetting();
            return(component);
        }
Exemple #6
0
 public static T CreateUIObject <T>(string name, Transform parent) where T : Component
 {
     return(UIExtension.CreateUIObject <T>(name, parent, Vector2.zero, Vector2.zero, Vector3.one, Quaternion.identity));
 }
Exemple #7
0
 public static T CreateUIObject <T>(string name, Transform parent, Vector2 anchoredPos, Vector2 size, Vector3 scale) where T : Component
 {
     return(UIExtension.CreateUIObject <T>(name, parent, anchoredPos, size, scale, Quaternion.identity));
 }
Exemple #8
0
        protected override void OnEditorSetting()
        {
            base.OnEditorSetting();

            if (!this.sprites)
            {
                this.sprites = this.GetComponent <SpritesComponent>();

                if (!this.sprites)
                {
                    Debug.LogWarning("NUMBER_BOX_EDITWARN:SPRITES_COMPONENT_IS_NULL!:" + this.name);
                    return;
                }
            }

            //int sprCount = this.sprites.Count;
            //if (0 != sprCount && 10 != sprCount)
            //{
            //    Debug.LogWarning("NUMBER_BOX_EDITWARN:MISMATCH_COUNT:SPR_COUNT:" + sprCount);
            //    foreach (SpriteCache sc in this.sprites.Elements)
            //        Debug.Log(sc);
            //}

            var alignBase = this.AlignBase;

            if (null != this.Elements && 0 < this.ElementsCount)
            {
                for (int n = this.ElementsCount - 1; -1 < n; --n)
                {
                    var co = this.Elements[n];
                    if (!co)
                    {
                        this.Elements.RemoveAt(n);
                    }
                }
            }
            else if (alignBase)
            {
                for (int n = 0; n < 999; ++n)
                {
                    var transChild = alignBase.Find(n.ToString());
                    if (!transChild)
                    {
                        break;
                    }

                    if (null == this.Elements)
                    {
                        this.EditorResetElements(new List <UICache>());
                    }

                    this.Elements.Add(new UICache(transChild.gameObject));
                }
            }

            if (alignBase && 0 < this.editorGenElems)
            {
                int cnt = this.editorGenElems;
                this.editorGenElems = 0;

                if (null == this.Elements)
                {
                    this.EditorResetElements(new List <UICache>(cnt));
                }

                var copyModel = this.editorGenElemsObjCopyModel;
                if (!copyModel && 0 < this.ElementsCount && this.Elements[0])
                {
                    copyModel = this.Elements[0].Graphic;
                }

                for (int n = 0; n < cnt; ++n)
                {
                    int    idx  = this.ElementsCount;
                    string name = idx.ToString();
                    if (copyModel)
                    {
                        var copyTrans = copyModel.rectTransform;

                        if (copyModel is Image)
                        {
                            var component = UIExtension.CreateUIObject <Image>(name, alignBase, Vector3.zero, copyTrans.sizeDelta, copyTrans.localScale, copyTrans.localRotation);
                            component.sprite = ((Image)copyModel).sprite;
                            var co = this.CreateElement(component.rectTransform, idx);
                            if (co)
                            {
                                this.Elements.Add(co);
                            }
                            continue;
                        }
                        else if (copyModel is RawImage)
                        {
                            var component = UIExtension.CreateUIObject <RawImage>(name, alignBase, Vector3.zero, copyTrans.sizeDelta, copyTrans.localScale, copyTrans.localRotation);
                            component.texture = ((RawImage)copyModel).texture;
                            var co = this.CreateElement(component.rectTransform, idx);
                            if (co)
                            {
                                this.Elements.Add(co);
                            }
                            continue;
                        }
                    }

                    // NOTE: 없다. 걍 대충 때려 박는다.
                    var componentDef = UIExtension.CreateUIObject <Image>(this.ElementsCount.ToString(), alignBase, Vector3.zero, new Vector2(20, 20));
                    var coDef        = this.CreateElement(componentDef.rectTransform, idx);
                    if (coDef)
                    {
                        this.Elements.Add(coDef);
                    }
                }

                this.Elements.Sort(this.SetupSort);
            }


            if (this.UseComma)
            {
                for (int n = 0, cnt = this.CommaCapacity; n < cnt; ++n)
                {
                    var comma = this.GetComma(n);
                    if (comma)
                    {
                        comma.Rebuild();
                    }
                }
            }

            if (null != this.signs)
            {
                for (int n = 0, cnt = this.SignCapacity; n < cnt; ++n)
                {
                    var sign = this.GetSign(n);
                    if (sign)
                    {
                        sign.Rebuild();
                    }
                }
            }

            this.SetupPositions();
        }
Exemple #9
0
        protected override void OnEditorSetting()
        {
            base.OnEditorSetting();

            if (!this.sprites)
            {
                this.sprites = this.GetComponent <SpritesComponent>();

                if (!this.sprites)
                {
                    Debug.LogWarning("IMAGE_TEXT_BOX_EDITWARN:SPRITES_COMPONENT_IS_NULL!:" + this.name);
                    return;
                }
            }

            int sprCount = this.sprites.Count;
            int idxCount = this.indexes.Length;

            if (sprCount != idxCount)
            {
                Debug.LogWarning("IMAGE_TEXT_BOX_EDITWARN:MISMATCH_COUNT:SPR_COUNT:" + sprCount + ", IDX_COUNT:" + idxCount);
                foreach (SpriteCache sc in this.sprites.Elements)
                {
                    Debug.Log(sc);
                }
            }

            if (null != this.Elements)
            {
                for (int n = this.ElementsCount - 1; -1 < n; --n)
                {
                    var co = this.Elements[n];
                    if (!co)
                    {
                        this.Elements.RemoveAt(n);
                    }
                }
            }

            var alignBase = this.AlignBase;

            if (alignBase && 0 < this.editorGenElems)
            {
                int cnt = this.editorGenElems;
                this.editorGenElems = 0;

                if (null == this.Elements)
                {
                    this.EditorResetElements(new List <UICache>(cnt));
                }

                var copyModel = this.editorGenElemsCopyModel;
                if (!copyModel && 0 < this.ElementsCount && this.Elements[0])
                {
                    copyModel = this.Elements[0].Graphic;
                }

                for (int n = 0; n < cnt; ++n)
                {
                    int    idx  = this.ElementsCount;
                    string name = idx.ToString();
                    if (copyModel)
                    {
                        var copyTrans = copyModel.rectTransform;

                        if (copyModel is Image)
                        {
                            var component = UIExtension.CreateUIObject <Image>(name, alignBase, Vector3.zero, copyTrans.sizeDelta, copyTrans.localScale, copyTrans.localRotation);
                            component.sprite = ((Image)copyModel).sprite;
                            var co = this.CreateElement(component.rectTransform, idx);
                            if (co)
                            {
                                this.Elements.Add(co);
                            }
                            continue;
                        }
                        else if (copyModel is RawImage)
                        {
                            var component = UIExtension.CreateUIObject <RawImage>(name, alignBase, Vector3.zero, copyTrans.sizeDelta, copyTrans.localScale, copyTrans.localRotation);
                            component.texture = ((RawImage)copyModel).texture;
                            var co = this.CreateElement(component.rectTransform, idx);
                            if (co)
                            {
                                this.Elements.Add(co);
                            }
                            continue;
                        }
                    }

                    // NOTE: 없다. 걍 대충 때려 박는다.
                    var componentDef = UIExtension.CreateUIObject <Image>(this.ElementsCount.ToString(), alignBase, Vector3.zero, new Vector2(20, 20));
                    var coDef        = this.CreateElement(componentDef.rectTransform, idx);
                    if (coDef)
                    {
                        this.Elements.Add(coDef);
                    }
                }

                this.Elements.Sort(this.SetupSort);
            }

            this.SetupPositions();
            this.SetText(this.editorTestString);

            if (-1 != this.editorTestAddCharIndex)
            {
                var ret = this.AddChar(this.editorTestAddCharValue, this.editorTestAddCharIndex);
                Debug.Log("ADD:" + ret);
            }
            if (-1 != this.editorTestRemoveCharIndex)
            {
                var ret = this.RemoveChar(this.editorTestRemoveCharIndex);
                Debug.Log("REMOVE:" + ret);
            }
        }