Example #1
0
        protected virtual void CreateRenderers()
        {
            int num = this._Colliders.Length;

            this.VolumeRenderers = new MeshRenderer[num];
            this.VolumeFilters   = new MeshFilter[num];
            Material sharedMaterial = (this._CullMode != CullMode.Back) ? this._Water.Materials.VolumeBackMaterial : this._Water.Materials.VolumeMaterial;

            for (int i = 0; i < num; i++)
            {
                Collider       collider = this._Colliders[i];
                BoxCollider    boxCollider;
                GameObject     gameObject;
                SphereCollider sphereCollider;
                MeshCollider   meshCollider;
                if ((boxCollider = (collider as BoxCollider)) != null)
                {
                    WaterVolumeBase.HandleBoxCollider(out gameObject, boxCollider);
                }
                else if ((sphereCollider = (collider as SphereCollider)) != null)
                {
                    WaterVolumeBase.HandleSphereCollider(out gameObject, sphereCollider);
                }
                else if ((meshCollider = (collider as MeshCollider)) != null)
                {
                    this.HandleMeshCollider(out gameObject, meshCollider);
                }
                else
                {
                    CapsuleCollider capsuleCollider;
                    if (!((capsuleCollider = (collider as CapsuleCollider)) != null))
                    {
                        throw new InvalidOperationException("Unsupported collider type.");
                    }
                    WaterVolumeBase.HandleCapsuleCollider(out gameObject, capsuleCollider);
                }
                gameObject.hideFlags = HideFlags.DontSave;
                gameObject.name      = "Volume Renderer";
                gameObject.layer     = WaterProjectSettings.Instance.WaterLayer;
                gameObject.transform.SetParent(base.transform, false);
                UnityEngine.Object.Destroy(gameObject.GetComponent <Collider>());
                MeshRenderer component = gameObject.GetComponent <MeshRenderer>();
                component.sharedMaterial    = sharedMaterial;
                component.shadowCastingMode = ShadowCastingMode.Off;
                component.receiveShadows    = false;
                component.lightProbeUsage   = LightProbeUsage.Off;
                component.enabled           = true;
                component.SetPropertyBlock(this._Water.Renderer.PropertyBlock);
                this.VolumeRenderers[i] = component;
                this.VolumeFilters[i]   = component.GetComponent <MeshFilter>();
            }
        }
Example #2
0
        public static Water FindWater(Vector3 position, float radius, List <Water> allowedWaters, out bool isInsideSubtractiveVolume, out bool isInsideAdditiveVolume)
        {
            isInsideSubtractiveVolume = false;
            isInsideAdditiveVolume    = false;
            int num = Physics.OverlapSphereNonAlloc(position, radius, Water._CollidersBuffer, 1 << WaterProjectSettings.Instance.WaterCollidersLayer, QueryTriggerInteraction.Collide);

            Water._PossibleWaters.Clear();
            Water._ExcludedWaters.Clear();
            for (int i = 0; i < num; i++)
            {
                WaterVolumeBase waterVolume = WaterVolumeBase.GetWaterVolume(Water._CollidersBuffer[i]);
                if (waterVolume != null)
                {
                    if (waterVolume is WaterVolumeAdd)
                    {
                        isInsideAdditiveVolume = true;
                        if (allowedWaters == null || allowedWaters.Contains(waterVolume.Water))
                        {
                            Water._PossibleWaters.Add(waterVolume.Water);
                        }
                    }
                    else
                    {
                        isInsideSubtractiveVolume = true;
                        Water._ExcludedWaters.Add(waterVolume.Water);
                    }
                }
            }
            for (int j = 0; j < Water._PossibleWaters.Count; j++)
            {
                if (!Water._ExcludedWaters.Contains(Water._PossibleWaters[j]))
                {
                    return(Water._PossibleWaters[j]);
                }
            }
            List <Water> boundlessWaters = ApplicationSingleton <WaterSystem> .Instance.BoundlessWaters;
            int          count           = boundlessWaters.Count;

            for (int k = 0; k < count; k++)
            {
                Water water = boundlessWaters[k];
                if ((allowedWaters == null || allowedWaters.Contains(water)) && water.Volume.IsPointInsideMainVolume(position, radius) && !Water._ExcludedWaters.Contains(water))
                {
                    return(water);
                }
            }
            return(null);
        }
Example #3
0
 public void OnTriggerExit(Collider other)
 {
     if (this._CurrentWater == null)
     {
         WaterVolumeBase waterVolume = WaterVolumeBase.GetWaterVolume <WaterVolumeSubtract>(other);
         if (waterVolume != null && waterVolume.EnablePhysics)
         {
             this.ScanWaters();
         }
     }
     else
     {
         WaterVolumeBase waterVolume2 = WaterVolumeBase.GetWaterVolume <WaterVolumeAdd>(other);
         if (waterVolume2 != null && waterVolume2.Water == this._CurrentWater && waterVolume2.EnablePhysics)
         {
             this.LeaveCurrentWater();
         }
     }
 }
Example #4
0
 public static WaterVolumeBase GetWaterVolume <T>(Collider collider) where T : WaterVolumeBase
 {
     return(WaterVolumeBase.GetWaterVolume(collider) as T);
 }