Async api sample
This commit is contained in:
Родитель
7dfb425809
Коммит
6b3782c399
|
@ -2,7 +2,7 @@
|
|||
Id: 1e8aa650-da28-44e4-b76f-e7865c20fcd5
|
||||
SerializedVersion: {Stride: 3.1.0.1}
|
||||
Tags: []
|
||||
DefaultScene: 1e5ed5df-d685-4f73-beb0-2672147f9aef:Scenes/Audio/Completed-Audio
|
||||
DefaultScene: d5a14911-dddc-42d0-b9f1-7c57fca5d0cb:Scenes/Async/AsyncScriptsTriggers - Completed
|
||||
GraphicsCompositor: fe026ff4-fdf9-48b9-87fb-65764cb9153f:GraphicsCompositor
|
||||
Defaults:
|
||||
- !Stride.Graphics.RenderingSettings,Stride.Graphics
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
!MaterialAsset
|
||||
Id: 3690986c-39ec-4b3b-a116-24fc5181906d
|
||||
SerializedVersion: {Stride: 2.0.0.0}
|
||||
Tags: []
|
||||
Attributes:
|
||||
Diffuse: !MaterialDiffuseMapFeature
|
||||
DiffuseMap: !ComputeColor
|
||||
Value: {R: 1.0, G: 0.7914844, B: 0.018750012, A: 1.0}
|
||||
DiffuseModel: !MaterialDiffuseLambertModelFeature {}
|
||||
Specular: !MaterialMetalnessMapFeature
|
||||
MetalnessMap: !ComputeFloat
|
||||
Value: 0.0
|
||||
SpecularModel: !MaterialSpecularMicrofacetModelFeature
|
||||
Fresnel: !MaterialSpecularMicrofacetFresnelSchlick {}
|
||||
Visibility: !MaterialSpecularMicrofacetVisibilitySmithSchlickGGX {}
|
||||
NormalDistribution: !MaterialSpecularMicrofacetNormalDistributionGGX {}
|
||||
Environment: !MaterialSpecularMicrofacetEnvironmentGGXLUT {}
|
||||
Overrides:
|
||||
UVScale: {X: 1.0, Y: 1.0}
|
||||
ClearCoat: !MaterialClearCoatFeature
|
||||
LODDistance: !ComputeFloat
|
||||
Value: 1.0
|
||||
BasePaintDiffuseMap: !ComputeColor
|
||||
Value: {R: 0.0, G: 0.09411765, B: 0.32941177, A: 1.0}
|
||||
BasePaintGlossinessMap: !ComputeBinaryScalar
|
||||
Operator: Multiply
|
||||
LeftChild: !ComputeFloat
|
||||
Value: 0.5
|
||||
RightChild: !ComputeTextureScalar
|
||||
Texture: 7e2761d1-ef86-420a-b7a7-a0ed1c16f9bb:StrideClearCoatMetalFlakesNM
|
||||
FallbackValue:
|
||||
Value: 1.0
|
||||
Scale: {X: 128.0, Y: 128.0}
|
||||
Offset: {X: 0.0, Y: 0.0}
|
||||
UseRandomTextureCoordinates: true
|
||||
MetalFlakesDiffuseMap: !ComputeColor
|
||||
Value: {R: 0.0, G: 0.18039216, B: 0.6313726, A: 1.0}
|
||||
MetalFlakesGlossinessMap: !ComputeBinaryScalar
|
||||
Operator: Multiply
|
||||
LeftChild: !ComputeFloat
|
||||
Value: 1.0
|
||||
RightChild: !ComputeTextureScalar
|
||||
Texture: 7e2761d1-ef86-420a-b7a7-a0ed1c16f9bb:StrideClearCoatMetalFlakesNM
|
||||
FallbackValue:
|
||||
Value: 1.0
|
||||
Scale: {X: 128.0, Y: 128.0}
|
||||
Offset: {X: 0.0, Y: 0.0}
|
||||
UseRandomTextureCoordinates: true
|
||||
MetalFlakesMetalnessMap: !ComputeFloat
|
||||
Value: 1.0
|
||||
MetalFlakesNormalMap: !ComputeTextureColor
|
||||
Texture: 7e2761d1-ef86-420a-b7a7-a0ed1c16f9bb:StrideClearCoatMetalFlakesNM
|
||||
FallbackValue:
|
||||
Value: {R: 1.0, G: 1.0, B: 1.0, A: 1.0}
|
||||
Scale: {X: 128.0, Y: 128.0}
|
||||
Offset: {X: 0.0, Y: 0.0}
|
||||
UseRandomTextureCoordinates: true
|
||||
Swizzle: null
|
||||
ClearCoatGlossinessMap: !ComputeFloat
|
||||
Value: 1.0
|
||||
ClearCoatMetalnessMap: !ComputeFloat
|
||||
Value: 0.5
|
||||
OrangePeelNormalMap: !ComputeTextureColor
|
||||
Texture: 2f76bcba-ae9f-4954-b98d-f94c2102ff86:StrideClearCoatOrangePeelNM
|
||||
FallbackValue:
|
||||
Value: {R: 1.0, G: 1.0, B: 1.0, A: 1.0}
|
||||
Scale: {X: 8.0, Y: 8.0}
|
||||
Offset: {X: 0.0, Y: 0.0}
|
||||
Swizzle: null
|
||||
Layers: {}
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -4,6 +4,7 @@
|
|||
<RootNamespace>CSharpIntermediate</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
<PackageReference Include="Stride.Engine" Version="4.1.0.1-beta" />
|
||||
<PackageReference Include="Stride.Navigation" Version="4.1.0.1-beta" />
|
||||
<PackageReference Include="Stride.Video" Version="4.1.0.1-beta" />
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
using System.Threading.Tasks;
|
||||
using Stride.Engine;
|
||||
using Stride.Rendering;
|
||||
|
||||
namespace CSharpIntermediate.Code
|
||||
{
|
||||
public class AsyncCollisionTriggerDemo : AsyncScript
|
||||
{
|
||||
PhysicsComponent triggerCollider;
|
||||
private Material yellowMaterial;
|
||||
private Material redMaterial;
|
||||
|
||||
public override async Task Execute()
|
||||
{
|
||||
// Store the collider component
|
||||
triggerCollider = Entity.Get<PhysicsComponent>();
|
||||
|
||||
//Preload some materials
|
||||
redMaterial = Content.Load<Material>("Materials/Red");
|
||||
yellowMaterial = Content.Load<Material>("Materials/Yellow");
|
||||
|
||||
while (Game.IsRunning)
|
||||
{
|
||||
// Wait for an entity to collide with the trigger
|
||||
var collision = await triggerCollider.NewCollision();
|
||||
var ballCollider = triggerCollider == collision.ColliderA ? collision.ColliderB : collision.ColliderA;
|
||||
|
||||
// Change the material on the entity
|
||||
ballCollider.Entity.Get<ModelComponent>().Materials[0] = yellowMaterial;
|
||||
|
||||
// Wait for the entity to exit the trigger
|
||||
await collision.Ended();
|
||||
|
||||
// Change the material back to the original one
|
||||
ballCollider.Entity.Get<ModelComponent>().Materials[0] = redMaterial;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Cancel()
|
||||
{
|
||||
Content.Unload(yellowMaterial);
|
||||
Content.Unload(redMaterial);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Stride.Engine;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System;
|
||||
|
||||
namespace CSharpIntermediate.Code
|
||||
{
|
||||
public class AsyncWebApi : AsyncScript
|
||||
{
|
||||
public override async Task Execute()
|
||||
{
|
||||
|
||||
while (Game.IsRunning)
|
||||
{
|
||||
if (Input.IsKeyPressed(Stride.Input.Keys.G)){
|
||||
await RetrieveStrideRepos();
|
||||
}
|
||||
|
||||
await Script.NextFrame();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task RetrieveStrideRepos()
|
||||
{
|
||||
var sw = new Stopwatch();
|
||||
sw.Start();
|
||||
|
||||
var client = new HttpClient();
|
||||
HttpResponseMessage response = await client.GetAsync("https://opencollective.com/stride3d/events.json?limit=4");
|
||||
|
||||
Log.Info(sw.Elapsed.ToString());
|
||||
|
||||
if (response.StatusCode == System.Net.HttpStatusCode.OK)
|
||||
{
|
||||
string responseContent = await response.Content.ReadAsStringAsync();
|
||||
var githubRepos = JsonConvert.DeserializeObject<List<OpenCollectiveEvent>>(responseContent);
|
||||
|
||||
foreach (var repo in githubRepos)
|
||||
{
|
||||
Log.Info($"{repo.Name} took place at {repo.StartsAt}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class OpenCollectiveEvent
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public string StartsAt { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using Stride.Audio;
|
||||
using Stride.Core.Mathematics;
|
||||
|
@ -18,9 +19,12 @@ namespace CSharpIntermediate.Code
|
|||
|
||||
public override async Task Execute()
|
||||
{
|
||||
var stopWatch = new Stopwatch();
|
||||
stopWatch.Start();
|
||||
musicInstance = BackgroundMusic.CreateInstance();
|
||||
|
||||
await musicInstance.ReadyToPlay();
|
||||
Log.Info(stopWatch.Elapsed.ToString());
|
||||
|
||||
while (Game.IsRunning)
|
||||
{
|
||||
|
|
|
@ -1,46 +0,0 @@
|
|||
using System.Threading.Tasks;
|
||||
using Stride.Engine;
|
||||
using Stride.Rendering;
|
||||
|
||||
namespace CSharpIntermediate.Code
|
||||
{
|
||||
public class AsyncCollisionTriggerDemo : AsyncScript
|
||||
{
|
||||
PhysicsComponent triggerCollider;
|
||||
private Material material1;
|
||||
private Material material2;
|
||||
|
||||
public override async Task Execute()
|
||||
{
|
||||
triggerCollider = Entity.Get<PhysicsComponent>();
|
||||
//triggerCollider.ProcessCollisions = true;
|
||||
|
||||
material1 = Content.Load<Material>("Materials/Yellow");
|
||||
material2 = Content.Load<Material>("Materials/Green");
|
||||
|
||||
while (Game.IsRunning)
|
||||
{
|
||||
// 1. Wait for an entity to collide with the trigger
|
||||
var firstCollision = await triggerCollider.NewCollision();
|
||||
var ballCollider = triggerCollider == firstCollision.ColliderA
|
||||
? firstCollision.ColliderB
|
||||
: firstCollision.ColliderA;
|
||||
|
||||
// 2. Change the material on the entity
|
||||
ballCollider.Entity.Get<ModelComponent>().Materials[0] = material2;
|
||||
|
||||
// 3. Wait for the entity to exit the trigger
|
||||
await firstCollision.Ended();
|
||||
|
||||
// 4. Change the material back to the original one
|
||||
ballCollider.Entity.Get<ModelComponent>().Materials[0] = material1;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Cancel()
|
||||
{
|
||||
Content.Unload(material1);
|
||||
Content.Unload(material2);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -15,4 +15,6 @@ ExplicitFolders: []
|
|||
Bundles: []
|
||||
TemplateFolders: []
|
||||
RootAssets:
|
||||
- 3690986c-39ec-4b3b-a116-24fc5181906d:Materials/Yellow
|
||||
- bc1eb91c-bd3e-4f75-b30a-b74729cba531:Materials/Red
|
||||
- c2da4379-f33e-40b3-aae2-1404bf5e6cb6:UI/Ebrima
|
||||
|
|
Загрузка…
Ссылка в новой задаче