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("transition", (int)button.transition); // 0-3 JSONObject onClickList = new JSONObject(JSONObject.Type.ARRAY); data.AddField("onClickList", onClickList); int count = button.onClick.GetPersistentEventCount(); for (int i = 0; i < count; i++) { var __onClick = new JSONObject(JSONObject.Type.OBJECT); var target = button.onClick.GetPersistentTarget(i); var targetType = target.GetType().ToString(); __onClick.AddField("targetType", targetType); if (targetType == "UnityEngine.GameObject") { GameObject _go = (GameObject)target; __onClick.AddField("target", WXUIUCommonScript.AddComponent(_go, entity, context)); } else { //todo 其他类型的到时候再考虑 MonoBehaviour _target = (MonoBehaviour)target; __onClick.AddField("target", context.AddComponent(new WXEngineMonoBehaviour(_target), _target)); } __onClick.AddField("method", button.onClick.GetPersistentMethodName(i)); onClickList.Add(__onClick); } JSONObject scriptList = WXUIUCommonScript.AddInteractionScript(go, entity, context, false); data.AddField("scriptList", scriptList); var graphic = button.targetGraphic; if (button.targetGraphic != null) { int idf = context.AddComponent(new WXUIUGraphicScript(graphic, go, entity), graphic); data.AddField("graphic", idf); entity.components.Add(idf); } data.AddField("ref", context.AddComponent(new WXUIUButton(button, go, entity), button)); return(json); }
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); if (toggle.group) { var addComp = new WXUIUToggleGroup(toggle.group, go, entity); data.AddField("toggleGroup", context.AddComponent( addComp, toggle.group )); } JSONObject onValueChangedList = new JSONObject(JSONObject.Type.ARRAY); data.AddField("onValueChanged", onValueChangedList); int onChangeCount = toggle.onValueChanged.GetPersistentEventCount(); for (int i = 0; i < onChangeCount; i++) { var __onChange = new JSONObject(JSONObject.Type.OBJECT); var target = toggle.onValueChanged.GetPersistentTarget(i); var targetType = target.GetType().ToString(); __onChange.AddField("targetType", targetType); if (targetType == "UnityEngine.GameObject") { GameObject _go = (GameObject)target; __onChange.AddField("target", WXUIUCommonScript.AddComponent(_go, entity, context)); } else { //todo 其他类型的到时候再考虑 MonoBehaviour _target = (MonoBehaviour)target; __onChange.AddField("target", context.AddComponent(new WXEngineMonoBehaviour(_target), _target)); } __onChange.AddField("method", toggle.onValueChanged.GetPersistentMethodName(i)); onValueChangedList.Add(__onChange); } JSONObject scriptList = WXUIUCommonScript.AddInteractionScript(go, entity, context, false); data.AddField("scriptList", scriptList); data.AddField("ref", context.AddComponent(new WXUIUToggle(toggle, go, entity), toggle)); return(json); }
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); JSONObject scriptList = WXUIUCommonScript.AddInteractionScript(go, entity, context, true); data.AddField("scriptList", scriptList); data.AddField("ref", context.AddComponent(new WXUIUSprite(image, go, entity), image)); return(json); }
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); JSONObject scriptList = WXUIUCommonScript.AddInteractionScript(go, entity, context, false); data.AddField("scriptList", scriptList); Image targetGraphic = (Image)input.targetGraphic; if (targetGraphic != null) { data.AddField("targetGraphic", context.AddComponent(new WXUIUSpriteScript(targetGraphic, go, entity), targetGraphic)); } JSONObject onValueChangedList = new JSONObject(JSONObject.Type.ARRAY); data.AddField("onValueChanged", onValueChangedList); int onChangeCount = input.onValueChanged.GetPersistentEventCount(); for (int i = 0; i < onChangeCount; i++) { var __onChange = new JSONObject(JSONObject.Type.OBJECT); var target = input.onValueChanged.GetPersistentTarget(i); var targetType = target.GetType().ToString(); __onChange.AddField("targetType", targetType); if (targetType == "UnityEngine.GameObject") { GameObject _go = (GameObject)target; __onChange.AddField("target", WXUIUCommonScript.AddComponent(_go, entity, context)); } else { //todo 其他类型的到时候再考虑 MonoBehaviour _target = (MonoBehaviour)target; __onChange.AddField("target", context.AddComponent(new WXEngineMonoBehaviour(_target), _target)); } __onChange.AddField("method", input.onValueChanged.GetPersistentMethodName(i)); onValueChangedList.Add(__onChange); } JSONObject onEditEndList = new JSONObject(JSONObject.Type.ARRAY); data.AddField("onEditEnd", onEditEndList); int onEidtEndCount = input.onEndEdit.GetPersistentEventCount(); for (int i = 0; i < onEidtEndCount; i++) { var __onEnd = new JSONObject(JSONObject.Type.OBJECT); var target = input.onEndEdit.GetPersistentTarget(i); var targetType = target.GetType().ToString(); __onEnd.AddField("targetType", targetType); if (targetType == "UnityEngine.GameObject") { GameObject _go = (GameObject)target; __onEnd.AddField("target", WXUIUCommonScript.AddComponent(_go, entity, context)); } else { //todo 其他类型的到时候再考虑 MonoBehaviour _target = (MonoBehaviour)target; __onEnd.AddField("target", context.AddComponent(new WXEngineMonoBehaviour(_target), _target)); } __onEnd.AddField("method", input.onEndEdit.GetPersistentMethodName(i)); onEditEndList.Add(__onEnd); } Text placeHolder = (Text)input.placeholder; if (placeHolder != null) { JSONObject color = new JSONObject(JSONObject.Type.ARRAY); color.Add(255f * placeHolder.color.r); color.Add(255f * placeHolder.color.g); color.Add(255f * placeHolder.color.b); color.Add(255f * placeHolder.color.a); data.AddField("promptColor", color); input.placeholder.gameObject.SetActive(false); } data.AddField("ref", context.AddComponent(new WXUIUInputField(input, go, entity), input)); return(json); }
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("interactable", (bool)slider.interactable); data.AddField("transition", (int)slider.transition); // 0-3 // RectTransform sliderRect = slider.GetComponent<RectTransform>(); // sliderRect.pivot = new Vector2(0, 0); JSONObject colorPressed = new JSONObject(JSONObject.Type.ARRAY); var pressedColor = slider.colors.pressedColor; colorPressed.Add(255f * pressedColor.r); colorPressed.Add(255f * pressedColor.g); colorPressed.Add(255f * pressedColor.b); colorPressed.Add(255f * pressedColor.a); data.AddField("pressedColor", colorPressed); JSONObject colorDisabled = new JSONObject(JSONObject.Type.ARRAY); var disabledColor = slider.colors.disabledColor; colorDisabled.Add(255f * disabledColor.r); colorDisabled.Add(255f * disabledColor.g); colorDisabled.Add(255f * disabledColor.b); colorDisabled.Add(255f * disabledColor.a); data.AddField("disabledColor", colorDisabled); JSONObject colorNormal = new JSONObject(JSONObject.Type.ARRAY); var normalColor = slider.colors.normalColor; colorNormal.Add(255f * normalColor.r); colorNormal.Add(255f * normalColor.g); colorNormal.Add(255f * normalColor.b); colorNormal.Add(255f * normalColor.a); data.AddField("normalColor", colorNormal); Image targetGraphic = (Image)slider.targetGraphic; if (targetGraphic != null) { data.AddField("targetGraphic", context.AddComponent(new WXUIUSpriteScript(targetGraphic, go, entity), targetGraphic)); } SpriteState state = slider.spriteState; if (state.pressedSprite != null) { string pressedSpriteKey = this.getStateSprite(context, state.pressedSprite); if (pressedSpriteKey != null) { data.AddField("pressedSprite", pressedSpriteKey); } else { data.AddField("pressedSprite", new JSONObject(JSONObject.Type.NULL)); } } if (state.disabledSprite != null) { string disabledSpriteKey = this.getStateSprite(context, state.disabledSprite); if (disabledSpriteKey != null) { data.AddField("disabledSprite", disabledSpriteKey); } else { data.AddField("disabledSprite", new JSONObject(JSONObject.Type.NULL)); } } if (slider.fillRect != null) { data.AddField("fillRect", context.AddComponent(new WXUGUITransform2DComponent(slider.fillRect))); Image fillRectImage = (Image)slider.fillRect.transform.GetComponent <Image>(); if (fillRectImage != null) { RectTransform t = fillRectImage.transform as RectTransform; if (slider.direction == Slider.Direction.LeftToRight) { t.pivot = new Vector2(0, 0); } if (slider.direction == Slider.Direction.RightToLeft) { t.pivot = new Vector2(1, 0); } if (slider.direction == Slider.Direction.TopToBottom) { t.pivot = new Vector2(0, 1); } if (slider.direction == Slider.Direction.BottomToTop) { t.pivot = new Vector2(0, 0); } data.AddField("fillRectImage", context.AddComponent(new WXUIUSpriteScript(fillRectImage, go, entity), fillRectImage)); } } if (slider.handleRect != null) { data.AddField("handleRect", context.AddComponent(new WXUGUITransform2DComponent(slider.handleRect))); Image handleRectImage = (Image)slider.handleRect.transform.GetComponent <Image>(); if (handleRectImage != null) { data.AddField("handleRectImage", context.AddComponent(new WXUIUSpriteScript(handleRectImage, go, entity), handleRectImage)); } } JSONObject onValueChangedList = new JSONObject(JSONObject.Type.ARRAY); data.AddField("onValueChanged", onValueChangedList); int onChangeCount = slider.onValueChanged.GetPersistentEventCount(); for (int i = 0; i < onChangeCount; i++) { var __onChange = new JSONObject(JSONObject.Type.OBJECT); var target = slider.onValueChanged.GetPersistentTarget(i); var targetType = target.GetType().ToString(); __onChange.AddField("targetType", targetType); if (targetType == "UnityEngine.GameObject") { GameObject _go = (GameObject)target; __onChange.AddField("target", WXUIUCommonScript.AddComponent(_go, entity, context)); } else { //todo 其他类型的到时候再考虑 MonoBehaviour _target = (MonoBehaviour)target; __onChange.AddField("target", context.AddComponent(new WXEngineMonoBehaviour(_target), _target)); } __onChange.AddField("method", slider.onValueChanged.GetPersistentMethodName(i)); onValueChangedList.Add(__onChange); } data.AddField("direction", (int)slider.direction); data.AddField("maxValue", slider.maxValue); data.AddField("minValue", slider.minValue); data.AddField("normalizedValue", slider.normalizedValue); data.AddField("wholeNumbers", slider.wholeNumbers); data.AddField("value", slider.value); data.AddField("active", slider.IsActive()); return(json); }