#if UNITY_EDITOR using System; using System.IO; using System.Text; using System.Text.RegularExpressions; using AIGame.EditorTools; using TMPro; using UnityEditor; using UnityEditor.SceneManagement; using UnityEngine; namespace AOT.Editor.WeChat { public static class WeChatLoadingCover { public static void Configure(string mini) { string repo = Path.GetFullPath(Path.Combine(Application.dataPath,"../..")); string module = Path.Combine(repo,"Tools/WeChat/startup-loading.js"); string gamePath = Path.Combine(mini,"game.js"); string game = File.ReadAllText(gamePath); const string import = "import startupLoading from './startup-loading';"; if (!game.Contains(import)) { var pattern = new Regex(@"loadingPageConfig:\s*\{.*?(?=\r?\n\s{8}\}\);)",RegexOptions.Singleline); if (pattern.Matches(game).Count != 1) throw new InvalidOperationException("Cannot identify SDK loading-page configuration."); game = pattern.Replace(game,"loadingPageConfig: startupLoading,",1); game = import + Environment.NewLine + game; } if (!game.Contains("loadingPageConfig: startupLoading,")) throw new InvalidOperationException("SDK cover import has no configuration."); string output = Path.Combine(repo,"Tools/output/startup_presentation/startup-cover.png"); Render(output); Directory.CreateDirectory(Path.Combine(mini,"images")); File.Copy(output,Path.Combine(mini,"images/startup-cover.png"),true); File.Copy(module,Path.Combine(mini,"startup-loading.js"),true); File.WriteAllText(gamePath,game,new UTF8Encoding(false)); } static void Render(string path) { var prefab = AssetDatabase.LoadAssetAtPath(BuildBootLoading.PrefabPath); if (prefab == null) throw new InvalidOperationException("Build the local loading prefab first."); var active = UnityEngine.SceneManagement.SceneManager.GetActiveScene(); var scene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene,NewSceneMode.Additive); var previous = RenderTexture.active; var target = new RenderTexture(720,1280,24); var pixels = new Texture2D(720,1280,TextureFormat.RGB24,false); try { var root = (GameObject)PrefabUtility.InstantiatePrefab(prefab,scene); root.transform.Find("LoadingCard").gameObject.SetActive(false); var cameraObject = new GameObject("CoverRenderCamera",typeof(Camera)); UnityEngine.SceneManagement.SceneManager.MoveGameObjectToScene(cameraObject,scene); var camera = cameraObject.GetComponent(); camera.targetTexture=target;camera.cullingMask=1<(); canvas.renderMode=RenderMode.ScreenSpaceCamera;canvas.worldCamera=camera;canvas.planeDistance=1; Canvas.ForceUpdateCanvases(); foreach(var text in root.GetComponentsInChildren()) text.ForceMeshUpdate(); camera.Render();RenderTexture.active=target; pixels.ReadPixels(new Rect(0,0,720,1280),0,0);pixels.Apply(); var colors = pixels.GetPixels32(); var first=colors[0]; int varied=0; foreach(var color in colors) if(Mathf.Abs(color.r-first.r)+Mathf.Abs(color.g-first.g)+Mathf.Abs(color.b-first.b)>30) varied++; if(varied