/// <summary>
 /// Sets the id of each registered Aura light's cookiemap in the texture2DArray
 /// </summary>
 private void SetSpotCookieMapId(AuraLight auraLight)
 {
     if (auraLight.CastsCookie)
     {
         auraLight.SetCookieMapIndex(_spotLightsCookieMapsCollector.GetTextureIndex(auraLight.cookieMapRenderTexture));
     }
 }
 /// <summary>
 /// Sets the id of the Aura light's shadowmap in the texture2DArray
 /// </summary>
 private void SetSpotShadowMapId(AuraLight auraLight)
 {
     if (auraLight.CastsShadows)
     {
         auraLight.SetShadowMapIndex(_spotLightsShadowMapsCollector.GetTextureIndex(auraLight.shadowMapRenderTexture));
     }
 }
 /// <summary>
 /// Sets the id of each registered Aura light's cookiemap in the texture2DArray
 /// </summary>
 private void SetDirectionalCookieMapId(AuraLight auraLight)
 {
     if (auraLight.CastsCookie)
     {
         auraLight.SetCookieMapIndex(_directionalLightsCookieMapsCollector.GetTextureIndex(auraLight.cookieMapRenderTexture));
     }
 }
Example #4
0
        static void DrawGizmoForAuraLight(AuraLight component, GizmoType gizmoType)
        {
            bool isFaded = (int)gizmoType == (int)GizmoType.NonSelected || (int)gizmoType == (int)GizmoType.NotInSelectionHierarchy || (int)gizmoType == (int)GizmoType.NonSelected + (int)GizmoType.NotInSelectionHierarchy;

            if (isFaded && !AuraEditorPrefs.DisplayGizmosWhenUnselected || !isFaded && !AuraEditorPrefs.DisplayGizmosWhenSelected)
            {
                return;
            }

            float opacity = isFaded ? 0.15f : 1.0f;

            DrawGizmo(component, opacity);
        }
        public override void OnInspectorGUI()
        {
            try
            {
                serializedObject.Update();
                _defaultEditor.OnInspectorGUI();
                serializedObject.ApplyModifiedProperties();

                if (AuraEditorPrefs.DisplayAuraGuiInParentComponents)
                {
                    EditorGUILayout.Separator();
                    EditorGUILayout.BeginVertical(GuiStyles.Background);

                    AuraLight component = _targetObject.gameObject.GetComponent <AuraLight>();
                    if (component == null)
                    {
                        if (GUILayout.Button(new GUIContent(" Add <b>Aura Light</b>", Aura.ResourcesCollection.cameraUiIconTexture), new GUIStyle(GuiStyles.ButtonNoBorder)
                        {
                            fontSize = 18
                        }, GUILayout.Height(32)))
                        {
                            Undo.AddComponent <AuraLight>(_targetObject.gameObject);
                        }
                    }
                    else
                    {
                        EditorGUILayout.BeginHorizontal();
                        if (GUILayout.Button(new GUIContent((component.enabled ? " Disable" : " Enable") + " <b>Aura Light</b>", Aura.ResourcesCollection.cameraUiIconTexture), new GUIStyle(GuiStyles.ButtonNoBorder)
                        {
                            fontSize = 18
                        }, GUILayout.Height(32)))
                        {
                            component.enabled = !component.enabled;
                        }
                        if (GUILayout.Button(new GUIContent(Aura.ResourcesCollection.removeIconTexture, "Remove Aura Light"), GuiStyles.ButtonImageOnlyNoBorder, GUILayout.Width(32), GUILayout.Height(32)))
                        {
                            component.Destroy();
                            component = null;
                        }
                        EditorGUILayout.EndHorizontal();
                    }

                    EditorGUILayout.EndVertical();
                    EditorGUILayout.Separator();
                }
            }
            catch {}
        }
Example #6
0
        /// <summary>
        /// Returns an array with all the aura light matching the type parameter
        /// </summary>
        /// <param name="type">The wanted type of light</param>
        /// <param name="minAmount">Creates default Aura cameras to reach the minimum amount</param>
        /// <returns>An array with the aura lights</returns>
        public static AuraLight[] GetAuraLights(LightType type, int minAmount = 0)
        {
            AuraLight[] auraLights   = GetAuraLights();
            AuraLight[] sortedLights = auraLights.SortOutByType(type);
            if (minAmount > sortedLights.Length)
            {
                AuraLight[] newLights = new AuraLight[minAmount - sortedLights.Length];
                for (int i = 0; i < newLights.Length; ++i)
                {
                    newLights[i] = AuraLight.CreateGameObject("Aura " + type + " Light", type).GetComponent <AuraLight>();
                }

                sortedLights = sortedLights.Append(newLights);
            }

            return(sortedLights);
        }
Example #7
0
        /// <summary>
        /// Draws the gizmo
        /// </summary>
        /// <param name="component">The target component</param>
        /// <param name="opacity">The gizmo opacity</param>
        private static void DrawGizmo(AuraLight component, float opacity)
        {
            Color color = CustomGizmo.color;

            color.a = CustomGizmo.color.a * opacity;

            switch (component.Type)
            {
            case LightType.Directional:
            {
                float       size       = HandleUtility.GetHandleSize(component.transform.position);
                const int   stepAmount = 8;
                const float width      = 1.0f;
                const float length     = 3.0f;
                CustomGizmo.DrawCircle(Matrix4x4.TRS(component.transform.position, component.transform.rotation * Quaternion.AngleAxis(90, Vector3.right), Vector3.one * size * width), color, CustomGizmo.pixelWidth);
                for (int i = 0; i < stepAmount; ++i)
                {
                    float   ratio = (float)i / (float)stepAmount * 2.0f * Mathf.PI;
                    Vector3 localStartPosition       = new Vector3(Mathf.Sin(ratio), Mathf.Cos(ratio), 0) * size * width * 0.5f;
                    Vector3 transformedStartPosition = component.transform.localToWorldMatrix.MultiplyPoint(localStartPosition);
                    CustomGizmo.DrawLineSegment(transformedStartPosition, transformedStartPosition + component.transform.forward * size * length, color, CustomGizmo.pixelWidth);
                }
            }
            break;

            case LightType.Spot:
            {
                float angleToWidth = Mathf.Tan(component.GetComponent <Light>().spotAngle *Mathf.Deg2Rad * 0.5f) * 2.0f * component.GetComponent <Light>().range;
                CustomGizmo.DrawCone(Matrix4x4.TRS(component.transform.position, component.transform.rotation, new Vector3(angleToWidth, angleToWidth, component.GetComponent <Light>().range)), color, CustomGizmo.pixelWidth);
            }
            break;

            case LightType.Point:
            {
                CustomGizmo.DrawSphere(Matrix4x4.TRS(component.transform.position, component.transform.rotation, Vector3.one * component.GetComponent <Light>().range * 2.0f), color, CustomGizmo.pixelWidth);
            }
            break;
            }
        }
        /// <summary>
        /// Function called when the light is being disabled
        /// </summary>
        private void AuraLight_OnUninitialize(AuraLight auraLight, LightType typeBeforeUninitialize)
        {
            switch (typeBeforeUninitialize)
            {
            case LightType.Directional:
            {
                if (RegisteredDirectionalLightsList.Contains(auraLight))
                {
                    if (_directionalLightsShadowMapsCollector != null && _directionalLightsShadowMapsCollector.RemoveTexture(auraLight.shadowMapRenderTexture))
                    {
                        _directionalLightsShadowDataCollector.RemoveTexture(auraLight.shadowDataRenderTexture);
                        SetDirectionalShadowMapsId();
                    }

                    if (_directionalLightsCookieMapsCollector != null && _directionalLightsCookieMapsCollector.RemoveTexture(auraLight.cookieMapRenderTexture))
                    {
                        SetDirectionalCookieMapsId();
                    }

                    RegisteredDirectionalLightsList.Remove(auraLight);
                }
            }
            break;

            case LightType.Spot:
            {
                if (RegisteredSpotLightsList.Contains(auraLight))
                {
                    if (_spotLightsShadowMapsCollector != null && _spotLightsShadowMapsCollector.RemoveTexture(auraLight.shadowMapRenderTexture))
                    {
                        SetSpotShadowMapsId();
                    }

                    if (_spotLightsCookieMapsCollector != null && _spotLightsCookieMapsCollector.RemoveTexture(auraLight.cookieMapRenderTexture))
                    {
                        SetSpotCookieMapsId();
                    }

                    RegisteredSpotLightsList.Remove(auraLight);

                    if (OnUnregisterSpotLight != null)
                    {
                        OnUnregisterSpotLight(auraLight);
                    }
                }
            }
            break;

            case LightType.Point:
            {
                if (RegisteredPointLightsList.Contains(auraLight))
                {
                    if (_pointLightsShadowMapsCollector != null && _pointLightsShadowMapsCollector.RemoveTexture(auraLight.shadowMapRenderTexture))
                    {
                        SetPointShadowMapsId();
                    }

                    if (_pointLightsCookieMapsCollector != null && _pointLightsCookieMapsCollector.RemoveTexture(auraLight.cookieMapRenderTexture))
                    {
                        SetPointCookieMapsId();
                    }

                    RegisteredPointLightsList.Remove(auraLight);

                    if (OnUnregisterPointLight != null)
                    {
                        OnUnregisterPointLight(auraLight);
                    }
                }
            }
            break;
            }

            auraLight.OnUninitialize -= AuraLight_OnUninitialize;
        }
        /// <summary>
        /// Registers the Aura light to the global manager
        /// </summary>
        /// <param name="auraLight">The Aura Light to register</param>
        public void RegisterLight(AuraLight auraLight)
        {
            switch (auraLight.Type)
            {
            case LightType.Directional:
            {
                if (!RegisteredDirectionalLightsList.Contains(auraLight))
                {
                    RegisteredDirectionalLightsList.Add(auraLight);

                    if (auraLight.CastsShadows)
                    {
                        if (_directionalLightsShadowMapsCollector == null)
                        {
                            _directionalLightsShadowMapsCollector = new ShadowmapsCollector(DirectionalLightsManager.ShadowMapSize.x, DirectionalLightsManager.ShadowMapSize.y);
                        }

                        _directionalLightsShadowMapsCollector.AddTexture(auraLight.shadowMapRenderTexture);
                        SetDirectionalShadowMapsId();

                        if (_directionalLightsShadowDataCollector == null)
                        {
                            _directionalLightsShadowDataCollector = new DirectionalShadowDataCollector();
                        }
                        _directionalLightsShadowDataCollector.AddTexture(auraLight.shadowDataRenderTexture);
                    }


                    if (auraLight.CastsCookie)
                    {
                        if (_directionalLightsCookieMapsCollector == null)
                        {
                            _directionalLightsCookieMapsCollector = new Texture2DArrayComposer(DirectionalLightsManager.cookieMapSize.x, DirectionalLightsManager.cookieMapSize.y, TextureFormat.R8, true);
                        }
                        _directionalLightsCookieMapsCollector.AddTexture(auraLight.cookieMapRenderTexture);
                        SetDirectionalCookieMapsId();
                    }
                }
            }
            break;

            case LightType.Spot:
            {
                if (!RegisteredSpotLightsList.Contains(auraLight))
                {
                    RegisteredSpotLightsList.Add(auraLight);

                    if (auraLight.CastsShadows)
                    {
                        if (_spotLightsShadowMapsCollector == null)
                        {
                            _spotLightsShadowMapsCollector = new ShadowmapsCollector(SpotLightsManager.shadowMapSize.x, SpotLightsManager.shadowMapSize.y);
                        }
                        _spotLightsShadowMapsCollector.AddTexture(auraLight.shadowMapRenderTexture);
                        SetSpotShadowMapsId();
                    }

                    if (auraLight.CastsCookie)
                    {
                        if (_spotLightsCookieMapsCollector == null)
                        {
                            _spotLightsCookieMapsCollector = new Texture2DArrayComposer(SpotLightsManager.cookieMapSize.x, SpotLightsManager.cookieMapSize.y, TextureFormat.R8, true);
                        }
                        _spotLightsCookieMapsCollector.AddTexture(auraLight.cookieMapRenderTexture);
                        SetSpotCookieMapsId();
                    }

                    if (OnRegisterSpotLight != null)
                    {
                        OnRegisterSpotLight(auraLight);
                    }
                }
            }
            break;

            case LightType.Point:
            {
                if (!RegisteredPointLightsList.Contains(auraLight))
                {
                    RegisteredPointLightsList.Add(auraLight);

                    if (auraLight.CastsShadows)
                    {
                        if (_pointLightsShadowMapsCollector == null)
                        {
                            _pointLightsShadowMapsCollector = new ShadowmapsCollector(PointLightsManager.shadowMapSize.x, PointLightsManager.shadowMapSize.y);
                        }
                        _pointLightsShadowMapsCollector.AddTexture(auraLight.shadowMapRenderTexture);
                        SetPointShadowMapsId();
                    }

                    if (auraLight.CastsCookie)
                    {
                        if (_pointLightsCookieMapsCollector == null)
                        {
                            _pointLightsCookieMapsCollector = new Texture2DArrayComposer(PointLightsManager.cookieMapSize.x, PointLightsManager.cookieMapSize.y, TextureFormat.R8, true);
                            _pointLightsCookieMapsCollector.alwaysGenerateOnUpdate = true;
                        }
                        _pointLightsCookieMapsCollector.AddTexture(auraLight.cookieMapRenderTexture);
                        SetPointCookieMapsId();
                    }

                    if (OnRegisterPointLight != null)
                    {
                        OnRegisterPointLight(auraLight);
                    }
                }
            }
            break;
            }

            auraLight.OnUninitialize += AuraLight_OnUninitialize;
        }
Example #10
0
 /// <summary>
 /// Returns an array with all the aura lights
 /// </summary>
 /// <returns>An array with the aura lights</returns>
 public static AuraLight[] GetAuraLights()
 {
     return(AuraLight.FindObjectsOfType <AuraLight>());
 }
        static void HierarchyWindowItemOnGUI(int instanceID, Rect selectionRect)
        {
            if (AuraEditorPrefs.DisplayButtonsInHierarchy)
            {
                GameObject gameObject = (GameObject)EditorUtility.InstanceIDToObject(instanceID);

                if (gameObject != null)
                {
                    float  size = selectionRect.height;
                    Rect   rect = new Rect(selectionRect.x + selectionRect.width, selectionRect.y, size, size);
                    string tooltip;
                    bool   state;


                    //// Cameras

                    Camera     camera     = gameObject.GetComponent <Camera>();
                    AuraCamera auraCamera = gameObject.GetComponent <AuraCamera>();
                    if (camera != null && auraCamera == null)
                    {
                        tooltip = "Add Aura Camera Component";
                        rect.x -= size;

                        if (GUI.Button(rect, new GUIContent(Aura.ResourcesCollection.addIconTexture, tooltip), GuiStyles.ButtonImageOnlyNoBorder))
                        {
                            gameObject.AddComponent <AuraCamera>();
                        }
                    }

                    if (auraCamera != null)
                    {
                        state   = auraCamera.enabled;
                        tooltip = (state ? "Disable" : "Enable") + " Aura Camera";
                        rect.x -= size;

                        if (GUI.Button(rect, new GUIContent(Aura.ResourcesCollection.cameraMiniIconTexture, tooltip), state ? GuiStyles.ButtonPressedImageOnlyNoBorder : GuiStyles.ButtonImageOnlyNoBorder)) // TODO : MAKE THIS A GENERIC HELPER
                        {
                            auraCamera.enabled = !state;
                        }
                    }

                    //// Lights

                    Light     light     = gameObject.GetComponent <Light>();
                    AuraLight auraLight = gameObject.GetComponent <AuraLight>();
                    if (light != null && auraLight == null)
                    {
                        tooltip = "Add Aura Light Component";
                        rect.x -= size;

                        if (GUI.Button(rect, new GUIContent(Aura.ResourcesCollection.addIconTexture, tooltip), GuiStyles.ButtonImageOnlyNoBorder))
                        {
                            gameObject.AddComponent <AuraLight>();
                        }
                    }

                    if (auraLight != null && auraLight.Type != LightType.Area)
                    {
                        state   = auraLight.enabled;
                        tooltip = (state ? "Disable" : "Enable") + " Aura Light";
                        rect.x -= size;
                        Texture2D texture = Aura.ResourcesCollection.pointLightMiniIconTexture;
                        switch (auraLight.Type)
                        {
                        case LightType.Directional:
                        {
                            texture = Aura.ResourcesCollection.directionalLightMiniIconTexture;
                        }
                        break;

                        case LightType.Spot:
                        {
                            texture = Aura.ResourcesCollection.spotLightMiniIconTexture;
                        }
                        break;
                        }

                        if (GUI.Button(rect, new GUIContent(texture, tooltip), state ? GuiStyles.ButtonPressedImageOnlyNoBorder : GuiStyles.ButtonImageOnlyNoBorder)) // TODO : MAKE THIS A GENERIC HELPER
                        {
                            auraLight.enabled = !state;
                        }
                    }

                    //// Volumes

                    AuraVolume auraVolume = gameObject.GetComponent <AuraVolume>();
                    if (auraVolume != null)
                    {
                        state   = auraVolume.enabled;
                        tooltip = (state ? "Disable" : "Enable") + " Aura Volume";
                        rect.x -= size;

                        if (GUI.Button(rect, new GUIContent(Aura.ResourcesCollection.shapeMiniIconTexture, tooltip), state ? GuiStyles.ButtonPressedImageOnlyNoBorder : GuiStyles.ButtonImageOnlyNoBorder)) // TODO : MAKE THIS A GENERIC HELPER
                        {
                            auraVolume.enabled = !state;
                        }
                    }

                    //// Sprites

                    SpriteRenderer spriteRenderer = gameObject.GetComponent <SpriteRenderer>();
                    AuraSprite     auraSprite     = gameObject.GetComponent <AuraSprite>();
                    if (spriteRenderer != null && auraSprite == null)
                    {
                        tooltip = "Add Aura Sprite Component";
                        rect.x -= size;

                        if (GUI.Button(rect, new GUIContent(Aura.ResourcesCollection.addIconTexture, tooltip), GuiStyles.ButtonImageOnlyNoBorder))
                        {
                            gameObject.AddComponent <AuraSprite>();
                        }
                    }

                    if (auraSprite != null)
                    {
                        tooltip = "Aura Sprite";
                        rect.x -= size;
                        GUI.Label(rect, new GUIContent(Aura.ResourcesCollection.spriteMiniIconTexture, tooltip), GuiStyles.ButtonPressedImageOnlyNoBorder);
                    }
                }
            }
        }
Example #12
0
 /// <summary>
 /// Called when a spot light unregisters from the global list
 /// </summary>
 /// <param name="auraLight">The unregistering light</param>
 private void LightsCommonDataManager_OnUnregisterSpotLight(AuraLight auraLight)
 {
     _culler.Unregister(auraLight);
 }
 /// <summary>
 /// Called when a new point light registers onto the global list
 /// </summary>
 /// <param name="auraLight">The newly registered light</param>
 private void LightsCommonDataManager_OnRegisterPointLight(AuraLight auraLight)
 {
     _culler.Register(auraLight);
 }