コード例 #1
0
        public void ApplyCorrectSky(Renderer rend)
        {
            //filter by ignored layers
            bool localCube = false;

            //if the anchor is a direct link to a sky, ignore applicators all together
            mset.SkyAnchor anchor = rend.GetComponent <SkyAnchor>();
            if (anchor && anchor.BindType == SkyAnchor.AnchorBindType.TargetSky)
            {
                anchor.Apply();
                localCube = true;
            }

            //look for localized applicators to bind this renderer to
            foreach (mset.SkyApplicator app in skyApplicators)
            {
                if (localCube)
                {
                    app.RemoveRenderer(rend);
                }
                else if (app.RendererInside(rend))
                {
                    localCube = true;
                }
            }

            //no local applicator found, but we have a global sky
            if (!localCube && _GlobalSky != null)
            {
                if (anchor != null)
                {
                    if (anchor.CurrentApplicator != null)
                    {
                        anchor.CurrentApplicator.RemoveRenderer(rend);
                        anchor.CurrentApplicator = null;
                    }
                    //start last blend to global sky and tell the anchor it's gone global
                    anchor.BlendToGlobalSky(_GlobalSky);
                }
                else
                {
                    //HACK: no applying to renderers outside of a sky anchor! it leaks memory.
                    //_GlobalSky.Apply(rend,0);
                }

                if (!globalSkyChildren.Contains(rend))
                {
                    globalSkyChildren.Add(rend);
                }
            }

            //if a local cube was found or there is no global sky, remove rend
            if (localCube || _GlobalSky == null)
            {
                if (globalSkyChildren.Contains(rend))
                {
                    globalSkyChildren.Remove(rend);
                }
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        //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);
        }
コード例 #4
0
        private void EditorApplyToList(object[] renderers, mset.SkyApplicator[] apps, bool forceApply)
        {
            foreach (object mr in renderers)
            {
                Renderer rend = (Renderer)mr;

                //filter by ignored layers
                int layerFlag = 1 << rend.gameObject.layer;
                if ((IgnoredLayerMask & layerFlag) != 0)
                {
                    continue;
                }
                if (!rend.gameObject.activeInHierarchy)
                {
                    continue;
                }

                                #if USE_PROPERTY_BLOCKS
                //HACK: force clear all property blocks just in case
                if (forceApply)
                {
                    MaterialPropertyBlock pb = new MaterialPropertyBlock();
                    pb.Clear();
                    rend.SetPropertyBlock(pb);
                }
                                #endif
                //mset.Sky.ScrubKeywords(rend.sharedMaterials);

                mset.SkyAnchor anchor = rend.gameObject.GetComponent <mset.SkyAnchor>();
                if (anchor && !anchor.enabled)
                {
                    anchor = null;
                }

                bool rendHasChanged = rend.transform.hasChanged || (anchor && anchor.HasChanged);
                bool localFound     = false;

                if (anchor && anchor.BindType == mset.SkyAnchor.AnchorBindType.TargetSky)
                {
                    anchor.Apply();
                    localFound = true;
                }
                //trigger stuff is only processed if the game will auto apply as well
                if (GameAutoApply && !localFound)
                {
                    foreach (mset.SkyApplicator app in apps)
                    {
                        if (!app.gameObject.activeInHierarchy)
                        {
                            continue;
                        }
                        if (app.TargetSky)
                        {
                            if (forceApply || app.HasChanged || app.TargetSky.Dirty || rendHasChanged)
                            {
                                localFound         |= app.ApplyInside(rend);
                                app.TargetSky.Dirty = false;
                            }
                        }
                        app.HasChanged = false;
                    }
                }

                if (!localFound && _GlobalSky)
                {
                    if (forceApply || _GlobalSky.Dirty || rendHasChanged)
                    {
                        _GlobalSky.Apply(rend, 0);
                    }
                }
                //HACK: we are checking and clearing hasChanged in a weird place during the editor loop. Hopefully that won't conflict with other plugins?
                rend.transform.hasChanged = false;
                if (anchor)
                {
                    anchor.HasChanged = false;
                }
            }

            //this is always called in EditorUpdate, only run if forced externally
            if (forceApply && _GlobalSky)
            {
                _GlobalSky.Apply(0);
                if (_SkyboxMaterial)
                {
                    _GlobalSky.Apply(_SkyboxMaterial, 0);
                }
                _GlobalSky.Dirty = false;
            }
        }