Unity and Cocos stay as parallel schemes; apps/minigame ships the Godot 4.7 WeChat pack for DevTools. Co-authored-by: Cursor <cursoragent@cursor.com>
87 lines
3.2 KiB
C#
87 lines
3.2 KiB
C#
#if UNITY_EDITOR
|
|
using System.IO;
|
|
using UnityEditor;
|
|
using UnityEditor.SceneManagement;
|
|
using UnityEngine;
|
|
using UnityEngine.Rendering;
|
|
using WeChatWASM;
|
|
|
|
namespace Nomadro.Minigame.Editor
|
|
{
|
|
public static class WeChatExport
|
|
{
|
|
const string DstRel = "Build/wechat";
|
|
const string AppId = "wx2900cac0858ca7dc";
|
|
|
|
[MenuItem("Nomadro/Fix Magenta Materials")]
|
|
public static void FixMaterials()
|
|
{
|
|
GraphicsSettings.defaultRenderPipeline = null;
|
|
QualitySettings.renderPipeline = null;
|
|
var lit = Shader.Find("Standard");
|
|
var n = 0;
|
|
foreach (var r in Object.FindObjectsOfType<Renderer>(true))
|
|
{
|
|
if (r == null) continue;
|
|
Color c = Color.gray;
|
|
if (r.sharedMaterial != null)
|
|
{
|
|
if (r.sharedMaterial.HasProperty("_Color")) c = r.sharedMaterial.color;
|
|
else if (r.sharedMaterial.HasProperty("_BaseColor")) c = r.sharedMaterial.GetColor("_BaseColor");
|
|
}
|
|
r.sharedMaterial = new Material(lit) { color = c };
|
|
n++;
|
|
}
|
|
EditorSceneManager.MarkAllScenesDirty();
|
|
EditorSceneManager.SaveOpenScenes();
|
|
Debug.Log($"[Nomadro] Fixed {n} materials → Standard");
|
|
}
|
|
|
|
[MenuItem("Nomadro/Export WeChat Mini Game")]
|
|
public static void ExportMenu() => ExportCli();
|
|
|
|
public static void ExportCli()
|
|
{
|
|
try
|
|
{
|
|
GraphicsSettings.defaultRenderPipeline = null;
|
|
QualitySettings.renderPipeline = null;
|
|
|
|
var scenePath = "Assets/Scenes/Main.unity";
|
|
if (File.Exists(Path.Combine(Application.dataPath, "Scenes/Main.unity")))
|
|
EditorSceneManager.OpenScene(scenePath);
|
|
|
|
// rebuild clean scene for built-in RP
|
|
NomadSceneSetup.Setup();
|
|
EditorSceneManager.OpenScene(scenePath);
|
|
|
|
WXConvertCore.Init();
|
|
var conf = UnityUtil.GetEditorConf();
|
|
conf.ProjectConf.Appid = AppId;
|
|
conf.ProjectConf.projectName = "nomadro-minigame";
|
|
conf.ProjectConf.relativeDST = DstRel;
|
|
conf.ProjectConf.DST = Path.GetFullPath(Path.Combine(Application.dataPath, "..", DstRel));
|
|
conf.ProjectConf.assetLoadType = 1;
|
|
conf.ProjectConf.CDN = "";
|
|
conf.ProjectConf.Orientation = WXScreenOritation.Portrait;
|
|
conf.CompileOptions.DevelopBuild = true;
|
|
conf.CompileOptions.Webgl2 = false;
|
|
EditorUtility.SetDirty(conf);
|
|
AssetDatabase.SaveAssets();
|
|
|
|
Directory.CreateDirectory(conf.ProjectConf.DST);
|
|
Debug.Log("[Nomadro] DoExport → " + conf.ProjectConf.DST);
|
|
var err = WXConvertCore.DoExport(true);
|
|
Debug.Log("[Nomadro] DoExport result = " + err);
|
|
EditorApplication.Exit(err == WXConvertCore.WXExportError.SUCCEED ? 0 : 2);
|
|
}
|
|
catch (System.Exception e)
|
|
{
|
|
Debug.LogError(e);
|
|
EditorApplication.Exit(3);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endif
|