public static string TextfieldWithOk(string label, string value, Action <string> onSubmit, string submitLbl = "OK") { EU.HGroup(() => { value = EditorGUILayout.TextField(label, value); EU.Btn(submitLbl, () => onSubmit.Invoke(value)); }); return(value); }
public void Build(string lbl, Action <UploadedModel> onUpload) { if (GUILayout.Button(lbl)) { string path = EditorUtility.OpenFilePanel(lbl, string.IsNullOrEmpty(_lastUploadPath) ? "~/" : _lastUploadPath, "png,jpg"); if (path.Length != 0) { _lastUploadPath = path; _model = new UploadedModel(path, path.LastSplit()); } } bool hasUploadedTexture = null != _model ? _model.Texture != null : false; EU.HGroup(() => { EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (hasUploadedTexture && GUILayout.Button("X")) { _model = null; } EditorGUILayout.EndHorizontal(); }); if (hasUploadedTexture && null != _model) { EU.VSpacing(); Rect r = GUILayoutUtility.GetLastRect(); float windowWidth = EditorGUIUtility.currentViewWidth; r.size = _model.TextureSize.AspectRatio(windowWidth - 30f); EditorGUI.DrawPreviewTexture(r, _model.Texture); EU.VSpacing(r.height); EditorGUILayout.LabelField(_lastUploadPath, EditorStyles.miniBoldLabel); EU.VPadding(() => { _model.Filename = EditorGUILayout.TextField("Filename", _model.Filename); }); EU.VPadding(() => { if (_model.FilenameExists && GUILayout.Button("UPLOAD")) { onUpload(_model); } }); } }
public void Build(ToggleState state, List <Item> items, Action <ToggleState> onToggle) { EU.HGroup(() => { items.Loop((it, idx) => { bool selected = state.Idx == idx; var style = new GUIStyle(GUI.skin.button); style.normal.textColor = selected ? Color.blue : Color.black; if (GUILayout.Button(it.Text, style) && !selected) { onToggle(new ToggleState(!state.State)); } }); }); Item item = items[state.Idx]; EU.VPadding(() => item.Build()); }
public bool Build(BuildCallback cb) { int cur = cb.Origins.IndexOf(cb.Value); EU.VPadding(() => { if (null != cb.AddAction && GUILayout.Button(cb.AddAction.Label)) { T item = new T(); cb.Origins.Add(item); if (null != cb.AddAction.OnAdd) { cb.AddAction.OnAdd.Invoke(cb.Origins.Count); } } EditorGUILayout.LabelField(cb.Label, EditorStyles.boldLabel); if (m_alignment == Align.V) { GUILayout.BeginVertical(); } else { GUILayout.BeginHorizontal(); } cb.Origins.Loop((t, idx) => { EU.HGroup(() => { bool isSelected = idx == cur; var style = new GUIStyle(GUI.skin.button); style.normal.textColor = isSelected ? Color.cyan : Color.white; if (null != cb.Prefix) { cb.Prefix(t); } if (GUILayout.Button(cb.Mapper(t), style)) { cb.OnSelected.Invoke(new SelectState <T>(idx, cb.Origins[idx])); cur = idx; } if (null != cb.Suffix) { cb.Suffix(t); } if (null != cb.MoveAction && cb.Origins.Count > idx + 1) { EU.BtnWithAlert("V", () => { if (cb.MoveAction.Move != null) { cb.MoveAction.Move(idx); } else { cb.Origins.Swap(idx, idx + 1); } cb.MoveAction.OnMoved.Invoke(); }, GUILayout.Width(20f)); } if (null != cb.DelAction) { EU.BtnWithAlert(cb.DelAction.Label, () => { if (null != cb.DelAction.OnDelete) { cb.DelAction.OnDelete(new SelectState <T>(idx, cb.Origins[idx])); } else { cb.Origins.RemoveAt(idx); } if (null != cb.DelAction.OnDeleted) { cb.DelAction.OnDeleted.Invoke(idx); } }, GUILayout.Width(20f)); } }); }); if (m_alignment == Align.V) { GUILayout.EndVertical(); } else { GUILayout.EndHorizontal(); } }); return(cur > -1); }