private void PerformUpdate() { UISystemProfilerApi.BeginSample(UISystemProfilerApi.SampleType.Layout); this.CleanInvalidItems(); this.m_PerformingLayoutUpdate = true; this.m_LayoutRebuildQueue.Sort(CanvasUpdateRegistry.s_SortLayoutFunction); for (int i = 0; i <= 2; i++) { for (int j = 0; j < this.m_LayoutRebuildQueue.Count; j++) { ICanvasElement canvasElement = CanvasUpdateRegistry.instance.m_LayoutRebuildQueue[j]; try { if (this.ObjectValidForUpdate(canvasElement)) { canvasElement.Rebuild((CanvasUpdate)i); } } catch (Exception exception) { Debug.LogException(exception, canvasElement.transform); } } } for (int k = 0; k < this.m_LayoutRebuildQueue.Count; k++) { this.m_LayoutRebuildQueue[k].LayoutComplete(); } CanvasUpdateRegistry.instance.m_LayoutRebuildQueue.Clear(); this.m_PerformingLayoutUpdate = false; ClipperRegistry.instance.Cull(); this.m_PerformingGraphicUpdate = true; for (int l = 3; l < 5; l++) { for (int m = 0; m < CanvasUpdateRegistry.instance.m_GraphicRebuildQueue.Count; m++) { try { ICanvasElement canvasElement2 = CanvasUpdateRegistry.instance.m_GraphicRebuildQueue[m]; if (this.ObjectValidForUpdate(canvasElement2)) { canvasElement2.Rebuild((CanvasUpdate)l); } } catch (Exception exception2) { Debug.LogException(exception2, CanvasUpdateRegistry.instance.m_GraphicRebuildQueue[m].transform); } } } for (int n = 0; n < this.m_GraphicRebuildQueue.Count; n++) { this.m_GraphicRebuildQueue[n].GraphicUpdateComplete(); } CanvasUpdateRegistry.instance.m_GraphicRebuildQueue.Clear(); this.m_PerformingGraphicUpdate = false; UISystemProfilerApi.EndSample(UISystemProfilerApi.SampleType.Layout); }
public static int BeginSample_s(IntPtr l) { int result; try { UISystemProfilerApi.SampleType type; LuaObject.checkEnum <UISystemProfilerApi.SampleType>(l, 1, out type); UISystemProfilerApi.BeginSample(type); LuaObject.pushValue(l, true); result = 1; } catch (Exception e) { result = LuaObject.error(l, e); } return(result); }
//类初始化时,绑定Canvas.willRenderCanvases事件,Canvas重构时,执行这个方法 private void PerformUpdate() { UISystemProfilerApi.BeginSample(UISystemProfilerApi.SampleType.Layout); CleanInvalidItems(); m_PerformingLayoutUpdate = true; //需要重建的布局元素,根据子对象数量排序 m_LayoutRebuildQueue.Sort(s_SortLayoutFunction); for (int i = 0; i <= (int)CanvasUpdate.PostLayout; i++) { for (int j = 0; j < m_LayoutRebuildQueue.Count; j++) { var rebuild = instance.m_LayoutRebuildQueue[j]; try { if (ObjectValidForUpdate(rebuild)) { rebuild.Rebuild((CanvasUpdate)i); //注册的元素回调布局重建 } } catch (Exception e) { Debug.LogException(e, rebuild.transform); } } } for (int i = 0; i < m_LayoutRebuildQueue.Count; ++i) { m_LayoutRebuildQueue[i].LayoutComplete(); } //构建完成后情况队列 instance.m_LayoutRebuildQueue.Clear(); m_PerformingLayoutUpdate = false; // now layout is complete do culling... ClipperRegistry.instance.Cull(); //Mask2D裁剪 //重建Graphic元素 m_PerformingGraphicUpdate = true; for (var i = (int)CanvasUpdate.PreRender; i < (int)CanvasUpdate.MaxUpdateValue; i++) { for (var k = 0; k < instance.m_GraphicRebuildQueue.Count; k++) { try { var element = instance.m_GraphicRebuildQueue[k]; if (ObjectValidForUpdate(element)) { element.Rebuild((CanvasUpdate)i); } } catch (Exception e) { Debug.LogException(e, instance.m_GraphicRebuildQueue[k].transform); } } } for (int i = 0; i < m_GraphicRebuildQueue.Count; ++i) { m_GraphicRebuildQueue[i].GraphicUpdateComplete(); } instance.m_GraphicRebuildQueue.Clear(); m_PerformingGraphicUpdate = false; UISystemProfilerApi.EndSample(UISystemProfilerApi.SampleType.Layout); }
void OnGUI() { UnityEngine.Profiling.Profiler.BeginSample("Snapper Quick Settings"); UISystemProfilerApi.BeginSample(UISystemProfilerApi.SampleType.Render); EditorGUILayout.BeginHorizontal("Box", GUILayout.Height(fButtonHeight)); #region Small Buttons EditorGUILayout.BeginVertical(buttonSmallWidth); if (GUILayout.Button((Texture)EditorGUIUtility.Load("Icons/Snapper.png")))//, "|Open Snapper Editor.")) { BlocklyPlayground.OpenSnapperEditor(); } // Two Buttons EditorGUILayout.BeginHorizontal(); if (GUILayout.Button(EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector).GetStyle("Icon.Activation").normal.background)) { AssessmentWizard.CreateWizard(); } if (GUILayout.Button(EditorGUIUtility.IconContent("LookDevSideBySide", "|Publish."))) { BlocklyPlayground.PublishTo(); } EditorGUILayout.EndHorizontal(); if (GUILayout.Button(EditorGUIUtility.IconContent("renderdoc", "|Me."))) { Debug.Log(Application.companyName); } EditorGUILayout.EndVertical(); #endregion #region Big Buttons EditorGUILayout.BeginHorizontal(); if (GUILayout.Button(EditorGUIUtility.IconContent("cs Script Icon", "|Save as C# Script."))) { BlocklyPlayground.SaveAsCSharp(); } /*if (GUILayout.Button(EditorGUIUtility.IconContent("js Script Icon", "|Save as JS."))) * { * BlocklyPlayground.SaveAsJavaScript(); * }*/ // Create primitive with our most recent Snapper script. EditorGUILayout.BeginVertical(); op = (E_PRIMITIVE_STATE)EditorGUILayout.EnumPopup("Primitive to create:", op); EditorGUILayout.LabelField(string.Format("Last Snapper Script: \"{0}\"", BlocklyPlayground.LastSnapperComponent)); // If we're not compiling... if (!EditorApplication.isCompiling) { // ... allow us to create a primitive. if (GUILayout.Button(EditorGUIUtility.IconContent("GameObject Icon", "|Adds the latest Snapper script to a primitive."), GUILayout.Height(fButtonHeight - fPadding * 8f))) { InstantiatePrimitive(op); } } // ... We don't want to create a primitive if we're compiling. else { GUIStyle style = new GUIStyle(); style.richText = true; EditorGUILayout.LabelField("<color=red>Compiling!</color> Please Wait.", style); } EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); #endregion EditorGUILayout.EndHorizontal(); UISystemProfilerApi.EndSample(UISystemProfilerApi.SampleType.Render); UnityEngine.Profiling.Profiler.EndSample(); }
private void PerformUpdate() { UISystemProfilerApi.BeginSample(UISystemProfilerApi.SampleType.Layout); CleanInvalidItems(); m_PerformingLayoutUpdate = true; m_LayoutRebuildQueue.Sort(s_SortLayoutFunction); for (int i = 0; i <= (int)CanvasUpdate.PostLayout; i++) { UnityEngine.Profiling.Profiler.BeginSample(m_CanvasUpdateProfilerStrings[i]); for (int j = 0; j < m_LayoutRebuildQueue.Count; j++) { var rebuild = instance.m_LayoutRebuildQueue[j]; try { if (ObjectValidForUpdate(rebuild)) { rebuild.Rebuild((CanvasUpdate)i); } } catch (Exception e) { Debug.LogException(e, rebuild.transform); } } UnityEngine.Profiling.Profiler.EndSample(); } for (int i = 0; i < m_LayoutRebuildQueue.Count; ++i) { m_LayoutRebuildQueue[i].LayoutComplete(); } instance.m_LayoutRebuildQueue.Clear(); m_PerformingLayoutUpdate = false; UISystemProfilerApi.EndSample(UISystemProfilerApi.SampleType.Layout); UISystemProfilerApi.BeginSample(UISystemProfilerApi.SampleType.Render); // now layout is complete do culling... UnityEngine.Profiling.Profiler.BeginSample(m_CullingUpdateProfilerString); ClipperRegistry.instance.Cull(); UnityEngine.Profiling.Profiler.EndSample(); m_PerformingGraphicUpdate = true; for (var i = (int)CanvasUpdate.PreRender; i < (int)CanvasUpdate.MaxUpdateValue; i++) { UnityEngine.Profiling.Profiler.BeginSample(m_CanvasUpdateProfilerStrings[i]); for (var k = 0; k < instance.m_GraphicRebuildQueue.Count; k++) { try { var element = instance.m_GraphicRebuildQueue[k]; if (ObjectValidForUpdate(element)) { element.Rebuild((CanvasUpdate)i); } } catch (Exception e) { Debug.LogException(e, instance.m_GraphicRebuildQueue[k].transform); } } UnityEngine.Profiling.Profiler.EndSample(); } for (int i = 0; i < m_GraphicRebuildQueue.Count; ++i) { m_GraphicRebuildQueue[i].GraphicUpdateComplete(); } instance.m_GraphicRebuildQueue.Clear(); m_PerformingGraphicUpdate = false; UISystemProfilerApi.EndSample(UISystemProfilerApi.SampleType.Render); }
/*void OnEnable() * { * base.hideFlags = HideFlags.HideAndDontSave; * this.InitializeHorizontalSplitter(); * * AnimEditor.s_AnimationWindows.Add(this); * if (this.m_State == null) * { * this.m_State = (ScriptableObject.CreateInstance(typeof(AnimationWindowState)) as AnimationWindowState); * this.m_State.hideFlags = HideFlags.HideAndDontSave; * this.m_State.animEditor = this; * this.InitializeHorizontalSplitter(); * this.InitializeClipSelection(); * this.InitializeDopeSheet(); * this.InitializeEvents(); * this.InitializeCurveEditor(); * this.InitializeOverlay(); * } * this.InitializeNonserializedValues(); * this.m_State.timeArea = ((!this.m_State.showCurveEditor) ? this.m_DopeSheet : this.m_CurveEditor); * this.m_DopeSheet.state = this.m_State; * this.m_ClipPopup.state = this.m_State; * this.m_Overlay.state = this.m_State; * CurveEditor expr_E9 = this.m_CurveEditor; * expr_E9.curvesUpdated = (CurveEditor.CallbackFunction)Delegate.Combine(expr_E9.curvesUpdated, new CurveEditor.CallbackFunction(this.SaveChangedCurvesFromCurveEditor)); * this.m_CurveEditor.OnEnable();*/ /*// Shows an instance of custom window, SnapperWindow * SnapperWindow window = GetWindow<SnapperWindow>("Snapper"); * // Loads an icon from an image stored at the specified path * Texture icon = AssetDatabase.LoadAssetAtPath<Texture>("Assets/Editor Default Resources/Icons/Snapper.png"); * // Create the instance of GUIContent to assign to the window. Gives the title "SnapperWindow" and the icon * GUIContent titleContent = new GUIContent("SnapperWindow", icon); * window.titleContent = titleContent;* / * }*/ #region GUI void OnGUI() { UnityEngine.Profiling.Profiler.BeginSample("Snapper"); UISystemProfilerApi.BeginSample(UISystemProfilerApi.SampleType.Render); //Event currentEvent = Event.current; GUISkin _editorSkin = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector); //GUILayout.BeginArea(headingsRect, GUI.skin.box); //DrawMenu(); DrawHeadings(); //GUILayout.EndArea(); GUILayout.BeginHorizontal("Box");//, GUILayout.Width(GetWindow<SnapperWindow>().maxSize.x - 8)); //EditorGUILayout.Space(); DrawBlocks(); DrawGrid(); GUILayout.EndHorizontal(); //scrollPosition = GUILayout.BeginScrollView(scrollPosition); DrawColoriser(); DrawGenHeadings(); EditorGUILayout.BeginVertical(); // https://github.com/MattRix/UnityDecompiled/blob/82e03c823811032fd970ffc9a75246e95c626502/UnityEditor/UnityEditor/ProjectWindowUtil.cs //Or you can simply use the style itself when rendering a control: if (GUILayout.Button("", _editorSkin.GetStyle("Icon.Mute"))) { Debug.Log("Icon"); } if (GUILayout.Button("", _editorSkin.GetStyle("VisibilityToggle"))) { Debug.Log("Vis Tog"); //Debug.Log("Assets/Editor Default Resources/" + EditorResourcesUtility.iconsPath); } GUILayout.Label("", _editorSkin.GetStyle("MeTransPlayhead")); GUILayout.Label(_editorSkin.GetStyle("MeTransPlayhead").normal.background); EditorGUILayout.BeginHorizontal(); GUILayout.Button(EditorGUIUtility.IconContent("Animation.EventMarker", "|Add.")); GUILayout.Button(EditorGUIUtility.IconContent("LookDevClose", "|Add.")); GUILayout.Button(EditorGUIUtility.IconContent("renderdoc", "Capture|Capture the current view and open in RenderDoc.")); //GUILayout.Button(EditorGUIUtility.LoadIcon("animationkeyframe")); GUILayout.Button(EditorGUIUtility.IconContent("Mirror", "|Add.")); GUILayout.Button(EditorGUIUtility.IconContent("LookDevSingle1", "|Add.")); GUILayout.Button(EditorGUIUtility.IconContent("LookDevSingle2", "|Add.")); GUILayout.Button(EditorGUIUtility.IconContent("LookDevSideBySide", "|Add.")); GUILayout.Button(EditorGUIUtility.IconContent("Toolbar Plus", "|Add.")); GUILayout.Button(EditorGUIUtility.IconContent("Toolbar Minus", "|Minus.")); EditorGUILayout.EndHorizontal(); /*using (new EditorGUI.DisabledScope(false)) * { * GUILayout.BeginHorizontal();// new GUILayoutOption[0]); * SplitterGUILayout.BeginHorizontalSplit(this.m_HorizontalSplitter, new GUILayoutOption[0]); * GUILayout.BeginVertical();// new GUILayoutOption[0]); * GUILayout.BeginHorizontal();// EditorStyles.toolbarButton, new GUILayoutOption[0]); * GUILayout.FlexibleSpace(); * GUILayout.EndHorizontal(); * GUILayout.EndVertical(); * SplitterGUILayout.EndHorizontalSplit(); * GUILayout.EndHorizontal(); * }*/ EditorGUILayout.BeginHorizontal(); GUILayout.Button(EditorGUIUtility.IconContent("GameObject Icon", "|Game Object.")); //GUILayout.Button(EditorResourcesUtility.emptyFolderIconName, "|Game Object")); GUILayout.Button(EditorGUIUtility.IconContent("cs Script Icon", "|C# Script Icon.")); GUILayout.Button(EditorGUIUtility.IconContent("AnimatorController Icon", "|Add.")); GUILayout.Button(_editorSkin.GetStyle("MeTransPlayhead").normal.background); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); // TODO: remove later System.Type[] categories = new System.Type[] // UnityEngine.Object[] { typeof(Mesh), typeof(ParticleSystem), typeof(Physics), typeof(Physics2D), typeof(Behaviour), typeof(NavMeshAgent), typeof(AudioSource), typeof(VideoClip), typeof(Renderer), typeof(LayoutElement), typeof(VRDevice), typeof(Network), typeof(Transform), typeof(RectTransform), typeof(AudioLowPassFilter) }; for (int i = 0; i < categories.Length; i++) { if (i == 6) //categories.Length * 0.5f) { EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); } if (GUILayout.Button(EditorGUIUtility.ObjectContent(null, categories[i]).image)) { Debug.Log(categories[i].Name + " Image."); //Debug.Log(nameof(categories[i]) + " Image"); } } /*if (GUILayout.Button(EditorGUIUtility.ObjectContent(null, typeof(Transform)).image)) * { * Debug.Log("Transform Image"); * }*/ EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); // Draw Side Window /*sideWindowWidth = System.Math.Min(600, System.Math.Max(200, (int)(position.width / 5))); * GUILayout.BeginArea(sideWindowRect, GUI.skin.box); * DrawSideWindow(); * GUILayout.EndArea(); */ UISystemProfilerApi.EndSample(UISystemProfilerApi.SampleType.Render); UnityEngine.Profiling.Profiler.EndSample(); }
public void FindNearAuxins() { //clear them all, for obvious reasons myAuxins.Clear(); //get all auxins on my cell List <AuxinController> cellAuxins = cell.GetComponent <CellController>().GetAuxins(); UISystemProfilerApi.BeginSample(UISystemProfilerApi.SampleType.Layout); //iterate all cell auxins to check distance between auxins and agent for (int i = 0; i < cellAuxins.Count; i++) { //see if the distance between this agent and this auxin is smaller than the actual value, and inside agent radius float distance = Vector3.Distance(transform.position, cellAuxins[i].position); //compara o produto distancia x calmo do agente dono da auxina com o que quer pegar //caso não tenha agente dono da auxina A2 fica como 1 if (cellAuxins[i].taken == true) { GameObject otherAgent = cellAuxins[i].GetAgent(); } //if (distance < cellAuxins[i].GetMinDistance() && distance <= agentRadius && !cellAuxins[i].takenByRuler) if (distance < cellAuxins[i].GetMinDistance() && distance <= agentRadius) { //take the auxin!! //if this auxin already was taken, need to remove it from the agent who had it if (cellAuxins[i].taken == true) { GameObject otherAgent = cellAuxins[i].GetAgent(); otherAgent.GetComponent <AgentController>().myAuxins.Remove(cellAuxins[i]); } //auxin is taken cellAuxins[i].taken = true; //change the color (visual purpose) //cellAuxins[i].material.color = color; //auxin has agent cellAuxins[i].SetAgent(this.gameObject); //update min distance cellAuxins[i].SetMinDistance(distance); //update my auxins myAuxins.Add(cellAuxins[i]); } } UISystemProfilerApi.EndSample(UISystemProfilerApi.SampleType.Layout); //find all neighbours cells //default int startX = (int)cell.transform.position.x - 2; int startZ = (int)cell.transform.position.z - 2; int endX = (int)cell.transform.position.x + 2; int endZ = (int)cell.transform.position.z + 2; //distance from agent to cell, to define agent new cell float distanceToCell = Vector3.Distance(transform.position, cell.transform.position); //see if it is in some border if ((int)cell.transform.position.x == 1) { startX = (int)cell.transform.position.x; } if ((int)cell.transform.position.z == 1) { startZ = (int)cell.transform.position.z; } if ((int)cell.transform.position.x == (int)terrain.terrainData.size.x - 1) { endX = (int)cell.transform.position.x; } if ((int)cell.transform.position.z == (int)terrain.terrainData.size.z - 1) { endZ = (int)cell.transform.position.z; } //iterate to find the cells //2 in 2, since the radius of each cell is 1 = diameter 2 UISystemProfilerApi.BeginSample(UISystemProfilerApi.SampleType.Layout); for (int i = startX; i <= endX; i = i + 2) { for (int j = startZ; j <= endZ; j = j + 2) { int nameX = i - 1; int nameZ = j - 1; //find the cell //Debug.LogWarning(gameObject.name); GameObject neighbourCell = CellController.GetCellByName("cell" + nameX + "-" + nameZ); //get all auxins on neighbourcell cellAuxins = neighbourCell.GetComponent <CellController>().GetAuxins(); //iterate all cell auxins to check distance between auxins and agent for (int c = 0; c < cellAuxins.Count; c++) { //see if the distance between this agent and this auxin is smaller than the actual value, and smaller than agent radius float distance = Vector3.Distance(transform.position, cellAuxins[c].position); // caso ele seja afoito a sua distnacia diminui o que leva a uma prioridade maior sobre os outros if (cellAuxins[c].taken == true) { GameObject otherAgent = cellAuxins[c].GetAgent(); } if (distance < cellAuxins[c].GetMinDistance() && distance <= agentRadius) { //take the auxin!! //if this auxin already was taken, need to remove it from the agent who had it if (cellAuxins[c].taken == true) { GameObject otherAgent = cellAuxins[c].GetAgent(); otherAgent.GetComponent <AgentController>().myAuxins.Remove(cellAuxins[c]); } //auxin is taken cellAuxins[c].taken = true; //change the color (visual purpose) //cellAuxins[i].material.color = color; //auxin has agent cellAuxins[c].SetAgent(this.gameObject); //update min distance cellAuxins[c].SetMinDistance(distance); //update my auxins myAuxins.Add(cellAuxins[c]); } } //see distance to this cell float distanceToNeighbourCell = Vector3.Distance(transform.position, neighbourCell.transform.position); if (distanceToNeighbourCell < distanceToCell) { distanceToCell = distanceToNeighbourCell; SetCell(neighbourCell); } } } UISystemProfilerApi.EndSample(UISystemProfilerApi.SampleType.Layout); }
/// <summary> ///这里需要思考的是,有可能一个Image对象,RectTransform和Graphics同时发生了修改,它们的更新含义不同需要区分对待 ///1.修改了Image的宽高,这样Mesh的顶点会发生变化,此时该对象会加入m_LayoutRebuildQueue队列 ///2.修改了Image的Sprite,它并不会影响顶点位置信息,此时该对象会加入m_GraphicRebuildQueue队列 ///所以上面代码在遍历的时候会分层 ////for (int i = 0; i <= (int)CanvasUpdate.PostLayout; i++) ////for (var i = (int)CanvasUpdate.PreRender; i < (int)CanvasUpdate.MaxUpdateValue; i++) ///Rebuild的时候会把层传进去,保证Image知道现在是要更新布局,还是只更新渲染。 /// </summary> private void PerformUpdate() { //开始BeginSample() //在Profiler中看到的标志性函数Canvas.willRenderCanvases耗时就在这里了 //EndSample() UISystemProfilerApi.BeginSample(UISystemProfilerApi.SampleType.Layout); CleanInvalidItems();//从两个序列中,删除不可用元素 //(1)布局更新开始 m_PerformingLayoutUpdate = true; m_LayoutRebuildQueue.Sort(s_SortLayoutFunction); //分别以PreLayout,Layout,PostLayout的参数顺序调用每一个元素的Rebuild方法 for (int i = 0; i <= (int)CanvasUpdate.PostLayout; i++) { for (int j = 0; j < m_LayoutRebuildQueue.Count; j++) { var rebuild = instance.m_LayoutRebuildQueue[j]; try { if (ObjectValidForUpdate(rebuild)) { rebuild.Rebuild((CanvasUpdate)i);//重建布局元素 } } catch (Exception e) { Debug.LogException(e, rebuild.transform); } } } //调用布局更新完成的接口 for (int i = 0; i < m_LayoutRebuildQueue.Count; ++i) { m_LayoutRebuildQueue[i].LayoutComplete(); } instance.m_LayoutRebuildQueue.Clear(); m_PerformingLayoutUpdate = false; // now layout is complete do culling... // 布局构建结束,开始进行Mask2D裁切(详细内容下面会介绍) ClipperRegistry.instance.Cull(); //(2)图形更新开始 m_PerformingGraphicUpdate = true; //以PreRender,LatePreRender的参数顺序调用每一个元素的Rebulid方法 for (var i = (int)CanvasUpdate.PreRender; i < (int)CanvasUpdate.MaxUpdateValue; i++) { for (var k = 0; k < instance.m_GraphicRebuildQueue.Count; k++) { try { var element = instance.m_GraphicRebuildQueue[k]; if (ObjectValidForUpdate(element)) { element.Rebuild((CanvasUpdate)i);//重建UI元素 } } catch (Exception e) { Debug.LogException(e, instance.m_GraphicRebuildQueue[k].transform); } } } //调用图形更新成功的接口 for (int i = 0; i < m_GraphicRebuildQueue.Count; ++i) { m_GraphicRebuildQueue[i].GraphicUpdateComplete(); } instance.m_GraphicRebuildQueue.Clear(); m_PerformingGraphicUpdate = false; UISystemProfilerApi.EndSample(UISystemProfilerApi.SampleType.Layout); }
private void PerformUpdate() { UISystemProfilerApi.BeginSample(UISystemProfilerApi.SampleType.Layout); CleanInvalidItems(); // 18/5 2020 Image源码学习 //标记当前正在执行layout的rebuild //避免此时注册到队列中或者从队列中移除 m_PerformingLayoutUpdate = true; m_LayoutRebuildQueue.Sort(s_SortLayoutFunction); for (int i = 0; i <= (int)CanvasUpdate.PostLayout; i++) { for (int j = 0; j < m_LayoutRebuildQueue.Count; j++) { // 18/5 2020 Image源码学习 //从队列中取得一个element var rebuild = instance.m_LayoutRebuildQueue[j]; try { // 18/5 2020 Image源码学习 //element可用的情况下进行rebuild,这里调用基本上是layoutRebuilder中的rebuild方法 if (ObjectValidForUpdate(rebuild)) { rebuild.Rebuild((CanvasUpdate)i); } } catch (Exception e) { Debug.LogException(e, rebuild.transform); } } } // 18/5 2020 Image源码学习 //更新完毕之后,调用layout rebuild Complete方法,执行完成后需要做的一些事情 //清除队列,并且更新m_PerformingLayoutUpdate的值为false,开始接受新一轮的注册和删除 for (int i = 0; i < m_LayoutRebuildQueue.Count; ++i) { m_LayoutRebuildQueue[i].LayoutComplete(); } instance.m_LayoutRebuildQueue.Clear(); m_PerformingLayoutUpdate = false; // now layout is complete do culling... // 18/5 2020 Image源码学习 //布局完成之后,进行裁剪 ClipperRegistry.instance.Cull(); // 18/5 2020 Image源码学习 //Graphic rebuild同layout rebuild,只不过没有裁剪操作 m_PerformingGraphicUpdate = true; for (var i = (int)CanvasUpdate.PreRender; i < (int)CanvasUpdate.MaxUpdateValue; i++) { for (var k = 0; k < instance.m_GraphicRebuildQueue.Count; k++) { try { var element = instance.m_GraphicRebuildQueue[k]; if (ObjectValidForUpdate(element)) { element.Rebuild((CanvasUpdate)i); } } catch (Exception e) { Debug.LogException(e, instance.m_GraphicRebuildQueue[k].transform); } } } for (int i = 0; i < m_GraphicRebuildQueue.Count; ++i) { m_GraphicRebuildQueue[i].GraphicUpdateComplete(); } instance.m_GraphicRebuildQueue.Clear(); m_PerformingGraphicUpdate = false; UISystemProfilerApi.EndSample(UISystemProfilerApi.SampleType.Layout); }