123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using System.Reflection;
- using UnityEditor;
- using UnityEditor.Build;
- using UnityEditor.Build.Reporting;
- using UnityEngine;
- public class SDKSettings : EditorWindow {
- [InitializeOnLoadMethod]
- static void CheckSettings() {
- if(EditorUserBuildSettings.activeBuildTarget == BuildTarget.Android) {
- if(!IsIgnor && IsApply() == false) {
- Init();
- }
- }
- }
- static EditorWindow window;
- [MenuItem("SDK/ProjectSettings")]
- static void Init() {
- if(window == null) {
- // window = EditorWindow.GetWindow(typeof(SDKSettings));
- // window.autoRepaintOnSceneChange = true;
- // window.minSize = new Vector2(720, 420);
- // window.maxSize = new Vector2(720, 420);
- }
- }
- static bool isQualityApply = true;
- static bool isPlayerApply = true;
- void OnGUI() {
- GUILayout.Space(10);
- NoticWindow();
-
- if(EditorUserBuildSettings.activeBuildTarget != BuildTarget.Android) {
- return;
- }
- GUILayout.Space(10);
- isQualityApply = QualityWindow();
- GUILayout.Space(10);
- isPlayerApply = PlayerWindow();
- if(IsApply() == false) {
- GUILayout.Space(60);
- ApplyWindow();
- }
- }
- static bool IsApply() {
- if(EditorUserBuildSettings.activeBuildTarget != BuildTarget.Android) {
- return true;
- }
- if(PlayerCheck() && QualityCheck())
- return true;
- return false;
- }
- static bool IsIgnor { get { return GetAssetDataBase(); } }
- static void Ignor() {
- SaveAssetDataBase(true);
- }
- static string assetPath = "Assets/SDK/Common/Base/Editor/BuildSettings/Parm.asset";
- static void SaveAssetDataBase(bool isIgnor) {
- ParmScriptableObject asset;
- if(File.Exists(assetPath)) {
- asset = AssetDatabase.LoadAssetAtPath<ParmScriptableObject>(assetPath);
- } else {
- asset =(ParmScriptableObject) CreateInstance("ParmScriptableObject");
- AssetDatabase.CreateAsset(asset, assetPath);
- }
- asset.IsIgnor = isIgnor;
- AssetDatabase.SaveAssets();
- AssetDatabase.Refresh();//must Refresh
- }
- static bool GetAssetDataBase() {
- ParmScriptableObject asset;
- if(File.Exists(assetPath)) {
- asset = AssetDatabase.LoadAssetAtPath<ParmScriptableObject>(assetPath);
- return asset.IsIgnor;
- }
- return false;
- }
-
- static void NoticWindow() {
- GUILayout.Space(20);
- EditorGUILayout.BeginHorizontal();
- GUIStyle styleNoticeText = new GUIStyle();
- styleNoticeText.alignment = TextAnchor.MiddleCenter;
- styleNoticeText.fontSize = 14;
- styleNoticeText.fontStyle = FontStyle.Bold;
- if(EditorUserBuildSettings.activeBuildTarget == BuildTarget.Android) {
- GUILayout.Label("Notice: Recommended Project settings for SDK", styleNoticeText);
- } else {
- GUILayout.Label("This Only Effect When Platform Select Android", styleNoticeText);
- }
- EditorGUILayout.EndHorizontal();
- GUILayout.Space(20);
- }
- void ApplyWindow() {
- EditorGUILayout.BeginHorizontal();
- EditorGUILayout.LabelField("", GUILayout.Width(100));
- GUIStyle styleApply = new GUIStyle("LargeButton");
- styleApply.alignment = TextAnchor.MiddleCenter;
- if(GUILayout.Button("Apply", styleApply)) {
- QualitySet();
- PlayerSet();
- }
-
- EditorGUILayout.LabelField("", GUILayout.Width(100));
- GUIStyle style1Apply = new GUIStyle("LargeButton");
- styleApply.alignment = TextAnchor.MiddleCenter;
- if(GUILayout.Button("Ignor", style1Apply)) {
- Ignor();
- window.Close();
- Close();
- }
- EditorGUILayout.LabelField("", GUILayout.Width(100));
- //if(GUILayout.Button(strBtnApply[(int)elanguage], styleApply, GUILayout.Width(100), GUILayout.Height(30))) {
- // EditorApplication.delayCall += OnClickApply;
- //}
- //styleApply = null;
- //EditorGUILayout.LabelField("", GUILayout.Width(200));
- //if(GUILayout.Button("xxx", GUILayout.Width(100), GUILayout.Height(30))) {
- //}
- EditorGUILayout.EndHorizontal();
- }
- #region ProjectSettings->Player
- static bool PlayerWindow() {
- bool isApply = true;
- GUILayout.Label("PlayerSettings", EditorStyles.boldLabel);
- EditorGUILayout.BeginHorizontal();
- GUILayout.Label("Minimum API Level:API26(or higher)");
- if(PlayerSettings.Android.minSdkVersion < AndroidSdkVersions.AndroidApiLevel26) {
- GUIStyle styleSlide = new GUIStyle();
- styleSlide.normal.textColor = Color.red;
- GUILayout.Label("Failed", styleSlide);
- isApply = false;
- } else {
- GUIStyle styleApplied = new GUIStyle();
- styleApplied.normal.textColor = Color.green;
- GUILayout.Label("Applied", styleApplied);
- }
- EditorGUILayout.EndHorizontal();
- EditorGUILayout.BeginHorizontal();
- GUILayout.Label("APICompatibilityLevel:.NET4.x");
- if(PlayerSettings.GetApiCompatibilityLevel(BuildTargetGroup.Android) != ApiCompatibilityLevel.NET_4_6) {
- GUIStyle styleSlide = new GUIStyle();
- styleSlide.normal.textColor = Color.red;
- GUILayout.Label("Failed", styleSlide);
- isApply = false;
- } else {
- GUIStyle styleApplied = new GUIStyle();
- styleApplied.normal.textColor = Color.green;
- GUILayout.Label("Applied", styleApplied);
- }
- EditorGUILayout.EndHorizontal();
- EditorGUILayout.BeginHorizontal();
- GUILayout.Label("Multithreaded Rendering:True");
- if(PlayerSettings.GetMobileMTRendering(BuildTargetGroup.Android)==false) {
- GUIStyle styleSlide = new GUIStyle();
- styleSlide.normal.textColor = Color.red;
- GUILayout.Label("Failed", styleSlide);
- isApply = false;
- } else {
- GUIStyle styleApplied = new GUIStyle();
- styleApplied.normal.textColor = Color.green;
- GUILayout.Label("Applied", styleApplied);
- }
- EditorGUILayout.EndHorizontal();
- EditorGUILayout.BeginHorizontal();
- GUILayout.Label("Graphics APIs:Only OpenGLES3");
-
- UnityEngine.Rendering.GraphicsDeviceType[] gapi = PlayerSettings.GetGraphicsAPIs(BuildTarget.Android);
- if(gapi.Length != 1 || gapi[0] != UnityEngine.Rendering.GraphicsDeviceType.OpenGLES3) {
- GUIStyle styleSlide = new GUIStyle();
- styleSlide.normal.textColor = Color.red;
- GUILayout.Label("Failed", styleSlide);
- isApply = false;
- } else {
- GUIStyle styleApplied = new GUIStyle();
- styleApplied.normal.textColor = Color.green;
- GUILayout.Label("Applied", styleApplied);
- }
- EditorGUILayout.EndHorizontal();
- EditorGUILayout.BeginHorizontal();
- int staticBatchingValue = 0;
- int dynamicBatchingValue = 0;
- Type playerSettingsType = typeof(PlayerSettings);
- MethodInfo method = playerSettingsType.GetMethod("GetBatchingForPlatform",BindingFlags.NonPublic | BindingFlags.Static);
- object[] param = new object[] { BuildTarget.Android, staticBatchingValue, dynamicBatchingValue };
- method.Invoke(null, param);
- GUILayout.Label("Dynamic Batching:Enable");
- if ((int)param[2] != 1)
- {
- GUIStyle styleSlide = new GUIStyle();
- styleSlide.normal.textColor = Color.red;
- GUILayout.Label("Failed", styleSlide);
- isApply = false;
- }
- else
- {
- GUIStyle styleApplied = new GUIStyle();
- styleApplied.normal.textColor = Color.green;
- GUILayout.Label("Applied", styleApplied);
- }
- EditorGUILayout.EndHorizontal();
- EditorGUILayout.BeginHorizontal();
- GUILayout.Label("Asset Serialization:ForceText");
- if (EditorSettings.serializationMode != SerializationMode.ForceText)
- {
- GUIStyle styleSlide = new GUIStyle();
- styleSlide.normal.textColor = Color.red;
- GUILayout.Label("Failed", styleSlide);
- isApply = false;
- }
- else
- {
- GUIStyle styleApplied = new GUIStyle();
- styleApplied.normal.textColor = Color.green;
- GUILayout.Label("Applied", styleApplied);
- }
- EditorGUILayout.EndHorizontal();
- EditorGUILayout.BeginHorizontal();
- GUILayout.Label("Orientation:Landscape Left");
- if(PlayerSettings.defaultInterfaceOrientation != UIOrientation.LandscapeLeft) {
- GUIStyle styleSlide = new GUIStyle();
- styleSlide.normal.textColor = Color.red;
- GUILayout.Label("Failed", styleSlide);
- isApply = false;
- } else {
- GUIStyle styleApplied = new GUIStyle();
- styleApplied.normal.textColor = Color.green;
- GUILayout.Label("Applied", styleApplied);
- }
- EditorGUILayout.EndHorizontal();
- return isApply;
-
- }
- static bool PlayerCheck() {
- bool isApply = true;
- if(PlayerSettings.Android.minSdkVersion < AndroidSdkVersions.AndroidApiLevel26) {
- isApply = false;
- }
- if(PlayerSettings.GetApiCompatibilityLevel(BuildTargetGroup.Android) != ApiCompatibilityLevel.NET_4_6) {
- isApply = false;
- }
- if(PlayerSettings.GetMobileMTRendering(BuildTargetGroup.Android) == false) {
- isApply = false;
- }
- UnityEngine.Rendering.GraphicsDeviceType[] gapi = PlayerSettings.GetGraphicsAPIs(BuildTarget.Android);
- if(gapi.Length != 1 || gapi[0] != UnityEngine.Rendering.GraphicsDeviceType.OpenGLES3) {
- isApply = false;
- }
- if(PlayerSettings.defaultInterfaceOrientation != UIOrientation.LandscapeLeft) {
- isApply = false;
- }
- if(EditorSettings.serializationMode != SerializationMode.ForceText) {
- isApply = false;
- }
- int staticBatchingValue = 0;
- int dynamicBatchingValue = 0;
- Type playerSettingsType = typeof(PlayerSettings);
- MethodInfo method = playerSettingsType.GetMethod("GetBatchingForPlatform", BindingFlags.NonPublic | BindingFlags.Static);
- object[] param = new object[] { BuildTarget.Android, staticBatchingValue, dynamicBatchingValue };
- method.Invoke(null, param);
- if((int)param[2] != 1) {
- isApply = false;
- }
- return isApply;
- }
- static void PlayerSet() {
- PlayerSettings.Android.minSdkVersion = AndroidSdkVersions.AndroidApiLevel26;
- PlayerSettings.Android.targetSdkVersion = AndroidSdkVersions.AndroidApiLevelAuto;
- PlayerSettings.SetApiCompatibilityLevel(BuildTargetGroup.Android, ApiCompatibilityLevel.NET_4_6);
- PlayerSettings.SetMobileMTRendering(BuildTargetGroup.Android, true);
- PlayerSettings.SetUseDefaultGraphicsAPIs(BuildTarget.Android,false);
- PlayerSettings.SetGraphicsAPIs(BuildTarget.Android,new UnityEngine.Rendering.GraphicsDeviceType[1] { UnityEngine.Rendering.GraphicsDeviceType.OpenGLES3 });
- PlayerSettings.defaultInterfaceOrientation = UIOrientation.LandscapeLeft;
- EditorSettings.serializationMode = SerializationMode.ForceText;
-
- Type playerSettingsType = typeof(PlayerSettings);
- MethodInfo method = playerSettingsType.GetMethod("SetBatchingForPlatform", BindingFlags.NonPublic | BindingFlags.Static);
- int staticBatchingValue = 1;
- int dynamicBatchingValue = 1;
- object[] param = new object[] { BuildTarget.Android, staticBatchingValue, dynamicBatchingValue };
- method.Invoke(null, param);
- }
- [InitializeOnLoadMethod]
- static void PlayerSetMust() {
- if(PlayerSettings.productName == "New Unity Project") {
- PlayerSettings.productName = "SDK";
- }
- if(PlayerSettings.companyName == "DefaultCompany") {
- PlayerSettings.companyName = "XR";
- }
- }
- #endregion
- #region ProjectSettings->Tags and Layers
- //[InitializeOnLoadMethod]
- //static void TagsAndLayerSet() {
- // bool isExist = false;
- // foreach(var item in UnityEditorInternal.InternalEditorUtility.layers) {
- // if(item == "focus") {
- // isExist = true;
- // break;
- // }
- // }
- // if(isExist == false) {
- // AutoAddLayer("focus");
- // }
- // isExist = false;
- // foreach(var item in UnityEditorInternal.InternalEditorUtility.layers) {
- // if(item == "no light") {
- // isExist = true;
- // break;
- // }
- // }
- // if(isExist == false) {
- // AutoAddLayer("no light");
- // }
- // isExist = false;
- // foreach(var item in UnityEditorInternal.InternalEditorUtility.tags) {
- // if(item == "SlamCamera") {
- // isExist = true;
- // break;
- // }
- // }
- // if(isExist == false) {
- // UnityEditorInternal.InternalEditorUtility.AddTag("SlamCamera");
- // }
- //}
- static void AutoAddLayer(string layer) {
- SerializedObject tagMagager = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/Tagmanager.asset"));
- SerializedProperty it = tagMagager.GetIterator();
- while(it.NextVisible(true)) {
- if(it.name.Equals("layers")) {
- for(int i = 0; i < it.arraySize; i++) {
- if(i <= 7) {
- continue;
- }
- SerializedProperty sp = it.GetArrayElementAtIndex(i);
- if(string.IsNullOrEmpty(sp.stringValue)) {
- sp.stringValue = layer;
- tagMagager.ApplyModifiedProperties();
- return;
- }
- }
- }
- }
- }
- //static void AutoAddLayer(string layer) {
- // if(!HasThisLayer(layer)) {
- // SerializedObject tagMagager = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/Tagmanager.asset"));
- // SerializedProperty it = tagMagager.GetIterator();
- // while(it.NextVisible(true)) {
- // if(it.name.Equals("layers")) {
- // for(int i = 0; i < it.arraySize; i++) {
- // if(i <= 7) {
- // continue;
- // }
- // SerializedProperty sp = it.GetArrayElementAtIndex(i);
- // if(string.IsNullOrEmpty(sp.stringValue)) {
- // sp.stringValue = layer;
- // tagMagager.ApplyModifiedProperties();
- // return;
- // }
- // }
- // }
- // }
- // }
- //}
- //static bool HasThisLayer(string layer) {
- // //先清除已保存的
- // SerializedObject tagManager = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/Tagmanager.asset"));
- // SerializedProperty it = tagManager.GetIterator();
- // while(it.NextVisible(true)) {
- // if(it.name.Equals("layers")) {
- // for(int i = 0; i < it.arraySize; i++) {
- // if(i <= 7) {
- // continue;
- // }
- // SerializedProperty sp = it.GetArrayElementAtIndex(i);
- // if(!string.IsNullOrEmpty(sp.stringValue)) {
- // if(sp.stringValue.Equals(layer)) {
- // sp.stringValue = string.Empty;
- // tagManager.ApplyModifiedProperties();
- // }
- // }
- // }
- // }
- // }
- // for(int i = 0; i < UnityEditorInternal.InternalEditorUtility.layers.Length; i++) {
- // if(UnityEditorInternal.InternalEditorUtility.layers[i].Contains(layer)) {
- // return true;
- // }
- // }
- // return false;
- //}
- #endregion
- #region ProjectSettings->Quality
- static bool QualityWindow() {
- bool isApply = true;
- GUILayout.Label("QulitySettings", EditorStyles.boldLabel);
- EditorGUILayout.BeginHorizontal();
- GUILayout.Label("QulityLevel:Middle");
- if(QualitySettings.GetQualityLevel() != 2) {
- GUIStyle styleSlide = new GUIStyle();
- styleSlide.normal.textColor = Color.red;
- GUILayout.Label("Failed", styleSlide);
- isApply = false;
- } else {
- GUIStyle styleApplied = new GUIStyle();
- styleApplied.normal.textColor = Color.green;
- GUILayout.Label("Applied", styleApplied);
- }
- EditorGUILayout.EndHorizontal();
- return isApply;
- }
- static bool QualityCheck() {
- bool isApply = true;
- if(QualitySettings.GetQualityLevel() != 2) {
- isApply = false;
- }
- return isApply;
- }
- static void QualitySet() {
- QualitySettings.SetQualityLevel(2);
- }
- #endregion
- }
|