Esempio n. 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();
            }
        }
Esempio n. 2
0
        public void Update()
        {
            if (GameManager.Is(FGameState.Cutscene | FGameState.GameLoading))
            {
                mLerpThisFrame   = 1f;
                mUpdateLights    = 10;
                mUpdateMaterials = 30;
            }

            mUpdateLights++;
            if (mUpdateLights > 10)
            {
                mUpdateLights = 0;

                for (int i = WorldLights.LastIndex(); i >= 0; i--)
                {
                    WorldLight wl = WorldLights [i];
                    if (wl == null)
                    {
                        WorldLights.RemoveAt(i);
                    }
                    else
                    {
                        wl.UpdateBrightness();
                    }
                }
            }

            mUpdateMaterials++;
            if (mUpdateMaterials > 5)
            {
                mUpdateMaterials = 0;
                bool lightsOn = WorldClock.IsNight || !Player.Local.Surroundings.IsOutside || GameWorld.Get.CurrentBiome.OuterSpace;
                if (lightsOn)
                {
                    mTargetEmissionBrightness = 1f;
                }
                else
                {
                    mTargetEmissionBrightness = 0f;
                }

                mEmissionBrightness = Mathf.Lerp(mEmissionBrightness, mTargetEmissionBrightness, 0.35f);

                for (int i = 0; i < Mats.Get.TimedGlowMaterials.Count; i++)
                {
                    Material mat = Mats.Get.TimedGlowMaterials [i];
                    mat.SetColor("_EmiTint", Colors.Alpha(mat.GetColor("_EmiTint"), mEmissionBrightness));
                }
            }
        }
Esempio n. 3
0
 public static void DeactivateWorldLight(WorldLight lightToRetire)
 {
     //Debug.Log ("Deactivating light");
     if (lightToRetire != null)
     {
         //send it to the queue to be removed
         if (!Get.DisabledWorldLights.Contains(lightToRetire))
         {
             Get.DisabledWorldLights.Add(lightToRetire);
         }
         Get.ActiveWorldLights.Remove(lightToRetire);
         lightToRetire.TurnOff();
     }
 }
Esempio n. 4
0
        public void Execute(ref WooState state)
        {
            Vector3 colourVec = _ColourExpr.EvaluateVector(ref state);
            Colour  colour    = new Colour(colourVec.x, colourVec.y, colourVec.z);

            double samples = _SamplesExpr.EvaluateFloat(ref state);

            if (samples < 1)
            {
                samples = 1;
            }

            WorldLight worldLight = new WorldLight(colour, (int)samples);

            worldLight.CreateElement(state._Parent, new Vector3(0, 0, 0));
        }
Esempio n. 5
0
        public void OnRestorePower()
        {
            creature.TryToRevive();             //won't do anything if it's not stunned
            //SearchLight.LightEnabled = true;
            LuminteTrail.enabled = true;
            //create our search light
            if (SearchLight == null)
            {
                SearchLight = LightManager.GetWorldLight("RefinedLightLuminite", LuminiteLightPivot, Vector3.zero, true, WorldLightType.AlwaysOn);
            }
            OrbSpotlightForward.enabled      = true;
            OrbSpotlightBottom.enabled       = true;
            OrbPointLight.enabled            = true;
            LuminiteParticles.enableEmission = true;

            PowerSource.CanRemoveSource = false;

            OrbSpeak(OrbSpeakUnit.ResumingNormalRoutine, worlditem.tr);
        }
Esempio n. 6
0
        public MotileAction FleeFromLight()
        {
            Body.EyeMode = BodyEyeMode.Scared;
            Motile motile = null;

            if (photosensitive.HasNearbyLights && worlditem.Is <Motile> (out motile))
            {
                WorldLight nearestLight = photosensitive.NearestLight;
                if (mFleeThreatAction.IsFinished || mFleeThreatAction.LiveTarget != nearestLight)
                {
                    mFleeThreatAction.Reset();
                    mFleeThreatAction.LiveTarget    = nearestLight;
                    mFleeThreatAction.Range         = nearestLight.TargetBaseRange;
                    mFleeThreatAction.OutOfRange    = nearestLight.TargetBaseRange + 1f;
                    mFleeThreatAction.YieldBehavior = MotileYieldBehavior.DoNotYield;
                    motile.PushMotileAction(mFleeThreatAction, MotileActionPriority.ForceTop);
                }
            }
            return(mFleeThreatAction);
        }
Esempio n. 7
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;
         }
     }
 }
Esempio n. 8
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);
        }
Esempio n. 9
0
        protected static WorldLight CreateWorldLight()
        {
            Debug.Log("Creating world light");

            if (Get.WorldLightPrefab.SpotlightTop == null)
            {
                Debug.Log("SPOTLIGHT TOP WAS NULL IN PREFAB");
            }

            GameObject newWorldLightObject = GameObject.Instantiate(Get.WorldLightPrefab.gameObject, mInstantiateOffset, Quaternion.identity) as GameObject;
            WorldLight newWorldLight       = newWorldLightObject.GetComponent <WorldLight> ();

            newWorldLight.Template = Get.DefaultTemplate;
            newWorldLight.LightCollider.enabled = false;

            if (newWorldLight.SpotlightTop == null)
            {
                Debug.Log("SPOTLIGHT TOP WAS NULL!");
            }

            Get.WorldLights.Add(newWorldLight);
            Get.ActiveWorldLights.Add(newWorldLight);
            return(newWorldLight);
        }
Esempio n. 10
0
        public void Execute(ref WooState state)
        {
            Vector3 colourVec = _ColourExpr.EvaluateVector(ref state);
            Colour colour = new Colour(colourVec.x, colourVec.y, colourVec.z);

            double samples = _SamplesExpr.EvaluateFloat(ref state);
            if (samples < 1) samples = 1;

            WorldLight worldLight = new WorldLight(colour, (int)samples);
            worldLight.CreateElement(state._Parent, new Vector3(0, 0, 0));
        }
Esempio n. 11
0
 public void Awake()
 {
     wl = (WorldLight)target;
 }
Esempio n. 12
0
 public static void DestroyWorldLight(WorldLight lightToDestroy)
 {
     //this will be cleand up during update
 }
Esempio n. 13
0
        public static WorldLight GetWorldLight(WorldLight existingLight, string templateName, Transform lightParent, Vector3 lightOffset, Vector3 lightRotation, bool enabled, WorldLightType wlType)
        {
                        #if UNITY_EDITOR
            if (Get == null)
            {
                Mods.WakeUp <LightManager> ("Frontiers_ObjectManagers");
            }
            if (Colors.Get == null)
            {
                Mods.WakeUp <Colors> ("Frontiers_ArtResourceManagers");
            }
                        #endif
            WorldLightTemplate wlt = null;
            //if the existing light isn't null, just apply the new template
            if (existingLight != null)
            {
                existingLight.gameObject.SetActive(true);
                existingLight.tr.parent = null;
                //set the scale first so the collider range isn't affected
                existingLight.tr.localScale    = Vector3.one;
                existingLight.tr.parent        = lightParent;
                existingLight.tr.localPosition = lightOffset;
                if (lightRotation != Vector3.zero)
                {
                    existingLight.tr.localRotation = Quaternion.Euler(lightRotation);
                }
                else
                {
                    existingLight.tr.localRotation = Quaternion.identity;
                }
                if (!mTemplateLookup.TryGetValue(templateName, out wlt))
                {
                    wlt = Get.DefaultTemplate;
                }
                existingLight.SetTemplate(wlt);
                return(existingLight);
            }

            WorldLight newWorldLight = null;
            if (Get.InactiveWorldLights.Count > 0)
            {
                newWorldLight = Get.InactiveWorldLights.Dequeue();
                Get.ActiveWorldLights.Add(newWorldLight);
            }
            else
            {
                newWorldLight = CreateWorldLight();
            }
            newWorldLight.Reset();
            newWorldLight.Type = wlType;
            newWorldLight.Enable(true);
            newWorldLight.tr.parent = null;
            //set the scale first so the collider range isn't affected
            newWorldLight.tr.localScale    = Vector3.one;
            newWorldLight.tr.parent        = lightParent;
            newWorldLight.tr.localPosition = lightOffset;
            if (lightRotation != Vector3.zero)
            {
                newWorldLight.tr.localRotation = Quaternion.Euler(lightRotation);
            }
            else
            {
                newWorldLight.tr.localRotation = Quaternion.identity;
            }
            if (!mTemplateLookup.TryGetValue(templateName, out wlt))
            {
                wlt = Get.DefaultTemplate;
            }
            newWorldLight.SetTemplate(wlt);
            newWorldLight.UpdateBrightness();

            return(newWorldLight);
        }