示例#1
0
        public static IDisposable SetActiveScene(Scene scene)
        {
            var currentScene = SceneManager.GetActiveScene();

            SceneManager.SetActiveScene(scene);
            return(DisposableLock.Lock(() => SceneManager.SetActiveScene(currentScene)));
        }
示例#2
0
 public static IDisposable Property(Rect totalPosition, GUIContent label, SerializedProperty property, out GUIContent content)
 {
     content = EditorGUI.BeginProperty(totalPosition, label, property);
     return(DisposableLock.Lock(() => {
         EditorGUI.EndProperty();
     }));
 }
示例#3
0
 /// <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);
     }
 }
示例#4
0
        public static IDisposable LabelWidth(float newWidth)
        {
            float oldWidth = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = newWidth;

            return(DisposableLock.Lock(() => EditorGUIUtility.labelWidth = oldWidth));
        }
示例#5
0
        public static IDisposable SelectGameObject(this GameObject go)
        {
            var ago = Selection.activeGameObject;

            Selection.activeGameObject = go;
            return(DisposableLock.Lock(() => {
                Selection.activeGameObject = ago;
            }));
        }
示例#6
0
        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;
            }));
        }
示例#7
0
 public static IDisposable ChangeCheck(Action OnChange, bool ignore = false)
 {
     EditorGUI.BeginChangeCheck();
     return(DisposableLock.Lock(() => {
         if (!ignore && EditorGUI.EndChangeCheck())
         {
             OnChange?.Invoke();
         }
     }));
 }
示例#8
0
 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);
     }
 }
示例#10
0
 public static IDisposable EnsureDisabled(this Behaviour c)
 {
     if (c.enabled)
     {
         c.enabled = false;
         return(DisposableLock.Lock(() => c.enabled = true));
     }
     else
     {
         return(DisposableLock.empty);
     }
 }
示例#11
0
        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");
        }
示例#12
0
        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);
            }
        }
示例#13
0
    /// <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));
    }
示例#14
0
 public LockZone(DisposableLock baseLock)
 {
     BaseLock = baseLock;
 }
 public IDisposable SuspendChangePageCellsSize()
 {
     return(DisposableLock.Lock(ref lockChangePageCellsSize));
 }
示例#16
0
 public static IDisposable BeginSample(string name)
 {
     Profiler.BeginSample(name);
     return(DisposableLock.Lock(() => Profiler.EndSample()));
 }
示例#17
0
 public LockZone(DisposableLock baseLock)
 {
     BaseLock = baseLock;
 }
示例#18
0
 private ReaderWriterLockZone(DisposableLock @lock)
 {
     UnderlaidReaderLock = @lock;
     UnderlaidWriterLock = @lock;
 }
示例#19
0
 public void Dispose()
 {
     DisposeAction?.Invoke();
     DisposableLock?.Dispose();
 }
示例#20
0
 public static IDisposable ScrollView(ref Vector2 scrollPosition, params GUILayoutOption[] options)
 {
     scrollPosition = GUILayout.BeginScrollView(scrollPosition, options);
     return(DisposableLock.Lock(() => GUILayout.EndScrollView()));
 }
示例#21
0
 public static IDisposable Horizontal(params GUILayoutOption[] options)
 {
     GUILayout.BeginHorizontal(options);
     return(DisposableLock.Lock(() => GUILayout.EndHorizontal()));
 }
示例#22
0
 public static IDisposable Area(Rect screenRect)
 {
     GUILayout.BeginArea(screenRect);
     return(DisposableLock.Lock(() => GUILayout.EndArea()));
 }
示例#23
0
 public IDisposable SuspendUpdateVisualImage()
 {
     return(DisposableLock.Lock(ref updateVisualImageLock, UpdateVisualImageIfNeeded));
 }
示例#24
0
 public static IDisposable Vertical(params GUILayoutOption[] options)
 {
     GUILayout.BeginVertical(options);
     return(DisposableLock.Lock(() => GUILayout.EndVertical()));
 }
示例#25
0
 /// <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));
 }
示例#26
0
 public IDisposable SuspendCallManipulations()
 {
     return(DisposableLock.Lock(ref callManipulationsLock, CallManipulationsIfNeeded));
 }
示例#27
0
 private ReaderWriterLockZone(DisposableLock @lock)
 {
     UnderlaidReaderLock = @lock;
     UnderlaidWriterLock = @lock;
 }