private void VisitChildren(ProfilerSample sample, System.Func <ProfilerSample, bool> filter) { if (sample == null) { return; } if (filter(sample)) { return; } if (sample.children == null) { return; } foreach (var child in sample.children) { VisitChildren(child, filter); } }
void Update() //NOTE: using FixedUpdate the camera follow bhv should be also updated in FixedUpdate after this script is executed { //RpgMapHelper.DebugDrawRect( transform.position, CollRect, Color.white ); if (Dir.sqrMagnitude > 0f) { // divide by n per second ( n:2 ) m_speed += (MaxSpeed - m_speed) / Mathf.Pow(2f, Time.deltaTime); } else { m_speed /= Mathf.Pow(2f, Time.deltaTime); } Dir.z = 0f; transform.position += Dir * m_speed * Time.deltaTime; if (IsCollEnabled) { ProfilerSample.BeginSample("DoCollisions"); DoCollisions(); ProfilerSample.EndSample(); } }
private void ContainsPoint() { ProfilerSample.BeginSample("ContainsPoint"); for (int i = 0, length = centers.Length; i < length; i++) { result[i] = ContainsPoint(centers[i]) ? 1 : 0; } ProfilerSample.EndSample(); ProfilerSample.BeginSample("ContainsPointJobSystem"); // Create a native array of a single float to store the result. This example waits for the job to complete for illustration purposes AABBJob job = new AABBJob(); job.max = max; job.min = min; pointArray.CopyFrom(centers); job.points = pointArray; job.result = rs; // Schedule the job JobHandle handle = job.Schedule(); // Wait for the job to complete handle.Complete(); rs.CopyTo(result); ProfilerSample.EndSample(); ProfilerSample.BeginSample("ContainsPointComputeShader"); computeShader.SetVector(Shader.PropertyToID("box_min"), min); //cpu->gpu computeShader.SetVector(Shader.PropertyToID("box_max"), max); //cpu->gpu computeShader.SetInt(Shader.PropertyToID("size"), count); //cpu->gpu pointsBuffer.SetData(centers); computeShader.SetBuffer(_kernel, Shader.PropertyToID("points"), pointsBuffer); //cpu->gpu computeShader.SetBuffer(_kernel, Shader.PropertyToID("output"), output); ////cpu->gpu->cpu //Debug.Log(output.count + " " + result.Length); computeShader.Dispatch(_kernel, 1024, 1, 1); //调用核函数 output.GetData(result); //获取compute shader中计算后的结果数据 ProfilerSample.EndSample(); }
const int k_subDiv = 6; // sub divisions public bool IsColliding(Vector3 vPos) { Vector3 vCheckedPos = Vector3.zero; for (int i = 0; i < k_subDiv; ++i) { for (int j = 0; j < k_subDiv; ++j) { vCheckedPos.x = vPos.x + Mathf.Lerp(CollRect.x, CollRect.x + CollRect.width, (float)i / (k_subDiv - 1)); vCheckedPos.y = vPos.y + Mathf.Lerp(CollRect.y, CollRect.y + CollRect.height, (float)j / (k_subDiv - 1)); ProfilerSample.BeginSample("GetAutotileCollisionAtPosition"); eTileCollisionType collType = AutoTileMap.Instance.GetAutotileCollisionAtPosition(vCheckedPos); ProfilerSample.EndSample(); if (collType != eTileCollisionType.PASSABLE && collType != eTileCollisionType.OVERLAY) { return(true); } } } return(false); }
private void Intersects() { ProfilerSample.BeginSample("Intersects"); for (int i = 0, length = aabbs.Length; i < length; i++) { AABB aabb = aabbs[i]; result[i] = Intersects(aabb.aabbMin, aabb.aabbMax) ? 1 : 0; } ProfilerSample.EndSample(); //ProfilerSample.BeginSample("IntersectsJobSystem"); //// Create a native array of a single float to store the result. This example waits for the job to complete for illustration purposes //AABBJob job = new AABBJob(); //job.max = max; //job.min = min; //aabbArray.CopyFrom(aabbs); //job.aabbs = aabbArray; //job.result = rs; //// Schedule the job //JobHandle handle = job.Schedule(); //// Wait for the job to complete //handle.Complete(); //rs.CopyTo(result); //ProfilerSample.EndSample(); ProfilerSample.BeginSample("IntersectsComputeShader"); computeShader.SetVector(Shader.PropertyToID("box_min"), min); //cpu->gpu computeShader.SetVector(Shader.PropertyToID("box_max"), max); //cpu->gpu computeShader.SetInt(Shader.PropertyToID("size"), count); //cpu->gpu aabbsBuffer.SetData(aabbs); computeShader.SetBuffer(_kernel, Shader.PropertyToID("aabbs"), aabbsBuffer); //cpu->gpu computeShader.SetBuffer(_kernel, Shader.PropertyToID("output"), output); ////cpu->gpu->cpu //Debug.Log(output.count + " " + result.Length); computeShader.Dispatch(_kernel, 1024, 1, 1); //调用核函数 output.GetData(result); //获取compute shader中计算后的结果数据 ProfilerSample.EndSample(); }
public override void DoGUI(Rect rect) { using (ProfilerSample.Get()) { rect.yMin++; rect.xMin++; GUI.changed = false; GUI.Button(rect, lastContent, EditorStyles.label); if (!GUI.changed) { return; } var affectedObjsList = GetSelectedObjectsAndCurrent(); var affectedObjsEnum = affectedObjsList.AsEnumerable(); var changeMode = AskChangeModeIfNecessary(affectedObjsList, Preferences.IconAskMode.Value, "Change Icons", "Do you want to change children icons as well?"); switch (changeMode) { case ChildrenChangeMode.ObjectAndChildren: affectedObjsEnum = affectedObjsEnum.SelectMany(go => go.GetComponentsInChildren <Transform>(true).Select(t => t.gameObject)); break; } affectedObjsEnum = affectedObjsEnum.Distinct(); var affectedObjsArray = affectedObjsEnum.ToArray(); foreach (var obj in affectedObjsArray) { Undo.RegisterCompleteObjectUndo(obj, "Icon Changed"); } Reflected.ShowIconSelector(affectedObjsArray, rect, true); } }
private float GetSumOfTimeInSampleChildren(ProfilerSample sample, string matchStr, ref int count) { float sum = 0.0f; if (sample == null) { return(sum); } if (sample.sampleName == matchStr) { count += 1; return(sample.timeUS / 1000.0f); } if (sample.children == null) { return(sum); } foreach (var child in sample.children) { sum += GetSumOfTimeInSampleChildren(child, matchStr, ref count); } return(sum); }
private List <ProfilerSample> FindChildren(ProfilerSample profilerSample, string name) { List <ProfilerSample> results = new List <ProfilerSample>(); return(results); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { GatherEvents(Allocator.TempJob, out var pointerEvents, out var keyboardEvents); var pointerFrameData = GatherPointerFrameData(Allocator.TempJob); NativeArray <Entity> roots = m_RootGroup.ToEntityArray(Allocator.TempJob, out var rootsDeps); inputDeps = JobHandle.CombineDependencies(inputDeps, rootsDeps); var profilerSample = new ProfilerSample("PrepareBuffers"); var childrenFromEntity = GetBufferFromEntity <Child>(true); var worldSpaceRectFromEntity = GetComponentDataFromEntity <WorldSpaceRect>(true); var parentFromEntity = GetComponentDataFromEntity <Parent>(true); var pointerReceiverFromEntity = GetComponentDataFromEntity <PointerInputReceiver>(true); var stateComponentFromEntity = GetComponentDataFromEntity <InputSystemState>(); var stateEntity = GetSingletonEntity <InputSystemState>(); NativeArray <Entity> perCanvasHits = new NativeArray <Entity>(pointerFrameData.Length * roots.Length, Allocator.TempJob); NativeArray <Entity> globalHits = new NativeArray <Entity>(pointerFrameData.Length, Allocator.TempJob); LowLevelUtils.MemSet(perCanvasHits, default); LowLevelUtils.MemSet(globalHits, default); profilerSample.Dispose(); ProcessPerCanvasInput process = new ProcessPerCanvasInput() { Roots = roots, ChildrenFromEntity = childrenFromEntity, Hits = perCanvasHits, LocalToWorldFromEntity = worldSpaceRectFromEntity, PointerInputReceiver = pointerReceiverFromEntity, PointersPosition = pointerFrameData }; inputDeps = process.Schedule(roots.Length, 1, inputDeps); var canvasLayerFromEntity = GetComponentDataFromEntity <CanvasSortLayer>(); CanvasHitsToGlobal canvasHits = new CanvasHitsToGlobal() { Roots = roots, CanvasLayerFromEntity = canvasLayerFromEntity, GlobalHits = globalHits, PerCanvasHits = perCanvasHits }; inputDeps = canvasHits.Schedule(inputDeps); EntityCommandBuffer ecb = m_CommandBufferSystem.CreateCommandBuffer(); NativeMultiHashMap <Entity, PointerInputBuffer> targetToEvent = new NativeMultiHashMap <Entity, PointerInputBuffer>(16, Allocator.TempJob); UpdatePointerEvents updatePointerJob = new UpdatePointerEvents() { ButtonStates = m_ButtonStates, StateEntity = stateEntity, Hits = globalHits, ReceiverFromEntity = pointerReceiverFromEntity, StateFromEntity = stateComponentFromEntity, PointerEvents = pointerEvents, ParentFromEntity = parentFromEntity, PointerFrameData = pointerFrameData, DragThreshold = DragThreshold, TargetToEvent = targetToEvent }; inputDeps = updatePointerJob.Schedule(inputDeps); SpawnPointerEvents spawnEventsJob = new SpawnPointerEvents() { EventArchetype = m_PointerEventArchetype, Ecb = ecb, TargetToEvent = targetToEvent }; inputDeps = spawnEventsJob.Schedule(inputDeps); inputDeps = targetToEvent.Dispose(inputDeps); UpdateKeyboardEvents updateKeyboardJob = new UpdateKeyboardEvents() { KeyboardEvents = keyboardEvents, EventArchetype = m_KeyboardEventArchetype, Manager = ecb, StateEntity = stateEntity, StateFromEntity = stateComponentFromEntity }; inputDeps = updateKeyboardJob.Schedule(inputDeps); m_CommandBufferSystem.AddJobHandleForProducer(inputDeps); m_LastFrameMousePos = (Vector2)UnityEngine.Input.mousePosition; return(inputDeps); }