Beispiel #1
0
        public virtual void ResetDimensions()
        {
            var option = data.option;

            if (option != null)
            {
                if (data.type == BaseGUI.ControlType.PrefixLabel)
                {
                    width = UnityEditor.EditorGUIUtility.labelWidth - 5f;
                }
                else if (option.width.HasValue)
                {
                    width = option.width.Value;
                }
                else if (option.fit)
                {
                    var size = data.style.CalcSize(data.content);
                    width = size.x;
                }
                height = option.height.HasValue ? option.height.Value : BaseGUI.GetHeight(data.type);
            }
            else
            {
                width  = null;
                height = BaseGUI.GetHeight(data.type);
            }
        }
Beispiel #2
0
        public BaseDrawer Initialize(EditorMember member, Attribute[] attributes, BaseGUI gui, EditorRecord prefs)
        {
            if (attributes == null)
                attributes = Empty;

            if (this.prefs == null)
                this.prefs = prefs;

            this.member     = member;
            this.attributes = attributes;
            this.gui        = gui;

            if (_dynamicFormatter != null)
            {
                _formatArgs[0] = member.Value;
                displayText = _dynamicFormatter(rawTarget, _formatArgs);
            }

            if (_hasInit)
            {
#if DBG
                Log(this + " is Already initialized");
#endif
                return this;
            }
#if DBG
            Log("Initializing: " + this);
#endif
            var displayAttr = attributes.GetAttribute<DisplayAttribute>();
            if (displayAttr != null && MemberDrawersHandler.IsApplicableAttribute(memberType, displayAttr, attributes))
            {
                var hasCustomFormat = !string.IsNullOrEmpty(displayAttr.FormatMethod);
                var formatMethod = hasCustomFormat ? displayAttr.FormatMethod : ("Format" + member.Name);
                var method = targetType.GetMemberFromAll(formatMethod, Flags.StaticInstanceAnyVisibility) as MethodInfo;
                if (method == null)
                {
                    if (hasCustomFormat)
                        Debug.Log("Couldn't find format method: " + displayAttr.FormatMethod);
                }
                else
                {
                    if (method.ReturnType != typeof(string) && method.GetParameters().Length > 0)
                        Debug.Log("Format Method should return a string and take no parameters: " + method);
                    else
                    {
                        _dynamicFormatter = method.DelegateForCall<object, string>();
                        _formatArgs[0] = member.Value;
                        displayText = _dynamicFormatter(rawTarget, _formatArgs);
                    }
                }
            }

            _hasInit = true;
            InternalInitialize();
            Initialize();
            return this;
        }
Beispiel #3
0
        public GUIControl(ControlData data)
        {
            this.data = data;

            vSpacing = BaseGUI.GetVSpacing(data.type);
            hSpacing = BaseGUI.GetHSpacing(data.type);

            width  = null;
            height = null;
        }
		public void Initialize(MethodInfo method, object rawTarget, UnityObject unityTarget, int id, BaseGUI gui, EditorRecord prefs)
		{
            this.prefs = prefs;
			this.gui = gui;
			this.rawTarget = rawTarget;
            this.unityTarget = unityTarget;
			this.id = id;

			if (initialized) return;
			initialized = true;

            isCoroutine = method.ReturnType == typeof(IEnumerator);

            var commentAttr = method.GetCustomAttribute<CommentAttribute>();
            if (commentAttr != null)
                comment = commentAttr.comment;

			niceName = method.GetNiceName();

            if (niceName.IsPrefix("dbg") || niceName.IsPrefix("Dbg"))
                niceName = niceName.Remove(0, 3);

			invoke	     = method.DelegateForCall();
			var argInfos = method.GetParameters();
			int len      = argInfos.Length;
			argValues    = new object[len];
			argKeys      = new int[len];
			argMembers   = new EditorMember[len];

			for (int iLoop = 0; iLoop < len; iLoop++)
			{
				int i = iLoop;
				var argInfo = argInfos[i];

				argKeys[i] = RuntimeHelper.CombineHashCodes(id, argInfo.ParameterType.Name + argInfo.Name);

				argValues[i] = TryLoad(argInfos[i].ParameterType, argKeys[i]);

                argMembers[i] = EditorMember.WrapGetSet(
                        @get         : () =>  argValues[i],
                        @set         : x => argValues[i] = x,
                        @rawTarget   : rawTarget,
                        @unityTarget : unityTarget,
                        @attributes  : argInfo.GetCustomAttributes(true) as Attribute[],
                        @name        : argInfo.Name,
                        @id          : argKeys[i],
                        @dataType    : argInfo.ParameterType
                    );
			}

#if DBG
			Log("Method drawer init");
#endif
		}
		private void Initialize(Tab[] tabs, Action onClose)
		{
			// TODO: Use RabbitGUI when we implement BeginScrollView
			gui = new TurtleGUI();

			this.onClose = onClose;
			this.tabs = tabs;

			for (int i = 0; i < tabs.Length; i++)
			{
				var t = tabs[i];
				t.gui = gui;
				t.selectionStyle = GUIHelper.SelectionRect;
			}
			currentTab = lastTabIndex >= tabs.Length ? tabs[0] : tabs[lastTabIndex];
			search = string.Empty;
		}
 public IndentBlock(BaseGUI gui)
 {
     this.gui = gui;
     indents  = new Stack <float>();
 }
			public ScrollViewBlock(BaseGUI gui)
			{
				this.gui = gui;
			}
 public ScrollViewBlock(BaseGUI gui)
 {
     this.gui = gui;
 }
Beispiel #9
0
 public IndentBlock(BaseGUI gui)
 {
     this.gui = gui;
     indents = new Stack<float>();
 }
        private void OnGUI()
        {
            if (gui == null || guiType != gui.GetType())
            {
                gui = BaseGUI.Create(guiType);
                Repaint();
            }

            gui.OnGUI(GUICode, new Vector2(5f, 5f), id); // the vector is just padding (or border offsets). x coord is left, y is right
        }
Beispiel #11
0
 /// <summary>
 /// Call this if you're inlining this editor and you're using your own gui instance
 /// It's important in that case to use the same gui in order to have the same layout
 /// </summary>
 public void OnInlinedGUI(BaseGUI otherGui)
 {
     this.gui = otherGui;
     OnGUI();
 }