Initial commit
This commit is contained in:
21
Assets/GUI Pro-CasualGame/Scripts/PanelCasualGame.cs
Normal file
21
Assets/GUI Pro-CasualGame/Scripts/PanelCasualGame.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace LayerLab.CasualGame
|
||||
{
|
||||
public class PanelCasualGame : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private GameObject[] otherPanels;
|
||||
|
||||
public void OnEnable()
|
||||
{
|
||||
for (int i = 0; i < otherPanels.Length; i++) otherPanels[i].SetActive(true);
|
||||
}
|
||||
|
||||
public void OnDisable()
|
||||
{
|
||||
for (int i = 0; i < otherPanels.Length; i++) otherPanels[i].SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/GUI Pro-CasualGame/Scripts/PanelCasualGame.cs.meta
Normal file
11
Assets/GUI Pro-CasualGame/Scripts/PanelCasualGame.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9a00128818eda43dfaa959b83527b255
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
84
Assets/GUI Pro-CasualGame/Scripts/PanelControlCasualGame.cs
Normal file
84
Assets/GUI Pro-CasualGame/Scripts/PanelControlCasualGame.cs
Normal file
@ -0,0 +1,84 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
|
||||
namespace LayerLab.CasualGame
|
||||
{
|
||||
public class PanelControlCasualGame : MonoBehaviour
|
||||
{
|
||||
private int page = 0;
|
||||
private bool isReady = false;
|
||||
[SerializeField] private List<GameObject> panels = new List<GameObject>();
|
||||
private TextMeshProUGUI textTitle;
|
||||
[SerializeField] private Transform panelTransform;
|
||||
[SerializeField] private Button buttonPrev;
|
||||
[SerializeField] private Button buttonNext;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
textTitle = transform.GetComponentInChildren<TextMeshProUGUI>();
|
||||
buttonPrev.onClick.AddListener(Click_Prev);
|
||||
buttonNext.onClick.AddListener(Click_Next);
|
||||
|
||||
foreach (Transform t in panelTransform)
|
||||
{
|
||||
panels.Add(t.gameObject);
|
||||
t.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
panels[page].SetActive(true);
|
||||
isReady = true;
|
||||
|
||||
CheckControl();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (panels.Count <= 0 || !isReady) return;
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.LeftArrow))
|
||||
Click_Prev();
|
||||
else if (Input.GetKeyDown(KeyCode.RightArrow))
|
||||
Click_Next();
|
||||
}
|
||||
|
||||
//Click_Prev
|
||||
public void Click_Prev()
|
||||
{
|
||||
|
||||
if (page <= 0 || !isReady) return;
|
||||
|
||||
panels[page].SetActive(false);
|
||||
panels[page -= 1].SetActive(true);
|
||||
textTitle.text = panels[page].name;
|
||||
CheckControl();
|
||||
}
|
||||
|
||||
//Click_Next
|
||||
public void Click_Next()
|
||||
{
|
||||
if (page >= panels.Count - 1) return;
|
||||
|
||||
panels[page].SetActive(false);
|
||||
panels[page += 1].SetActive(true);
|
||||
CheckControl();
|
||||
}
|
||||
|
||||
void SetArrowActive()
|
||||
{
|
||||
buttonPrev.gameObject.SetActive(page > 0);
|
||||
buttonNext.gameObject.SetActive(page < panels.Count - 1);
|
||||
}
|
||||
|
||||
//SetTitle, SetArrow Active
|
||||
private void CheckControl()
|
||||
{
|
||||
textTitle.text = panels[page].name.Replace("_", " ");
|
||||
SetArrowActive();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bf55aa2c0d7914b348b9d193f622141c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user