Skip to content

Instantly share code, notes, and snippets.

@baobao
Created July 11, 2019 18:16
Show Gist options
  • Select an option

  • Save baobao/4708cabb73b5f1d90b3b40083580d0ac to your computer and use it in GitHub Desktop.

Select an option

Save baobao/4708cabb73b5f1d90b3b40083580d0ac to your computer and use it in GitHub Desktop.
using System;
using Unity.Entities;
[Serializable]
public struct MyData : IComponentData
{
public float hoge;
}
using Unity.Entities;
using UnityEngine;
[RequiresEntityConversion]
public class MyEntity:MonoBehaviour, IConvertGameObjectToEntity
{
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
{
var data = new MyData() {hoge = 2f};
dstManager.AddComponentData(entity, data);
}
}
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;
using UnityEngine;
public class MySystem : ComponentSystem
{
protected override void OnUpdate()
{
Entities.ForEach((ref MyData mydata, ref Rotation rotation)=>
{
var deltaTime = Time.frameCount;
rotation.Value = Quaternion.Euler(deltaTime*mydata.hoge, 0, 0);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment