Files
2026-02-21 16:45:37 +08:00

73 lines
1.3 KiB
C#

using UnityEngine;
namespace UnityStandardAssets.Utility
{
public class PlatformSpecificContent : MonoBehaviour
{
private enum BuildTargetGroup
{
Standalone = 0,
Mobile = 1
}
[SerializeField]
private BuildTargetGroup m_BuildTargetGroup;
[SerializeField]
private GameObject[] m_Content = new GameObject[0];
[SerializeField]
private MonoBehaviour[] m_MonoBehaviours = new MonoBehaviour[0];
[SerializeField]
private bool m_ChildrenOfThisObject;
private void OnEnable()
{
CheckEnableContent();
}
private void CheckEnableContent()
{
if (m_BuildTargetGroup == BuildTargetGroup.Mobile)
{
EnableContent(false);
}
else
{
EnableContent(true);
}
}
private void EnableContent(bool enabled)
{
if (m_Content.Length > 0)
{
GameObject[] content = m_Content;
foreach (GameObject gameObject in content)
{
if (gameObject != null)
{
gameObject.SetActive(enabled);
}
}
}
if (m_ChildrenOfThisObject)
{
foreach (Transform item in base.transform)
{
item.gameObject.SetActive(enabled);
}
}
if (m_MonoBehaviours.Length > 0)
{
MonoBehaviour[] monoBehaviours = m_MonoBehaviours;
foreach (MonoBehaviour monoBehaviour in monoBehaviours)
{
monoBehaviour.enabled = enabled;
}
}
}
}
}