Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
ai.fluctio.fluctio-sim / EditorUtils / Gui / ChangeCheck.cs
Size: Mime:
using System;
using UnityEditor;
using UnityEngine;

namespace Fluctio.FluctioSim.EditorUtils.Gui
{
	// Unity's ChangeCheckScope is not sane
	public class ChangeCheck
	{
		private ChangeCheckScope _scope = null;

		public IDisposable Scope()
		{
			if (_scope != null)
			{
				throw new InvalidOperationException("Can not create scope multiple times");
			}
			_scope = new ChangeCheckScope();
			return _scope;
		}

		public bool Changed
		{
			get
			{
				if (_scope == null)
				{
					throw new InvalidOperationException("Can not check change without creating scope");
				}
				return _scope.Changed;
			}
		}

		private class ChangeCheckScope : GUI.Scope
		{
			private bool _changed;
			private bool _checkEnded = false;
			public bool Changed
			{
				get
				{
					if (!_checkEnded)
					{
						throw new InvalidOperationException("Can not check change before scope ended");
					}
					return _changed;
				}
			}
		
			public ChangeCheckScope() {
				EditorGUI.BeginChangeCheck();
			}
		
			protected override void CloseScope()
			{
				_changed = EditorGUI.EndChangeCheck();
				_checkEnded = true;
			}
		}
	}
}