Browse Source

Fixes on Tabs Controller

James Peret 2 years ago
parent
commit
75be36db1a

+ 9 - 12
Prefabs/TooltipPrefabExample.prefab

@@ -21,7 +21,7 @@ GameObject:
   m_Icon: {fileID: 0}
   m_NavMeshLayer: 0
   m_StaticEditorFlags: 0
-  m_IsActive: 1
+  m_IsActive: 0
 --- !u!224 &1285702112934205051
 RectTransform:
   m_ObjectHideFlags: 0
@@ -66,6 +66,7 @@ MonoBehaviour:
   m_Material: {fileID: 0}
   m_Color: {r: 0.1509434, g: 0.1509434, b: 0.1509434, a: 0.92156863}
   m_RaycastTarget: 1
+  m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
   m_Maskable: 1
   m_OnCullStateChanged:
     m_PersistentCalls:
@@ -105,6 +106,7 @@ MonoBehaviour:
   m_ChildControlHeight: 1
   m_ChildScaleWidth: 0
   m_ChildScaleHeight: 0
+  m_ReverseArrangement: 0
 --- !u!114 &1285702112934205046
 MonoBehaviour:
   m_ObjectHideFlags: 0
@@ -126,7 +128,7 @@ MonoBehaviour:
   m_PrefabInstance: {fileID: 0}
   m_PrefabAsset: {fileID: 0}
   m_GameObject: {fileID: 1285702112934205050}
-  m_Enabled: 1
+  m_Enabled: 0
   m_EditorHideFlags: 0
   m_Script: {fileID: 11500000, guid: 306cc8c2b49d7114eaa3623786fc2126, type: 3}
   m_Name: 
@@ -157,6 +159,7 @@ MonoBehaviour:
   rectTransform: {fileID: 1285702112934205051}
   characterWrapLimit: 80
   positionOffset: {x: 10, y: -50}
+  header: Logs
 --- !u!1 &1285702113314851622
 GameObject:
   m_ObjectHideFlags: 0
@@ -217,19 +220,12 @@ MonoBehaviour:
   m_Material: {fileID: 0}
   m_Color: {r: 1, g: 1, b: 1, a: 1}
   m_RaycastTarget: 1
+  m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
   m_Maskable: 1
   m_OnCullStateChanged:
     m_PersistentCalls:
       m_Calls: []
-  m_text: 'This is a description text... A very long description.
-
-    With multiple
-    lines of text.
-
-    Short ones.
-
-    And very, very, very, very very, very very
-    long lines with line breaks after the character limit.'
+  m_text: 
   m_isRightToLeft: 0
   m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
   m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
@@ -358,11 +354,12 @@ MonoBehaviour:
   m_Material: {fileID: 0}
   m_Color: {r: 1, g: 1, b: 1, a: 1}
   m_RaycastTarget: 1
+  m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
   m_Maskable: 1
   m_OnCullStateChanged:
     m_PersistentCalls:
       m_Calls: []
-  m_text: Tooltip Header Text
+  m_text: Logs
   m_isRightToLeft: 0
   m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
   m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}

+ 1 - 1
Runtime/MenuComponents/MenuButtomData.cs

@@ -19,7 +19,7 @@ namespace KairoEngine.UI
         [HideInInspector] public bool useSubMenus = true;
         [FoldoutGroup("@name"), Tooltip("Title of the parent button."), ShowIf("@useSubMenus")] public string parent= "";
         [FoldoutGroup("@name"), Tooltip("Is this button the parent of other buttons?"), ShowIf("@useSubMenus")] public bool subMenuParent = false;
-        [HideInInspector] public GameObject button;
+        [FoldoutGroup("@name")] public GameObject button;
     }
 }
 

+ 10 - 6
Runtime/MenuComponents/MenuUI.cs

@@ -51,18 +51,21 @@ namespace KairoEngine.UI
                 DestroyMenu();
                 CreateMenu();
             }
-            if(visibleOnStart) UiManager.ShowElement(this);
-            else UiManager.HideElement(this);
+            if(menuCanvas != null)
+            {
+                if(visibleOnStart) UiManager.ShowElement(this);
+                else UiManager.HideElement(this);
+            }
         }
 
         private void OnDisable()
         {
-            UiManager.UnregisterElement(this);
+            if(menuCanvas != null) UiManager.UnregisterElement(this);
         }
 
         private void OnEnable()
         {
-            UiManager.RegisterElement(elementTitle, this, this.transform, isVisible);
+            if(menuCanvas != null) UiManager.RegisterElement(elementTitle, this, this.transform, isVisible);
         }
 
         public virtual void OnClick(string title)
@@ -82,15 +85,16 @@ namespace KairoEngine.UI
 
         public void Hide()
         {
+            
             if(uiAnimator != null) uiAnimator.Disable();
-            else menuCanvas.gameObject.SetActive(false);
+            else if(menuCanvas != null) menuCanvas.gameObject.SetActive(false);
             isVisible = false;
         }
 
         public void Show()
         {
             if(uiAnimator != null) uiAnimator.Enable();
-            else menuCanvas.gameObject.SetActive(true);
+            else if(menuCanvas != null) menuCanvas.gameObject.SetActive(true);
             isVisible = true;
 
         }

+ 31 - 12
Runtime/Tabs/TabsController.cs

@@ -28,31 +28,31 @@ namespace KairoEngine.UI
                 DestroyTabMenu();
                 CreateTabMenu();
             }
+            else LinkButtons();
         }
 
         public void OnClick(string id)
         {
-            TabData tab = null;
             int tabIndex = 0;
             for (int i = 0; i < tabs.Count; i++)
             {
                 if(id == tabs[i].id)
                 {
-                    tab = tabs[i];
                     tabIndex = i;
                     break;
                 }
             }
-            if(tab != null && (tabIndex != currentTab || tabs[tabIndex].content.activeSelf == false))
-            {
-                tabs[currentTab].content.SetActive(false);
-                tab.content.SetActive(true);
-                UpdateButton(tabs[currentTab].id, false);
-                UpdateButton(tabs[tabIndex].id, true);
-                currentTab = tabIndex;
-                if(debug) Debug.Log("Showing tab " + tabs[currentTab].id);
-                
-            }
+            if(tabIndex != currentTab && tabs[tabIndex].content.activeSelf == false) ChangeToTab(tabIndex);
+
+        }
+        public void ChangeToTab(int tabIndex)
+        {
+            tabs[currentTab].content.SetActive(false);
+            tabs[tabIndex].content.SetActive(true);
+            UpdateButton(tabs[currentTab].id, false);
+            UpdateButton(tabs[tabIndex].id, true);
+            currentTab = tabIndex;
+            if(debug) Debug.Log("Showing tab " + tabs[currentTab].id);
         }
 
         [ButtonGroup("Buttons"), Button("Create Tab Menu")]
@@ -84,6 +84,8 @@ namespace KairoEngine.UI
         {
             menuUI.DestroyMenu();
             menuUI.buttons.Clear();
+            if(tabs[currentTab] == null) return;
+            if(tabs[currentTab].content == null) return;
             tabs[currentTab].content.SetActive(false);
         }
 
@@ -108,5 +110,22 @@ namespace KairoEngine.UI
                 if(debug) Debug.LogError("Could not find button with id " + id + " in MenuUI", this.gameObject);
             }
         }
+
+        public void LinkButtons()
+        {
+            for (int i = 0; i < menuUI.buttons.Count; i++)
+            {
+                if(menuUI.buttons[i].button != null)
+                {
+                    var clickHandler = menuUI.buttons[i].button.GetComponent<ClickHandler>();
+                    if(clickHandler != null) 
+                    {
+                        clickHandler.receiver = this;
+                        clickHandler.title = tabs[i].id;
+                    }
+                }
+            }
+            ChangeToTab(currentTab);
+        }
     }
 }