您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
53 行
1.4 KiB
53 行
1.4 KiB
using UnityEngine;
|
|
|
|
namespace Unity.QualitySettingsTools
|
|
{
|
|
/// <summary>
|
|
/// Activates children of this object based on the current quality settings.
|
|
/// </summary>
|
|
public class QualitySettingsObjectActivator : MonoBehaviour
|
|
{
|
|
private enum Quality
|
|
{
|
|
Optimal = 0,
|
|
Medium = 1,
|
|
HD = 2,
|
|
}
|
|
|
|
[SerializeField]
|
|
private Quality m_MinimalTargetQuality;
|
|
[SerializeField]
|
|
private int m_CheckIntervalInFrames = 360;
|
|
private int m_FrameCount;
|
|
|
|
private Transform[] children;
|
|
private void Start()
|
|
{
|
|
m_FrameCount = 0;
|
|
children = transform.GetComponentsInChildren<Transform>();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (m_FrameCount % m_CheckIntervalInFrames == 0)
|
|
{
|
|
CheckCurrentQualitySettings();
|
|
}
|
|
|
|
m_FrameCount++;
|
|
}
|
|
|
|
private void CheckCurrentQualitySettings()
|
|
{
|
|
int currentQualityLevel = QualitySettings.GetQualityLevel();
|
|
if (currentQualityLevel < (int)m_MinimalTargetQuality)
|
|
{
|
|
foreach (var child in children)
|
|
{
|
|
child.gameObject.SetActive(false);
|
|
}
|
|
gameObject.SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
}
|