public override void Draw(InspectorField field, GUIStyle style) { DateTime time = field.GetValue <DateTime>(); if (time == DateTime.MinValue) { time = DateTime.Now; } string title = time.ToString(); if (field.Mixed) { title = " - - - "; } EditorGUILayout.BeginHorizontal(); EditorGUILayout.Space(); if (GUILayout.Button(Calendar, GUIStyle.none, GUILayout.Width(18), GUILayout.Height(18))) { this.field = field; DateTimeDialog.Create(this, time, GUIUtility.GUIToScreenPoint(Event.current.mousePosition)); } TextAnchor anchor = GUI.skin.label.alignment; GUI.skin.label.alignment = TextAnchor.MiddleLeft; GUILayout.Label(title); GUI.skin.label.alignment = anchor; GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); }
/// <summary> /// Create this dialog. /// </summary> public static DateTimeDialog Create(IModal owner, DateTime time, Vector2 position) { DateTimeDialog dialog = DateTimeDialog.CreateInstance <DateTimeDialog>(); float halfWidth = WIDTH / 2; float x = position.x - halfWidth; float y = position.y; Rect rect = new Rect(x, y, 0, 0); dialog.owner = owner; dialog.time = time; dialog.position = rect; dialog.titleContent.text = "Date Time"; DateTime month = new DateTime(1, 1, 1); for (int i = 0; i < 12; i++) { dialog.months[i] = month.ToString("MMMM"); month = month.AddMonths(1); } dialog.ShowAsDropDown(rect, new Vector2(WIDTH, HEIGHT)); return(dialog); }