提交Unity 联机Pro

This commit is contained in:
PC-20230316NUNE\Administrator
2024-08-17 14:27:18 +08:00
parent f00193b000
commit 894100ae37
7448 changed files with 854473 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
/*
* This file has been deleted.
* This empty file is left here to ensure it is properly overwritten when importing a new version of the package over an old version.
*/

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3172283e0204f3e47968b9f791c5a2df
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,22 @@
namespace SRDebugger.Profiler
{
using System;
using UnityEngine;
/// <summary>
/// The profiler has a separate monobehaviour to listen for LateUpdate, and is placed
/// at the end of the script execution order.
/// </summary>
public class ProfilerLateUpdateListener : MonoBehaviour
{
public Action OnLateUpdate;
private void LateUpdate()
{
if (OnLateUpdate != null)
{
OnLateUpdate();
}
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 21048b348f7dc284ab97209ec32253c4
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 32001
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,128 @@
namespace SRDebugger.Profiler
{
using System.Diagnostics;
using Services;
using SRF;
using SRF.Service;
using UnityEngine;
public class ProfilerServiceImpl : SRServiceBase<IProfilerService>, IProfilerService
{
public float AverageFrameTime { get; private set; }
public float LastFrameTime { get; private set; }
public CircularBuffer<ProfilerFrame> FrameBuffer
{
get { return _frameBuffer; }
}
private const int FrameBufferSize = 400;
private readonly CircularBuffer<ProfilerFrame>
_frameBuffer = new CircularBuffer<ProfilerFrame>(FrameBufferSize);
private ProfilerLateUpdateListener _lateUpdateListener;
private readonly Stopwatch _stopwatch = new Stopwatch();
// Time between first Update() and last LateUpdate().
private double _updateDuration;
// Time that first camera rendered.
private double _renderStartTime;
// Time between first camera prerender and last camera postrender.
private double _renderDuration;
private int _camerasThisFrame;
protected override void Awake()
{
base.Awake();
_lateUpdateListener = gameObject.AddComponent<ProfilerLateUpdateListener>();
_lateUpdateListener.OnLateUpdate = OnLateUpdate;
CachedGameObject.hideFlags = HideFlags.NotEditable;
CachedTransform.SetParent(Hierarchy.Get("SRDebugger"), true);
Camera.onPreRender += OnCameraPreRender;
Camera.onPostRender += OnCameraPostRender;
}
protected override void Update()
{
base.Update();
_camerasThisFrame = 0;
EndFrame();
// Set the frame time for the last frame
if (FrameBuffer.Count > 0)
{
var frame = FrameBuffer.Back();
frame.FrameTime = Time.unscaledDeltaTime;
FrameBuffer[FrameBuffer.Count - 1] = frame;
}
LastFrameTime = Time.unscaledDeltaTime;
var frameCount = Mathf.Min(20, FrameBuffer.Count);
var f = 0d;
for (var i = 0; i < frameCount; i++)
{
f += FrameBuffer[FrameBuffer.Count - 1 - i].FrameTime;
}
AverageFrameTime = (float) f / frameCount;
_stopwatch.Start();
}
protected void PushFrame(double totalTime, double updateTime, double renderTime)
{
//UnityEngine.Debug.Log("Frame: u: {0} r: {1}".Fmt(updateTime, renderTime));
_frameBuffer.PushBack(new ProfilerFrame
{
OtherTime = totalTime - updateTime - renderTime,
UpdateTime = updateTime,
RenderTime = renderTime
});
}
private void OnLateUpdate()
{
_updateDuration = _stopwatch.Elapsed.TotalSeconds;
}
private void OnCameraPreRender(Camera cam)
{
if (_camerasThisFrame == 0)
{
_renderStartTime = _stopwatch.Elapsed.TotalSeconds;
}
_camerasThisFrame++;
}
private void OnCameraPostRender(Camera cam)
{
_renderDuration = _stopwatch.Elapsed.TotalSeconds - _renderStartTime;
}
private void EndFrame()
{
if (_stopwatch.IsRunning)
{
PushFrame(_stopwatch.Elapsed.TotalSeconds, _updateDuration, _renderDuration);
_stopwatch.Reset();
_stopwatch.Start();
}
_updateDuration = _renderDuration = 0;
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ff0319556f3fbc341b877ff4b1ff94ba
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: -32000
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,139 @@
#if UNITY_2018_1_OR_NEWER
namespace SRDebugger.Profiler
{
using System.Collections;
using System.Diagnostics;
using SRDebugger.Services;
using SRF;
using SRF.Service;
using UnityEngine;
#if UNITY_2019_3_OR_NEWER
using UnityEngine.Rendering;
#else
using UnityEngine.Experimental.Rendering;
#endif
public class SRPProfilerService : SRServiceBase<IProfilerService>, IProfilerService
{
public float AverageFrameTime { get; private set; }
public float LastFrameTime { get; private set; }
public CircularBuffer<ProfilerFrame> FrameBuffer
{
get { return _frameBuffer; }
}
private const int FrameBufferSize = 400;
private readonly CircularBuffer<ProfilerFrame> _frameBuffer = new CircularBuffer<ProfilerFrame>(FrameBufferSize);
private ProfilerLateUpdateListener _lateUpdateListener;
// Time between first Update() and last LateUpdate()
private double _updateDuration;
// Time that render pipeline starts
private double _renderStartTime;
// Time between scripted render pipeline starts + EndOfFrame
private double _renderDuration;
private readonly Stopwatch _stopwatch = new Stopwatch();
protected override void Awake()
{
base.Awake();
_lateUpdateListener = gameObject.AddComponent<ProfilerLateUpdateListener>();
_lateUpdateListener.OnLateUpdate = OnLateUpdate;
CachedGameObject.hideFlags = HideFlags.NotEditable;
CachedTransform.SetParent(Hierarchy.Get("SRDebugger"), true);
#if UNITY_2019_3_OR_NEWER
RenderPipelineManager.beginFrameRendering += RenderPipelineOnBeginFrameRendering;
#else
RenderPipeline.beginFrameRendering += RenderPipelineOnBeginFrameRendering;
#endif
StartCoroutine(EndOfFrameCoroutine());
}
protected override void Update()
{
base.Update();
EndFrame();
// Set the frame time for the last frame
if (FrameBuffer.Count > 0)
{
var frame = FrameBuffer.Back();
frame.FrameTime = Time.unscaledDeltaTime;
FrameBuffer[FrameBuffer.Count - 1] = frame;
}
LastFrameTime = Time.unscaledDeltaTime;
var frameCount = Mathf.Min(20, FrameBuffer.Count);
var f = 0d;
for (var i = 0; i < frameCount; i++)
{
f += FrameBuffer[FrameBuffer.Count - 1 - i].FrameTime;
}
AverageFrameTime = (float)f / frameCount;
_stopwatch.Start();
}
IEnumerator EndOfFrameCoroutine()
{
var endOfFrame = new WaitForEndOfFrame();
while (true)
{
yield return endOfFrame;
_renderDuration = _stopwatch.Elapsed.TotalSeconds - _renderStartTime;
}
}
protected void PushFrame(double totalTime, double updateTime, double renderTime)
{
_frameBuffer.PushBack(new ProfilerFrame
{
OtherTime = totalTime - updateTime - renderTime,
UpdateTime = updateTime,
RenderTime = renderTime
});
}
private void OnLateUpdate()
{
_updateDuration = _stopwatch.Elapsed.TotalSeconds;
}
#if UNITY_2019_3_OR_NEWER
private void RenderPipelineOnBeginFrameRendering(ScriptableRenderContext context, Camera[] cameras)
#else
private void RenderPipelineOnBeginFrameRendering(Camera[] obj)
#endif
{
_renderStartTime = _stopwatch.Elapsed.TotalSeconds;
}
private void EndFrame()
{
if (_stopwatch.IsRunning)
{
PushFrame(_stopwatch.Elapsed.TotalSeconds, _updateDuration, _renderDuration);
_stopwatch.Reset();
_stopwatch.Start();
}
_updateDuration = _renderDuration = 0;
}
}
}
#endif

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3f6b60357b55b3a438c0f79ba2be864c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: