Created
January 11, 2016 09:58
-
-
Save tsubaki/0f43e394feba8e42e212 to your computer and use it in GitHub Desktop.
カリンググループのサンプルコードその2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using UnityEngine.SceneManagement; | |
public class CullingGroupSpawn : MonoBehaviour | |
{ | |
[SerializeField] Transform[] positions; | |
[SerializeField] string sceneName; // 読み込むシーン名 | |
private CullingGroup cullingGroup = null; | |
void Start () | |
{ | |
// cullingGroupの初期化 | |
cullingGroup = new CullingGroup (); | |
cullingGroup.targetCamera = Camera.main; | |
// 視認のステータスが更新された時に受け取るコールバック登録 | |
cullingGroup.onStateChanged += OnStateChange; | |
// 座標を登録 | |
BoundingSphere[] bounds = new BoundingSphere[positions.Length]; | |
for (int i = 0; i < bounds.Length; i++) { | |
bounds [i].position = positions [i].position; | |
bounds [i].radius = positions[i].localScale.magnitude; | |
} | |
cullingGroup.SetBoundingSpheres (bounds); | |
cullingGroup.SetBoundingSphereCount (positions.Length); | |
} | |
void OnStateChange (CullingGroupEvent ev) | |
{ | |
// 見えたら、シーンをAditiveで読み込み | |
// cullinggroupは停止する | |
if (ev.hasBecomeVisible) { | |
cullingGroup.enabled = false; | |
var result = SceneManager.LoadSceneAsync (sceneName, LoadSceneMode.Additive); | |
result.priority = 2; | |
} | |
} | |
void OnDestroy () | |
{ | |
cullingGroup.Dispose (); | |
cullingGroup = null; | |
} | |
void OnDrawGizmos () | |
{ | |
#if UNITY_EDITOR | |
UnityEditor.Handles.color = Color.red; | |
foreach (var pos in positions) { | |
UnityEditor.Handles.CircleCap( | |
0, pos.position, | |
UnityEditor.SceneView.currentDrawingSceneView.camera.transform.rotation, | |
pos.localScale.magnitude); | |
} | |
#endif | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment