internal static void AddToRenderingModulesList(RenderingModule renderingModule) { _renderingModulesList.Add(renderingModule); _resortRenderingModulesList = true; renderingModule._mainModule.OnDepthChange += ResortRenderingModulesList; #if UNITY_EDITOR renderingModule._materialModule.OnRenderQueueChange += ResortRenderingModulesList; #endif if (_renderingModulesList.Count == 1) { #if GAME_2D_WATER_KIT_LWRP || GAME_2D_WATER_KIT_URP UnityEngine.Rendering.RenderPipelineManager.beginFrameRendering += OnBeginFrameRendering; UnityEngine.Rendering.RenderPipelineManager.endFrameRendering += OnEndFrameRendering; #else Camera.onPreCull += RenderObjects; #endif Game2DWaterKitObject.FrameUpdate += OnFrameUpdate; Game2DWaterKitObject.AllWaterKitObjectsDestroyed -= OnAllWaterKitObjectsDestroyed; Game2DWaterKitObject.AllWaterKitObjectsDestroyed += OnAllWaterKitObjectsDestroyed; } }
private static int CompareDepth(RenderingModule a, RenderingModule b) { float aDepth = a._mainModule.Depth; float bDepth = b._mainModule.Depth; if (aDepth == bDepth) { return(0); } else { return(aDepth < bDepth ? 1 : -1); } }
private static int RenderingModulesSortComparer(RenderingModule a, RenderingModule b) { bool aIsOpaque = a._materialModule.RenderQueue <= 2500; bool bIsOpaque = b._materialModule.RenderQueue <= 2500; if (aIsOpaque == bIsOpaque) { if (aIsOpaque) // Both renderers are opaque { int dc = CompareDepth(a, b); if (dc == 0) { return(CompareSortingLayers(a, b)); } else { return(dc); } } else // Both renderers are transparent { int sc = CompareSortingLayers(a, b); if (sc == 0) { return(CompareDepth(a, b)); } else { return(sc); } } } else // One renderer is opaque and the other is transparent { int dc = CompareDepth(a, b); if (dc == 0) { return(aIsOpaque ? -1 : 1); } else { return(dc); } } }
internal static void RemoveFromRenderingModulesList(RenderingModule renderingModule) { _renderingModulesList.Remove(renderingModule); _resortRenderingModulesList = true; renderingModule._mainModule.OnDepthChange -= ResortRenderingModulesList; #if UNITY_EDITOR renderingModule._materialModule.OnRenderQueueChange -= ResortRenderingModulesList; #endif if (_renderingModulesList.Count == 0) { #if GAME_2D_WATER_KIT_LWRP || GAME_2D_WATER_KIT_URP UnityEngine.Rendering.RenderPipelineManager.beginFrameRendering -= OnBeginFrameRendering; UnityEngine.Rendering.RenderPipelineManager.endFrameRendering -= OnEndFrameRendering; #else Camera.onPreCull -= RenderObjects; #endif Game2DWaterKitObject.FrameUpdate -= OnFrameUpdate; } }
private static int CompareSortingLayers(RenderingModule a, RenderingModule b) { int aLayerOrder = SortingLayer.GetLayerValueFromID(a._sortingLayerID); int bLayerOrder = SortingLayer.GetLayerValueFromID(b._sortingLayerID); if (aLayerOrder == bLayerOrder) { int aOrderInLayer = a._sortingOrder; int bOrderInLayer = b._sortingOrder; if (aOrderInLayer == bOrderInLayer) { return(0); } else { return(aOrderInLayer < bOrderInLayer ? -1 : 1); } } else { return(aLayerOrder < bLayerOrder ? -1 : 1); } }