private void OnEnable()
        {
            script = (StylizedGrassRenderer)target;
#if URP
            if (script.bendRenderer == null)
            {
                DrawGrassBenders.ValidatePipelineRenderers();

                script.bendRenderer = StylizedGrassEditor.GetGrassBendRendererInProject();
                script.OnEnable();
                script.OnDisable();
            }
#endif

            renderExtends     = serializedObject.FindProperty("renderExtends");
            followSceneCamera = serializedObject.FindProperty("followSceneCamera");
            followTarget      = serializedObject.FindProperty("followTarget");
            renderLayer       = serializedObject.FindProperty("renderLayer");
            maskEdges         = serializedObject.FindProperty("maskEdges");
            colorMap          = serializedObject.FindProperty("colorMap");
            listenToWindZone  = serializedObject.FindProperty("listenToWindZone");
            windZone          = serializedObject.FindProperty("windZone");

            layerStr = UnityEditorInternal.InternalEditorUtility.layers;
        }
Esempio n. 2
0
        private Camera CreateCamera()
        {
            Camera cam = new GameObject().AddComponent <Camera>();

            cam.gameObject.name            = "GrassBendCamera " + GetInstanceID();
            cam.transform.localEulerAngles = new Vector3(90f, 0f, 0f);
            cam.gameObject.hideFlags       = HideFlags.HideAndDontSave;
            if (actualFollowTarget)
            {
                cam.gameObject.transform.position = new Vector3(actualFollowTarget.transform.position.x, actualFollowTarget.transform.position.y + renderExtends, actualFollowTarget.transform.position.z);
            }

            cam.orthographic = true;
            cam.depth        = -100f;
            cam.allowHDR     = false;
            cam.allowMSAA    = false;
            cam.clearFlags   = CameraClearFlags.SolidColor;
            cam.cullingMask  = 0;
            //Neutral bend direction and zero strength/mask
            cam.backgroundColor = neutralVector;

            cam.useOcclusionCulling    = false;
            cam.allowHDR               = true;
            cam.allowMSAA              = false;
            cam.forceIntoRenderTexture = true;

#if URP
            UniversalAdditionalCameraData camData = cam.gameObject.AddComponent <UniversalAdditionalCameraData>();
            camData.renderShadows        = false;
            camData.renderPostProcessing = false;
            camData.antialiasing         = AntialiasingMode.None;
            camData.requiresColorOption  = CameraOverrideOption.Off;
            camData.requiresDepthOption  = CameraOverrideOption.Off;
            camData.requiresColorTexture = false;
            camData.requiresDepthTexture = false;

            if (UniversalRenderPipeline.asset)
            {
#if UNITY_EDITOR
                //Only runs in editor, but will be referenced in instance from there on
                if (!bendRenderer)
                {
                    bendRenderer = GetGrassBendRenderer();
                }
                DrawGrassBenders.ValidatePipelineRenderers();
#endif

                if (bendRenderer)
                {
                    //Assign DrawGrassBenders renderer (list is internal, so perform reflection workaround)
                    ScriptableRendererData[] rendererDataList = (ScriptableRendererData[])typeof(UniversalRenderPipelineAsset).GetField("m_RendererDataList", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(UniversalRenderPipeline.asset);

                    for (int i = 0; i < rendererDataList.Length; i++)
                    {
                        if (rendererDataList[i] == bendRenderer)
                        {
                            camData.SetRenderer(i);
                        }
                    }
                }
                else
                {
                    this.enabled = false;
                }
            }
            else
            {
                Debug.LogError("[StylizedGrassRenderer] No Universal Render Pipeline is currently active.");
            }
#endif

            return(cam);
        }