Exemplo n.º 1
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));
            }
        }
Exemplo n.º 2
0
        protected override JSONObject ToJSON(WXHierarchyContext context)
        {
            JSONObject json = new JSONObject(JSONObject.Type.OBJECT);

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


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

            var activeSprite = uiToggle.activeSprite;

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

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

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

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

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

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

            json.AddField("data", subJSON);

            return(json);
        }
        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);
        }
Exemplo n.º 4
0
        // 一个LOD里的renderer可能有多种renderer: meshRenderer\lineRenderer等
        private string HandleRenderer(JSONObject rendererList, Renderer renderer, WXHierarchyContext context)
        {
            GameObject   go             = renderer.gameObject;
            MeshRenderer meshRenderer   = go.GetComponent(typeof(MeshRenderer)) as MeshRenderer;
            string       targetRenderer = "";

            if ((UnityEngine.Object)meshRenderer != (UnityEngine.Object)null)
            {
                targetRenderer = context.AddComponentInProperty(
                    new WXMeshRenderer(meshRenderer),
                    meshRenderer
                    );
                rendererList.Add(targetRenderer);
            }
            LineRenderer lineRenderer = go.GetComponent(typeof(LineRenderer)) as LineRenderer;

            if ((UnityEngine.Object)lineRenderer != (UnityEngine.Object)null)
            {
                targetRenderer = context.AddComponentInProperty(
                    new WXLineRenderer(lineRenderer),
                    lineRenderer
                    );
                rendererList.Add(targetRenderer);
            }
            TrailRenderer trailRenderer = go.GetComponent(typeof(TrailRenderer)) as TrailRenderer;

            if ((UnityEngine.Object)trailRenderer != (UnityEngine.Object)null)
            {
                targetRenderer = context.AddComponentInProperty(
                    new WXTrailRenderer(trailRenderer),
                    trailRenderer
                    );
                rendererList.Add(targetRenderer);
            }
            SkinnedMeshRenderer skinnedMeshRenderer = go.GetComponent(typeof(SkinnedMeshRenderer)) as SkinnedMeshRenderer;

            if ((UnityEngine.Object)skinnedMeshRenderer != (UnityEngine.Object)null)
            {
                targetRenderer = context.AddComponentInProperty(
                    new WXSkinnedMeshRenderer(skinnedMeshRenderer),
                    skinnedMeshRenderer
                    );
                rendererList.Add(targetRenderer);
            }
            return(targetRenderer);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        protected override JSONObject ToJSON(WXHierarchyContext context)
        {
            JSONObject json = new JSONObject(JSONObject.Type.OBJECT);

            json.AddField("type", "UIWidget");
            JSONObject data = new JSONObject(JSONObject.Type.OBJECT);

            data.AddField("execute", (int)uiWidget.updateAnchors);

            data.AddField("leftAnchor", (float)uiWidget.leftAnchor.relative);
            if (uiWidget.leftAnchor.target != null)
            {
                data.AddField("leftAnchorTarget",
                              context.AddComponentInProperty(
                                  new WXTransform2DComponent(uiWidget.leftAnchor.target),
                                  uiWidget.leftAnchor.target
                                  )
                              );
            }
            data.AddField("leftOffset", (int)uiWidget.leftAnchor.absolute);

            data.AddField("rightAnchor", (float)uiWidget.rightAnchor.relative);
            if (uiWidget.rightAnchor.target != null)
            {
                data.AddField("rightAnchorTarget",
                              context.AddComponentInProperty(
                                  new WXTransform2DComponent(uiWidget.rightAnchor.target),
                                  uiWidget.rightAnchor.target
                                  )
                              );
            }
            data.AddField("rightOffset", (int)uiWidget.rightAnchor.absolute);

            data.AddField("bottomAnchor", (float)uiWidget.bottomAnchor.relative);
            if (uiWidget.bottomAnchor.target != null)
            {
                data.AddField("bottomAnchorTarget",
                              context.AddComponentInProperty(
                                  new WXTransform2DComponent(uiWidget.bottomAnchor.target),
                                  uiWidget.bottomAnchor.target
                                  )
                              );
            }
            data.AddField("bottomOffset", (int)uiWidget.bottomAnchor.absolute);

            data.AddField("topAnchor", (float)uiWidget.topAnchor.relative);
            if (uiWidget.topAnchor.target != null)
            {
                data.AddField("topAnchorTarget",
                              context.AddComponentInProperty(
                                  new WXTransform2DComponent(uiWidget.topAnchor.target),
                                  uiWidget.topAnchor.target
                                  )
                              );
            }
            data.AddField("topOffset", (int)uiWidget.topAnchor.absolute);

            json.AddField("data", data);
            return(json);


            //JSONObject data = new JSONObject(JSONObject.Type.OBJECT);

            /* if (uiWidget.rawPivot.ToString() == "Left")
             * {
             *  transform.anchor[0] = 0;
             *
             * } else if (uiWidget.rawPivot.ToString() == "Right")
             * {
             *  transform.anchor[0] = 1;
             * } else if (uiWidget.rawPivot.ToString() == "Center")
             * {
             *  // transform.anchor[0] = 0.5;
             * }
             *
             * if (uiWidget.pivot.ToString() == "Top")
             * {
             *  transform.anchor[1] = 0;
             * }
             * else if (uiWidget.pivot.ToString() == "Bottom")
             * {
             *  transform.anchor[1] = 1;
             * }
             * else if (uiWidget.pivot.ToString() == "Center")
             * {
             *  // transform.anchor[1] = 0.5;
             * }*/

            //json.AddField("data", data);

            //if (uiWidget.isAnchored == true)
            //{
            //    Debug.Log(uiWidget.name);
            //    if (uiWidget.parent == uiWidget.topAnchor.target)
            //    {
            //        data.AddField("topMargin", uiWidget.topAnchor.absolute);
            //    }
            //    if (uiWidget.parent == uiWidget.leftAnchor.target)
            //    {
            //        data.AddField("leftMargin", uiWidget.leftAnchor.absolute);
            //    }
            //    if (uiWidget.parent == uiWidget.rightAnchor.target)
            //    {
            //        data.AddField("rightMargin", uiWidget.rightAnchor.absolute);
            //    }
            //    if (uiWidget.parent == uiWidget.bottomAnchor.target)
            //    {
            //        data.AddField("bottomMargin", uiWidget.bottomAnchor.absolute);
            //    }
            //}

            //if(uiWidget.name == "GemFull")
            //{
            //    Debug.Log(uiWidget);
            //}
        }
Exemplo n.º 8
0
        protected override JSONObject ToJSON(WXHierarchyContext context)
        {
            JSONObject json        = new JSONObject(JSONObject.Type.OBJECT);
            JSONObject data        = new JSONObject(JSONObject.Type.OBJECT);
            JSONObject bindingsArr = new JSONObject(JSONObject.Type.OBJECT);

            json.AddField("type", getTypeName());
            json.AddField("data", data);
            int timeUpdateMode;

            UpdateMode.TryGetValue(playableDirector.timeUpdateMode, out timeUpdateMode);
            data.AddField("timeUpdateMode", timeUpdateMode);
            data.AddField("playOnAwake", playableDirector.playOnAwake); // 貌似unity怎么搞playOnAwake都是false
            int wrapMode;

            WrapMode.TryGetValue(playableDirector.extrapolationMode, out wrapMode);
            data.AddField("wrapMode", wrapMode);
            data.AddField("initialTime", (float)playableDirector.initialTime);
            data.AddField("duration", (float)playableDirector.duration);
            data.AddField("sceneBindings", bindingsArr);

            TimelineAsset timelineAsset = (TimelineAsset)playableDirector.playableAsset;

            if ((UnityEngine.Object)timelineAsset != (UnityEngine.Object)null && timelineAsset.outputTrackCount > 0) // 有output
            {
                WXTimelineAssets converter         = new WXTimelineAssets(timelineAsset, gameObject);
                string           timelineAssetPath = converter.Export(context.preset);
                if (timelineAssetPath != null && timelineAssetPath != "")
                {
                    data.AddField("playableAsset", timelineAssetPath);
                    context.AddResource(timelineAssetPath);
                    string playableAssetPath = AssetDatabase.GetAssetPath(timelineAsset); // timeline资源路径
                    IEnumerator <PlayableBinding> outputsEnumerator = timelineAsset.outputs.GetEnumerator();
                    List <TrackAsset>             outputTracks      = timelineAsset.GetOutputTracks().ToList();;
                    int num = 0;
                    while (outputsEnumerator.MoveNext()) // 遍历bindings
                    {
                        JSONObject      bindingData  = new JSONObject(JSONObject.Type.OBJECT);
                        PlayableBinding binding      = (PlayableBinding)outputsEnumerator.Current;
                        var             sourceObject = playableDirector.GetGenericBinding(binding.sourceObject); // 获取binding里sourceobject对应的entity
                        string          componentId  = "";
                        string          localId      = WXTimelineAssets.GetTrackLocalIdByInstanceID(playableAssetPath, outputTracks[num].GetInstanceID());
                        if ((UnityEngine.Object)sourceObject != (UnityEngine.Object)null)
                        {
                            if (binding.sourceObject.GetType() == typeof(ActivationTrack)) // active track绑定的是entity
                            {
                                Transform transform = (sourceObject as GameObject).GetComponent(typeof(Transform)) as Transform;
                                componentId = context.AddComponentInProperty(
                                    new WXTransform3DComponent(transform),
                                    transform
                                    );
                            }
                            else if (binding.sourceObject.GetType() == typeof(AudioTrack)) // audio track 绑定AudioSource
                            {
                                componentId = context.AddComponentInProperty(
                                    new WXAudioSource((AudioSource)sourceObject, (GameObject)(sourceObject as AudioSource).gameObject),
                                    (AudioSource)sourceObject
                                    );
                            }
                            else if (binding.sourceObject.GetType() == typeof(AnimationTrack)) // animation track 绑定Animator
                            {
                                Animator animator;
                                if (sourceObject.GetType() == typeof(Animator))
                                {
                                    animator    = sourceObject as Animator;
                                    componentId = context.AddComponentInProperty(
                                        new WXAnimator(animator, (sourceObject as Animator).gameObject),
                                        animator
                                        );
                                }
                                else
                                {
                                    animator    = (sourceObject as GameObject).GetComponent <Animator>();
                                    componentId = context.AddComponentInProperty(
                                        new WXAnimator(animator, (GameObject)sourceObject),
                                        animator
                                        );
                                }
                            }
                            else
                            {
                                EditorUtility.DisplayDialog("Error", "导出的Playable Director Bingdings格式不支持", "确定");
                                componentId = "";
                            }
                        }
                        else
                        {
                            componentId = "";
                        }
                        if (string.IsNullOrEmpty(componentId))
                        {
                            bindingsArr.AddField(localId, JSONObject.nullJO);
                        }
                        else
                        {
                            bindingsArr.AddField(localId, componentId);
                        }

                        num++;
                    }
                }
            }
            else
            {
                data.AddField("playableAsset", JSONObject.nullJO);
            }
            return(json);
        }