79 lines
2.7 KiB
C#
79 lines
2.7 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using BITKit;
|
|
using Cysharp.Threading.Tasks;
|
|
using UnityEngine;
|
|
using YooAsset;
|
|
using Object = UnityEngine.Object;
|
|
|
|
namespace BITFALL.Debuger
|
|
{
|
|
public class BITFALLCommands
|
|
{
|
|
[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;
|
|
Object.Instantiate(assetHandle.AssetObject.As<AssetableItem>().GetPrefab(), camera.position, camera.rotation);
|
|
}
|
|
[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");
|
|
var sos = new List<AssetableItem>();
|
|
foreach (var info in infos)
|
|
{
|
|
var so = YooAssets.LoadAssetAsync<ScriptableObject>(info.AssetPath);
|
|
so.WaitForAsyncComplete();
|
|
sos.Add(so.AssetObject.As<AssetableItem>());
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|