private void OnScriptExported(IExportContainer container, Object asset, string path) { MonoScript script = (MonoScript)asset; MonoImporter importer = new MonoImporter(script); Meta meta = new Meta(importer, script.GUID); ExportMeta(container, meta, path); }
static SettingsInit() { Settings asset = Resources.Load <Settings>(Settings.SETTINGS_PATH); if (asset != null) { return; } if (!AssetDatabase.IsValidFolder(RESOURCES_PATH)) { string[] resourcesPath = RESOURCES_PATH.Split('/'); AssetDatabase.CreateFolder(resourcesPath[0], resourcesPath[1]); } asset = ScriptableObject.CreateInstance <Settings>(); string path = RESOURCES_PATH + "/" + Settings.SETTINGS_PATH + ".asset"; AssetDatabase.CreateAsset(asset, path); //Setup injector script execution order MonoScript injector = AssetDatabase.LoadAssetAtPath <MonoScript>(INJECTOR_PATH); int currentExecutionOrder = MonoImporter.GetExecutionOrder(injector); if (currentExecutionOrder != -100) { MonoImporter.SetExecutionOrder(injector, -100); } AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); }
static AudioScriptOrderManager() { if (EditorApplication.isPlayingOrWillChangePlaymode) { return; } foreach (var monoScript in MonoImporter.GetAllRuntimeMonoScripts()) { if (monoScript.GetClass() == null) { continue; } foreach (var a in Attribute.GetCustomAttributes(monoScript.GetClass(), typeof(AudioScriptOrder))) { var currentOrder = MonoImporter.GetExecutionOrder(monoScript); var newOrder = ((AudioScriptOrder)a).Order; if (currentOrder != newOrder) { MonoImporter.SetExecutionOrder(monoScript, newOrder); } } } }
static ExecutionOrderSetter() { #if CSHARP_7_OR_LATER // Get the max execution order. Use reflection to get the const value just in case Unity decides to change it in the future. int maxExecutionOrder = int.MaxValue; // For some dumb reason, type.GetRuntimeField() only returns public fields. GetRuntimeFields() returns private fields. foreach (var field in typeof(MonoImporter).Assembly.GetType("UnityEditor.ScriptExecutionOrderInspector").GetRuntimeFields()) { if (field.Name == "kOrderRangeMax") { maxExecutionOrder = (int)field.GetRawConstantValue(); break; } } #else // GetRuntimeFields doesn't exist prior to .Net 4.0, and GetFields doesn't get private const fields. // Also, we can be confident that the max execution order will forever be 32000 in the deprecated scripting runtime version. int maxExecutionOrder = 32000; #endif foreach (MonoScript monoScript in MonoImporter.GetAllRuntimeMonoScripts()) { if (monoScript.GetClass() == typeof(PromiseBehaviour)) { var currentOrder = MonoImporter.GetExecutionOrder(monoScript); if (currentOrder != maxExecutionOrder) { // Set the PromiseBehaviour to always execute last. MonoImporter.SetExecutionOrder(monoScript, maxExecutionOrder); } break; } } }
//[UnityEditor.Callbacks.DidReloadScripts] public static void ForceReCompile() { MonoScript[] cMonoScript = MonoImporter.GetAllRuntimeMonoScripts(); UnityEditorInternal.InternalEditorUtility.RequestScriptReload(); AssetDatabase.Refresh(); }
public override BuildState OnUpdate() { MonoScript cMonoScript = null; foreach (var script in MonoImporter.GetAllRuntimeMonoScripts()) { var assetPath = AssetDatabase.GetAssetPath(script); if (assetPath.StartsWith("Assets")) { Debug.Log("Reimport : " + assetPath); cMonoScript = script; break; } } if (cMonoScript != null) { AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(cMonoScript)); } else { Debug.LogError("No found any runtime script to reimport"); } return(BuildState.Success); }
static void Replace(string fileNameWithoutExtension) { string filePath = string.Format("Assets/Editor/PlayerScripts/{0}.txt", fileNameWithoutExtension); MonoScript monoScript = null; foreach (var _monoScript in MonoImporter.GetAllRuntimeMonoScripts()) { if (_monoScript.name == "Player") { monoScript = _monoScript; break; } } if (monoScript == null) { EditorUtility.DisplayDialog("Player.csが見つかりません", "ファイル名が間違っていませんか?", "OK"); return; } File.WriteAllBytes(AssetDatabase.GetAssetPath(monoScript), File.ReadAllBytes(filePath)); AssetDatabase.Refresh(); Debug.Log("スクリプトコードを書き換えました"); }
static Creator() { #if UNITY_EDITOR foreach (var monoScript in MonoImporter.GetAllRuntimeMonoScripts()) { var type = monoScript.GetClass(); if (type == null) { continue; } if (type.IsSubclassOf(typeof(GlobalGameManagerObject)) == false) { continue; } if (ExistGlobalGameManager(type) == false) { GlobalGameManager(type); } if (ExistGameManagerInspector(type) == false) { GlobalGameManagerInspector(type); } } #endif }
public static QObjectList createObjectListInScene(Scene scene) { QObjectList objectList; if (!objectListDictionary.ContainsKey(scene)) { GameObject gameObjectList = new GameObject(); gameObjectList.name = ObjectListName; if (scene != gameObjectList.scene) { EditorSceneManager.MoveGameObjectToScene(gameObjectList, scene); } objectList = gameObjectList.AddComponent <QObjectList>(); objectListDictionary.Add(scene, objectList); } else { objectList = objectListDictionary[scene]; } objectList.tag = null; MonoScript monoScript = MonoScript.FromMonoBehaviour(objectList); if (MonoImporter.GetExecutionOrder(monoScript) != -10000) { MonoImporter.SetExecutionOrder(monoScript, -10000); } return(objectList); }
public void OnDrawGizmosSelected() { if (Application.isPlaying) { return; } Input.Autoconfigure(); #if UNITY_EDITOR if (!OrderOfScriptChanged) { // Get the name of the script we want to change it's execution order string scriptName = typeof(Input).Name; // Iterate through all scripts (Might be a better way to do this?) foreach (MonoScript monoScript in MonoImporter.GetAllRuntimeMonoScripts()) { // If found our script if (monoScript.name == scriptName) { MonoImporter.SetExecutionOrder(monoScript, -9999); } } OrderOfScriptChanged = true; } #endif }
static BoltExecutionOrderManager() { //return; Dictionary <string, MonoScript> monoScripts = new Dictionary <string, MonoScript>(); foreach (MonoScript monoScript in MonoImporter.GetAllRuntimeMonoScripts()) { try { switch (monoScript.name) { case "BoltPoll": SetExecutionOrder(monoScript, -10000); break; case "BoltSend": SetExecutionOrder(monoScript, +10000); break; case "BoltEntity": SetExecutionOrder(monoScript, -2500); break; default: monoScripts.Add(monoScript.name, monoScript); break; } } catch { } } foreach (var asm in AppDomain.CurrentDomain.GetAssemblies()) { bool exc = false; try { asm.GetTypes(); } catch (System.Reflection.ReflectionTypeLoadException e) { Debug.Log("Exception thrown on assembly: " + asm.ToString()); Debug.LogException(e); exc = true; } if (!exc) { foreach (var type in asm.GetTypes()) { if (monoScripts.ContainsKey(type.Name)) { try { foreach (BoltExecutionOrderAttribute attribute in type.GetCustomAttributes(typeof(BoltExecutionOrderAttribute), false)) { SetExecutionOrder(monoScripts[type.Name], attribute.executionOrder); } } catch (Exception exn) { Debug.LogException(exn); } } } } } }