diff --git a/src/UI/Inspectors/GameObjectInspector.cs b/src/UI/Inspectors/GameObjectInspector.cs index 2b22695..e664dff 100644 --- a/src/UI/Inspectors/GameObjectInspector.cs +++ b/src/UI/Inspectors/GameObjectInspector.cs @@ -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.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(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(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(); + //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(rightGroup, false, false, true, true, 2); diff --git a/src/UI/Inspectors/GameObjectWidgets/ComponentList.cs b/src/UI/Inspectors/GameObjectWidgets/ComponentList.cs index 05b3106..606dbbd 100644 --- a/src/UI/Inspectors/GameObjectWidgets/ComponentList.cs +++ b/src/UI/Inspectors/GameObjectWidgets/ComponentList.cs @@ -99,11 +99,14 @@ namespace UnityExplorer.UI.Inspectors { cell.BehaviourToggle.interactable = true; cell.BehaviourToggle.Set(comp.TryCast().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. diff --git a/src/UI/Inspectors/GameObjectWidgets/GameObjectControls.cs b/src/UI/Inspectors/GameObjectWidgets/GameObjectControls.cs index 4a5854b..f4cb64c 100644 --- a/src/UI/Inspectors/GameObjectWidgets/GameObjectControls.cs +++ b/src/UI/Inspectors/GameObjectWidgets/GameObjectControls.cs @@ -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()) 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().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(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(); + //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); diff --git a/src/UI/Panels/CSConsolePanel.cs b/src/UI/Panels/CSConsolePanel.cs index 1a4bdc3..109872e 100644 --- a/src/UI/Panels/CSConsolePanel.cs +++ b/src/UI/Panels/CSConsolePanel.cs @@ -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; diff --git a/src/UI/Panels/InspectorPanel.cs b/src/UI/Panels/InspectorPanel.cs index 5d1db78..1c08e14 100644 --- a/src/UI/Panels/InspectorPanel.cs +++ b/src/UI/Panels/InspectorPanel.cs @@ -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; diff --git a/src/UI/UIFactory.cs b/src/UI/UIFactory.cs index 371ef63..914e14c 100644 --- a/src/UI/UIFactory.cs +++ b/src/UI/UIFactory.cs @@ -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("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(); - 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 + /// /// Get and/or Add a LayoutElement component to the GameObject, and set any of the values on it. /// @@ -235,6 +240,11 @@ namespace UnityExplorer.UI return groupObj; } + #endregion + + + #region Default Control Elements + /// /// Create a Label object. /// @@ -410,8 +420,9 @@ namespace UnityExplorer.UI toggle = toggleObj.AddComponent(); 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(); - 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(); 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 + + /// + /// Create a ScrollPool for the ICell. + /// public static ScrollPool CreateScrollPool(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; } + /// + /// Create a SliderScrollbar, using a Slider to mimic a scrollbar. + /// public static GameObject CreateSliderScrollbar(GameObject parent, out Slider slider) { GameObject mainObj = CreateUIObject("SliderScrollbar", parent, _smallElementSize); + mainObj.AddComponent(); + mainObj.AddComponent().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(); + RectTransform bgRect = bgImageObj.GetComponent(); bgRect.pivot = new Vector2(0, 1); bgRect.anchorMin = Vector2.zero; @@ -758,13 +781,13 @@ namespace UnityExplorer.UI var handleRect = handleObj.GetComponent(); 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(); sliderBarLayout.minWidth = 25; sliderBarLayout.flexibleWidth = 0; sliderBarLayout.minHeight = 30; - sliderBarLayout.flexibleHeight = 5000; + sliderBarLayout.flexibleHeight = 9999; slider = mainObj.AddComponent(); slider.handleRect = handleObj.GetComponent(); @@ -783,65 +806,63 @@ namespace UnityExplorer.UI } /// - /// Create a ScrollView element. + /// Create a ScrollView and a SliderScrollbar for non-pooled content. /// - 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(mainObj, false, true, true, true, 2); + var mainRect = mainObj.GetComponent(); + mainRect.anchorMin = Vector2.zero; + mainRect.anchorMax = Vector2.one; Image mainImage = mainObj.AddComponent(); 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(); 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().color = Color.white; viewportObj.AddComponent().showMaskGraphic = false; content = CreateUIObject("Content", viewportObj); + SetLayoutGroup(content, true, false, true, true, childAlignment: TextAnchor.UpperLeft); + SetLayoutElement(content, flexibleHeight: 9999); var contentRect = content.GetComponent(); - SetLayoutGroup(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().verticalFit = ContentSizeFitter.FitMode.PreferredSize; // Slider - + GameObject scrollBarObj = CreateUIObject("AutoSliderScrollbar", mainObj); - SetLayoutGroup(scrollBarObj, true, true, true, true); - SetLayoutElement(scrollBarObj, minWidth: 25, flexibleWidth: 0, flexibleHeight: 9999); + var scrollBarRect = scrollBarObj.GetComponent(); + scrollBarRect.anchorMin = new Vector2(1, 0); + scrollBarRect.anchorMax = Vector2.one; + scrollBarRect.offsetMin = new Vector2(-25, 0); + SetLayoutGroup(scrollBarObj, false, true, true, true); scrollBarObj.AddComponent().color = Color.white; scrollBarObj.AddComponent().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(); - + // Set up the ScrollRect component - + var scrollRect = mainObj.AddComponent(); 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; } /// - /// Create a Scrollable Input Field control (custom InputFieldScroller). + /// Create a Scrollable Input Field control /// - 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 } } diff --git a/src/UI/Widgets/AutoSliderScrollbar.cs b/src/UI/Widgets/AutoSliderScrollbar.cs index 69e56f5..86b92d4 100644 --- a/src/UI/Widgets/AutoSliderScrollbar.cs +++ b/src/UI/Widgets/AutoSliderScrollbar.cs @@ -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