コード例 #1
0
        protected override JSONObject ToJSON(WXHierarchyContext context)
        {
            JSONObject json = new JSONObject(JSONObject.Type.OBJECT);

            json.AddField("type", "UITextInput");
            JSONObject subJSON = new JSONObject(JSONObject.Type.OBJECT);


            if (uiInput.label)
            {
                subJSON.AddField("label", context.AddComponentInProperty(new WXUILabel(uiInput.label, gameObject, entity), uiInput.label));
            }

            WXUIMask    mask    = new WXUIMask();
            WXUIGraphic graphic = new WXUIGraphic(0);
            WXKeyboardInputComponent keyboardInput = new WXKeyboardInputComponent(this.uiInput, gameObject, entity);

            entity.components.Add(context.AddComponent(keyboardInput, null));
            entity.components.Add(context.AddComponent(mask, null));
            entity.components.Add(context.AddComponent(graphic, null));

            subJSON.AddField("maxChars", uiInput.characterLimit);

            subJSON.AddField("active", this.uiInput.enabled);
            json.AddField("data", subJSON);
            return(json);
        }
コード例 #2
0
        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);

            UIScrollView.ShowCondition showScrollBars = uiScrollView.showScrollBars;
            data.AddField("showScrollBars", (int)showScrollBars);

            var horizontalScrollBar = (UIScrollBar)uiScrollView.horizontalScrollBar;

            if (horizontalScrollBar != null)
            {
                data.AddField("horizontalScrollBar", context.AddComponent(new WXUIScrollBarScript(horizontalScrollBar, go, entity), horizontalScrollBar));
            }

            var verticalScrollBar = (UIScrollBar)uiScrollView.verticalScrollBar;

            if (verticalScrollBar != null)
            {
                data.AddField("verticalScrollBar", context.AddComponent(new WXUIScrollBarScript(verticalScrollBar, go, entity), verticalScrollBar));
            }


            data.AddField("ref", context.AddComponent(new WXUIScrollView(uiScrollView, go, entity), uiScrollView));

            return(json);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        // public void init (WXBeefBallHierarchyContext context) {
        //     // 添加控制父节点
        //     WXBeefBallEntity scrollViewControllerEntity = context.CreateEntity(null);
        //     scrollViewControllerEntity.isExtraEntity = false;
        //     scrollViewControllerEntity.isNguiChild = true;

        //     WXBBTransform2DComponent transformController = new WXBBTransform2DComponent(gameObj.transform);
        //     WXBBUIScrollViewController scrollViewController = new WXBBUIScrollViewController(uiScrollView, gameObj, transformController);
        //     scrollViewControllerEntity.components.Add(context.addComponent(scrollViewController, null));
        //     WXBeefBallTouchInputComponent touchInput = new WXBeefBallTouchInputComponent(gameObj, null);
        //     scrollViewControllerEntity.components.Add(context.addComponent(touchInput, null));
        //     // 蒙版区域
        //     WXBBUIMask mask = new WXBBUIMask();
        //     WXBBUIGraphic graphic = new WXBBUIGraphic(0);
        //     scrollViewControllerEntity.components.Add(context.addComponent(mask, null));
        //     scrollViewControllerEntity.components.Add(context.addComponent(graphic, null));

        //     // 内容区域矫正
        //     UIPanel uiPanel = gameObj.GetComponent(typeof(UIPanel)) as UIPanel;
        //     if ((UnityEngine.Object)uiPanel != (UnityEngine.Object)null)
        //     {
        //         Vector4 offSet = uiPanel.clipOffset;
        //         Vector2 center = uiPanel.baseClipRegion;

        //         transform.size[0] = uiPanel.width;
        //         transform.size[1] = uiPanel.height;

        //         transform.setPosition(-((float)offSet.x + (float)center.x), -((float)offSet.y + (float)center.y));
        //     }

        //     scrollViewControllerEntity.components.Add(context.addComponent(transformController, null));
        //     // 修改父子关系
        //     scrollViewControllerEntity.parent = entity.parent;
        //     entity.parent = scrollViewControllerEntity;


        // }

        protected override JSONObject ToJSON(WXHierarchyContext context)
        {
            entity.components.Add(context.AddComponent(new WXTouchInputComponent(null, gameObject, entity), null));
            entity.components.Add(context.AddComponent(new WXUIMask(), null));
            entity.components.Add(context.AddComponent(new WXUIGraphic(0), null));

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

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

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

            UIScrollView.Movement movement = uiScrollView.movement;
            subJSON.AddField("movement", (int)movement);

            bool disableDragIfFits = uiScrollView.disableDragIfFits;

            subJSON.AddField("disableDragIfFits", (bool)disableDragIfFits);

            UIPanel uiPanel = gameObject.GetComponent(typeof(UIPanel)) as UIPanel;

            if ((UnityEngine.Object)uiPanel != (UnityEngine.Object)null)
            {
                Vector4 offSet = uiPanel.clipOffset;
                Vector2 center = uiPanel.baseClipRegion;
                subJSON.AddField("offSetX", (float)offSet.x);
                subJSON.AddField("offSetY", (float)offSet.y);
                subJSON.AddField("centerX", (float)center.x);
                subJSON.AddField("centerY", (float)center.y);
            }

            UIWidget.Pivot contentPivot   = uiScrollView.contentPivot;
            float          cellAlignmentX = (
                contentPivot == UIWidget.Pivot.Left ||
                contentPivot == UIWidget.Pivot.TopLeft ||
                contentPivot == UIWidget.Pivot.BottomLeft
                ) ? 0.0f : ((
                                contentPivot == UIWidget.Pivot.Center ||
                                contentPivot == UIWidget.Pivot.Top ||
                                contentPivot == UIWidget.Pivot.Bottom) ? 0.5f : 1.0f);

            float cellAlignmentY = (
                contentPivot == UIWidget.Pivot.Bottom ||
                contentPivot == UIWidget.Pivot.BottomLeft ||
                contentPivot == UIWidget.Pivot.BottomRight
                ) ? 0.0f : ((
                                contentPivot == UIWidget.Pivot.Left ||
                                contentPivot == UIWidget.Pivot.Center ||
                                contentPivot == UIWidget.Pivot.Right) ? 0.5f : 1.0f);

            subJSON.AddField("cellAlignmentX", cellAlignmentX);
            subJSON.AddField("cellAlignmentY", cellAlignmentY);



            json.AddField("data", subJSON);
            return(json);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        protected override JSONObject ToJSON(WXHierarchyContext context)
        {
            //           entity.components.Add(context.AddComponent(new WXUIUMask(null, gameObject, entity), null));
            entity.components.Add(context.AddComponent(new WXUGUIKeyboardInputComponent(input, gameObject, entity), null));
            entity.components.Add(context.AddComponent(new WXUGUITouchInputComponent(gameObject, entity), null));
            entity.components.Add(context.AddComponent(new WXUIUGraphic(0), null));


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

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

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

            subJSON.AddField("text", input.text);
            subJSON.AddField("editable", !input.readOnly);

            Text textComponent = input.textComponent;

            if (textComponent != null)
            {
                subJSON.AddField("label", context.AddComponentInProperty(new WXUIULabel(textComponent, gameObject, entity), textComponent));
            }


            Text placeHolder = (Text)input.placeholder;

            Debug.Log(input.placeholder);
            if (placeHolder != null)
            {
                subJSON.AddField("prompt", placeHolder.text);
                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);
                subJSON.AddField("promptColor", color);
                subJSON.AddField("fontSize", placeHolder.fontSize);
            }

            subJSON.AddField("maxChar", input.characterLimit == 0 ? -1 : input.characterLimit);

            subJSON.AddField("multiline", input.multiLine);


            subJSON.AddField("active", input.IsActive());
            json.AddField("data", subJSON);

            return(json);
        }
コード例 #8
0
        private static void GetGameObjectReferenceIndex(WXHierarchyContext context, GameObject go, ref JSONObject innerData, bool isGameObject = true)
        {
            if (WXBridge.isNGUIPreset)
            {
                // ngui hack
                innerData = JSONObject.Create(context.AddComponentInProperty(
                                                  (WXComponent)Activator.CreateInstance(Type.GetType("WXEngine.WXTransform2DComponent"),
                                                                                        (object)go.transform), go.transform)
                                              );
                return;
            }
            if (WXBridge.isUGUIPreset)
            {
                // ugui hack
                innerData = JSONObject.Create((int)context.AddComponent(
                                                  (WXComponent)Activator.CreateInstance(Type.GetType("WXEngine.WXUGUITransform2DComponent"),
                                                                                        (object)go.transform), go.transform)
                                              );
                return;
            }

            if (isGameObject)
            {
                innerData.AddField("type", "UnityEngine.GameObject".EscapeNamespaceSimple());
                innerData.AddField("value", context.AddComponentInProperty(new WXTransform3DComponent(go.transform), go.transform));    // temp impl: add the referring engine.transform3D index
            }
            else
            {
                innerData.AddField("value", context.AddComponentInProperty(new WXUnityComponent(go.transform), go.transform));
            }
        }
コード例 #9
0
        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("ref", context.AddComponent(new WXUIToggle(uiToggle, go, entity), uiToggle));

            if (uiToggle.group != null)
            {
                data.AddField("group", (string)uiToggle.group);
            }


            JSONObject onChange = new JSONObject(JSONObject.Type.ARRAY);

            data.AddField("onChange", onChange);


            foreach (var change in uiToggle.onChange)
            {
                var __onChange = new JSONObject(JSONObject.Type.OBJECT);
                __onChange.AddField("target", context.AddComponent(new WXEngineMonoBehaviour(change.target), change.target));
                __onChange.AddField("method", change.methodName);

                var _params = new JSONObject(JSONObject.Type.ARRAY);
                __onChange.AddField("params", _params);
                if (change.parameters != null)
                {
                    foreach (var p in change.parameters)
                    {
                        if (p.obj != null)
                        {
                            _params.Add(WXMonoBehaviourPropertiesHandler.InvokePropertyHandler(p.expectedType, p.obj, context));
                        }
                    }
                }

                onChange.Add(__onChange);
            }


            return(json);
        }
コード例 #10
0
        private static void Iterate3DComponent(GameObject go, WXEntity obj, WXHierarchyContext context, ExportPreset preset)
        {
            BoxCollider boxCollider = go.GetComponent <BoxCollider>();

            if (boxCollider != null)
            {
                obj.components.Add(context.AddComponent(new WXBoxCollider(boxCollider.center, boxCollider.size, boxCollider.isTrigger, boxCollider.sharedMaterial), boxCollider));
            }

            CapsuleCollider capsuleCollider = go.GetComponent <CapsuleCollider>();

            if (capsuleCollider != null)
            {
                obj.components.Add(context.AddComponent(
                                       new WXCapsuleCollider(capsuleCollider.isTrigger, capsuleCollider.sharedMaterial, capsuleCollider.center, capsuleCollider.radius, capsuleCollider.height, capsuleCollider.direction),
                                       capsuleCollider));
            }

            MeshCollider meshCollider = go.GetComponent <MeshCollider>();

            if (meshCollider != null)
            {
                obj.components.Add(context.AddComponent(
                                       new WXMeshCollider(meshCollider.convex, meshCollider.isTrigger,
                    #if UNITY_2017_1_OR_NEWER
                                                          (int)meshCollider.cookingOptions,
                    #endif
                                                          meshCollider.sharedMaterial, meshCollider.sharedMesh),
                                       meshCollider));
            }

            Rigidbody rigidbody = go.GetComponent <Rigidbody>();
            if (rigidbody != null)
            {
                obj.components.Add(context.AddComponent(new WXRigidbody(rigidbody), rigidbody));
            }

            SphereCollider sphereCollider = go.GetComponent <SphereCollider>();
            if (sphereCollider != null)
            {
                obj.components.Add(context.AddComponent(new WXSphereCollider(sphereCollider.isTrigger, sphereCollider.sharedMaterial, sphereCollider.center, sphereCollider.radius), sphereCollider));
            }
        }
コード例 #11
0
        protected override JSONObject ToJSON(WXHierarchyContext context)
        {
            entity.components.Add(context.AddComponent(new WXUGUITouchInputComponent(gameObject, entity), null));

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

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


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

            Image targetImage = toggle.graphic.GetComponent <Image>();

            if (targetImage != null)
            {
                var addComp = new WXUIUSprite(targetImage, gameObject, entity);
                subJSON.AddField("target", context.AddComponent(
                                     addComp,
                                     targetImage
                                     ));
            }


            if (toggle.group)
            {
                var addComp = new WXUIUToggleGroup(toggle.group, gameObject, entity);
                subJSON.AddField("toggleGroup", context.AddComponent(
                                     addComp,
                                     toggle.group
                                     ));
            }

            subJSON.AddField("isChecked", toggle.isOn);

            subJSON.AddField("active", toggle.IsActive());
            json.AddField("data", subJSON);

            return(json);
        }
コード例 #12
0
        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("ref", context.AddComponent(new WXUIGrid(uiGrid, go, entity), uiGrid));

            return(json);
        }
コード例 #13
0
        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("ref", context.AddComponent(new WXUIUToggleGroup(toggleGroup, go, entity), toggleGroup));

            return(json);
        }
コード例 #14
0
        protected override JSONObject ToJSON(WXHierarchyContext context)
        {
            entity.components.Add(context.AddComponent(new WXUGUITouchInputComponent(gameObject, entity), null));
            entity.components.Add(context.AddComponent(new WXUIUGraphic(0), null));

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

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


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

            subJSON.AddField("movement", scrollRect.horizontal ? 0 : 1); //引擎只支持一个方向的滚动


            subJSON.AddField("autoFix", true);

            subJSON.AddField("active", scrollRect.IsActive());
            json.AddField("data", subJSON);

            return(json);
        }
コード例 #15
0
        public static JSONObject AddInteractionScript(GameObject gameObject, WXEntity entity, WXHierarchyContext context, bool needTouchInputComponent)
        {
            //判断是否可以点击

            bool isClickable = false;

            JSONObject scriptList = new JSONObject(JSONObject.Type.ARRAY);

            var bes = gameObject.GetComponents <MonoBehaviour>();

            for (var i = 0; i < bes.Length; i++)
            {
                var type = bes[i].GetType();
                if (Regex.Match(type.ToString(), @"^UnityEngine\.UI\b").Length == 0)
                {
                    if (
                        typeof(IPointerClickHandler).IsAssignableFrom(type) ||
                        typeof(IPointerDownHandler).IsAssignableFrom(type) ||
                        typeof(IPointerUpHandler).IsAssignableFrom(type)
                        )
                    {
                        isClickable = true;
                    }

                    var scripts = new JSONObject(JSONObject.Type.OBJECT);
                    scripts.AddField("target", context.AddComponent(new WXEngineMonoBehaviour(bes[i]), bes[i]));
                    scriptList.Add(scripts);
                }
            }

            if (isClickable && needTouchInputComponent)
            {
                entity.components.Add(context.AddComponent(new WXUGUITouchInputComponent(gameObject, entity), null));
            }

            return(scriptList);
        }
コード例 #16
0
        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);
        }
コード例 #17
0
        protected override JSONObject ToJSON(WXHierarchyContext context)
        {
            entity.components.Add(context.AddComponent(new WXUGUITouchInputComponent(gameObject, entity), null));

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

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


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


            subJSON.AddField("allowSwitchOff", toggleGroup.allowSwitchOff);

            subJSON.AddField("active", toggleGroup.IsActive());
            json.AddField("data", subJSON);

            return(json);
        }
コード例 #18
0
        public static int AddComponent(GameObject go, WXEntity obj, WXHierarchyContext context)
        {
            int  id   = -999;
            Text text = go.GetComponent <Text>();

            if (text != null)
            {
                id = context.AddComponent(new WXUIULabelScript(text, go, obj), text);
            }

            Image image = go.GetComponent <Image>();

            if (image != null)
            {
                id = context.AddComponent(new WXUIUSpriteScript(image, go, obj), image);
            }

            Button button = go.GetComponent <Button>();

            if (button != null)
            {
                id = context.AddComponent(new WXUIUButtonScript(button, go, obj), button);
            }

            Slider slider = go.GetComponent <Slider>();

            if (slider != null)
            {
                id = context.AddComponent(new WXUIUSliderScript(slider, go, obj), slider);
            }

            Toggle toggle = go.GetComponent <Toggle>();

            if (toggle != null)
            {
                id = context.AddComponent(new WXUIUToggleScript(toggle, go, obj), toggle);
            }

            ToggleGroup toggleGroup = go.GetComponent <ToggleGroup>();

            if (toggleGroup != null)
            {
                id = context.AddComponent(new WXUIUToggleGroupScript(toggleGroup, go, obj), toggleGroup);
            }

            ScrollRect scrollRect = go.GetComponent <ScrollRect>();

            if (scrollRect != null)
            {
                id = context.AddComponent(new WXUIUScrollRectScript(scrollRect, go, obj), scrollRect);
            }

            InputField input = go.GetComponent <InputField>();

            if (input != null)
            {
                id = context.AddComponent(new WXUIUInputFieldScript(input, go, obj), input);
            }

            return(id);
        }
コード例 #19
0
        private static void IterateNguiComponent(
            GameObject gameObject,
            WXEntity entity,
            WXHierarchyContext context,
            ExportPreset preset
            )
        {
            if (!preset.presetKey.Contains("ngui"))
            {
                return;
            }

            bool   isUIRoot = false;
            UIRoot uiRoot   = gameObject.GetComponent(typeof(UIRoot)) as UIRoot;

            if (uiRoot != null)
            {
                isUIRoot = true;
            }

            UISprite uiSprite = gameObject.GetComponent(typeof(UISprite)) as UISprite;

            if (uiSprite != null)
            {
                entity.components.Add(context.AddComponent(new WXUISprite(uiSprite, gameObject, entity), uiSprite));
            }

            UILabel uiLabel = gameObject.GetComponent(typeof(UILabel)) as UILabel;

            if (uiLabel != null)
            {
                entity.components.Add(context.AddComponent(new WXUILabel(uiLabel, gameObject, entity), uiLabel));
            }

            UIInput uiInput = gameObject.GetComponent(typeof(UIInput)) as UIInput;

            if (uiInput != null)
            {
                entity.components.Add(context.AddComponent(new WXUITextInput(uiInput, gameObject, entity), uiInput));
            }

            UITexture uiTexture = gameObject.GetComponent(typeof(UITexture)) as UITexture;

            if (uiTexture != null)
            {
                entity.components.Add(context.AddComponent(new WXUITexture(uiTexture, gameObject, entity), uiTexture));
            }

            WXTransform2DComponent transform2D = new WXTransform2DComponent(gameObject.transform);
            //if (isUIRoot)
            //{
            //    transform2D = new WXTransform2DComponent(go);
            //}
            //else
            //{
            //    // 如果不是UIRoot,那么该Transform有可能在遍历之前的节点的时候,被用target指向,并且已经转换过。
            //    // 所以这里要把之前的取出来
            //    transform2D = (WXTransform2DComponent)context.GetConvertedComponent(typeof(WXTransform2DComponent), go.transform);
            //    if (transform2D == null)
            //    {
            //        // 如果没有,才去创建新的transform2D
            //        transform2D = new WXTransform2DComponent(go.transform, go);
            //    }
            //}

            UIWidget uiWidget = gameObject.GetComponent(typeof(UIWidget)) as UIWidget;

            if (uiWidget != null)
            {
                if (uiWidget.isAnchored)
                {
                    entity.components.Add(context.AddComponent(new WXUIWidget(uiWidget, gameObject, entity), uiWidget));
                }
            }

            UIGrid uiGrid = gameObject.GetComponent(typeof(UIGrid)) as UIGrid;

            if (uiGrid != null)
            {
                entity.components.Add(context.AddComponent(new WXUIGrid(uiGrid, gameObject, entity), uiGrid));
            }

            UIAnchor uiAnchor = gameObject.GetComponent(typeof(UIAnchor)) as UIAnchor;

            if (uiAnchor != null)
            {
                entity.components.Add(context.AddComponent(new WXUIAnchor(uiAnchor, gameObject, entity), uiAnchor));
            }

            UITable uiTable = gameObject.GetComponent(typeof(UITable)) as UITable;

            if (uiTable != null)
            {
                entity.components.Add(context.AddComponent(new WXUITable(uiTable, gameObject, entity), uiTable));
            }

            UIScrollView uiScrollView = gameObject.GetComponent(typeof(UIScrollView)) as UIScrollView;

            if (uiScrollView != null)
            {
                /* delete 19/8.5 roamye 更新使用逻辑,将center,offset等属性作为动态创建的mask元素的坐标位移量 */
                entity.components.Add(context.AddComponent(new WXUIScrollView(uiScrollView, gameObject, entity), uiScrollView));
            }

            entity.components.Add(context.AddComponent(transform2D, gameObject.transform));


            UIButton uiButton = gameObject.GetComponent(typeof(UIButton)) as UIButton;

            if (uiButton != null)
            {
                if (uiSprite == null)
                {
                    // obj.components.Add(context.AddComponent(new WXUISprite(null), null));
                }
                entity.components.Add(context.AddComponent(new WXUIButton(uiButton, gameObject, entity), uiButton));
                // TODO pivot
            }

            BoxCollider boxCollider = gameObject.GetComponent(typeof(BoxCollider)) as BoxCollider;

            if (boxCollider != null)
            {
                entity.components.Add(context.AddComponent(new WXTouchInputComponent(boxCollider, gameObject, entity), boxCollider));
            }

            UIToggle uiToggle = gameObject.GetComponent(typeof(UIToggle)) as UIToggle;

            if (uiToggle != null)
            {
                entity.components.Add(context.AddComponent(new WXUIToggle(uiToggle, gameObject, entity), uiToggle));
            }

            UIAtlas uiAtlas = gameObject.GetComponent(typeof(UIAtlas)) as UIAtlas;

            if (uiAtlas != null)
            {
                entity.components.Add(context.AddComponent(new WXUIAtlas(uiAtlas, gameObject, entity), uiAtlas));
            }
        }
コード例 #20
0
        // inner recursion method, thus each if-statement must have @return in the end of the following block.
        private static void innerHandleProperty(Type type, FieldInfo field, object obj, JSONObject data, WXHierarchyContext context)
        {
            if (ExportLogger.LOGGING)
            {
                ExportLogger.AddLog(new ExportLogger.Log(ExportLogger.Log.Type.Inner, "Type: " + type + "\nObject: " + obj + "\nJson: " + data));
            }

            if (obj == null ||
                type == null ||
                type == typeof(System.Object) ||
                field.IsDefined(typeof(NonSerializedAttribute)) ||
                field.IsDefined(typeof(HideInInspector)))
            {
                return;
            }

            if (WXBridge.isNGUIPreset)
            {
                Type wxnguiType = WXMonoBehaviourExportHelper.GetWXNGUIComponentType(type);
                if (wxnguiType != null)
                {
                    var nativeComp = (Component)field.GetValue(obj);

                    if (nativeComp != null)
                    {
                        var go = nativeComp.gameObject;
                        Debug.Log(nativeComp);
                        var entity = context.MakeEntity(go);

                        // 特殊处理
                        if (wxnguiType.FullName == "WXEngine.WXTransform2DComponent")
                        {
                            data.AddField(field.Name, context.AddComponentInProperty(
                                              (WXComponent)Activator.CreateInstance(wxnguiType, (object)nativeComp.transform),
                                              nativeComp.transform
                                              ));
                        }
                        else
                        {
                            data.AddField(field.Name, context.AddComponentInProperty(
                                              (WXComponent)Activator.CreateInstance(wxnguiType, nativeComp, go, entity),
                                              nativeComp
                                              ));
                        }
                    }
                }
            }

            if (WXBridge.isUGUIPreset)
            {
                Type wxuguiType = WXMonoBehaviourExportHelper.GetWXUGUIComponentType(type);
                if (wxuguiType != null)
                {
                    var nativeComp = (Component)field.GetValue(obj);

                    if (nativeComp != null)
                    {
                        var go = nativeComp.gameObject;
                        Debug.Log(nativeComp);
                        var entity = context.MakeEntity(go);

                        // 特殊处理
                        if (wxuguiType.FullName == "WeChat.WXUGUITransform2DComponent")
                        {
                            data.AddField(field.Name, context.AddComponent(
                                              (WXComponent)Activator.CreateInstance(wxuguiType, (object)nativeComp.transform),
                                              nativeComp.transform
                                              ));
                        }
                        else
                        {
                            data.AddField(field.Name, context.AddComponent(
                                              (WXComponent)Activator.CreateInstance(wxuguiType, nativeComp, go, entity),
                                              nativeComp
                                              ));
                        }
                    }
                }
            }

            if (WXBridge.isUGUIPreset)
            {
                Type wxuguiType = WXMonoBehaviourExportHelper.GetWXUGUIComponentType(type);
                if (wxuguiType != null)
                {
                    var nativeComp = (Component)field.GetValue(obj);

                    if (nativeComp != null)
                    {
                        var go = nativeComp.gameObject;
                        Debug.Log(nativeComp);
                        var entity = context.MakeEntity(go);

                        // 特殊处理
                        if (wxuguiType.FullName == "WeChat.WXUGUITransform2DComponent")
                        {
                            data.AddField(field.Name, context.AddComponent(
                                              (WXComponent)Activator.CreateInstance(wxuguiType, (object)nativeComp.transform),
                                              nativeComp.transform
                                              ));
                        }
                        else
                        {
                            data.AddField(field.Name, context.AddComponent(
                                              (WXComponent)Activator.CreateInstance(wxuguiType, nativeComp, go, entity),
                                              nativeComp
                                              ));
                        }
                    }
                }
            }

            if (WXMonoBehaviourExportHelper.IsInBlackList(type))
            {
                return;
            }
            if (propertiesHandlerDictionary.ContainsKey(type))
            {
                var res = InvokePropertyHandler(type, field.GetValue(obj), context);
                if (res)
                {
                    data.AddField(field.Name, res);
                }
                return;
            }
            else if (type.IsArray || (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List <>)))
            {
                var res = InvokePropertyHandler(typeof(List <>), field.GetValue(obj), context);
                if (res)
                {
                    data.AddField(field.Name, res);
                }
                return;
            }
            else if (type.IsEnum)
            {
                var res = JSONObject.Create((int)field.GetValue(obj));
                if (res)
                {
                    data.AddField(field.Name, res);
                }
                return;
            }
            else if (type.IsSubclassOf(typeof(UnityEngine.Component)) || type == typeof(UnityEngine.GameObject))
            {
                // Prefab or not
                var        o  = (UnityEngine.Object)field.GetValue(obj);
                GameObject go = null;

                if (o == null)
                {
                    return;
                }
                if (type.IsSubclassOf(typeof(UnityEngine.Component)))
                {
                    go = ((Component)o).gameObject;
                }
                else if (type == typeof(UnityEngine.GameObject))
                {
                    go = (GameObject)o;
                }
                var path = AssetDatabase.GetAssetPath(o);

                if (go.transform.IsChildOf(context.Root.transform) || path == "")
                {
                    if (type.IsSerializable)
                    {
                        var _innerData = new JSONObject(JSONObject.Type.OBJECT);
                        data.AddField(field.Name, _innerData);
                        SerializableHandler(type, _innerData, field.GetValue(obj), context);
                        return;
                    }
                    innerHandleProperty(type.BaseType, field, obj, data, context);
                    return;
                }

                if (!WXMonoBehaviourExportHelper.exportedResourcesSet.Contains(go))
                {
                    WXMonoBehaviourExportHelper.exportedResourcesSet.Add(go);
                    WXPrefab converter  = new WXPrefab(go, path);
                    string   prefabPath = converter.Export(ExportPreset.GetExportPreset("prefab"));
                    context.AddResource(prefabPath);
                }

                var prefabInfo = new JSONObject(JSONObject.Type.OBJECT);
                prefabInfo.AddField("type", type.FullName.EscapeNamespaceSimple());
                prefabInfo.AddField("path", path);

                var innerData = new JSONObject(JSONObject.Type.OBJECT);
                innerData.AddField("type", "UnityPrefabWrapper");
                innerData.AddField("value", prefabInfo);
                data.AddField(field.Name, innerData);
                return;
            }
            else if (type.IsSerializable)
            {
                // data of serializable object as a new JSONObject to be added
                var innerData = new JSONObject(JSONObject.Type.OBJECT);
                data.AddField(field.Name, innerData);
                SerializableHandler(type, innerData, field.GetValue(obj), context);
                return;
            }
            innerHandleProperty(type.BaseType, field, obj, data, context);
        }
コード例 #21
0
        private static void IterateNGUIScriptComponent(GameObject go, WXEntity obj, WXHierarchyContext context, ExportPreset preset)
        {
            UITexture texture = go.GetComponent <UITexture>();

            if (texture != null)
            {
                obj.components.Add(context.AddComponent(new WXUITextureScript(texture, go, obj), texture));
            }

            UISprite sprite = go.GetComponent <UISprite>();

            if (sprite != null)
            {
                obj.components.Add(context.AddComponent(new WXUISpriteScript(sprite, go, obj), sprite));
            }

            UIButton button = go.GetComponent <UIButton>();

            if (button != null)
            {
                obj.components.Add(context.AddComponent(new WXUIButtonScript(button, go, obj), button));
            }

            UILabel label = go.GetComponent <UILabel>();

            if (label != null)
            {
                obj.components.Add(context.AddComponent(new WXUILabelScript(label, go, obj), label));
            }

            UIInput input = go.GetComponent <UIInput>();

            if (input != null)
            {
                obj.components.Add(context.AddComponent(new WXUITextInputScript(input, go, obj), input));
            }

            UIScrollView sv = go.GetComponent <UIScrollView>();

            if (sv != null)
            {
                obj.components.Add(context.AddComponent(new WXUIScrollViewScript(sv, go, obj), sv));
            }

            UIScrollBar sb = go.GetComponent <UIScrollBar>();

            if (sb != null)
            {
                obj.components.Add(context.AddComponent(new WXUIScrollBarScript(sb, go, obj), sb));
            }

            UIGrid grid = go.GetComponent <UIGrid>();

            if (grid != null)
            {
                obj.components.Add(context.AddComponent(new WXUIGridScript(grid, go, obj), grid));
            }

            UIToggle toggle = go.GetComponent <UIToggle>();

            if (toggle != null)
            {
                obj.components.Add(context.AddComponent(new WXUIToggleScript(toggle, go, obj), toggle));
            }

            UIWidget widget = go.GetComponent <UIWidget>();

            if (widget != null)
            {
                obj.components.Add(context.AddComponent(new WXUIWidgetScript(widget, go, obj), widget));
            }
        }
コード例 #22
0
        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);
        }
コード例 #23
0
        protected override JSONObject ToJSON(WXHierarchyContext context)
        {
            entity.components.Add(context.AddComponent(new WXUGUITouchInputComponent(gameObject, entity), null));

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

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


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


            JSONObject colorPressed = new JSONObject(JSONObject.Type.ARRAY);
            var        pressedColor = button.colors.pressedColor;

            if (pressedColor != null)
            {
                colorPressed.Add(255f * pressedColor.r);
                colorPressed.Add(255f * pressedColor.g);
                colorPressed.Add(255f * pressedColor.b);
                colorPressed.Add(255f * pressedColor.a);
                subJSON.AddField("pressedColor", colorPressed);
            }


            JSONObject colorDisabled = new JSONObject(JSONObject.Type.ARRAY);
            var        disabledColor = button.colors.disabledColor;

            if (disabledColor != null)
            {
                colorDisabled.Add(255f * disabledColor.r);
                colorDisabled.Add(255f * disabledColor.g);
                colorDisabled.Add(255f * disabledColor.b);
                colorDisabled.Add(255f * disabledColor.a);
                subJSON.AddField("disabledColor", colorDisabled);
            }



            JSONObject colorNormal = new JSONObject(JSONObject.Type.ARRAY);
            var        normalColor = button.colors.normalColor;

            if (normalColor != null)
            {
                colorNormal.Add(255f * normalColor.r);
                colorNormal.Add(255f * normalColor.g);
                colorNormal.Add(255f * normalColor.b);
                colorNormal.Add(255f * normalColor.a);
                subJSON.AddField("normalColor", colorNormal);
            }


            SpriteState state = button.spriteState;

            if (state.pressedSprite != null)
            {
                string pressedSpriteKey = this.getStateSprite(context, state.pressedSprite);
                if (pressedSpriteKey != null)
                {
                    subJSON.AddField("pressedSprite", pressedSpriteKey);
                }
                else
                {
                    subJSON.AddField("pressedSprite", new JSONObject(JSONObject.Type.NULL));
                }
            }

            if (state.disabledSprite != null)
            {
                string disabledSpriteKey = this.getStateSprite(context, state.disabledSprite);
                if (disabledSpriteKey != null)
                {
                    subJSON.AddField("disabledSprite", disabledSpriteKey);
                }
                else
                {
                    subJSON.AddField("disabledSprite", new JSONObject(JSONObject.Type.NULL));
                }
            }

            Image targetImage = button.targetGraphic.GetComponent <Image>();

            if (targetImage != null)
            {
                string normalSpriteKey = this.getStateSprite(context, targetImage.sprite);
                if (normalSpriteKey != null)
                {
                    subJSON.AddField("normalSprite", normalSpriteKey);
                }
                else
                {
                    subJSON.AddField("normalSprite", new JSONObject(JSONObject.Type.NULL));
                }
            }



            subJSON.AddField("active", button.IsActive());
            json.AddField("data", subJSON);

            return(json);
        }
コード例 #24
0
        private static void IterateUguiComponent(
            GameObject gameObject,
            WXEntity entity,
            WXHierarchyContext context,
            ExportPreset preset
            )
        {
            if (!preset.presetKey.Contains("ugui"))
            {
                return;
            }

            //Canvas uiCanvas = gameObject.GetComponent(typeof(Canvas)) as Canvas;
            //if (uiCanvas != null)
            //{
            //    entity.components.Add(context.AddComponent(new WXUIUCanvas(uiCanvas, gameObject, entity), uiCanvas));
            //}

            Image uiSprite = gameObject.GetComponent(typeof(Image)) as Image;

            if (uiSprite != null)
            {
                entity.components.Add(context.AddComponent(new WXUIUSprite(uiSprite, gameObject, entity), uiSprite));
            }

            Text uiLabel = gameObject.GetComponent(typeof(Text)) as Text;

            if (uiLabel != null)
            {
                entity.components.Add(context.AddComponent(new WXUIULabel(uiLabel, gameObject, entity), uiLabel));
            }

            Button button = gameObject.GetComponent(typeof(Button)) as Button;

            if (button != null)
            {
                entity.components.Add(context.AddComponent(new WXUIUButton(button, gameObject, entity), button));
            }

            Toggle toggle = gameObject.GetComponent(typeof(Toggle)) as Toggle;

            if (toggle != null)
            {
                entity.components.Add(context.AddComponent(new WXUIUToggle(toggle, gameObject, entity), toggle));
            }

            ToggleGroup toggleGroup = gameObject.GetComponent(typeof(ToggleGroup)) as ToggleGroup;

            if (toggleGroup != null)
            {
                entity.components.Add(context.AddComponent(new WXUIUToggleGroup(toggleGroup, gameObject, entity), toggleGroup));
            }

            ScrollRect scrollRect = gameObject.GetComponent(typeof(ScrollRect)) as ScrollRect;

            if (scrollRect != null)
            {
                entity.components.Add(context.AddComponent(new WXUIUScrollRect(scrollRect, gameObject, entity), scrollRect));
            }

            Mask mask = gameObject.GetComponent(typeof(Mask)) as Mask;

            if (mask != null)
            {
                entity.components.Add(context.AddComponent(new WXUIUMask(mask, gameObject, entity), mask));
            }

            InputField input = gameObject.GetComponent(typeof(InputField)) as InputField;

            if (input != null)
            {
                entity.components.Add(context.AddComponent(new WXUIUInputField(input, gameObject, entity), input));
            }


            WXUGUITransform2DComponent transform2D = new WXUGUITransform2DComponent(gameObject.transform);



            entity.components.Add(context.AddComponent(transform2D, gameObject.transform));
        }
コード例 #25
0
        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);
        }
コード例 #26
0
        private static void IterateBridgeComponent(GameObject go, WXEntity obj, WXHierarchyContext context, ExportPreset preset)
        {
            if (preset.presetKey == "ngui-prefab" || preset.presetKey == "ngui-asset" || preset.presetKey == "ngui-prefabfolder" || preset.presetKey == "ngui-rootScene")
            {
                WXBridge.isNGUIPreset = true;
            }
            if (preset.presetKey == "ugui-prefab" || preset.presetKey == "ugui-asset" || preset.presetKey == "ugui-prefabfolder" || preset.presetKey == "ugui-rootScene")
            {
                WXBridge.isUGUIPreset = true;
            }

            var monoBehaviours = go.GetComponents <MonoBehaviour>();

            foreach (var behaviour in monoBehaviours)
            {
                // 处理用户脚本丢失的情况
                if (behaviour == null)
                {
                    continue;
                }
                // user's MonoBehaviour or not?
                if (!BridgeExport.GetDevTypesSet().Contains(behaviour.GetType()))
                {
                    continue;
                }
                if (WXMonoBehaviourExportHelper.IsInBlackList(behaviour.GetType()))
                {
                    continue;
                }

                obj.components.Add(context.AddComponent(new WXEngineMonoBehaviour(behaviour), behaviour));
            }

            // for a ngui-prefab, we don't need to export any other components
            if (WXBridge.isNGUIPreset)
            {
                return;
            }
            if (WXBridge.isUGUIPreset)
            {
                return;
            }

            /**
             * 下面的Component为adaptor对齐unity独有的组件
             * 需要根据对应类型新建一个对应的Component的class
             */

            // Colliders
            Collider[] colliders = go.GetComponents <Collider>();
            if (colliders != null && colliders.Length > 0)
            {
                foreach (var collider in colliders)
                {
                    if (collider is BoxCollider)
                    {
                        //obj.components.Add(context.AddComponent(new WXBoxCollider((BoxCollider)collider), collider));
                        obj.components.Add(context.AddComponent(new WXUnityComponent(collider), collider));
                    }
                    else if (collider is SphereCollider)
                    {
                        //obj.components.Add(context.AddComponent(new WXSphereCollider((SphereCollider)collider), collider));
                        obj.components.Add(context.AddComponent(new WXUnityComponent(collider), collider));
                    }
                    else if (collider is CapsuleCollider)
                    {
                        //obj.components.Add(context.AddComponent(new WXCapsuleCollider((CapsuleCollider)collider), collider));
                        obj.components.Add(context.AddComponent(new WXUnityComponent(collider), collider));
                    }
                    else if (collider is MeshCollider)
                    {
                        //obj.components.Add(context.AddComponent(new WXMeshCollider((MeshCollider)collider), collider));
                        obj.components.Add(context.AddComponent(new WXUnityComponent(collider), collider));
                    }
                }
            }

            // AudioSource(s)
            AudioSource[] audioSources = go.GetComponents <AudioSource>();
            if (audioSources != null && audioSources.Length > 0)
            {
                foreach (var audioSource in audioSources)
                {
                    obj.components.Add(context.AddComponent(new WXEngineAudioSource(audioSource), audioSource));
                }
            }

            Rigidbody rigidbody = go.GetComponent <Rigidbody>();

            if (rigidbody != null)
            {
                //obj.components.Add(context.AddComponent(new WXRigidbody(rigidbody), rigidbody));
                obj.components.Add(context.AddComponent(new WXUnityComponent(rigidbody), rigidbody));
            }


            /**
             * 下面的Component为adaptor对齐unity,但引擎也有类似Component的组件
             * 需要在WXUnityComponent中对应做处理,增加ref对象指向对应引擎对象
             */

            obj.components.Add(context.AddComponent(new WXUnityComponent(go.transform), go.transform));

            // Particle System
            ParticleSystem particle = go.GetComponent <ParticleSystem>();

            if (particle != null)
            {
                //Debug.Log("addComponentParticleSystem");
                obj.components.Add(context.AddComponent(new WXUnityComponent(particle), particle));
            }

            // Animator
            Animator animator = go.GetComponent <Animator>();

            if (animator != null)
            {
                obj.components.Add(context.AddComponent(new WXUnityComponent(animator), animator));
            }

            // Animation
            Animation animation = go.GetComponent <Animation>();

            if (animation != null)
            {
                obj.components.Add(context.AddComponent(new WXUnityComponent(animation), animation));
            }

            // Renderers
            Renderer renderer = go.GetComponent <Renderer>();

            if (renderer != null)
            {
                if (renderer is MeshRenderer)
                {
                    obj.components.Add(context.AddComponent(new WXUnityComponent((MeshRenderer)renderer), renderer));
                    // 由于引擎没有MeshFilter组件,这里强制在导出MeshRenderer的时候带上一个MeshFilter
                    obj.components.Add(context.AddComponent(new WXMeshFilter(), renderer));
                }
                else if (renderer is LineRenderer)
                {
                    obj.components.Add(context.AddComponent(new WXUnityComponent((LineRenderer)renderer), renderer));
                }
                else if (renderer is SkinnedMeshRenderer)
                {
                    obj.components.Add(context.AddComponent(new WXUnityComponent((SkinnedMeshRenderer)renderer), renderer));
                    obj.components.Add(context.AddComponent(new WXMeshFilter(), renderer));
                }
            }

            // Camera
            Camera camera = go.GetComponent <Camera>();

            if (camera != null)
            {
                obj.components.Add(context.AddComponent(new WXUnityComponent(camera), camera));
            }

            // Light
            Light light = go.GetComponent <Light>();

            if (light != null)
            {
                obj.components.Add(context.AddComponent(new WXUnityComponent(light), light));
            }
        }
コード例 #27
0
        private static void IteratePuertsComponent(GameObject go, WXEntity obj, WXHierarchyContext context, ExportPreset preset)
        {
            PuertsBeefBallBehaviour[] behaviours = go.GetComponents <PuertsBeefBallBehaviour>();

            if (context.preset.presetKey == "scene" && go.transform.parent == null)
            {
                obj.components.Add(context.AddComponent(new PuertsBeefBallRootBehaviour(), null));
            }

            if (behaviours.Length != 0)
            {
                foreach (PuertsBeefBallBehaviour behaviour in behaviours)
                {
                    obj.components.Add(context.AddComponent(new PuertsBeefBallBehaviourConverter(behaviour), behaviour));
                }
            }

            /**
             * 下面的Component为adaptor对齐unity,但引擎也有类似Component的组件
             * 需要在WXUnityComponent中对应做处理,增加ref对象指向对应引擎对象
             */

            obj.components.Add(context.AddComponent(new WXUnityComponent(go.transform), go.transform));

            // Particle System
            ParticleSystem particle = go.GetComponent <ParticleSystem>();

            if (particle != null)
            {
                //Debug.Log("addComponentParticleSystem");
                obj.components.Add(context.AddComponent(new WXUnityComponent(particle), particle));
            }

            // Animator
            Animator animator = go.GetComponent <Animator>();

            if (animator != null)
            {
                obj.components.Add(context.AddComponent(new WXUnityComponent(animator), animator));
            }

            // Animation
            Animation animation = go.GetComponent <Animation>();

            if (animation != null)
            {
                obj.components.Add(context.AddComponent(new WXUnityComponent(animation), animation));
            }

            // Renderers
            Renderer renderer = go.GetComponent <Renderer>();

            if (renderer != null)
            {
                if (renderer is MeshRenderer)
                {
                    obj.components.Add(context.AddComponent(new WXUnityComponent((MeshRenderer)renderer), renderer));
                    // 由于引擎没有MeshFilter组件,这里强制在导出MeshRenderer的时候带上一个MeshFilter
                    obj.components.Add(context.AddComponent(new WXMeshFilter(), renderer));
                }
                else if (renderer is LineRenderer)
                {
                    obj.components.Add(context.AddComponent(new WXUnityComponent((LineRenderer)renderer), renderer));
                }
                else if (renderer is SkinnedMeshRenderer)
                {
                    obj.components.Add(context.AddComponent(new WXUnityComponent((SkinnedMeshRenderer)renderer), renderer));
                    obj.components.Add(context.AddComponent(new WXMeshFilter(), renderer));
                }
            }

            // Camera
            Camera camera = go.GetComponent <Camera>();

            if (camera != null)
            {
                obj.components.Add(context.AddComponent(new WXUnityComponent(camera), camera));
            }

            // Light
            Light light = go.GetComponent <Light>();

            if (light != null)
            {
                obj.components.Add(context.AddComponent(new WXUnityComponent(light), light));
            }

            // Colliders
            // Collider[] colliders = go.GetComponents<Collider>();
            // if (colliders != null && colliders.Length > 0)
            // {
            //     foreach (var collider in colliders)
            //     {
            //         if (collider is BoxCollider)
            //         {
            //             //obj.components.Add(context.AddComponent(new WXBoxCollider((BoxCollider)collider), collider));
            //             obj.components.Add(context.AddComponent(new WXUnityComponent(collider), collider));
            //         }
            //         else if (collider is SphereCollider)
            //         {
            //             //obj.components.Add(context.AddComponent(new WXSphereCollider((SphereCollider)collider), collider));
            //             obj.components.Add(context.AddComponent(new WXUnityComponent(collider), collider));
            //         }
            //         else if (collider is CapsuleCollider)
            //         {
            //             //obj.components.Add(context.AddComponent(new WXCapsuleCollider((CapsuleCollider)collider), collider));
            //             obj.components.Add(context.AddComponent(new WXUnityComponent(collider), collider));
            //         }
            //         else if (collider is MeshCollider)
            //         {
            //             //obj.components.Add(context.AddComponent(new WXMeshCollider((MeshCollider)collider), collider));
            //             obj.components.Add(context.AddComponent(new WXUnityComponent(collider), collider));
            //         }
            //     }
            // }
            // Colliders
            Collider[] colliders = go.GetComponents <Collider>();
            if (colliders != null && colliders.Length > 0)
            {
                foreach (var collider in colliders)
                {
                    if (collider is BoxCollider)
                    {
                        obj.components.Add(context.AddComponent(new WXBoxCollider((BoxCollider)collider), collider));
                    }
                    else if (collider is SphereCollider)
                    {
                        obj.components.Add(context.AddComponent(new WXSphereCollider((SphereCollider)collider), collider));
                    }
                    else if (collider is CapsuleCollider)
                    {
                        obj.components.Add(context.AddComponent(new WXCapsuleCollider((CapsuleCollider)collider), collider));
                    }
                    else if (collider is MeshCollider)
                    {
                        obj.components.Add(context.AddComponent(new WXMeshCollider((MeshCollider)collider), collider));
                    }
                }
            }

            Rigidbody rigidbody = go.GetComponent <Rigidbody>();

            if (rigidbody != null)
            {
                obj.components.Add(context.AddComponent(new WXRigidbody(rigidbody), rigidbody));
            }
        }
コード例 #28
0
        private static void IterateUGUIScriptComponent(GameObject go, WXEntity obj, WXHierarchyContext context, ExportPreset preset)
        {
            Text text = go.GetComponent <Text>();

            if (text != null)
            {
                obj.components.Add(context.AddComponent(new WXUIULabelScript(text, go, obj), text));
            }

            Image image = go.GetComponent <Image>();

            if (image != null)
            {
                obj.components.Add(context.AddComponent(new WXUIUSpriteScript(image, go, obj), image));
            }

            Button button = go.GetComponent <Button>();

            if (button != null)
            {
                obj.components.Add(context.AddComponent(new WXUIUButtonScript(button, go, obj), button));
            }

            Slider slider = go.GetComponent <Slider>();

            if (slider != null)
            {
                obj.components.Add(context.AddComponent(new WXUIUSliderScript(slider, go, obj), slider));
            }

            Toggle toggle = go.GetComponent <Toggle>();

            if (toggle != null)
            {
                obj.components.Add(context.AddComponent(new WXUIUToggleScript(toggle, go, obj), toggle));
            }

            ToggleGroup toggleGroup = go.GetComponent <ToggleGroup>();

            if (toggleGroup != null)
            {
                obj.components.Add(context.AddComponent(new WXUIUToggleGroupScript(toggleGroup, go, obj), toggleGroup));
            }

            ScrollRect scrollRect = go.GetComponent <ScrollRect>();

            if (scrollRect != null)
            {
                obj.components.Add(context.AddComponent(new WXUIUScrollRectScript(scrollRect, go, obj), scrollRect));
            }

            CanvasScaler canvasScaler = go.GetComponent <CanvasScaler>();

            if (canvasScaler != null)
            {
                obj.components.Add(context.AddComponent(new WXUIUCanvasScalerScript(canvasScaler, go, obj), canvasScaler));
            }

            InputField input = go.GetComponent <InputField>();

            if (input != null)
            {
                obj.components.Add(context.AddComponent(new WXUIUInputFieldScript(input, go, obj), input));
            }
        }
コード例 #29
0
        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("ref", context.AddComponent(new WXUIButton(uiButton, go, entity), uiButton));

            JSONObject onClick = new JSONObject(JSONObject.Type.ARRAY);

            data.AddField("onClick", onClick);

            JSONObject colorPressed = new JSONObject(JSONObject.Type.ARRAY);

            colorPressed.Add(255f * uiButton.pressed.r);
            colorPressed.Add(255f * uiButton.pressed.g);
            colorPressed.Add(255f * uiButton.pressed.b);
            colorPressed.Add(255f * uiButton.pressed.a);
            data.AddField("pressedColor", colorPressed);

            JSONObject colorDisabledColor = new JSONObject(JSONObject.Type.ARRAY);

            colorDisabledColor.Add(255f * uiButton.disabledColor.r);
            colorDisabledColor.Add(255f * uiButton.disabledColor.g);
            colorDisabledColor.Add(255f * uiButton.disabledColor.b);
            colorDisabledColor.Add(255f * uiButton.disabledColor.a);
            data.AddField("disabledColor", colorDisabledColor);

            if (uiButton.tweenTarget != null)
            {
                JSONObject colorNormal = new JSONObject(JSONObject.Type.ARRAY);
                var        mWidget     = uiButton.tweenTarget.GetComponent <UIWidget>();
                colorNormal.Add(255f * mWidget.color.r);
                colorNormal.Add(255f * mWidget.color.g);
                colorNormal.Add(255f * mWidget.color.b);
                colorNormal.Add(255f * mWidget.color.a);
                data.AddField("normalColor", colorNormal);
            }

            // onClick
            // onClick.AddField("");
            foreach (var click in uiButton.onClick)
            {
                var __onClick = new JSONObject(JSONObject.Type.OBJECT);
                // var target = new JSONObject(JSONObject.Type.OBJECT);
                // target.AddField(click.target.GetType().FullName.EscapeNamespaceSimple(), context.AddComponent(new WXEngineMonoBehaviour(click.target), click.target));
                // onClick.AddField("target", WXMonoBehaviourPropertiesHandler.InvokePropertyHandler(typeof(UnityEngine.MonoBehaviour), click.target, context));
                __onClick.AddField("target", context.AddComponent(new WXEngineMonoBehaviour(click.target), click.target));
                __onClick.AddField("method", click.methodName);

                var _params = new JSONObject(JSONObject.Type.ARRAY);
                __onClick.AddField("params", _params);
                if (click.parameters != null)
                {
                    foreach (var p in click.parameters)
                    {
                        if (p.obj != null)
                        {
                            _params.Add(WXMonoBehaviourPropertiesHandler.InvokePropertyHandler(p.expectedType, p.obj, context));
                        }
                    }
                }

                onClick.Add(__onClick);
            }

            return(json);
        }
コード例 #30
0
        private static void Iterate3DComponent(GameObject go, WXEntity obj, WXHierarchyContext context, ExportPreset preset)
        {
            // 导UI的时候报bug,先注释掉

            MonoBehaviour[] scripts = go.GetComponents <MonoBehaviour>();
            foreach (MonoBehaviour script in scripts)
            {
                if (script == null)
                {
                    continue;
                }
                string __uuid = "";
                Type   type   = script.GetType();
                // 从public property中获取tsPath属性
                foreach (System.Reflection.FieldInfo fieldInfo in type.GetFields())
                {
                    if (fieldInfo.Name == "__beefballSerialize" && (string)fieldInfo.GetValue(script) != "")
                    {
                        __uuid = (string)fieldInfo.GetValue(script);
                    }
                }
                // 从attribute中获取的tsPath属性
                // foreach (System.Object attributes in type.GetCustomAttributes(false))
                // {
                //     BeefballSerialize bs = (BeefballSerialize)attributes;
                //     if (bs != null)
                //     {
                //         __uuid = bs.__beefballSerialize;
                //     }
                // }
                // __uuid是导出标签,只有找到__uuid属性,才加入到components列表
                if (__uuid != "" && __uuid != null)
                {
                    obj.components.Add(context.AddComponent(new WXScript(script, go, __uuid), script));
                }
            }

            ParticleSystem particle = go.GetComponent <ParticleSystem>();

            if (particle != null)
            {
                //Debug.Log("addComponentParticleSystem");
                obj.components.Add(context.AddComponent(new WXParticleSystem(particle, go), particle));
            }

            MeshRenderer meshRenderer = go.GetComponent(typeof(MeshRenderer)) as MeshRenderer;

            if ((UnityEngine.Object)meshRenderer != (UnityEngine.Object)null)
            {
                obj.components.Add(context.AddComponent(new WXMeshRenderer(meshRenderer), meshRenderer));
            }

            LineRenderer lineRenderer = go.GetComponent(typeof(LineRenderer)) as LineRenderer;

            if ((UnityEngine.Object)lineRenderer != (UnityEngine.Object)null)
            {
                obj.components.Add(context.AddComponent(new WXLineRenderer(lineRenderer), lineRenderer));
            }

            TrailRenderer trailRenderer = go.GetComponent(typeof(TrailRenderer)) as TrailRenderer;

            if ((UnityEngine.Object)trailRenderer != (UnityEngine.Object)null)
            {
                obj.components.Add(context.AddComponent(new WXTrailRenderer(trailRenderer), trailRenderer));
            }

            SkinnedMeshRenderer skinnedMeshRenderer = go.GetComponent(typeof(SkinnedMeshRenderer)) as SkinnedMeshRenderer;

            if ((UnityEngine.Object)skinnedMeshRenderer != (UnityEngine.Object)null)
            {
                obj.components.Add(context.AddComponent(new WXSkinnedMeshRenderer(skinnedMeshRenderer), skinnedMeshRenderer));
            }

            Animator animator = go.GetComponent(typeof(Animator)) as Animator;

            if ((UnityEngine.Object)animator != (UnityEngine.Object)null)
            {
                obj.components.Add(context.AddComponent(new WXAnimator(animator, go), animator));
            }

            Animation animation = go.GetComponent(typeof(Animation)) as Animation;

            if ((UnityEngine.Object)animation != (UnityEngine.Object)null)
            {
                obj.components.Add(context.AddComponent(new WXAnimation(animation, go), animation));
            }

            // DirectionalLight,
            // PointLight,
            // SpotLight,

            Light light = go.GetComponent(typeof(Light)) as Light;

            if ((UnityEngine.Object)light != (UnityEngine.Object)null)
            {
                // baked的灯光不导出
                bool isBaked = false;
#if UNITY_5_6_OR_NEWER
                isBaked = light.lightmapBakeType == LightmapBakeType.Baked;
#else
                isBaked = light.lightmappingMode == LightmappingMode.Baked;
#endif
                if (!isBaked)
                {
                    obj.components.Add(context.AddComponent(new WXLight(light), light));
                }
            }

            Camera camera = go.GetComponent(typeof(Camera)) as Camera;
            if (camera != null)
            {
                obj.components.Add(context.AddComponent(new WXCamera(camera), camera));
            }

            WXPostProcess postProcess = go.GetComponent <WXPostProcess>();
            if (postProcess != null)
            {
                obj.components.Add(context.AddComponent(new WXEnginePostProcess(postProcess), postProcess));
            }

            // obj.active = go.activeSelf;
            if (!preset.is2d)
            {
                obj.components.Add(context.AddComponent(new WXTransform3DComponent(go.transform), go.transform));
            }


            WXRawResourceCollection collection = go.GetComponent <WXRawResourceCollection>();
            if ((UnityEngine.Object)collection != (UnityEngine.Object)null)
            {
                obj.components.Add(context.AddComponent(new WXEngineRawResourceCollection(collection), collection));
            }
        }