该项目的目的是同时测试和演示来自 Unity DOTS 技术堆栈的多个新包。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

52 行
1.7 KiB

using System.Collections.Generic;
using Unity.Entities;
using Unity.Mathematics;
using UnityEngine;
public struct TeleporterServer : IComponentData
{
public Entity targetTeleporter;
public Entity entityInside;
public float3 spawnPos;
public float3 triggerPos;
public float triggerDist;
public quaternion spawnRot;
}
[DisallowMultipleComponent]
[ServerOnlyComponent]
public class TeleporterServerAuthoring : MonoBehaviour, IConvertGameObjectToEntity
{
public TeleporterServerAuthoring targetTeleporter;
public Transform spawnMarker;
public Transform triggerMarker;
public float triggerDist = 1.0f;
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
{
var t = new TeleporterServer();
t.spawnPos = spawnMarker.transform.position;
t.spawnRot = spawnMarker.transform.rotation;
t.triggerPos = triggerMarker.transform.position;
t.targetTeleporter = conversionSystem.GetPrimaryEntity(targetTeleporter);
t.triggerDist = triggerDist;
dstManager.AddComponentData(entity, t);
dstManager.AddComponentData(entity, new TeleporterPresentationData());
}
#if UNITY_EDITOR
void OnDrawGizmosSelected()
{
if (UnityEditor.Selection.activeGameObject == null)
return;
if (triggerMarker != null && gameObject == UnityEditor.Selection.activeGameObject)
{
// If we are directly selected (and not just our parent is selected)
// draw with negative size to get an 'inside out' cube we can see from the inside
Gizmos.color = new Color(1.0f, 1.0f, 0.5f, 0.8f);
Gizmos.DrawSphere(triggerMarker.position, triggerDist);
}
}
#endif
}