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; }
private void ExportAllResourcesDirectories() { var res = ConfigManager.configEntry.exportDirectoryListConfig.exportDirectories; if (res == null || res.Count == 0) { EditorUtility.DisplayDialog("Resources目录配置", "未找到任何Resources目录或未添加至列表中", "ok"); return; } int i = 0; foreach (var r in res) { UnityEngine.Object dir = r.directory; if (dir != null) { EditorUtility.FocusProjectWindow(); Selection.activeObject = dir; if (r.isNGUI) { ExportPreset.GetExportPreset("ngui-prefabfolder").Export(); } else if (r.isUGUI) { ExportPreset.GetExportPreset("ugui-prefabfolder").Export(); } else { ExportPreset.GetExportPreset("prefabfolder").Export(); } i++; } } Debug.Log("导出资源文件夹: " + i); }
private void ExportAllScenes() { var activeScene = EditorSceneManager.GetActiveScene(); string currentScenePath = ""; if (activeScene != null && activeScene.path != "") { currentScenePath = EditorSceneManager.GetActiveScene().path; } int i = 0; var scenes = sceneExportConfig.exportScenes; if (scenes != null && scenes.Count > 0) { scenes.ForEach(scene => { var path = AssetDatabase.GetAssetPath(scene.scene); try { EditorSceneManager.OpenScene(path); if (scene.isNGUI) { ExportPreset.GetExportPreset("ngui-rootScene").WillPresetShow(); ExportPreset.GetExportPreset("ngui-rootScene").Export(); } else if (scene.isUGUI) { ExportPreset.GetExportPreset("ugui-rootScene").WillPresetShow(); ExportPreset.GetExportPreset("ugui-rootScene").Export(); } else { ExportPreset.GetExportPreset("scene").Export(); } i++; } catch (ArgumentException e) { // 被添加的Scene不存在,不做处理 } }); } if (currentScenePath != "") { EditorSceneManager.OpenScene(currentScenePath); } Debug.Log("导出场景: " + i); }
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)); }); }
// 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); }
private static void RegisterConditionProperties() { AddConditionPropertyHandler( (Type type) => { return(type.IsArray || (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List <>))); }, (type, value, context, requireList) => { return(typePropertiesHandlerDictionary[typeof(List <>)](value, context, requireList)); } ); AddConditionPropertyHandler( (Type type) => { return(type.IsEnum); }, (type, value, context, requireList) => { return(JSONObject.Create((int)value)); } ); AddConditionPropertyHandler( (Type type) => { return(type.IsSubclassOf(typeof(UnityEngine.Component)) || type == typeof(UnityEngine.GameObject)); }, (type, value, context, requireList) => { // 取值 var o = (UnityEngine.Object)value; GameObject go = null; if (o == null) { return(null); } // 尝试获得资源路径 var path = AssetDatabase.GetAssetPath(o); // 如果是组件 if (type.IsSubclassOf(typeof(UnityEngine.Component))) { go = ((Component)o).gameObject; } // 如果直接是一个GameObject else if (type == typeof(UnityEngine.GameObject)) { go = (GameObject)o; } // 如果拿得到路径,且发现transform不属于当前场景,则当prefab处理 if (path != "" && !go.transform.IsChildOf(context.Root.transform)) { // 按prefab导出 // 排重? 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); // prefab数据 var innerData = new JSONObject(JSONObject.Type.OBJECT); innerData.AddField("type", "UnityPrefabWrapper"); innerData.AddField("value", prefabInfo); return(innerData); } return(null); } ); AddConditionPropertyHandler( (Type type) => { return(typePropertiesHandlerDictionary.ContainsKey(type)); }, (type, value, context, requireList) => { return(typePropertiesHandlerDictionary[type](value, context, requireList)); } ); AddConditionPropertyHandler( (Type type) => { // 基础类型都是isSerializable return(type.IsSerializable); }, (type, value, context, requireList) => { var innerData = new JSONObject(JSONObject.Type.OBJECT); SerializableHandler(type, innerData, value, context, requireList); return(innerData); } ); }
private void OnGUI() { verticalScrollPosition = GUILayout.BeginScrollView(verticalScrollPosition, false, false, GUIStyle.none, GUI.skin.verticalScrollbar); GUILayout.BeginHorizontal(); EditorGUILayout.Space(); GUILayout.BeginVertical(); EditorGUILayout.Space(); EditorGUILayout.HelpBox("一键快速导出可以按一定流程快速地执行多个导出任务。", MessageType.Info); // 全局配置 EditorGUILayout.Space(); { EditorGUILayout.BeginHorizontal(); GUIStyle sceneStyle = new GUIStyle(EditorStyles.foldout); sceneStyle.fixedWidth = 10; expandGlobalConfig = EditorGUILayout.Foldout(expandGlobalConfig, "==== 全局配置", true, sceneStyle); GUILayout.Label("", GUILayout.ExpandWidth(true)); EditorGUILayout.EndHorizontal(); if (expandGlobalConfig) { EditorGUI.indentLevel++; globalConfigEditor.OnInspectorGUI(); EditorGUI.indentLevel--; } } // 插件 EditorGUILayout.Space(); int PluginCodeFold = EditorHelper.FoldableTitleline("导出插件代码", expandPluginCodeConfig, checkPluginCodeConfig); expandPluginCodeConfig = (PluginCodeFold & 0x10) == 0x10; checkPluginCodeConfig = (PluginCodeFold & 0x1) == 0x1; if (expandPluginCodeConfig) { EditorGUI.indentLevel++; unityPluginConfigEditor.OnInspectorGUI(); EditorGUI.indentLevel--; } // 工程 EditorGUILayout.Space(); int PluginProjectFold = EditorHelper.FoldableTitleline("导出工程代码", expandProjectCodeConfig, checkProjectCodeConfig); expandProjectCodeConfig = (PluginProjectFold & 0x10) == 0x10; checkProjectCodeConfig = (PluginProjectFold & 0x1) == 0x1; if (expandProjectCodeConfig) { EditorGUI.indentLevel++; // globalConfigEditor.OnInspectorGUI(); projectScriptExportConfigEditor.OnInspectorGUI(); EditorGUI.indentLevel--; } // 场景 EditorGUILayout.Space(); int sceneFold = EditorHelper.FoldableTitleline("导出所有场景", expandSceneConfig, checkSceneConfig); expandSceneConfig = (sceneFold & 0x10) == 0x10; checkSceneConfig = (sceneFold & 0x1) == 0x1; if (expandSceneConfig) { EditorGUI.indentLevel++; hierarchyExportConfigEditor.OnInspectorGUI(); sceneExportEditor.OnInspectorGUI(); EditorGUI.indentLevel--; } // prefab EditorGUILayout.Space(); int prefabFold = EditorHelper.FoldableTitleline("导出目录下的 prefab", expandPrefabConfig, checkPrefabConfig); expandPrefabConfig = (prefabFold & 0x10) == 0x10; checkPrefabConfig = (prefabFold & 0x1) == 0x1; if (expandPrefabConfig) { EditorGUI.indentLevel++; directoryExportEditor.OnInspectorGUI(); EditorGUI.indentLevel--; } // 原始资源 EditorGUILayout.Space(); int rawFold = EditorHelper.FoldableTitleline("导出原始资源", expandRawResourceConfig, checkRawResourceConfig); expandRawResourceConfig = (rawFold & 0x10) == 0x10; checkRawResourceConfig = (rawFold & 0x1) == 0x1; if (expandRawResourceConfig) { EditorGUI.indentLevel++; rawResourceExportConfigEditor.OnInspectorGUI(); EditorGUI.indentLevel--; } EditorGUILayout.Space(); EditorGUILayout.Space(); GUIStyle exportButtonStyle = new GUIStyle(GUI.skin.button); exportButtonStyle.fontSize = 14; var isExportBtnPressed = GUILayout.Button("导出", exportButtonStyle, GUILayout.Height(40), GUILayout.Width(EditorGUIUtility.currentViewWidth - 20)); GUILayout.EndVertical(); EditorGUILayout.Space(); GUILayout.EndHorizontal(); EditorGUILayout.Space(); GUILayout.EndScrollView(); if (isExportBtnPressed) { if (checkPluginCodeConfig) { Debug.Log("导出插件代码..."); ExportPreset.GetExportPreset("plugins-script").Export(); } if (checkProjectCodeConfig) { Debug.Log("导出工程代码..."); ExportPreset.GetExportPreset("project-script").Export(); } if (checkSceneConfig) { Debug.Log("导出全部游戏场景..."); ExportAllScenes(); } if (checkPrefabConfig) { Debug.Log("导出资源文件夹..."); ExportAllResourcesDirectories(); } if (checkRawResourceConfig) { Debug.Log("导出裸资源文件..."); ExportPreset.GetExportPreset("rawres").Export(); } } }
private void OnGUI() { verticalScrollPosition = GUILayout.BeginScrollView(verticalScrollPosition, false, false, GUIStyle.none, GUI.skin.verticalScrollbar); GUILayout.BeginHorizontal(); EditorGUILayout.Space(); GUILayout.BeginVertical(); EditorGUILayout.Space(); bool createProjectButtonClicked = false; bool choosePathButtonClicked = false; bool openTargetButtonClicked = false; bool resetButtonClicked = false; bool exportButtonClicked = false; // 带文本的分割线 EditorHelper.LabeledSplitLine("1. 目标导出路径"); // 路径选择 start int pathButtonHeight = 28; GUIStyle pathLabelStyle = new GUIStyle(GUI.skin.textField); pathLabelStyle.fontSize = 12; pathLabelStyle.alignment = TextAnchor.MiddleLeft; pathLabelStyle.margin.top = 6; pathLabelStyle.margin.bottom = 6; // 如果没有设置过path,显示创建按钮 if (ExportStore.storagePath == null || ExportStore.storagePath == "") { GUILayout.BeginHorizontal(); #if UNITY_2017_1_OR_NEWER createProjectButtonClicked = GUILayout.Button("创建小游戏项目模板", GUILayout.Height(pathButtonHeight)); #endif choosePathButtonClicked = GUILayout.Button("手动选择导出路径", GUILayout.Height(pathButtonHeight)); GUILayout.EndHorizontal(); } else { GUILayout.BeginHorizontal(); // 路径框 GUILayout.Label(ExportStore.storagePath, pathLabelStyle, GUILayout.Height(pathButtonHeight - 6), GUILayout.ExpandWidth(true), GUILayout.MaxWidth(EditorGUIUtility.currentViewWidth - 106)); openTargetButtonClicked = GUILayout.Button("打开", GUILayout.Height(pathButtonHeight), GUILayout.Width(40)); resetButtonClicked = GUILayout.Button("重选", GUILayout.Height(pathButtonHeight), GUILayout.Width(40)); GUILayout.EndHorizontal(); // 路径选择 end // 带文本的分割线 EditorHelper.LabeledSplitLine("2. 导出模式"); // 模式选择 start // 确定本次导出所使用的preset List <string> presetNames = new List <string>(); List <ExportPreset> exportPresets = new List <ExportPreset>(); foreach (string key in ExportPreset.GetAllPresetKeys()) { ExportPreset preset = ExportPreset.GetExportPreset(key); if (preset.WillPresetShow()) { presetNames.Add(preset.GetChineseName()); exportPresets.Add(preset); } } // 绘制 exportModeScrollPosition = GUILayout.BeginScrollView(exportModeScrollPosition, false, false, GUILayout.Height(45)); selectingPresetIndex = GUILayout.Toolbar( selectingPresetIndex, presetNames.ToArray(), new GUIStyle(GUI.skin.button), #if UNITY_2018_1_OR_NEWER GUI.ToolbarButtonSize.Fixed, #endif GUILayout.Height(22) ); GUILayout.EndScrollView(); selectingPresetIndex = Math.Min(selectingPresetIndex, exportPresets.Count - 1); EditorGUILayout.Space(); // 模式选择 end // 模式配置 start exportPresets[selectingPresetIndex].Draw(); // 模式配置 end // 导出按钮 start // 带文本的分割线 EditorGUILayout.Space(); EditorGUILayout.Space(); EditorHelper.LabeledSplitLine("3. 最后一步"); // 样式定义 GUIStyle exportButtonStyle = new GUIStyle(GUI.skin.button); exportButtonStyle.fontSize = 14; exportButtonClicked = GUILayout.Button("导出", exportButtonStyle, GUILayout.Height(40), GUILayout.Width(EditorGUIUtility.currentViewWidth - 20)); // 导出按钮 end currentPreset = exportPresets[selectingPresetIndex]; } GUILayout.EndVertical(); EditorGUILayout.Space(); GUILayout.EndHorizontal(); EditorGUILayout.Space(); GUILayout.EndScrollView(); handleClickedOnGUI( createProjectButtonClicked, choosePathButtonClicked, openTargetButtonClicked, resetButtonClicked, exportButtonClicked ); }