protected override JSONObject ToJSON(WXHierarchyContext context)
        {
            JSONObject json = new JSONObject(JSONObject.Type.OBJECT);
            JSONObject data = new JSONObject(JSONObject.Type.OBJECT);

            json.AddField("type", getTypeName());
            json.AddField("data", data);
            data.AddField("active", true);

            data.AddField("barSize", (float)uiScrollBar.barSize);
            data.AddField("value", (float)uiScrollBar.value);
            data.AddField("alpha", (float)uiScrollBar.alpha);
            data.AddField("fillDirection", (int)uiScrollBar.fillDirection);

            if (uiScrollBar.foregroundWidget != null)
            {
                var foregroundWidget = new WXUISprite(uiScrollBar.foregroundWidget as UISprite, go, entity);
                data.AddField("foregroundWidget", context.AddComponent(
                                  foregroundWidget,
                                  uiScrollBar.foregroundWidget
                                  ));
            }

            if (uiScrollBar.backgroundWidget != null)
            {
                var backgroundWidget = new WXUISprite(uiScrollBar.backgroundWidget as UISprite, go, entity);
                data.AddField("backgroundWidget", context.AddComponent(
                                  backgroundWidget,
                                  uiScrollBar.backgroundWidget
                                  ));
            }


            return(json);
        }
Esempio n. 2
0
        protected override JSONObject ToJSON(WXHierarchyContext context)
        {
            JSONObject json = new JSONObject(JSONObject.Type.OBJECT);

            json.AddField("type", "UIToggle");


            JSONObject subJSON = new JSONObject(JSONObject.Type.OBJECT);

            var activeSprite = uiToggle.activeSprite;

            if (uiToggle.activeSprite)
            {
                var compType = uiToggle.activeSprite.GetType();

                if (compType == typeof(UILabel))
                {
                    var addComp = new WXUILabel(uiToggle.activeSprite as UILabel, gameObject, entity);
                    subJSON.AddField("target", context.AddComponentInProperty(
                                         addComp,
                                         uiToggle.activeSprite
                                         ));
                }
                else if (compType == typeof(UISprite))
                {
                    var addComp = new WXUISprite(uiToggle.activeSprite as UISprite, gameObject, entity);
                    subJSON.AddField("target", context.AddComponentInProperty(
                                         addComp,
                                         uiToggle.activeSprite
                                         ));
                }
            }

            subJSON.AddField("isChecked", uiToggle.startsActive);

            object toggleIndex = TryGetContainField(uiToggle, "index");

            if (toggleIndex != null)
            {
                subJSON.AddField("index", (int)toggleIndex);
            }

            subJSON.AddField("active", uiToggle.enabled);

            json.AddField("data", subJSON);

            return(json);
        }