public static IDisposable SetActiveScene(Scene scene) { var currentScene = SceneManager.GetActiveScene(); SceneManager.SetActiveScene(scene); return(DisposableLock.Lock(() => SceneManager.SetActiveScene(currentScene))); }
public static IDisposable Property(Rect totalPosition, GUIContent label, SerializedProperty property, out GUIContent content) { content = EditorGUI.BeginProperty(totalPosition, label, property); return(DisposableLock.Lock(() => { EditorGUI.EndProperty(); })); }
/// <summary> /// Initializes undo/redo provider and attaches it to image object. /// </summary> /// <param name="image">Image object to attach to.</param> public UndoRedoProvider(CodedImage image) : this() { using (DisposableLock.Lock(ref updateHasChangesLock)) { AttachToImage(image); } }
public static IDisposable LabelWidth(float newWidth) { float oldWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = newWidth; return(DisposableLock.Lock(() => EditorGUIUtility.labelWidth = oldWidth)); }
public static IDisposable SelectGameObject(this GameObject go) { var ago = Selection.activeGameObject; Selection.activeGameObject = go; return(DisposableLock.Lock(() => { Selection.activeGameObject = ago; })); }
public static IDisposable State(Random.State state, Action <Random.State> updateStateFn) { var oldState = Random.state; Random.state = state; return(DisposableLock.Lock(() => { updateStateFn(Random.state); Random.state = oldState; })); }
public static IDisposable ChangeCheck(Action OnChange, bool ignore = false) { EditorGUI.BeginChangeCheck(); return(DisposableLock.Lock(() => { if (!ignore && EditorGUI.EndChangeCheck()) { OnChange?.Invoke(); } })); }
public void RestoreManipulations() { if (IsManipulatedImageInitialized) { using (DisposableLock.Lock(ref imageChangedLock, OnImageChanged)) { CopySourceImage(); RestoreManipulationsCore(); } } }
public static IDisposable EnsureInactive(this GameObject go) { if (go.activeSelf) { go.SetActive(false); return(DisposableLock.Lock(() => go.SetActive(true))); } else { return(DisposableLock.empty); } }
public static IDisposable EnsureDisabled(this Behaviour c) { if (c.enabled) { c.enabled = false; return(DisposableLock.Lock(() => c.enabled = true)); } else { return(DisposableLock.empty); } }
public void TestDisposableSuspender() { DisposableLock testLock1 = null; DisposableLock testLock2 = null; Assert.IsFalse(testLock1.IsLocked()); Assert.IsFalse(testLock2.IsLocked()); int unlockCounter = 0; Action unlockAction = () => unlockCounter++; Assert.AreEqual(0, unlockCounter); using (DisposableLock.Lock(ref testLock1, unlockAction)) { Assert.IsTrue(testLock1.IsLocked()); Assert.IsFalse(testLock2.IsLocked()); Assert.AreEqual(0, unlockCounter); using (DisposableLock.Lock(ref testLock1, unlockAction)) { Assert.IsTrue(testLock1.IsLocked()); Assert.IsFalse(testLock2.IsLocked()); Assert.AreEqual(0, unlockCounter); using (DisposableLock.Lock(ref testLock2, unlockAction)) { Assert.IsTrue(testLock1.IsLocked()); Assert.IsTrue(testLock2.IsLocked()); Assert.AreEqual(0, unlockCounter); } Assert.IsTrue(testLock1.IsLocked()); Assert.IsFalse(testLock2.IsLocked()); Assert.AreEqual(1, unlockCounter, "Action for counter 2 should be fired"); } Assert.IsTrue(testLock1.IsLocked()); Assert.IsFalse(testLock2.IsLocked()); Assert.AreEqual(1, unlockCounter); } Assert.IsFalse(testLock1.IsLocked()); Assert.IsFalse(testLock2.IsLocked()); Assert.AreEqual(2, unlockCounter, "Action for counter 1 should be fired"); }
public async Task <IDisposable> AcquireLock(LockType lockType) { while (true) { EnsureObjectNotDisposed(); var lck = new PersistentLock(_instanceName, lockType, DateTimeOffset.UtcNow, _instanceId, _lockTtl); if (await _lockRepository.TrySave(lck)) { var disposableLock = new DisposableLock(this, lck); return(disposableLock); } await Task.Delay(SleepThreshold); } }
/// <summary> /// Runs the operation /// </summary> /// <returns>The disposable wrapper</returns> public async Task <IDisposable> RunAsync() { // Await the lock and get the disposable IDisposable d = await DisposableLock.LockAsync(); try { // Run start action StartAction.Invoke(); } catch { d.Dispose(); throw; } // Create the disposable action return(new DisposableAction(DisposeAction, d)); }
public LockZone(DisposableLock baseLock) { BaseLock = baseLock; }
public IDisposable SuspendChangePageCellsSize() { return(DisposableLock.Lock(ref lockChangePageCellsSize)); }
public static IDisposable BeginSample(string name) { Profiler.BeginSample(name); return(DisposableLock.Lock(() => Profiler.EndSample())); }
private ReaderWriterLockZone(DisposableLock @lock) { UnderlaidReaderLock = @lock; UnderlaidWriterLock = @lock; }
public void Dispose() { DisposeAction?.Invoke(); DisposableLock?.Dispose(); }
public static IDisposable ScrollView(ref Vector2 scrollPosition, params GUILayoutOption[] options) { scrollPosition = GUILayout.BeginScrollView(scrollPosition, options); return(DisposableLock.Lock(() => GUILayout.EndScrollView())); }
public static IDisposable Horizontal(params GUILayoutOption[] options) { GUILayout.BeginHorizontal(options); return(DisposableLock.Lock(() => GUILayout.EndHorizontal())); }
public static IDisposable Area(Rect screenRect) { GUILayout.BeginArea(screenRect); return(DisposableLock.Lock(() => GUILayout.EndArea())); }
public IDisposable SuspendUpdateVisualImage() { return(DisposableLock.Lock(ref updateVisualImageLock, UpdateVisualImageIfNeeded)); }
public static IDisposable Vertical(params GUILayoutOption[] options) { GUILayout.BeginVertical(options); return(DisposableLock.Lock(() => GUILayout.EndVertical())); }
/// <summary> /// Suppresses removing unused colors from palette. /// </summary> /// <returns><see cref="IDisposable"/> object, which should be disposed to restore removing unused colors.</returns> public IDisposable SuppressRemoveColorsWithoutOccurrences() { return(DisposableLock.Lock(ref removeColorsWithoutOccurrencesLock)); }
public IDisposable SuspendCallManipulations() { return(DisposableLock.Lock(ref callManipulationsLock, CallManipulationsIfNeeded)); }