Example #1
0
        /// <summary>
        ///     Sets the clip plane for the teleportable object's material
        /// </summary>
        /// <param name="sourcePosition">The position of the plane</param>
        /// <param name="sourceNormal">The normal of the plane</param>
        /// <param name="destPosition">The position of the plane</param>
        /// <param name="destNormal">The normal of the plane</param>
        /// <param name="DopplegangerOnly">Is the clip transform only being applied to the doppleganger?</param>
        public void SetClipPlane(Vector3 sourcePosition, Vector3 sourceNormal, Vector3 destPosition, Vector3 destNormal,
                                 bool DopplegangerOnly = false)
        {
            if (!initialized)
            {
                return;
            }

            using (var r = Renderers.GetEnumerator()) {
                while (r.MoveNext())
                {
                    var key = r.Current.Key;
                    if (key && !DopplegangerOnly)
                    {
                        var rms = SharedMaterialsCache.GetSharedMaterials(key);
                        for (var i = 0; i < rms.Length; i++)
                        {
                            var rm = rms[i];
                            if (!rm)
                            {
                                continue;
                            }
                            rm.SetVector(Keywords.ShaderKeys.ClipPos, sourcePosition);
                            rm.SetVector(Keywords.ShaderKeys.ClipVec, sourceNormal);
                            if (!rm.HasProperty(Keywords.ShaderKeys.ClipPos) && SKSGlobalRenderSettings.Clipping)
                            {
                                Debug.LogWarning(
                                    "Valid pixel-perfect material not set on teleportable. Object will be able to" +
                                    " be seen through the back of portals unless this is replaced.");
                            }
                        }
                    }
                    var dr = r.Current.Value;
                    if (dr)
                    {
                        var rms = SharedMaterialsCache.GetSharedMaterials(dr);
                        for (var i = 0; i < rms.Length; i++)
                        {
                            var rm = rms[i];
                            if (!rm)
                            {
                                continue;
                            }
                            rm.SetVector(Keywords.ShaderKeys.ClipPos, destPosition);
                            rm.SetVector(Keywords.ShaderKeys.ClipVec, destNormal);
                            if (!rm.HasProperty(Keywords.ShaderKeys.ClipPos) && SKSGlobalRenderSettings.Clipping)
                            {
                                Debug.LogWarning(
                                    "Valid pixel-perfect material not set on teleportable. Object will be able to" +
                                    "be seen through the back of portals unless this is replaced.");
                            }
                        }
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        ///     Enable doppleganger rendering
        /// </summary>
        public void EnableDoppleganger()
        {
            StartCoroutine(DoppleAction(() => {
                if (Doppleganger)
                {
                    using (var c = Renderers.GetEnumerator())
                        while (c.MoveNext())
                        {
                            if (c.Current.Key && c.Current.Value)
                            {
                                c.Current.Value.enabled = c.Current.Key.enabled;
                            }
                        }

                    Doppleganger.SetActive(true);
                }
            }));
        }
Example #3
0
 IEnumerator IEnumerable.GetEnumerator()
 {
     return(Renderers.GetEnumerator());
 }