public bool RendererInside(Renderer rend) { //direct binding mset.SkyAnchor anchor = rend.gameObject.GetComponent <mset.SkyAnchor>(); if (anchor && anchor.BindType == mset.SkyAnchor.AnchorBindType.TargetSky) { if (anchor.AnchorSky == TargetSky) { AddRenderer(rend); anchor.Apply(); return(true); } } //trigger volume binding if (!TriggerIsActive) { return(false); } foreach (SkyApplicator childApp in Children) { if (childApp.RendererInside(rend)) { return(true); } } if (anchor == null) { anchor = rend.gameObject.AddComponent(typeof(mset.SkyAnchor)) as mset.SkyAnchor; } anchor.GetCenter(ref _center); _center = transform.worldToLocalMatrix.MultiplyPoint(_center); if (TriggerDimensions.Contains(_center)) { if (!AffectedRenderers.Contains(rend)) { AddRenderer(rend); if (!anchor.HasLocalSky) { //set the anchor up to blend from the most current global sky in its local blender anchor.SnapToSky(mset.SkyManager.Get().GlobalSky); } anchor.BlendToSky(TargetSky); } return(true); } RemoveRenderer(rend); return(false); }
//Directly applies sky to renderers within the bounds of this applicator or its Children //For editor use. public bool ApplyInside(Renderer rend) { if (this.TargetSky == null || !TriggerIsActive) { return(false); } mset.SkyAnchor anchor = rend.gameObject.GetComponent <mset.SkyAnchor>(); if (anchor) { //TODO: is this necessary? this was never running before if (anchor.BindType == mset.SkyAnchor.AnchorBindType.TargetSky && anchor.AnchorSky == TargetSky) { this.TargetSky.Apply(rend, 0); anchor.Apply(); return(true); } } //TODO: a bounds check against fat, child-inclusive bounds here could early-out before recursion //recurse foreach (SkyApplicator childApp in Children) { if (childApp.ApplyInside(rend)) { return(true); } } Vector3 rendCenter = rend.bounds.center; if (anchor) { anchor.GetCenter(ref rendCenter); } rendCenter = transform.worldToLocalMatrix.MultiplyPoint(rendCenter); if (TriggerDimensions.Contains(rendCenter)) { this.TargetSky.Apply(rend, 0); return(true); } return(false); }