added some stuff
This commit is contained in:
parent
9b69003715
commit
3dbf2f9010
520 changed files with 176780 additions and 2 deletions
67
Assets/Scripts/LemonGenericLib/UI/Tabs/TabButtonScript.cs
Normal file
67
Assets/Scripts/LemonGenericLib/UI/Tabs/TabButtonScript.cs
Normal file
|
@ -0,0 +1,67 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace Lemon.GenericLib.UI
|
||||
{
|
||||
public class TabButtonScript : MonoBehaviour, IPointerEnterHandler, IPointerClickHandler, IPointerExitHandler
|
||||
{
|
||||
|
||||
[SerializeField] TabGroup tabGroup;
|
||||
|
||||
|
||||
[SerializeField] private UnityEvent onTabEnter;
|
||||
[SerializeField] private UnityEvent onTabExit;
|
||||
[SerializeField] private UnityEvent onTabSelected;
|
||||
[SerializeField] private UnityEvent onTabDeselected;
|
||||
|
||||
|
||||
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
tabGroup.OnTabSelected(this);
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
tabGroup.OnTabEnter(this);
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
tabGroup.OnTabExit(this);
|
||||
}
|
||||
|
||||
|
||||
public void OnEnter()
|
||||
{
|
||||
onTabEnter?.Invoke();
|
||||
|
||||
}
|
||||
|
||||
public void OnExit()
|
||||
{
|
||||
onTabExit?.Invoke();
|
||||
|
||||
}
|
||||
|
||||
public void OnSelected()
|
||||
{
|
||||
onTabSelected?.Invoke();
|
||||
|
||||
}
|
||||
|
||||
public void OnDeselected()
|
||||
{
|
||||
onTabDeselected?.Invoke();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ccb3057007dfb1541810d434b448bcc8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
123
Assets/Scripts/LemonGenericLib/UI/Tabs/TabGroup.cs
Normal file
123
Assets/Scripts/LemonGenericLib/UI/Tabs/TabGroup.cs
Normal file
|
@ -0,0 +1,123 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
//TODO: make this system supprts tabs without using tab buttons
|
||||
// or redo the entire thing
|
||||
// yeah we need to redo the whole thing
|
||||
// for now make your own page system
|
||||
|
||||
namespace Lemon.GenericLib.UI
|
||||
{
|
||||
public class TabGroup : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private List<TabSet> tabSets;
|
||||
[SerializeField] private int defaultTabIndex;
|
||||
|
||||
|
||||
private TabButtonScript selectedButton;
|
||||
|
||||
[Serializable]
|
||||
struct TabSet
|
||||
{
|
||||
public TabButtonScript tabButton;
|
||||
public GameObject tabObject;
|
||||
|
||||
public TabSet(TabButtonScript tabButton, GameObject tabObject)
|
||||
{
|
||||
this.tabButton = tabButton;
|
||||
this.tabObject = tabObject;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return base.Equals(obj);
|
||||
}
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (tabSets == null || defaultTabIndex < 0 || defaultTabIndex > tabSets.Count)
|
||||
{
|
||||
Debug.LogError("default tab cannot be asisgned, pleace chect the default tab index and make sure the tab list is initialized");
|
||||
}
|
||||
else
|
||||
{
|
||||
OnTabSelected(tabSets[defaultTabIndex].tabButton);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void Subscribe(TabButtonScript button, GameObject tabObject)
|
||||
{
|
||||
if (tabSets == null)
|
||||
{
|
||||
tabSets = new List<TabSet>();
|
||||
}
|
||||
tabSets.Add(new TabSet(button, tabObject));
|
||||
}
|
||||
|
||||
public void OnTabEnter(TabButtonScript button)
|
||||
{
|
||||
ResetTabs();
|
||||
if (selectedButton == null || button != selectedButton)
|
||||
{
|
||||
button.OnEnter();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void OnTabExit(TabButtonScript button)
|
||||
{
|
||||
ResetTabs();
|
||||
|
||||
}
|
||||
|
||||
public void OnTabSelected(TabButtonScript button)
|
||||
{
|
||||
if (selectedButton != null)
|
||||
{
|
||||
selectedButton.OnDeselected();
|
||||
}
|
||||
|
||||
|
||||
selectedButton = button;
|
||||
button.OnSelected();
|
||||
|
||||
UpdateSelectedTab();
|
||||
ResetTabs();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void ResetTabs()
|
||||
{
|
||||
foreach (var item in tabSets)
|
||||
{
|
||||
if (selectedButton != null && item.tabButton == selectedButton) { continue; }
|
||||
item.tabButton.OnExit();
|
||||
}
|
||||
}
|
||||
|
||||
//can overwite this
|
||||
public void UpdateSelectedTab()
|
||||
{
|
||||
foreach (var tab in tabSets)
|
||||
{
|
||||
if (tab.tabButton == selectedButton)
|
||||
{
|
||||
tab.tabObject.SetActive(true);
|
||||
tab.tabObject.transform.SetSiblingIndex(tabSets.Count - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
tab.tabObject.SetActive(false);
|
||||
tab.tabObject.transform.SetSiblingIndex(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/LemonGenericLib/UI/Tabs/TabGroup.cs.meta
Normal file
11
Assets/Scripts/LemonGenericLib/UI/Tabs/TabGroup.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0206a02701fc75c4eb1f54e3113fd697
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue