void Start() { #if UNITY_EDITOR if (!UnityEditor.EditorApplication.isPlaying && VGlobal.GetSetting().saveBackup) { BroadcastMessage("SubscribeEvent", SendMessageOptions.RequireReceiver); UnityEditor.EditorApplication.CallbackFunction _event = UnityEditor.EditorApplication.playmodeStateChanged; string log = ""; for (int i = 0; i < _event.GetInvocationList().Length; i++) { log = log + i + "/" + _event.GetInvocationList().Length + ": " + _event.GetInvocationList() [i].Method.ToString() + "\n"; } Debug.LogWarning(log); } #endif if (VGlobal.GetSetting().FakeDeco) { if (!deco) { deco = new GameObject("Decoration"); deco.transform.parent = transform; deco.transform.localPosition = Vector3.zero; deco.transform.localRotation = Quaternion.Euler(Vector3.zero); } CreateVoxels(); } }
public static void ProcessWWW(UnityWebRequest www, System.Action <UnityWebRequest> callback, System.Action <string> onFail = null) { #if UNITY_EDITOR if (!UnityEditor.EditorApplication.isPlaying) { UnityEditor.EditorApplication.CallbackFunction routine = null; routine = () => { while (!www.isDone) { return; } if (www.error != null) { if (onFail != null) { onFail(www.error); } Debug.Log(www.error); } UnityEditor.EditorApplication.update -= routine; callback(www); }; UnityEditor.EditorApplication.update += routine; } #else //ToDO //DownloaderCoroutineHolderGObj = new GameObject. #endif }
private static void RunOnEditorThread(Action act) { // create enum which contains act(). var waitThenEnum = WaitUntilTrueThen( () => { return(true); }, () => { act(); } ); /* * set enum to Editor main thread. */ UnityEditor.EditorApplication.CallbackFunction exe = null; exe = () => { var contiune = waitThenEnum.MoveNext(); if (!contiune) { EditorApplication.update -= exe; } }; EditorApplication.update += exe; }
public static void RemoveModeChange(CallbackFunction method) { #if UNITY_2017_2_OR_NEWER #else EditorApplication.playmodeStateChanged -= method; #endif }
public static void AddModeChange(CallbackFunction method) { #if UNITY_2017_2_OR_NEWER EditorApplication.playModeStateChanged += (x) => method(); #else EditorApplication.playmodeStateChanged += method; #endif }
static EditorEvents() { Events.Register("On Global Event"); Events.Register("On Editor Update"); Events.Register("On Prefab Changed"); Events.Register("On Lightmap Baked"); Events.Register("On Windows Reordered"); Events.Register("On Hierarchy Changed"); Events.Register("On Asset Changed"); Events.Register("On Asset Saving"); Events.Register("On Asset Creating"); Events.Register("On Asset Deleting"); Events.Register("On Asset Moving"); Events.Register("On Scene Loaded"); Events.Register("On Editor Scene Loaded"); Events.Register("On Editor Quit"); Events.Register("On Mode Changed"); Events.Register("On Enter Play"); Events.Register("On Exit Play"); Events.Register("On Undo Flushing"); Events.Register("On Undo"); Events.Register("On Redo"); #if UNITY_5_0_OR_NEWER Camera.onPostRender += (Camera camera) => Events.Call("On Camera Post Render", camera); Camera.onPreRender += (Camera camera) => Events.Call("On Camera Pre Render", camera); Camera.onPreCull += (Camera camera) => Events.Call("On Camera Pre Cull", camera); Lightmapping.completed += () => Events.Call("On Lightmap Baked"); #endif UnityUndo.willFlushUndoRecord += () => Events.Call("On Undo Flushing"); UnityUndo.undoRedoPerformed += () => Events.Call("On Undo"); UnityUndo.undoRedoPerformed += () => Events.Call("On Redo"); ProxyEditor.prefabInstanceUpdated += (target) => Events.Call("On Prefab Changed", target); ProxyEditor.ProjectChanged(() => Events.Call("On Project Changed")); EditorApplication.playModeStateChanged += (PlayModeStateChange state) => { Events.Call("On Mode Changed"); bool changing = ProxyEditor.IsChanging(); bool playing = Proxy.IsPlaying(); if (changing && !playing) { Events.Call("On Enter Play"); } if (!changing && playing) { Events.Call("On Exit Play"); } }; ProxyEditor.HierarchyChanged(() => Events.DelayCall("On Hierarchy Changed", 0.25f)); EditorApplication.update += () => Events.Call("On Editor Update"); UnityCallback windowEvent = () => Events.Call("On Window Reordered"); UnityCallback globalEvent = () => Events.Call("On Global Event"); var editorQuitEvent = new UnityAction(() => Events.Call("On Editor Quit")); var windowsReordered = typeof(EditorApplication).GetVariable <UnityCallback>("windowsReordered"); var globalEventHandler = typeof(EditorApplication).GetVariable <UnityCallback>("globalEventHandler"); var editorQuitHandler = typeof(EditorApplication).GetVariable <UnityAction>("editorApplicationQuit"); typeof(EditorApplication).SetVariable("windowsReordered", windowsReordered + windowEvent); typeof(EditorApplication).SetVariable("globalEventHandler", globalEventHandler + globalEvent); typeof(EditorApplication).SetVariable("editorApplicationQuit", editorQuitHandler + editorQuitEvent); }
void OnValidate() { UnityEditor.EditorApplication.CallbackFunction autoUnregister = null; autoUnregister = () => { UnityEditor.EditorApplication.update -= autoUnregister; OnValidateImmediate(); }; UnityEditor.EditorApplication.update += autoUnregister; }
private static void RunEnumeratorOnEditorThread(IEnumerator cor) { UnityEditor.EditorApplication.CallbackFunction exe = null; exe = () => { var contiune = cor.MoveNext(); if (!contiune) { EditorApplication.update -= exe; } }; EditorApplication.update += exe; }
protected internal virtual void EditorValidateAssetPathAsync() { if (_updateCallback != null) { UnityEditor.EditorApplication.update -= _updateCallback; } _updateCallback = null; _updateCallback = () => { UnityEditor.EditorApplication.update -= _updateCallback; EditorValidateAssetPath(); }; UnityEditor.EditorApplication.update += _updateCallback; }
public static void MarkAllScenesDirty() { #if UNITY_EDITOR if (!Application.isPlaying) { UnityEditor.EditorApplication.CallbackFunction DelayCall = null; DelayCall = () => { UnityEditor.EditorApplication.delayCall -= DelayCall; UnityEditor.SceneManagement.EditorSceneManager.MarkAllScenesDirty(); }; UnityEditor.EditorApplication.delayCall += DelayCall; } #endif }
public static void SetEnabled(bool enabled, bool retrying = false) { if (retrying) { EditorApplication.delayCall -= s_onRetry; s_onRetry = null; Log.d("Retrying Android Plugin import..."); } var androidPathAAR = FileUtils.FixAssetPath(EditorConstants.EditorPathAndroidAAR); if (androidPathAAR == null || !FileUtils.AssetPathExists(androidPathAAR)) { Debug.LogErrorFormat("Can't {0} Android plugin: missing required file '{1}'. Re-install {2} to fix the issue.", enabled ? "enable" : "disable", androidPathAAR, Constants.PluginDisplayName); return; } var importer = (PluginImporter)AssetImporter.GetAtPath(androidPathAAR); if (importer == null) { // mleenhardt: Added delayed retry attempt to fix error caused by the fact that importer is // null the very first time the project is loaded when there is no Library folder yet. if (!retrying) { s_onRetry = () => SetEnabled(enabled, true); EditorApplication.delayCall += s_onRetry; return; } Debug.LogErrorFormat("Can't {0} Android plugin: unable to create importer for '{1}'. Re-install {2} to fix the issue.", enabled ? "enable" : "disable", androidPathAAR, Constants.PluginDisplayName); return; } if (importer.GetCompatibleWithPlatform(BuildTarget.Android) != enabled) { importer.SetCompatibleWithPlatform(BuildTarget.Android, enabled); importer.SaveAndReimport(); } }
private void DelayDestroy_EDITOR() { var toDestroy = this.componentsToDestroy.ToArray(); UnityEditor.EditorApplication.CallbackFunction delayCall = null; delayCall = () => { foreach (var c in toDestroy) { Component.DestroyImmediate(c, allowDestroyingAssets: true); } this.animationInputParams = this.animationInputParams.Where((i) => i != null).ToList(); UnityEditor.EditorApplication.delayCall -= delayCall; }; UnityEditor.EditorApplication.delayCall += delayCall; }
public override void OnValidateEditor() { base.OnValidateEditor(); if (this.editorPreload == false) { this.prefabResource.tempObject = this.prefab; this.prefabResource.Validate(); this.prefabNoResource = null; if (this.prefabResource.IsLoadable() == false) { this.prefabNoResource = this.prefab; } } if (this.editorPreloadRefresh == true && ME.EditorUtilities.IsPrefab(this.gameObject) == false) { this.editorPreloadRefresh = false; if (this._instance != null) { this.UnregisterSubComponent(this._instance); var oldInstance = this._instance; UnityEditor.EditorApplication.CallbackFunction onDelay = null; onDelay = () => { UnityEditor.EditorApplication.delayCall -= onDelay; GameObject.DestroyImmediate(oldInstance.gameObject, true); }; UnityEditor.EditorApplication.delayCall += onDelay; } if (this.editorPreload == true) { if (this.prefab != null) { this.Load_INTERNAL(this.prefab); } this.prefabNoResource = null; this.prefabResource.ResetToDefault(); } } }
public static void Destroy(Object component, System.Action callback = null) { if (component != null) { UnityEditor.EditorApplication.CallbackFunction action = null; action = () => { EditorApplication.delayCall -= action; if (component != null) { Object.DestroyImmediate(component, allowDestroyingAssets: true); } if (callback != null) { callback.Invoke(); } }; EditorApplication.delayCall += action; } }
protected internal virtual void EditorLoadAssetFromPathAsync() { if (_updateCallback != null) { UnityEditor.EditorApplication.update -= _updateCallback; } _updateCallback = null; _updateCallback = () => { UnityEditor.EditorApplication.update -= _updateCallback; if (!string.IsNullOrEmpty(m_assetPath)) { m_asset = Resources.Load <T>(m_assetPath); } EditorValidateAssetPath(); }; UnityEditor.EditorApplication.update += _updateCallback; }
public static Coroutine Start(IEnumerator coroutine) { #if UNITY_EDITOR // Special case to allow coroutines to run in the Editor if (!UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode) { UnityEditor.EditorApplication.CallbackFunction delg = null; delg = delegate() { if (!coroutine.MoveNext()) { UnityEditor.EditorApplication.update -= delg; } }; UnityEditor.EditorApplication.update += delg; return(null); } #endif return(pInstance.StartCoroutine(coroutine)); }
public static void DestroySelf(this Object obj, float t = 0f) { if (obj != null) { if (Application.isPlaying) { Object.Destroy(obj, t); } else { #if UNITY_EDITOR UnityEditor.EditorApplication.CallbackFunction delayedNotify = null; delayedNotify = () => { UnityEditor.EditorApplication.delayCall -= delayedNotify; Object.DestroyImmediate(obj); }; UnityEditor.EditorApplication.delayCall += delayedNotify; #endif } } }
public static void Apply(string themeName = "") { if (Theme.active.IsNull()) { return; } var theme = Theme.active; theme.skinset.Apply(theme); if (theme.name != "Default") { foreach (var color in theme.palette.colors["*"]) { if (color.Value.skipTexture) { continue; } color.Value.UpdateTexture(Theme.storagePath); } CallbackFunction UpdateDynamic = () => { if (theme.palette.swap.Count < 1) { return; } foreach (var file in FileManager.FindAll("#*.png")) { theme.palette.ApplyTexture(file.path, file.GetAsset <Texture2D>()); } }; if (Application.isPlaying) { UpdateDynamic(); } else { Utility.DelayCall("UpdateDynamicTextures", UpdateDynamic, 0.1f); } } }
public static void ProcessWebRequest(UnityWebRequest www, System.Action <UnityWebRequest> onComplete, System.Action <string> onError = null) { #if UNITY_EDITOR if (!UnityEditor.EditorApplication.isPlaying) { UnityEditor.EditorApplication.CallbackFunction routine = null; routine = () => { while (!www.isDone) { return; } UnityEditor.EditorApplication.update -= routine; if (www.error != null) { if (onError != null) { onError(www.error); } else { Debug.Log(www.error); } return; } onComplete(www); }; UnityEditor.EditorApplication.update += routine; } else { wwwProcessHolder.BeginWWWProcess(www, onComplete); } #else wwwProcessHolder.BeginWWWProcess(www, onComplete); #endif }
void DownloadRipGrep() { new Thread(() => { try { var outDir = Prefix + "Library/ripgrep"; var ext = Path.GetExtension(RipGrepReleaseUrl); var ext2 = Path.GetExtension(Path.GetFileNameWithoutExtension(RipGrepReleaseUrl)); if (!string.IsNullOrEmpty(ext2) && ext2.Length < 5) { ext = ext2 + ext; } var arcPath = Prefix + "Temp/ripgrep" + ext; if (!File.Exists(arcPath)) { #if UNITY_2017 var isDone = false; string error = null; UnityEditor.EditorApplication.delayCall += () => { var req = new UnityEngine.Networking.UnityWebRequest(RipGrepReleaseUrl, "GET"); req.downloadHandler = new UnityEngine.Networking.DownloadHandlerFile(arcPath); req.SendWebRequest(); UnityEditor.EditorApplication.CallbackFunction callback = null; callback = () => { if (!req.isDone && !req.isHttpError && !req.isNetworkError) { UnityEditor.EditorApplication.delayCall = callback; return; } if (!string.IsNullOrEmpty(req.error)) { error = req.error; } isDone = true; }; callback(); }; while (!isDone) { Thread.Sleep(500); } if (!string.IsNullOrEmpty(error)) { throw new Exception(error); } #else using (var client = new WebClient()) { Log("download.. " + RipGrepReleaseUrl); client.DownloadFile(RipGrepReleaseUrl, arcPath); } #endif } var fi = new FileInfo(arcPath); if (!fi.Exists || fi.Length < 1000) { if (fi.Exists) { File.Delete(arcPath); } throw new Exception("download failed"); } if (!Directory.Exists(outDir)) { Directory.CreateDirectory(outDir); } Log("extract.. " + arcPath); if (ext == ".zip") { using (var zip = ZipStorer.Open(arcPath, FileAccess.Read)) { foreach (var e in zip.ReadCentralDir()) { var path = Path.Combine(outDir, e.FilenameInZip); Log(path); zip.ExtractFile(e, path); } } } else if (ext == ".tar.gz") { ExecProcess("/usr/bin/tar", "zxvfk '" + arcPath + "' -C '" + outDir + "'"); } else { throw new Exception("unknown: " + ext); } if (!File.Exists(RipGrepPath)) { foreach (var f in Directory.GetFiles(outDir, "*.*", SearchOption.AllDirectories)) { var rel = f.Substring(outDir.Length + 1); Log(rel); var dir = Path.GetDirectoryName(rel).Replace("\\", "/"); if (!string.IsNullOrEmpty(dir)) { var destDir = string.Join("/", dir.Split('/').Skip(1).ToArray()); if (destDir == "") { File.Move(f, outDir + "/" + Path.GetFileName(f)); } else { if (!Directory.Exists(outDir + "/" + destDir)) { Directory.CreateDirectory(outDir + "/" + destDir); } File.Move(f, outDir + "/" + destDir + "/" + Path.GetFileName(f)); } } } } #if UNITY_EDITOR_OSX ExecProcess("/bin/chmod", "+x Library/ripgrep/rg"); #endif if (!File.Exists(RipGrepPath)) { throw new Exception("no rg"); } Log("done"); IsInitialized = true; } catch (Exception e) { Log(e.ToString()); } }).Start(); }
public static void AddUpdate(CallbackFunction method) { EditorApplication.update -= method; EditorApplication.update += method; }
public static void RemoveUpdate(CallbackFunction method) { EditorApplication.update -= method; }
public static void HierarchyChanged(CallbackFunction method) { EditorApplication.hierarchyWindowChanged += method; }
private void ConstructJoints() { if (joints == null) { GPUSkinningPlayerJoint[] existingJoints = go.GetComponentsInChildren <GPUSkinningPlayerJoint>(); GPUSkinningBone[] bones = res.anim.bones; int numBones = bones == null ? 0 : bones.Length; for (int i = 0; i < numBones; ++i) { GPUSkinningBone bone = bones[i]; if (bone.isExposed) { if (joints == null) { joints = new List <GPUSkinningPlayerJoint>(); } bool inTheExistingJoints = false; if (existingJoints != null) { for (int j = 0; j < existingJoints.Length; ++j) { if (existingJoints[j] != null && existingJoints[j].BoneGUID == bone.guid) { if (existingJoints[j].BoneIndex != i) { existingJoints[j].Init(i, bone.guid); GPUSkinningUtil.MarkAllScenesDirty(); } joints.Add(existingJoints[j]); existingJoints[j] = null; inTheExistingJoints = true; break; } } } if (!inTheExistingJoints) { GameObject jointGo = new GameObject(bone.name); jointGo.transform.parent = go.transform; jointGo.transform.localPosition = Vector3.zero; jointGo.transform.localScale = Vector3.one; GPUSkinningPlayerJoint joint = jointGo.AddComponent <GPUSkinningPlayerJoint>(); joints.Add(joint); joint.Init(i, bone.guid); GPUSkinningUtil.MarkAllScenesDirty(); } } } if (!Application.isPlaying) { #if UNITY_EDITOR UnityEditor.EditorApplication.CallbackFunction DelayCall = null; DelayCall = () => { UnityEditor.EditorApplication.delayCall -= DelayCall; DeleteInvalidJoints(existingJoints); }; UnityEditor.EditorApplication.delayCall += DelayCall; #endif } else { DeleteInvalidJoints(existingJoints); } } }
public static void ProjectChanged(CallbackFunction method) { EditorApplication.projectWindowChanged += method; }
internal static bool ActivateInternal( AudioMixerGroup g, AudioClip c, Parameters p, ActivationParams ap, Vector3 pos2, float pitch #if UNITY_EDITOR , Patch patch #endif ) { #if UNITY_EDITOR if (!Application.isPlaying) { UnityEditor.EditorApplication.CallbackFunction f = null; float n = Time.realtimeSinceStartup; f = () => { if (Time.realtimeSinceStartup - n >= ap.delay) { UnityEditor.EditorApplication.update -= f; PlayClip(c, p.loop); } }; UnityEditor.EditorApplication.update += f; return(false); } #endif var i = freeSources.Count > 0 ? freeSources.Pop() : CreateSource(); i.transform.position = pos2; i.Enable(p); var z = new ActiveSource { handle = ap.handle, keyOn = ap.delay, keyOff = false, #if UNITY_EDITOR patch = patch, #endif info = i, target = (ap.transform == null || ap.transform.gameObject.isStatic) ? null : ap.transform, localPosition = ap.position, volume = p.GetVolume() * Mathf.Clamp01(ap.volume), modVolume = ap.modVolume, envelope = Envelope.instant }; #if SYNTHESIZER_PARANOIA Debug.LogFormat( Time.frameCount.ToString("X4") + " Synthesizer.ActivateInternal: {0} {1} ({2})", g, c.name, z.target); #endif if (p.envelope.attack > Mathf.Epsilon) { z.envelope.SetAttack(p.envelope.attack); } if (p.envelope.release > Mathf.Epsilon) { z.envelope.SetRelease(p.envelope.release); } ActivateStatic(g, c, p, i.audioSource, ap.delay, z.GetVolume(), pitch); activeSources0.Add(z); return(p.loop); }