浏览代码

automated run from editor WIP

/seans-add-link-xml
Andre McGrail 4 年前
当前提交
a1c0887d
共有 4 个文件被更改,包括 302 次插入50 次删除
  1. 33
      Assets/Scripts/GameSystem/AppSettings.cs
  2. 65
      Assets/Scripts/System/Benchmark.cs
  3. 13
      Assets/Scripts/System/PerfomanceStats.cs
  4. 241
      Assets/scenes/Testing/benchmark_island-flythrough.unity

33
Assets/Scripts/GameSystem/AppSettings.cs


{
UniversalRenderPipeline.asset.useSRPBatcher = enabled;
}
public static void LoadScene(int buildIndex, LoadSceneMode mode)
public static void LoadScene(int buildIndex, LoadSceneMode mode = LoadSceneMode.Single)
Instance.StartCoroutine(LoadScene(buildIndex));
Instance.StartCoroutine(LoadSceneInternal(buildIndex));
break;
case LoadSceneMode.Additive:
SceneManager.LoadSceneAsync(buildIndex, LoadSceneMode.Additive);

}
}
private static IEnumerator LoadScene(int scene)
private static IEnumerator LoadSceneInternal(int scene)
Debug.Log($"loading scene {SceneUtility.GetScenePathByBuildIndex(scene)} at build index {scene}");
SceneManager.LoadScene(scene);
if(Debug.isDebugBuild)
Debug.Log($"loading scene {SceneUtility.GetScenePathByBuildIndex(scene)} at build index {scene}");
// get current scene and set a loading scene as active
var currentScene = SceneManager.GetActiveScene();
var loadingScene = SceneManager.CreateScene("Loading");
SceneManager.SetActiveScene(loadingScene);
// unload last scene
var unload = SceneManager.UnloadSceneAsync(currentScene, UnloadSceneOptions.None);
while (!unload.isDone) { yield return null; }
// clean up
var clean = Resources.UnloadUnusedAssets();
while (!clean.isDone) { yield return null; }
// load new scene
var load = SceneManager.LoadSceneAsync(scene);
while (!load.isDone) { yield return null; }
}
private static IEnumerator LoadPrefab<T>(AssetReference assetRef, AsyncOperationHandle assetLoading, Transform parent = null)

yield return assetLoading;
}
public void ExitGame()
public static void ExitGame()
{
#if UNITY_EDITOR
UnityEditor.EditorApplication.ExitPlaymode();

65
Assets/Scripts/System/Benchmark.cs


using System;
using System.Collections;
using System.Collections.Generic;
using Object = UnityEngine.Object;
#if UNITY_EDITOR
using System.Collections;
using UnityEditor;
using UnityEditor.SceneManagement;
#endif
public Object[] scenes;
private static bool _exitOnCompletion;
public string scene;
private void Start()
{
#if UNITY_EDITOR
#endif
DontDestroyOnLoad(gameObject);
LoadBenchmark(scene, 4, true, true);
}
public static void LoadBenchmark(string scene, int runs, bool perfstats, bool quitOnFinish)
{
_exitOnCompletion = quitOnFinish;
AppSettings.LoadScene(scene);
}
public static void EndBenchmark()
{
if (_exitOnCompletion)
{
AppSettings.ExitGame();
}
}
#if UNITY_EDITOR
[InitializeOnLoad]
public class BenchmarkTool
{
static BenchmarkTool()
{
EditorApplication.playModeStateChanged += Cleanup;
}
[MenuItem("Boat Attack/Benchmark/Island Flythrough")]
public static void IslandFlyThrough()
{
EditorApplication.EnterPlaymode();
//EditorSceneManager.NewScene(NewSceneSetup.EmptyScene);
var go = new GameObject("BenchmarkManager");
var bench = go.AddComponent<Benchmark>();
bench.scene = "benchmark_island-flythrough";
}
private static void Cleanup(PlayModeStateChange state)
{
Debug.Log("statechange");
if (state == PlayModeStateChange.EnteredEditMode)
{
var go = GameObject.Find("BenchmarkManager");
if(go)
Object.DestroyImmediate(go);
}
}
}
#endif
[Serializable]
public class PerfBasic

13
Assets/Scripts/System/PerfomanceStats.cs


public class PerfomanceStats : MonoBehaviour
{
private int _runNumber = 0;
private int _runNumber = 1;
public int runCount = 4;
public int runLength = 2000;

public PerfBasic Stats => _stats[_runNumber];
public PerfBasic Stats => _stats[_runNumber - 1];
private List<float> samples = new List<float>();
private int totalSamples = 250;
private int curFrame = 0;

curFrame = 0;
_stats.Add(new PerfBasic(runLength));
_runNumber++;
if (_runNumber < runCount)
{
_runNumber++;
}
else
{
Benchmark.EndBenchmark();
}
}
private void UpdateFrametime()

241
Assets/scenes/Testing/benchmark_island-flythrough.unity


debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &90223536
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 90223537}
- component: {fileID: 90223539}
- component: {fileID: 90223538}
m_Layer: 5
m_Name: BenchmarkSummary
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!224 &90223537
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 90223536}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 1461309628}
m_Father: {fileID: 359309057}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 300}
m_Pivot: {x: 0.5, y: 1}
--- !u!114 &90223538
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 90223536}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0, g: 0.5286536, b: 1, a: 0.5882353}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 0}
m_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!222 &90223539
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 90223536}
m_CullTransparentMesh: 0
--- !u!1 &359309052
GameObject:
m_ObjectHideFlags: 0

m_LocalScale: {x: 0, y: 0, z: 0}
m_Children:
- {fileID: 1658580747}
- {fileID: 90223537}
m_Father: {fileID: 0}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

m_Father: {fileID: 0}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!84 &1420008408
RenderTexture:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: WaterDepthMap
m_ImageContentsHash:
serializedVersion: 2
Hash: 00000000000000000000000000000000
m_ForcedFallbackFormat: 4
m_DownscaleFallback: 0
m_IsAlphaChannelOptional: 0
serializedVersion: 3
m_Width: 1024
m_Height: 1024
m_AntiAliasing: 1
m_MipCount: -1
m_DepthFormat: 2
m_ColorFormat: 142
m_MipMap: 0
m_GenerateMips: 1
m_SRGB: 0
m_UseDynamicScale: 0
m_BindMS: 0
m_EnableCompatibleFormat: 1
m_TextureSettings:
serializedVersion: 2
m_FilterMode: 1
m_Aniso: 1
m_MipBias: 0
m_WrapU: 1
m_WrapV: 1
m_WrapW: 1
m_Dimension: 2
m_VolumeDepth: 1
--- !u!1 &1461309627
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1461309628}
- component: {fileID: 1461309630}
- component: {fileID: 1461309629}
m_Layer: 5
m_Name: Text
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1461309628
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1461309627}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 90223537}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: -20, y: -20}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1461309629
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1461309627}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 0.88976014, b: 0, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 0
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 25
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 2
m_MaxSize: 156
m_Alignment: 2
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1.2
m_Text: '<b><size=50>Boat Attack Benchmark</size></b>
Unity2020.2.0a20.2611
URP10.0.0.preview.23 Build:1.0 WindowsEditor DX11 Windows10.sp2 Scene=_island_flythrough
Resolution:<b>1920x1080</b>
Quality=High
CurrentFrame=234 Mem=230.45mb GPUMem:255.45mb
Average
Frametime=16.44ms MinFrametime=13.43ms (frame1304) MaxFrametime=25.45ms (frame234)'
--- !u!222 &1461309630
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1461309627}
m_CullTransparentMesh: 0
--- !u!1 &1616875140
GameObject:
m_ObjectHideFlags: 0

- component: {fileID: 1658580749}
- component: {fileID: 1658580748}
m_Layer: 5
m_Name: Image
m_Name: BenchmarkStats
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0

m_EditorClassIdentifier:
cam: {fileID: 1725543951}
frameLength: 1000
--- !u!84 &1927563024
RenderTexture:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: WaterDepthMap
m_ImageContentsHash:
serializedVersion: 2
Hash: 00000000000000000000000000000000
m_ForcedFallbackFormat: 4
m_DownscaleFallback: 0
m_IsAlphaChannelOptional: 0
serializedVersion: 3
m_Width: 1024
m_Height: 1024
m_AntiAliasing: 1
m_MipCount: -1
m_DepthFormat: 2
m_ColorFormat: 142
m_MipMap: 0
m_GenerateMips: 1
m_SRGB: 0
m_UseDynamicScale: 0
m_BindMS: 0
m_EnableCompatibleFormat: 1
m_TextureSettings:
serializedVersion: 2
m_FilterMode: 1
m_Aniso: 1
m_MipBias: 0
m_WrapU: 1
m_WrapV: 1
m_WrapW: 1
m_Dimension: 2
m_VolumeDepth: 1
正在加载...
取消
保存