private void Start() { var config = (DepthDataSourceConfig)Resources.Load("DepthDataSourceConfig"); if (config != null && config.DepthDataSource != null) { s_DepthDataSource = config.DepthDataSource; } s_Instance = this; s_AlwaysUpdateDepth = true; // Default texture, will be updated each frame. s_DepthTexture = new Texture2D(2, 2); foreach (MyDepthTarget target in s_DepthTargets) { if (target.DepthTargetMaterial != null) { SetDepthTexture(target); UpdateScreenOrientationOnMaterial(target.DepthTargetMaterial); SetAlphaForBlendedOcclusionProperties(target.DepthTargetMaterial); } } }
/// <summary> /// Checks whether this component is part of the scene. /// </summary> private static void CheckAttachedToScene() { if (s_Instance == null) { if (Camera.main != null) { s_Instance = Camera.main.gameObject.AddComponent <MyDepthSource>(); } } }
private void OnEnable() { // Takes the material of the object's renderer, if no DepthTargetMaterial is explicitly set. if (DepthTargetMaterial == null) { var renderer = GetComponent <Renderer>(); if (renderer != null) { DepthTargetMaterial = renderer.sharedMaterial; } } MyDepthSource.AddDepthTarget(this); }
private void OnDisable() { MyDepthSource.RemoveDepthTarget(this); }