BITFALL/Assets/Artists/Scripts/Debuger/BITFALLCommands.cs

79 lines
2.7 KiB
C#
Raw Normal View History

2024-01-27 04:09:57 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using BITKit;
2024-02-21 01:40:53 +08:00
using Cysharp.Threading.Tasks;
2024-01-27 04:09:57 +08:00
using UnityEngine;
using YooAsset;
using Object = UnityEngine.Object;
namespace BITFALL.Debuger
{
public class BITFALLCommands
{
2024-02-21 01:40:53 +08:00
[BITCommand]
public static async void Give(string path)
{
await BITApp.SwitchToMainThread();
var assetHandle = YooAssets.GetPackage("DefaultPackages").LoadAssetAsync<ScriptableObject>(path);
await assetHandle;
var camera = Camera.main!.transform;
2024-04-06 16:33:57 +08:00
Object.Instantiate(assetHandle.AssetObject.As<ScriptableItem>().GetPrefab(), camera.position, camera.rotation);
2024-02-21 01:40:53 +08:00
}
2024-01-27 04:09:57 +08:00
[BITCommand]
public static async void Impulse(int code)
{
await BITApp.SwitchToMainThread();
switch (code)
{
case 101:
var sw = new Stopwatch();
sw.Start();
try
{
var package = YooAssets.GetPackage("DefaultPackages");
var infos = package.GetAssetInfos("item");
2024-04-06 16:33:57 +08:00
var sos = new List<ScriptableItem>();
2024-01-27 04:09:57 +08:00
foreach (var info in infos)
{
var so = YooAssets.LoadAssetAsync<ScriptableObject>(info.AssetPath);
so.WaitForAsyncComplete();
2024-04-06 16:33:57 +08:00
sos.Add(so.AssetObject.As<ScriptableItem>());
2024-01-27 04:09:57 +08:00
so.Release();
}
var pos = Camera.main.transform;
foreach (var so in sos)
{
BIT4Log.Log<BITFALLCommands>("准备生成:" + so.Name);
try
{
var instance = Object.Instantiate(so.GetPrefab(), pos.position, pos.rotation);
}
catch (Exception e)
{
BIT4Log.Warning<BITFALLCommands>(so.Name);
BIT4Log.LogException(e);
}
}
sw.Stop();
}
catch (Exception e)
{
BIT4Log.LogException(e);
sw.Stop();
}
BIT4Log.Log<BITFALLCommands>($"生成完成,耗时:{sw.ElapsedMilliseconds}ms");
break;
}
}
}
}