基础内容
必要插件安装 缓动曲线和动画基础 ElementFolder,Track与其次级模块,PathNode重构
This commit is contained in:
75
Assets/Modern UI Pack/Scripts/Toggle/CustomToggle.cs
Normal file
75
Assets/Modern UI Pack/Scripts/Toggle/CustomToggle.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Michsky.MUIP
|
||||
{
|
||||
[RequireComponent(typeof(Toggle))]
|
||||
[RequireComponent(typeof(Animator))]
|
||||
public class CustomToggle : MonoBehaviour
|
||||
{
|
||||
[HideInInspector] public Toggle toggleObject;
|
||||
[HideInInspector] public Animator toggleAnimator;
|
||||
|
||||
[Header("Settings")]
|
||||
public bool invokeOnAwake;
|
||||
bool isInitialized = false;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (toggleObject == null) { toggleObject = gameObject.GetComponent<Toggle>(); }
|
||||
if (toggleAnimator == null) { toggleAnimator = toggleObject.GetComponent<Animator>(); }
|
||||
if (invokeOnAwake == true) { toggleObject.onValueChanged.Invoke(toggleObject.isOn); }
|
||||
|
||||
toggleObject.onValueChanged.AddListener(UpdateState);
|
||||
UpdateState();
|
||||
isInitialized = true;
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if (isInitialized == false)
|
||||
return;
|
||||
|
||||
UpdateState();
|
||||
}
|
||||
|
||||
public void UpdateState()
|
||||
{
|
||||
if (gameObject.activeInHierarchy == true)
|
||||
{
|
||||
StopCoroutine("DisableAnimator");
|
||||
StartCoroutine("DisableAnimator");
|
||||
}
|
||||
|
||||
else { return; }
|
||||
|
||||
toggleAnimator.enabled = true;
|
||||
|
||||
if (toggleObject.isOn) { toggleAnimator.Play("On Instant"); }
|
||||
else { toggleAnimator.Play("Off Instant"); }
|
||||
}
|
||||
|
||||
public void UpdateState(bool value)
|
||||
{
|
||||
if (gameObject.activeInHierarchy == true)
|
||||
{
|
||||
StopCoroutine("DisableAnimator");
|
||||
StartCoroutine("DisableAnimator");
|
||||
}
|
||||
|
||||
else { return; }
|
||||
|
||||
toggleAnimator.enabled = true;
|
||||
|
||||
if (toggleObject.isOn) { toggleAnimator.Play("Toggle On"); }
|
||||
else { toggleAnimator.Play("Toggle Off"); }
|
||||
}
|
||||
|
||||
IEnumerator DisableAnimator()
|
||||
{
|
||||
yield return new WaitForSecondsRealtime(0.6f);
|
||||
toggleAnimator.enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
18
Assets/Modern UI Pack/Scripts/Toggle/CustomToggle.cs.meta
Normal file
18
Assets/Modern UI Pack/Scripts/Toggle/CustomToggle.cs.meta
Normal file
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fa5100cea443dc7448b10a5f20698420
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: b0f85f7da5042c0448a526d5ecacbfa9, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 201717
|
||||
packageName: Modern UI Pack
|
||||
packageVersion: 5.5.19
|
||||
assetPath: Assets/Modern UI Pack/Scripts/Toggle/CustomToggle.cs
|
||||
uploadId: 628721
|
||||
Reference in New Issue
Block a user