Exemple #1
0
        public static void RefreshExposure(IPhotosensitive ps)
        {
            float exposureBeforeRefresh = ps.LightExposure;
            float heatBeforeRefresh     = ps.HeatExposure;

            ps.FireSources.Clear();

            ps.LightExposure = 0f;
            for (int i = ps.LightSources.LastIndex(); i >= 0; i--)
            {
                WorldLight lightSource = ps.LightSources [i];
                if (lightSource == null)
                {
                    ps.LightSources.RemoveAt(i);
                }
                else
                {
                    ps.LightExposure += lightSource.TargetBaseIntensity;
                    if (lightSource.IsFireLight)
                    {
                        ps.FireSources.Add(lightSource.fire);
                    }
                }
            }
            ps.HeatExposure = 0f;
            for (int i = 0; i < ps.FireSources.Count; i++)
            {
                Fire fire = ps.FireSources [i];
                if (Vector3.Distance(ps.Position, fire.FireLight.Position) < fire.BurnScale)
                {
                    ps.HeatExposure += fire.BurnHeat;
                }
                else
                {
                    ps.HeatExposure += fire.WarmHeat;
                }
            }

            if (ps.LightExposure > exposureBeforeRefresh)
            {
                ps.OnExposureIncrease.SafeInvoke();
            }
            else if (ps.LightExposure < exposureBeforeRefresh)
            {
                ps.OnExposureDecrease.SafeInvoke();
            }

            if (ps.HeatExposure > heatBeforeRefresh)
            {
                ps.OnHeatIncrease.SafeInvoke();
            }
            else if (ps.HeatExposure < heatBeforeRefresh)
            {
                ps.OnHeatDecrease.SafeInvoke();
            }
        }
Exemple #2
0
 public static void CalculateExposure(IPhotosensitive ps, float wDeltaTime)
 {
     ps.LightExposure = 0;
     ps.HeatExposure  = 0;
     for (int i = ps.LightSources.LastIndex(); i >= 0; i--)
     {
         WorldLight worldLight = ps.LightSources [i];
         if (worldLight == null)
         {
             ps.LightSources.RemoveAt(i);
         }
         else
         {
             //distance to center point of light from outer edge of object
             float distance = Mathf.Clamp((Vector3.Distance(worldLight.tr.position, ps.Position) - ps.Radius), 0.0001f, worldLight.TargetBaseRange);
             //exposure = time * light intensity / distance or minimum intensity, whichever is greater
             //multiply that by global light exposure multiplier
             ps.LightExposure += ((wDeltaTime * worldLight.TargetBaseIntensity) / distance) * Globals.LightExposureMultiplier;
             ps.HeatExposure  += ((wDeltaTime * worldLight.TargetHeatIntensity) / distance) * Globals.HeatExposureMultiplier;
         }
     }
 }
Exemple #3
0
        public static void OnTriggerEnter(WorldLight lightObject, Collider other)
        {
            //see if other object is photosensitive
            //and if it is, keep track of it
            IItemOfInterest ioi = null;
            IPhotosensitive ps  = null;

            if (WorldItems.GetIOIFromGameObject(other.gameObject, out ioi))
            {
                switch (ioi.IOIType)
                {
                case ItemOfInterestType.WorldItem:
                    ps = ioi.worlditem.Get <Photosensitive> ();
                    break;

                case ItemOfInterestType.Player:
                    ps = Player.Local.Surroundings;
                    break;

                case ItemOfInterestType.Fire:
                case ItemOfInterestType.Light:
                case ItemOfInterestType.ActionNode:
                    break;

                default:
                    ps = (IPhotosensitive)ioi.gameObject.GetComponent(typeof(IPhotosensitive));
                    break;
                }
            }

            if (ps == null)
            {
                return;
            }

            ps.LightSources.SafeAdd(lightObject);
            RefreshExposure(ps);
        }