- PlatformSpecificContent.cs
- Utility /
- Standard Assets /
- Assets /
- project /
1 using System;
2 using UnityEngine;
3 #if UNITY_EDITOR
4 using UnityEditor;
5 #endif
6
7 namespace UnityStandardAssets.Utility
8 {
9 #if UNITY_EDITOR
10
11 [ExecuteInEditMode]
12 #endif
13 public class PlatformSpecificContent : MonoBehaviour
14 {
15 private enum BuildTargetGroup
16 {
17 Standalone,
18 Mobile
19 }
20
21 [SerializeField] private BuildTargetGroup m_BuildTargetGroup;
22 [SerializeField] private GameObject[] m_Content = new GameObject[0];
23 [SerializeField] private MonoBehaviour[] m_MonoBehaviours = new MonoBehaviour[0];
24 [SerializeField] private bool m_ChildrenOfThisObject;
25
26 #if !UNITY_EDITOR
27 void OnEnable()
28 {
29 CheckEnableContent();
30 }
31 #endif
32
33 #if UNITY_EDITOR
34
35 private void OnEnable()
36 {
37 EditorUserBuildSettings.activeBuildTargetChanged += Update;
38 EditorApplication.update += Update;
39 }
40
41
42 private void OnDisable()
43 {
44 EditorUserBuildSettings.activeBuildTargetChanged -= Update;
45 EditorApplication.update -= Update;
46 }
47
48
49 private void Update()
50 {
51 CheckEnableContent();
52 }
53 #endif
54
55
56 private void CheckEnableContent()
57 {
58 #if (UNITY_IPHONE || UNITY_ANDROID || UNITY_WP8 || UNITY_BLACKBERRY )
59 if (m_BuildTargetGroup == BuildTargetGroup.Mobile)
60 {
61 EnableContent(true);
62 } else {
63 EnableContent(false);
64 }
65 #endif
66
67 #if !(UNITY_IPHONE || UNITY_ANDROID || UNITY_WP8 || UNITY_BLACKBERRY )
68 if (m_BuildTargetGroup == BuildTargetGroup.Mobile)
69 {
70 EnableContent(false);
71 }
72 else
73 {
74 EnableContent(true);
75 }
76 #endif
77 }
78
79
80 private void EnableContent(bool enabled)
81 {
82 if (m_Content.Length > 0)
83 {
84 foreach (var g in m_Content)
85 {
86 if (g != null)
87 {
88 g.SetActive(enabled);
89 }
90 }
91 }
92 if (m_ChildrenOfThisObject)
93 {
94 foreach (Transform t in transform)
95 {
96 t.gameObject.SetActive(enabled);
97 }
98 }
99 if (m_MonoBehaviours.Length > 0)
100 {
101 foreach (var monoBehaviour in m_MonoBehaviours)
102 {
103 monoBehaviour.enabled = enabled;
104 }
105 }
106 }
107 }
108 }
2 using UnityEngine;
3 #if UNITY_EDITOR
4 using UnityEditor;
5 #endif
6
7 namespace UnityStandardAssets.Utility
8 {
9 #if UNITY_EDITOR
10
11 [ExecuteInEditMode]
12 #endif
13 public class PlatformSpecificContent : MonoBehaviour
14 {
15 private enum BuildTargetGroup
16 {
17 Standalone,
18 Mobile
19 }
20
21 [SerializeField] private BuildTargetGroup m_BuildTargetGroup;
22 [SerializeField] private GameObject[] m_Content = new GameObject[0];
23 [SerializeField] private MonoBehaviour[] m_MonoBehaviours = new MonoBehaviour[0];
24 [SerializeField] private bool m_ChildrenOfThisObject;
25
26 #if !UNITY_EDITOR
27 void OnEnable()
28 {
29 CheckEnableContent();
30 }
31 #endif
32
33 #if UNITY_EDITOR
34
35 private void OnEnable()
36 {
37 EditorUserBuildSettings.activeBuildTargetChanged += Update;
38 EditorApplication.update += Update;
39 }
40
41
42 private void OnDisable()
43 {
44 EditorUserBuildSettings.activeBuildTargetChanged -= Update;
45 EditorApplication.update -= Update;
46 }
47
48
49 private void Update()
50 {
51 CheckEnableContent();
52 }
53 #endif
54
55
56 private void CheckEnableContent()
57 {
58 #if (UNITY_IPHONE || UNITY_ANDROID || UNITY_WP8 || UNITY_BLACKBERRY )
59 if (m_BuildTargetGroup == BuildTargetGroup.Mobile)
60 {
61 EnableContent(true);
62 } else {
63 EnableContent(false);
64 }
65 #endif
66
67 #if !(UNITY_IPHONE || UNITY_ANDROID || UNITY_WP8 || UNITY_BLACKBERRY )
68 if (m_BuildTargetGroup == BuildTargetGroup.Mobile)
69 {
70 EnableContent(false);
71 }
72 else
73 {
74 EnableContent(true);
75 }
76 #endif
77 }
78
79
80 private void EnableContent(bool enabled)
81 {
82 if (m_Content.Length > 0)
83 {
84 foreach (var g in m_Content)
85 {
86 if (g != null)
87 {
88 g.SetActive(enabled);
89 }
90 }
91 }
92 if (m_ChildrenOfThisObject)
93 {
94 foreach (Transform t in transform)
95 {
96 t.gameObject.SetActive(enabled);
97 }
98 }
99 if (m_MonoBehaviours.Length > 0)
100 {
101 foreach (var monoBehaviour in m_MonoBehaviours)
102 {
103 monoBehaviour.enabled = enabled;
104 }
105 }
106 }
107 }
108 }