Ejemplo n.º 1
0
        public void Update()
        {
            if (!GameManager.Is(FGameState.InGame) || !mInitialized)
            {
                return;
            }

            //if we've equipped a tool with a light source
            if (player.Tool.IsEquipped && player.Tool.worlditem.HasLightSource)
            {
                //enable our projector
                LightSourceProjector.enabled = true;
                if (LastEquippedLightSource != player.Tool.worlditem)
                {
                    Debug.Log("Resetting color");
                    //reset our color so we can fade up again
                    CurrentColor = Color.black;
                    LightSourceProjector.farClipPlane = 1f;
                    LastEquippedLightSource           = player.Tool.worlditem;
                    //use its template to get the color, etc
                    WorldLightTemplate wlt = LastEquippedLightSource.Light.Template;
                    TargetRange = wlt.SpotlightRange;
                    TargetAngle = wlt.SpotlightAngle * 1.1f;                                                            //because we're seeing it farther away
                }
                TargetColor  = player.Tool.worlditem.Light.BaseLight.color;
                CurrentColor = Color.Lerp(CurrentColor, TargetColor, 0.05f);
                LightProjectorMaterial.color = CurrentColor;
                //lerp the range values etc of our projector
                LightSourceProjector.enabled      = true;
                LightSourceProjector.farClipPlane = Mathf.Lerp(LightSourceProjector.farClipPlane, TargetRange, 0.25f);
                LightSourceProjector.fieldOfView  = Mathf.Lerp(LightSourceProjector.fieldOfView, TargetAngle, 0.25f);
            }
            else
            {
                if (LastEquippedLightSource != null)
                {
                    Debug.Log("Setting light source to null");
                    LastEquippedLightSource = null;
                    TargetColor             = Color.black;
                }
                if (LightSourceProjector.enabled)
                {
                    //if it's not already off, fade it to black
                    CurrentColor = Color.Lerp(CurrentColor, TargetColor, 0.05f);
                    if (CurrentColor.r < 0.01f)
                    {
                        LightSourceProjector.enabled = false;
                    }
                    else
                    {
                        LightProjectorMaterial.color = CurrentColor;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void EditorLoadLightTemplates()
        {
            if (!Manager.IsAwake <Mods> ())
            {
                Manager.WakeUp <Mods> ("__MODS");
            }
            Mods.Get.Editor.InitializeEditor(true);
            Templates.Clear();

            List <string> availableTemplates = Mods.Get.Editor.Available("Light");

            foreach (string availableTemplate in availableTemplates)
            {
                WorldLightTemplate template = null;
                if (Mods.Get.Editor.LoadMod <WorldLightTemplate> (ref template, "Light", availableTemplate))
                {
                    Templates.Add(template);
                }
            }
        }
Ejemplo n.º 3
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);
        }