Example #1
0
        private static JSONObject GetPrefabOnSerializedField(WXHierarchyContext context, GameObject go, JSONObject innerData, bool isGameObject = true, Component comp = null)
        {
            // Prefab?
            var path = AssetDatabase.GetAssetPath(go);

            if (go.transform.IsChildOf(context.Root.transform) || path == "")
            {
                GetGameObjectReferenceIndex(context, go, ref innerData, isGameObject);
                return(innerData);
            }

            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);
            var typeName        = comp ? comp.GetType().FullName : "UnityEngine.GameObject";
            var escapedTypeName = WXMonoBehaviourExportHelper.EscapeNamespace(typeName);

            prefabInfo.AddField("type", escapedTypeName);
            prefabInfo.AddField("path", path);

            innerData.AddField("type", "UnityPrefabWrapper");
            innerData.AddField("value", prefabInfo);
            return(innerData);

            // GetGameObjectReferenceIndex(context, go, ref innerData, isGameObject);
            // return innerData;
        }
Example #2
0
        public override string getTypeName()
        {
            string result;

            if (audio)
            {
                result = this.audio.GetType().ToString();
            }
            else
            {
                result = "UnityEngine.AudioSource";
            }
            return(WXMonoBehaviourExportHelper.EscapeNamespace(result));
        }
Example #3
0
        private static void RegisterUnityProperties()
        {
            AddPropertyHandler(typeof(Vector2), (obj, context) => {
                Vector2 v = (Vector2)obj;
                if (v == null)
                {
                    return(null);
                }

                JSONObject vec2 = new JSONObject(JSONObject.Type.ARRAY);
                vec2.Add(v.x);
                vec2.Add(v.y);

                return(vec2);
            });

            AddPropertyHandler(typeof(Vector3), (obj, context) => {
                Vector3 v = (Vector3)obj;
                if (v == null)
                {
                    return(null);
                }

                JSONObject vec3 = new JSONObject(JSONObject.Type.ARRAY);
                vec3.Add(v.x);
                vec3.Add(v.y);
                vec3.Add(v.z);

                return(vec3);
            });

            AddPropertyHandler(typeof(Vector4), (obj, context) => {
                Vector4 v = (Vector4)obj;
                if (v == null)
                {
                    return(null);
                }

                JSONObject vec4 = new JSONObject(JSONObject.Type.ARRAY);
                vec4.Add(v.x);
                vec4.Add(v.y);
                vec4.Add(v.z);
                vec4.Add(v.w);

                return(vec4);
            });

            AddPropertyHandler(typeof(Quaternion), (obj, context) => {
                Quaternion v = (Quaternion)obj;
                if (v == null)
                {
                    return(null);
                }

                JSONObject array4 = new JSONObject(JSONObject.Type.ARRAY);
                array4.Add(v.x);
                array4.Add(v.y);
                array4.Add(v.z);
                array4.Add(v.w);

                return(array4);
            });


            AddPropertyHandler(typeof(Matrix4x4), (obj, context) => {
                Matrix4x4 v = (Matrix4x4)obj;
                if (v == null)
                {
                    return(null);
                }

                JSONObject array16 = new JSONObject(JSONObject.Type.ARRAY);
                array16.Add(v.m00);
                array16.Add(v.m01);
                array16.Add(v.m02);
                array16.Add(v.m03);
                array16.Add(v.m10);
                array16.Add(v.m11);
                array16.Add(v.m12);
                array16.Add(v.m13);
                array16.Add(v.m20);
                array16.Add(v.m21);
                array16.Add(v.m22);
                array16.Add(v.m23);
                array16.Add(v.m30);
                array16.Add(v.m31);
                array16.Add(v.m32);
                array16.Add(v.m33);

                return(array16);
            });

            AddPropertyHandler(typeof(Color), (obj, context) => {
                Color c = (Color)obj;
                if (c == null)
                {
                    return(null);
                }

                JSONObject vec4 = new JSONObject(JSONObject.Type.ARRAY);
                vec4.Add((int)(c.r * 255));
                vec4.Add((int)(c.g * 255));
                vec4.Add((int)(c.b * 255));
                vec4.Add((int)(c.a * 255));

                return(vec4);
            });

            AddPropertyHandler(typeof(TextAsset), (obj, context) => {
                TextAsset t = (TextAsset)obj;
                if (!t)
                {
                    return(null);
                }

                string path = AssetDatabase.GetAssetPath(t);
                // string copyToPath = Path.Combine(WXResourceStore.storagePath, path);
                // Debug.Log("WXResourceStore.storagePath:" + WXResourceStore.storagePath);
                // Debug.Log("path:" + path);
                // Debug.Log("copyToPath:" + copyToPath);

                // Regex regex = new Regex(".txt$");
                // copyToPath = regex.Replace(copyToPath, ".json");

                // if (!Directory.Exists(WXResourceStore.storagePath + "Assets/")) {
                //     Directory.CreateDirectory(WXResourceStore.storagePath + "Assets/");
                // }

                // FileStream fs = new FileStream(copyToPath, FileMode.Create, FileAccess.Write);

                // wxFileUtil.WriteData(fs, JsonConvert.SerializeObject(new { text = t.text }));
                // fs.Close();

                JSONObject json = new JSONObject(JSONObject.Type.OBJECT);
                JSONObject data = new JSONObject(JSONObject.Type.OBJECT);
                // Debug.Log("JsonConvert.SerializeObject(t.text): " + JsonConvert.SerializeObject(t.text));
                string text = JsonConvert.SerializeObject(t.text);
                // 去掉首尾双引号
                text = text.Remove(0, 1);
                text = text.Substring(0, text.Length - 1);
                data.AddField("text", text);
                data.AddField("path", path);
                json.AddField("type", "UnityEngine.TextAsset".EscapeNamespaceSimple());
                json.AddField("value", data);
                return(json);
            });

            AddPropertyHandler(typeof(Material), (obj, context) => {
                Material material = (Material)obj;
                if (material == null)
                {
                    return(null);
                }

                WXMaterial materialConverter = new WXMaterial(material, null);
                string materialPath          = materialConverter.Export(context.preset);
                context.AddResource(materialPath);

                JSONObject json = new JSONObject(JSONObject.Type.OBJECT);
                JSONObject data = new JSONObject(JSONObject.Type.OBJECT);
                json.AddField("type", "UnityEngine.Material".EscapeNamespaceSimple());
                json.AddField("value", data);
                data.AddField("path", materialPath);

                return(json);
            });

            AddPropertyHandler(typeof(List <>), (obj, context) => {
                IEnumerable list = (IEnumerable)obj;
                if (list == null)
                {
                    return(null);
                }

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

                var enumerator = ((IEnumerable)list).GetEnumerator();
                while (enumerator.MoveNext())
                {
                    object itemObj = enumerator.Current;
                    if (itemObj == null)
                    {
                        continue;
                    }
                    if (itemObj.GetType() == typeof(List <>))
                    {
                        throw new Exception("List不支持嵌套");
                    }
                    else
                    {
                        Type type = itemObj.GetType();

                        if (type.IsSubclassOf(typeof(UnityEngine.Component)) || type == typeof(UnityEngine.GameObject))
                        {
                            var o         = (UnityEngine.Object)itemObj;
                            GameObject go = null;
                            if (o == null)
                            {
                                continue;
                            }
                            if (type.IsSubclassOf(typeof(UnityEngine.Component)))
                            {
                                go = ((Component)o).gameObject;
                            }
                            else if (type == typeof(UnityEngine.GameObject))
                            {
                                go = (GameObject)o;
                            }

                            var path = AssetDatabase.GetAssetPath(o);

                            // Prefab?
                            if (go.transform.IsChildOf(context.Root.transform) || path == "")
                            {
                                if (!propertiesHandlerDictionary.ContainsKey(type) && !type.IsArray && (!type.IsGenericType || type.GetGenericTypeDefinition() != typeof(List <>)) && type.IsSerializable)
                                {
                                    var sobj = new JSONObject(JSONObject.Type.OBJECT);
                                    result.Add(sobj);
                                    SerializableHandler(type, sobj, itemObj, context);
                                }
                                else if (type != typeof(System.Object) && propertiesHandlerDictionary.ContainsKey(type))
                                {
                                    var res = propertiesHandlerDictionary[type](itemObj, context);
                                    result.Add(res);
                                }
                                continue;
                            }

                            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);
                            result.Add(innerData);
                        }
                        else if (!propertiesHandlerDictionary.ContainsKey(type) && !type.IsArray && (!type.IsGenericType || type.GetGenericTypeDefinition() != typeof(List <>)) && type.IsSerializable)
                        {
                            var sobj = new JSONObject(JSONObject.Type.OBJECT);
                            result.Add(sobj);
                            SerializableHandler(type, sobj, itemObj, context);
                        }
                        else if (type != typeof(System.Object) && propertiesHandlerDictionary.ContainsKey(type))
                        {
                            var res = propertiesHandlerDictionary[type](itemObj, context);
                            result.Add(res);
                        }
                    }
                }
                return(result);
            });

            // disgusting code logic :(
            // refactor should be needed
            AddPropertyHandler(typeof(MonoBehaviour), (obj, context) => {
                var m = (MonoBehaviour)obj;
                if (!m)
                {
                    return(null);
                }

                if (ExportLogger.LOGGING)
                {
                    ExportLogger.AddLog(new ExportLogger.Log(ExportLogger.Log.Type.Property, "Object: " + obj + "\nType: " + obj.GetType()));
                }

                var go = m.gameObject;
                JSONObject innerData = new JSONObject(JSONObject.Type.OBJECT);

                var path = AssetDatabase.GetAssetPath(go);

                // Prefab?
                if (go.transform.IsChildOf(context.Root.transform) || path == "")
                {
                    var typeName        = m.GetType().FullName;
                    var escapedTypeName = WXMonoBehaviourExportHelper.EscapeNamespace(typeName);
                    innerData.AddField("type", escapedTypeName);
                    innerData.AddField("value", context.AddComponentInProperty(new WXEngineMonoBehaviour(m), (Component)obj));
                    return(innerData);
                }

                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);

                {
                    var typeName        = m ? m.GetType().FullName : "UnityEngine.GameObject";
                    var escapedTypeName = WXMonoBehaviourExportHelper.EscapeNamespace(typeName);
                    prefabInfo.AddField("type", escapedTypeName);
                }
                prefabInfo.AddField("path", path);

                innerData.AddField("type", "UnityPrefabWrapper");
                innerData.AddField("value", prefabInfo);
                return(innerData);
            });

            AddPropertyHandler(typeof(Component), (obj, context) => {
                Component c = (Component)obj;
                if (!c)
                {
                    return(null);
                }

                if (ExportLogger.LOGGING)
                {
                    ExportLogger.AddLog(new ExportLogger.Log(ExportLogger.Log.Type.Property, "Object: " + obj + "\nType: " + obj.GetType()));
                }

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


                var escapedTypeName = WXMonoBehaviourExportHelper.EscapeNamespace(c.GetType().FullName);
                innerData.AddField("type", escapedTypeName);

                if (c is Transform)
                {
                    innerData = GetPrefabOnSerializedField(context, c.gameObject, innerData, false);
                }

                // 下面是adaptor独有的类才需要单独写
                // Physics
                //else if (c is BoxCollider) {
                //    innerData.AddField("value", context.AddComponent(new WXBoxCollider((BoxCollider)c), (BoxCollider)c));
                //} else if (c is SphereCollider) {
                //    innerData.AddField("value", context.AddComponent(new WXSphereCollider((SphereCollider)c), (SphereCollider)c));
                //} else if (c is CapsuleCollider) {
                //    innerData.AddField("value", context.AddComponent(new WXCapsuleCollider((CapsuleCollider)c), (CapsuleCollider)c));
                //} else if (c is MeshCollider) {
                //    innerData.AddField("value", context.AddComponent(new WXMeshCollider((MeshCollider)c), (MeshCollider)c));
                //} else if (c is Rigidbody) {
                //    innerData.AddField("value", context.AddComponent(new WXRigidbody((Rigidbody)c), (Rigidbody)c));
                //}

                else if (c is AudioSource)
                {
                    innerData.AddField("value", context.AddComponentInProperty(new WXEngineAudioSource((AudioSource)c), (AudioSource)c));
                }

                // 有ref的类
                else
                {
                    // if (context.componentDictionary.ContainsKey(c)) {
                    innerData.AddField("value", context.AddComponentInProperty(new WXUnityComponent(c), c));
                    // }
                }
                return(innerData);
            });

            AddPropertyHandler(typeof(GameObject), (obj, context) => {
                var go = (GameObject)obj;
                if (!go)
                {
                    return(null);
                }

                if (ExportLogger.LOGGING)
                {
                    ExportLogger.AddLog(new ExportLogger.Log(ExportLogger.Log.Type.Property, "Object: " + obj + "\nType: " + obj.GetType()));
                }

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

                return(GetPrefabOnSerializedField(context, go, innerData));
            });
        }
Example #4
0
        public override string getTypeName()
        {
            var result = rigidbody ? rigidbody.GetType().ToString() : "UnityEngine.Rigidbody";

            return(WXMonoBehaviourExportHelper.EscapeNamespace(result));
        }
Example #5
0
        public override string getTypeName()
        {
            var result = comp ? comp.GetType().ToString() : "UnityRefComponent";

            return(WXMonoBehaviourExportHelper.EscapeNamespace(result));
        }
Example #6
0
        private static void RegisterUnityProperties()
        {
            AddTypePropertyHandler(typeof(Vector2), (obj, context, requireList) =>
            {
                Vector2 v = (Vector2)obj;
                if (v == null)
                {
                    return(null);
                }

                JSONObject vec2 = new JSONObject(JSONObject.Type.ARRAY);
                vec2.Add(v.x);
                vec2.Add(v.y);

                return(vec2);
            });

            AddTypePropertyHandler(typeof(Vector3), (obj, context, requireList) =>
            {
                Vector3 v = (Vector3)obj;
                if (v == null)
                {
                    return(null);
                }

                JSONObject vec3 = new JSONObject(JSONObject.Type.ARRAY);
                vec3.Add(v.x);
                vec3.Add(v.y);
                vec3.Add(v.z);

                return(vec3);
            });

            AddTypePropertyHandler(typeof(Vector4), (obj, context, requireList) =>
            {
                Vector4 v = (Vector4)obj;
                if (v == null)
                {
                    return(null);
                }

                JSONObject vec4 = new JSONObject(JSONObject.Type.ARRAY);
                vec4.Add(v.x);
                vec4.Add(v.y);
                vec4.Add(v.z);
                vec4.Add(v.w);

                return(vec4);
            });

            AddTypePropertyHandler(typeof(Quaternion), (obj, context, requireList) =>
            {
                Quaternion v = (Quaternion)obj;
                if (v == null)
                {
                    return(null);
                }

                JSONObject array4 = new JSONObject(JSONObject.Type.ARRAY);
                array4.Add(v.x);
                array4.Add(v.y);
                array4.Add(v.z);
                array4.Add(v.w);

                return(array4);
            });


            AddTypePropertyHandler(typeof(Matrix4x4), (obj, context, requireList) =>
            {
                Matrix4x4 v = (Matrix4x4)obj;
                if (v == null)
                {
                    return(null);
                }

                JSONObject array16 = new JSONObject(JSONObject.Type.ARRAY);
                array16.Add(v.m00);
                array16.Add(v.m01);
                array16.Add(v.m02);
                array16.Add(v.m03);
                array16.Add(v.m10);
                array16.Add(v.m11);
                array16.Add(v.m12);
                array16.Add(v.m13);
                array16.Add(v.m20);
                array16.Add(v.m21);
                array16.Add(v.m22);
                array16.Add(v.m23);
                array16.Add(v.m30);
                array16.Add(v.m31);
                array16.Add(v.m32);
                array16.Add(v.m33);

                return(array16);
            });

            AddTypePropertyHandler(typeof(Color), (obj, context, requireList) =>
            {
                Color c = (Color)obj;
                if (c == null)
                {
                    return(null);
                }

                JSONObject vec4 = new JSONObject(JSONObject.Type.ARRAY);
                vec4.Add((int)(c.r * 255));
                vec4.Add((int)(c.g * 255));
                vec4.Add((int)(c.b * 255));
                vec4.Add((int)(c.a * 255));

                return(vec4);
            });

            AddTypePropertyHandler(typeof(TextAsset), (obj, context, requireList) =>
            {
                TextAsset t = (TextAsset)obj;
                if (!t)
                {
                    return(null);
                }

                string path = AssetDatabase.GetAssetPath(t);
                // string copyToPath = Path.Combine(WXResourceStore.storagePath, path);
                // Debug.Log("WXResourceStore.storagePath:" + WXResourceStore.storagePath);
                // Debug.Log("path:" + path);
                // Debug.Log("copyToPath:" + copyToPath);

                // Regex regex = new Regex(".txt$");
                // copyToPath = regex.Replace(copyToPath, ".json");

                // if (!Directory.Exists(WXResourceStore.storagePath + "Assets/")) {
                //     Directory.CreateDirectory(WXResourceStore.storagePath + "Assets/");
                // }

                // FileStream fs = new FileStream(copyToPath, FileMode.Create, FileAccess.Write);

                // wxFileUtil.WriteData(fs, JsonConvert.SerializeObject(new { text = t.text }));
                // fs.Close();

                JSONObject json = new JSONObject(JSONObject.Type.OBJECT);
                JSONObject data = new JSONObject(JSONObject.Type.OBJECT);
                // Debug.Log("JsonConvert.SerializeObject(t.text): " + JsonConvert.SerializeObject(t.text));
                string text = t.text.Replace("\r\n", "\\n").Replace("\\", "\\\\").Replace("\"", "\\\"");
                data.AddField("text", text);
                data.AddField("path", path);
                json.AddField("type", "UnityEngine.TextAsset".EscapeNamespaceSimple());
                json.AddField("value", data);
                return(json);
            });

            AddTypePropertyHandler(typeof(Material), (obj, context, requireList) =>
            {
                Material material = (Material)obj;
                if (material == null)
                {
                    return(null);
                }

                WXMaterial materialConverter = new WXMaterial(material, null);
                string materialPath          = materialConverter.Export(context.preset);
                context.AddResource(materialPath);

                JSONObject json = new JSONObject(JSONObject.Type.OBJECT);
                JSONObject data = new JSONObject(JSONObject.Type.OBJECT);
                json.AddField("type", "UnityEngine.Material".EscapeNamespaceSimple());
                json.AddField("value", data);
                data.AddField("path", materialPath);

                return(json);
            });

            AddTypePropertyHandler(typeof(UnityEngine.LayerMask), (obj, context, requireList) =>
            {
                LayerMask mask = (LayerMask)obj;

                return(JSONObject.Create(mask.value));
            });

            AddTypePropertyHandler(typeof(List <>), (obj, context, requireList) =>
            {
                IEnumerable list = (IEnumerable)obj;
                if (list == null)
                {
                    return(null);
                }

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

                var enumerator = ((IEnumerable)list).GetEnumerator();
                while (enumerator.MoveNext())
                {
                    object itemObj = enumerator.Current;
                    if (itemObj == null)
                    {
                        continue;
                    }
                    if (itemObj.GetType() == typeof(List <>))
                    {
                        throw new Exception("不支持嵌套List");
                    }
                    else
                    {
                        Type type             = itemObj.GetType();
                        JSONObject itemResult = innerHandleField(type, itemObj, context, requireList);
                        if (itemResult != null)
                        {
                            result.Add(itemResult);
                        }
                    }
                }
                return(result);
            });

            AddTypePropertyHandler(typeof(PuertsBeefBallSDK.RemoteResource), (obj, context, requireList) =>
            {
                var m = (PuertsBeefBallSDK.RemoteResource)obj;
                return(JSONObject.CreateStringObject(m.resourcePath));
            });

            // disgusting code logic :(
            // refactor should be needed
            AddTypePropertyHandler(typeof(PuertsBeefBallBehaviour), (obj, context, requireList) =>
            {
                var m = (PuertsBeefBallBehaviour)obj;
                if (!m)
                {
                    return(null);
                }

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

                var escapedTypeName = WXMonoBehaviourExportHelper.EscapeNamespace(m.GetType().FullName);
                innerData.AddField("type", escapedTypeName);
                innerData.AddField("value", context.AddComponentInProperty(new PuertsBeefBallBehaviourConverter(m), (Component)obj));
                return(innerData);
            });

            AddTypePropertyHandler(typeof(Component), (obj, context, requireList) =>
            {
                Component c = (Component)obj;
                if (!c)
                {
                    return(null);
                }

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

                var escapedTypeName = WXMonoBehaviourExportHelper.EscapeNamespace(c.GetType().FullName);
                innerData.AddField("type", escapedTypeName);
                innerData.AddField("value", context.AddComponentInProperty(new WXUnityComponent(c), c));
                return(innerData);
            });

            // 在前面condition逻辑里,理论上已经把所有可能为prefab的逻辑走完
            AddTypePropertyHandler(typeof(GameObject), (obj, context, requireList) =>
            {
                throw new Exception("不支持节点属性指向GameObject,请改为指向Transform或是具体逻辑组件");

                // var go = (GameObject)obj;
                // if (!go) return null;

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

                // return GetPrefabOnSerializedField(context, go, innerData);
            });
        }
        public void AfterOutput(ITranslator translator, string outputPath, bool nocore)
        {
            IEnumerable <TranslatorOutputItem> outputForHtml = translator.Outputs.GetOutputs();

            var     scriptTemplate = "import './{0}';";
            var     firstJs        = true;
            var     jsBuffer       = new StringBuilder();
            ILogger outputLogger   = this.Logger;

            foreach (var output in outputForHtml)
            {
                if (output.OutputType == TranslatorOutputType.JavaScript)
                {
                    var path = output.GetOutputPath(outputPath, true, outputLogger);

                    // blacklist
                    if (WXBridge.isWXBridgePlugin)
                    {
                        if (path.IndexOf("minigame-adaptor-lib.js") >= 0 ||
                            path.IndexOf("minigame-adaptor-lib.meta.js") >= 0 ||
                            path.IndexOf("minigame-adaptor-lib-patch.js") >= 0)
                        {
                            continue;
                        }
                    }

                    if (!firstJs)
                    {
                        jsBuffer.Append(NEW_LINE);
                    }

                    firstJs = false;


                    path = Uri.UnescapeDataString(path);
                    path = path.Replace("'", "\\\'");
                    jsBuffer.Append(string.Format(scriptTemplate, path));
                }
            }

            File.WriteAllText(Path.Combine(outputPath, pluginFullName + ".js"), jsBuffer.ToString(), Encoding.UTF8);

            Logger.Trace(String.Format("location: {0}", translator.Location));
            var bindingPath = Path.Combine(outputPath, "bindings");

            if (!Directory.Exists(bindingPath))
            {
                Directory.CreateDirectory(bindingPath);
            }
            foreach (var bindingTypePair in bindingTypes)
            {
                var jsFilePath = convertToOutputPath(translator, bindingPath, bindingTypePair.Key);

                if (File.Exists(jsFilePath))
                {
                    File.Delete(jsFilePath);
                }

                var output        = new StringBuilder();
                var importRelPath = GetRelativePath(Path.Combine(outputPath, "weapp-adapter"), Path.GetDirectoryName(jsFilePath));
                Logger.Trace(String.Format("generate binding js {0}", jsFilePath));

                // if (WXBridge.isWXBridgePlugin) {
                //     output.Append(String.Format("import {{ requireBridge }} from '{0}'\r\n", getBindingFileImportPath("bridge_util", outputPath, jsFilePath)));
                //     output.Append("requireBridge()\n");
                //     // output.Append("requireBridge({\n    pluginAlias: 'WXBridge',\n    useLocalFile: false,\n    useLocalBridgeAdaptor: false\n})})");
                // } else {
                //     output.Append(String.Format("import '{0}'\r\n", getBindingFileImportPath("bridge", outputPath, jsFilePath)));
                //     output.Append(String.Format("import '{0}'\r\n", getBindingFileImportPath("bridge.meta", outputPath, jsFilePath)));
                //     output.Append(String.Format("import '{0}'\r\n", getBindingFileImportPath("weapp-adapter", outputPath, jsFilePath)));
                //     output.Append(String.Format("import '{0}'\r\n", getBindingFileImportPath("bridge_adaptor", outputPath, jsFilePath)));
                // }

                output.Append(String.Format("import '{0}'\r\n", getBindingFileImportPath("minigame-adaptor-util", outputPath, jsFilePath)));

                output.Append(String.Format("import '{0}'\r\n", getBindingFileImportPath(pluginFullName, outputPath, jsFilePath)));

                foreach (var bindingType in bindingTypePair.Value)
                {
                    generateBindingFile(output, translator, bindingPath, jsFilePath, bindingType);
                }

                // EscapeNamespace
                var textToWrite = WXMonoBehaviourExportHelper.EscapeNamespace(output.ToString());
                File.WriteAllText(jsFilePath, textToWrite);
            }
        }
        public override string getTypeName()
        {
            var result = collider ? collider.GetType().ToString() : "UnityEngine.BoxCollider";

            return(WXMonoBehaviourExportHelper.EscapeNamespace(result));
        }