added some stuff

This commit is contained in:
Wong Sui Bin 2023-01-24 21:51:46 +08:00
parent 9b69003715
commit 3dbf2f9010
520 changed files with 176780 additions and 2 deletions

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 12d0daac2445aa64b89b3cd4c8e6bc59
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,110 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
namespace Lemon.GenericLib.UI
{
public class ImageUIManager : MonoBehaviour
{
public static ImageUIManager Instance;
//singleton pattern
private void Awake()
{
if (Instance == null)
{
Instance = this;
}
if (Instance != this)
{
Destroy(gameObject);
}
}
[SerializeField] ImageUIData[] ImageUIList;
[Serializable]
struct ImageUIData
{
public string UIName;
public Image ImageUI;
public float fillRate;
public float targetFill;
public float snapFillMargin;
public void UpdateFill()
{
if (ImageUI.fillAmount == targetFill) return;
ImageUI.fillAmount = Mathf.Lerp(ImageUI.fillAmount, targetFill, fillRate * Time.deltaTime);
if (Mathf.Abs(targetFill - ImageUI.fillAmount) <= snapFillMargin) ImageUI.fillAmount = targetFill;
}
public void SetFill(float value)
{
targetFill = value;
}
}
private void Update()
{
for (int i = 0; i < ImageUIList.Length; i++)
{
ImageUIList[i].UpdateFill();
}
}
public bool SetFill(string UIName, float fill)
{
for (int i = 0; i < ImageUIList.Length; i++)
{
if (UIName == ImageUIList[i].UIName)
{
ImageUIList[i].SetFill(fill);
return true;
}
}
Debug.LogError(" Image UI of nane " + UIName + " does not exist");
return false;
}
public bool SetFillForce(string UIName, float fill)
{
for (int i = 0; i < ImageUIList.Length; i++)
{
if (UIName == ImageUIList[i].UIName)
{
ImageUIList[i].ImageUI.fillAmount = fill;
return true;
}
}
Debug.LogError(" Image UI of nane " + UIName + " does not exist");
return false;
}
public bool SetImage(string UIName, Sprite image)
{
for (int i = 0; i < ImageUIList.Length; i++)
{
if (UIName == ImageUIList[i].UIName)
{
ImageUIList[i].ImageUI.sprite = image;
return true;
}
}
Debug.LogError(" Image UI of nane " + UIName + " does not exist");
return false;
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e6113c552c6f9e94190849ea5044d042
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,112 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using TMPro;
namespace Lemon.GenericLib.UI
{
public class TextUIManager : MonoBehaviour
{
public static TextUIManager Instance;
//singleton pattern
private void Awake()
{
if (Instance == null)
{
Instance = this;
}
if (Instance != this)
{
Destroy(gameObject);
}
InitTextUI();
}
public void InitTextUI()
{
for (int i = 0; i < textUIList.Length; i++)
{
textUIList[i].InitUI();
}
}
[SerializeField] TextUI[] textUIList;
[Serializable]
struct TextUI
{
public string UIName;
public TextMeshProUGUI textMesh;
public bool textGoUp;
public float textGoUpDistance;
public float textEffectTime;
public LeanTweenType easeType;
[SerializeField] private Vector3 originalPos;
private bool canAnimate;
[SerializeField] private bool explixitDefineStartY;
[SerializeField] Vector3 startPos;
public void SetText(string text)
{
textMesh.text = text;
if (textGoUp && canAnimate) LeanTween.moveLocalY(textMesh.gameObject, originalPos.y + textGoUpDistance, textEffectTime).setOnComplete(AnimateEffectBack);
}
public void SetColour(Color colour)
{
textMesh.color = colour;
}
public void InitUI()
{
if (explixitDefineStartY) originalPos = startPos;
else originalPos = textMesh.GetComponent<RectTransform>().localPosition;
canAnimate = true;
}
private void AnimateEffectBack()
{
LeanTween.moveLocalY(textMesh.gameObject, originalPos.y, textEffectTime);
}
}
public bool SetText(string UIName, string text)
{
for (int i = 0; i < textUIList.Length; i++)
{
if (UIName == textUIList[i].UIName)
{
textUIList[i].SetText(text);
return true;
}
}
Debug.LogError("text UI of nane " + UIName + " does not exist");
return false;
}
public bool SetColour(string UIName, Color colour)
{
for (int i = 0; i < textUIList.Length; i++)
{
if (UIName == textUIList[i].UIName)
{
textUIList[i].SetColour(colour);
return true;
}
}
Debug.LogError("text UI of nane " + UIName + " does not exist");
return false;
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 454e8a3504cc8734c861860dfef3875f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d8a913671c0abc9459f3e8a14d2cc066
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View 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();
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ccb3057007dfb1541810d434b448bcc8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View 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);
}
}
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0206a02701fc75c4eb1f54e3113fd697
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: