Some UI adjustments and layout fixes

This commit is contained in:
Sinai 2021-05-17 18:47:37 +10:00
parent fb6e413153
commit 2fc9657560
7 changed files with 108 additions and 63 deletions

View File

@ -18,6 +18,8 @@ namespace UnityExplorer.UI.Inspectors
{
public GameObject GOTarget => Target as GameObject;
public GameObject Content;
public GameObjectControls GOControls;
public TransformTree TransformTree;
@ -217,11 +219,17 @@ namespace UnityExplorer.UI.Inspectors
public override GameObject CreateContent(GameObject parent)
{
UIRoot = UIFactory.CreateVerticalGroup(Pool<GameObjectInspector>.Instance.InactiveHolder,
"GameObjectInspector", true, true, true, true, 5, new Vector4(4, 4, 4, 4), new Color(0.065f, 0.065f, 0.065f));
"GameObjectInspector", true, false, true, true, 5, new Vector4(4, 4, 4, 4), new Color(0.065f, 0.065f, 0.065f));
var scrollObj = UIFactory.CreateScrollView(UIRoot, "GameObjectInspector", out Content, out var scrollbar,
new Color(0.065f, 0.065f, 0.065f));
UIFactory.SetLayoutElement(scrollObj, minHeight: 300, flexibleWidth: 9999, flexibleHeight: 1);
UIFactory.SetLayoutGroup<VerticalLayoutGroup>(Content, spacing: 3, padTop: 2, padBottom: 2, padLeft: 2, padRight: 2);
// Construct GO Controls
GOControls = new GameObjectControls(this);
ConstructLists();
return UIRoot;
@ -231,9 +239,12 @@ namespace UnityExplorer.UI.Inspectors
private void ConstructLists()
{
var listHolder = UIFactory.CreateUIObject("ListTitles", UIRoot);
var listHolder = UIFactory.CreateUIObject("ListHolders", UIRoot);
UIFactory.SetLayoutGroup<HorizontalLayoutGroup>(listHolder, false, true, true, true, 8, 2, 2, 2, 2);
UIFactory.SetLayoutElement(listHolder, flexibleWidth: 9999, flexibleHeight: 9999);
UIFactory.SetLayoutElement(listHolder, minHeight: 350, flexibleWidth: 9999, flexibleHeight: 9999);
//var listRect = listHolder.GetComponent<RectTransform>();
//listRect.anchorMin = new Vector2(0, 1);
//listRect.anchorMax = new Vector2(1, 1);
// Left group (Children)
@ -268,7 +279,7 @@ namespace UnityExplorer.UI.Inspectors
// Right group (Components)
var rightGroup = UIFactory.CreateUIObject("ChildrenGroup", listHolder);
var rightGroup = UIFactory.CreateUIObject("ComponentGroup", listHolder);
UIFactory.SetLayoutElement(rightGroup, flexibleWidth: 9999, flexibleHeight: 9999);
UIFactory.SetLayoutGroup<VerticalLayoutGroup>(rightGroup, false, false, true, true, 2);

View File

@ -99,11 +99,14 @@ namespace UnityExplorer.UI.Inspectors
{
cell.BehaviourToggle.interactable = true;
cell.BehaviourToggle.Set(comp.TryCast<Behaviour>().enabled, false);
cell.BehaviourToggle.graphic.color = new Color(0.8f, 1, 0.8f, 0.3f);
}
else
{
cell.BehaviourToggle.interactable = false;
cell.BehaviourToggle.Set(false, false);
cell.BehaviourToggle.Set(true, false);
//RuntimeProvider.Instance.SetColorBlock(cell.BehaviourToggle,)
cell.BehaviourToggle.graphic.color = new Color(0.2f, 0.2f, 0.2f);
}
// if component is the first index it must be the transform, dont show Destroy button for it.

View File

@ -196,6 +196,8 @@ namespace UnityExplorer.UI.Inspectors
private void DoSetParent(Transform transform)
{
ExplorerCore.Log($"Setting target's transform parent to: {(transform == null ? "null" : $"'{transform.name}'")}");
if (GOTarget.GetComponent<RectTransform>())
GOTarget.transform.SetParent(transform, false);
else
@ -434,9 +436,10 @@ namespace UnityExplorer.UI.Inspectors
private void ConstructTopInfo()
{
var topInfoHolder = UIFactory.CreateVerticalGroup(Parent.UIRoot, "TopInfoHolder", false, false, true, true, 3,
var topInfoHolder = UIFactory.CreateVerticalGroup(Parent.Content, "TopInfoHolder", false, false, true, true, 3,
new Vector4(3, 3, 3, 3), new Color(0.1f, 0.1f, 0.1f), TextAnchor.MiddleLeft);
UIFactory.SetLayoutElement(topInfoHolder, minHeight: 25, flexibleWidth: 9999);
UIFactory.SetLayoutElement(topInfoHolder, minHeight: 100, flexibleWidth: 9999);
topInfoHolder.AddComponent<ContentSizeFitter>().verticalFit = ContentSizeFitter.FitMode.PreferredSize;
// first row (parent, path)
@ -449,11 +452,16 @@ namespace UnityExplorer.UI.Inspectors
UIFactory.SetLayoutElement(ViewParentButton.Component.gameObject, minHeight: 25, minWidth: 100);
ViewParentButton.OnClick += OnViewParentClicked;
this.PathInput = UIFactory.CreateInputField(firstRow, "PathInput", "Enter a GameObject name or path...");
this.PathInput = UIFactory.CreateInputField(firstRow, "PathInput", "...");
PathInput.Component.textComponent.color = Color.grey;
PathInput.Component.textComponent.fontSize = 14;
UIFactory.SetLayoutElement(PathInput.UIRoot, minHeight: 25, minWidth: 100, flexibleWidth: 9999);
PathInput.Component.lineType = InputField.LineType.MultiLineSubmit;
//var pathApplyBtn = UIFactory.CreateButton(firstRow, "PathButton", "Set Parent Path", new Color(0.2f, 0.2f, 0.2f));
//UIFactory.SetLayoutElement(pathApplyBtn.Component.gameObject, minHeight: 25, minWidth: 120);
//pathApplyBtn.OnClick += () => { OnPathEndEdit(PathInput.Text); };
PathInput.Component.onEndEdit.AddListener((string val) => { OnPathEndEdit(val); });
// Title and update row
@ -597,11 +605,14 @@ namespace UnityExplorer.UI.Inspectors
private void ConstructTransformControls()
{
//var transformGroup = UIFactory.CreateUIObject("TransformGroup", UIRoot);
//UIFactory.SetLayoutGroup<VerticalLayoutGroup>(transformGroup, false, false, true, true, 2, 2, 2);
var transformGroup = UIFactory.CreateVerticalGroup(Parent.UIRoot, "TransformControls", false, false, true, true, 2,
var transformGroup = UIFactory.CreateVerticalGroup(Parent.Content, "TransformControls", false, false, true, true, 2,
new Vector4(2, 2, 0, 0), new Color(0.1f, 0.1f, 0.1f));
UIFactory.SetLayoutElement(transformGroup, minHeight: 25, flexibleWidth: 9999);
UIFactory.SetLayoutElement(transformGroup, minHeight: 100, flexibleWidth: 9999);
//transformGroup.SetActive(false);
//var groupRect = transformGroup.GetComponent<RectTransform>();
//groupRect.anchorMin = new Vector2(0, 1);
//groupRect.anchorMax = new Vector2(1, 1);
//groupRect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 0, 100);
PositionControl = AddTransformRow(transformGroup, "Position:", TransformType.Position);
LocalPositionControl = AddTransformRow(transformGroup, "Local Position:", TransformType.LocalPosition);

View File

@ -124,7 +124,7 @@ namespace UnityExplorer.UI.Panels
int fontSize = 16;
var inputObj = UIFactory.CreateSrollInputField(this.content, "ConsoleInput", ConsoleController.STARTUP_TEXT, out var inputScroller, fontSize);
var inputObj = UIFactory.CreateScrollInputField(this.content, "ConsoleInput", ConsoleController.STARTUP_TEXT, out var inputScroller, fontSize);
InputScroll = inputScroller;
ConsoleController.defaultInputFieldAlpha = Input.Component.selectionColor.a;
Input.OnValueChanged += InvokeOnValueChanged;

View File

@ -19,7 +19,7 @@ namespace UnityExplorer.UI.Panels
public override string Name => "Inspector";
public override UIManager.Panels PanelType => UIManager.Panels.Inspector;
public override bool ShouldSaveActiveState => false;
public override int MinWidth => 800;
public override int MinWidth => 810;
public override int MinHeight => 350;
public GameObject NavbarHolder;

View File

@ -12,8 +12,10 @@ namespace UnityExplorer.UI
{
public static class UIFactory
{
internal static Vector2 _largeElementSize = new Vector2(160f, 30f);
internal static Vector2 _smallElementSize = new Vector2(160f, 20f);
#region Init, Core
internal static Vector2 _largeElementSize = new Vector2(100, 30);
internal static Vector2 _smallElementSize = new Vector2(25, 25);
internal static Color _defaultTextColor = Color.white;
internal static Font _defaultFont;
@ -22,13 +24,12 @@ namespace UnityExplorer.UI
_defaultFont = Resources.GetBuiltinResource<Font>("Arial.ttf");
}
public static GameObject CreateUIObject(string name, GameObject parent = null, Vector2 size = default)
public static GameObject CreateUIObject(string name, GameObject parent, Vector2 size = default)
{
if (!parent)
{
ExplorerCore.LogWarning("Cannot create UI object as the parent is null or destroyed! (" + name + ")");
ExplorerCore.LogWarning($"Warning: Creating {name} but parent is null");
ExplorerCore.Log(Environment.StackTrace);
return null;
}
var obj = new GameObject(name)
@ -37,12 +38,11 @@ namespace UnityExplorer.UI
hideFlags = HideFlags.HideAndDontSave,
};
obj.transform.SetParent(parent.transform, false);
if (parent)
obj.transform.SetParent(parent.transform, false);
RectTransform rect = obj.AddComponent<RectTransform>();
rect.sizeDelta = size == default
? _smallElementSize
: size;
rect.sizeDelta = size;
return obj;
}
@ -59,6 +59,11 @@ namespace UnityExplorer.UI
new Color(0.3f, 0.3f, 0.3f), new Color(0.15f, 0.15f, 0.15f));
}
#endregion
#region Default Layout Components
/// <summary>
/// Get and/or Add a LayoutElement component to the GameObject, and set any of the values on it.
/// </summary>
@ -235,6 +240,11 @@ namespace UnityExplorer.UI
return groupObj;
}
#endregion
#region Default Control Elements
/// <summary>
/// Create a Label object.
/// </summary>
@ -410,8 +420,9 @@ namespace UnityExplorer.UI
toggle = toggleObj.AddComponent<Toggle>();
toggle.isOn = true;
// second reference so we can use it inside the lambda, 'toggle' is an out var.
Toggle toggleComp = toggle;
toggle.onValueChanged.AddListener(Deselect);
void Deselect(bool _)
{
@ -419,9 +430,7 @@ namespace UnityExplorer.UI
}
Image bgImage = bgObj.AddComponent<Image>();
bgImage.color = bgColor == default
? new Color(0.04f, 0.04f, 0.04f, 0.75f)
: bgColor;
bgImage.color = bgColor == default ? new Color(0.04f, 0.04f, 0.04f, 0.75f) : bgColor;
Image checkImage = checkObj.AddComponent<Image>();
checkImage.color = new Color(0.8f, 1, 0.8f, 0.3f);
@ -518,8 +527,6 @@ namespace UnityExplorer.UI
inputTextRect.offsetMin = Vector2.zero;
inputTextRect.offsetMax = Vector2.zero;
//SetLayoutElement(inputTextObj, minWidth: 200, flexibleWidth: 5000);
inputField.textComponent = inputText;
inputField.characterLimit = UIManager.MAX_INPUTFIELD_CHARS;
@ -670,6 +677,15 @@ namespace UnityExplorer.UI
return dropdownObj;
}
#endregion
#region Custom Scroll Components
/// <summary>
/// Create a ScrollPool for the <typeparamref name="T"/> ICell.
/// </summary>
public static ScrollPool<T> CreateScrollPool<T>(GameObject parent, string name, out GameObject uiRoot,
out GameObject content, Color? bgColor = null) where T : ICell
{
@ -729,9 +745,14 @@ namespace UnityExplorer.UI
return scrollPool;
}
/// <summary>
/// Create a SliderScrollbar, using a Slider to mimic a scrollbar.
/// </summary>
public static GameObject CreateSliderScrollbar(GameObject parent, out Slider slider)
{
GameObject mainObj = CreateUIObject("SliderScrollbar", parent, _smallElementSize);
mainObj.AddComponent<Mask>();
mainObj.AddComponent<Image>().color = Color.white;
GameObject bgImageObj = CreateUIObject("Background", mainObj);
GameObject handleSlideAreaObj = CreateUIObject("Handle Slide Area", mainObj);
@ -741,6 +762,8 @@ namespace UnityExplorer.UI
bgImage.type = Image.Type.Sliced;
bgImage.color = new Color(0.05f, 0.05f, 0.05f, 1.0f);
bgImageObj.AddComponent<Mask>();
RectTransform bgRect = bgImageObj.GetComponent<RectTransform>();
bgRect.pivot = new Vector2(0, 1);
bgRect.anchorMin = Vector2.zero;
@ -758,13 +781,13 @@ namespace UnityExplorer.UI
var handleRect = handleObj.GetComponent<RectTransform>();
handleRect.pivot = new Vector2(0.5f, 0.5f);
UIFactory.SetLayoutElement(handleObj, minWidth: 21, flexibleWidth: 0);
SetLayoutElement(handleObj, minWidth: 21, flexibleWidth: 0);
var sliderBarLayout = mainObj.AddComponent<LayoutElement>();
sliderBarLayout.minWidth = 25;
sliderBarLayout.flexibleWidth = 0;
sliderBarLayout.minHeight = 30;
sliderBarLayout.flexibleHeight = 5000;
sliderBarLayout.flexibleHeight = 9999;
slider = mainObj.AddComponent<Slider>();
slider.handleRect = handleObj.GetComponent<RectTransform>();
@ -783,65 +806,63 @@ namespace UnityExplorer.UI
}
/// <summary>
/// Create a ScrollView element.
/// Create a ScrollView and a SliderScrollbar for non-pooled content.
/// </summary>
public static GameObject CreateAutoScrollView(GameObject parent, string name, out GameObject content, out AutoSliderScrollbar autoScrollbar,
public static GameObject CreateScrollView(GameObject parent, string name, out GameObject content, out AutoSliderScrollbar autoScrollbar,
Color color = default)
{
GameObject mainObj = CreateUIObject(name, parent);
SetLayoutElement(mainObj, minWidth: 100, minHeight: 30, flexibleWidth: 5000, flexibleHeight: 5000);
SetLayoutGroup<HorizontalLayoutGroup>(mainObj, false, true, true, true, 2);
var mainRect = mainObj.GetComponent<RectTransform>();
mainRect.anchorMin = Vector2.zero;
mainRect.anchorMax = Vector2.one;
Image mainImage = mainObj.AddComponent<Image>();
mainImage.type = Image.Type.Filled;
mainImage.color = (color == default) ? new Color(0.3f, 0.3f, 0.3f, 1f) : color;
GameObject viewportObj = CreateUIObject("Viewport", mainObj);
UIFactory.SetLayoutElement(viewportObj, minWidth: 1, flexibleWidth: 9999, flexibleHeight: 9999);
var viewportRect = viewportObj.GetComponent<RectTransform>();
viewportRect.anchorMin = Vector2.zero;
viewportRect.anchorMax = Vector2.one;
viewportRect.pivot = new Vector2(0.0f, 1.0f);
//viewportRect.sizeDelta = new Vector2(-15.0f, 0.0f);
//viewportRect.offsetMax = new Vector2(-25.0f, 0.0f);
viewportRect.offsetMax = new Vector2(-28, 0);
viewportObj.AddComponent<Image>().color = Color.white;
viewportObj.AddComponent<Mask>().showMaskGraphic = false;
content = CreateUIObject("Content", viewportObj);
SetLayoutGroup<VerticalLayoutGroup>(content, true, false, true, true, childAlignment: TextAnchor.UpperLeft);
SetLayoutElement(content, flexibleHeight: 9999);
var contentRect = content.GetComponent<RectTransform>();
SetLayoutGroup<VerticalLayoutGroup>(content, true, true, true, true);//, 5, 5, 5, 5, 5);
contentRect.anchorMin = new Vector2(0.0f, 1.0f);
contentRect.anchorMax = new Vector2(1.0f, 1.0f);
contentRect.anchorMin = Vector2.zero;
contentRect.anchorMax = Vector2.one;
contentRect.pivot = new Vector2(0.0f, 1.0f);
//contentRect.sizeDelta = new Vector2(5f, 0f);
//contentRect.offsetMax = new Vector2(0f, 0f);
content.AddComponent<ContentSizeFitter>().verticalFit = ContentSizeFitter.FitMode.PreferredSize;
// Slider
GameObject scrollBarObj = CreateUIObject("AutoSliderScrollbar", mainObj);
SetLayoutGroup<VerticalLayoutGroup>(scrollBarObj, true, true, true, true);
SetLayoutElement(scrollBarObj, minWidth: 25, flexibleWidth: 0, flexibleHeight: 9999);
var scrollBarRect = scrollBarObj.GetComponent<RectTransform>();
scrollBarRect.anchorMin = new Vector2(1, 0);
scrollBarRect.anchorMax = Vector2.one;
scrollBarRect.offsetMin = new Vector2(-25, 0);
SetLayoutGroup<VerticalLayoutGroup>(scrollBarObj, false, true, true, true);
scrollBarObj.AddComponent<Image>().color = Color.white;
scrollBarObj.AddComponent<Mask>().showMaskGraphic = false;
GameObject hiddenBar = CreateScrollbar(scrollBarObj, "HiddenScrollviewScroller", out var hiddenScrollbar);
hiddenScrollbar.SetDirection(Scrollbar.Direction.BottomToTop, true);
for (int i = 0; i < hiddenBar.transform.childCount; i++)
{
var child = hiddenBar.transform.GetChild(i);
child.gameObject.SetActive(false);
}
CreateSliderScrollbar(scrollBarObj, out Slider scrollSlider);
autoScrollbar = new AutoSliderScrollbar(hiddenScrollbar, scrollSlider, contentRect, viewportRect);
//var sliderContainer = autoScrollbar.Slider.m_HandleContainerRect.gameObject;
//SetLayoutElement(sliderContainer, minWidth: 25, flexibleWidth: 0, flexibleHeight: 9999);
//sliderContainer.AddComponent<Mask>();
// Set up the ScrollRect component
var scrollRect = mainObj.AddComponent<ScrollRect>();
scrollRect.horizontal = false;
scrollRect.vertical = true;
@ -850,18 +871,18 @@ namespace UnityExplorer.UI
scrollRect.scrollSensitivity = 35;
scrollRect.horizontalScrollbarVisibility = ScrollRect.ScrollbarVisibility.AutoHideAndExpandViewport;
scrollRect.verticalScrollbarVisibility = ScrollRect.ScrollbarVisibility.Permanent;
scrollRect.viewport = viewportRect;
scrollRect.content = contentRect;
return mainObj;
}
/// <summary>
/// Create a Scrollable Input Field control (custom InputFieldScroller).
/// Create a Scrollable Input Field control
/// </summary>
public static GameObject CreateSrollInputField(GameObject parent, string name, string placeHolderText, out InputFieldScroller inputScroll,
public static GameObject CreateScrollInputField(GameObject parent, string name, string placeHolderText, out InputFieldScroller inputScroll,
int fontSize = 14, Color color = default)
{
if (color == default)
@ -957,5 +978,7 @@ namespace UnityExplorer.UI
return mainObj;
}
#endregion
}
}

View File

@ -12,9 +12,6 @@ using UnityExplorer.UI.Models;
namespace UnityExplorer.UI.Utility
{
// A Slider Scrollbar which automatically resizes for the content size (no pooling).
// Currently just used for the C# Console input field.
public class AutoSliderScrollbar : UIBehaviourModel
{
public override GameObject UIRoot