Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Unity.Burst;
- using Unity.Entities;
- using Unity.Physics.Authoring;
- using UnityEngine;
- using UnityEngine.Assertions;
- namespace UGS {
- /// <summary>
- /// Tag component for causing things to stick.
- /// Could I also do this with a Physics.Material "Custom Flags" or "Collision Filter" ?
- /// </summary>
- [BurstCompile]
- public struct StickCause : IComponentData {
- public float radius; // to calculate contact point
- }
- public sealed class StickCauseMB : MonoBehaviour, IConvertGameObjectToEntity {
- public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem) {
- if (!enabled)
- return;
- var physicsShape = GetComponent<PhysicsShape>();
- Assert.IsNotNull(physicsShape, this.ToString());
- var componentData = new StickCause { radius = physicsShape.ConvexRadius * transform.localScale.x }; // assumes uniform scaling
- dstManager.AddComponentData(entity, componentData);
- Assert.IsTrue(GetComponent<PhysicsShape>().RaisesCollisionEvents, this.ToString()); // Causes dependency on Unity.Physics.Authoring in our asmdef
- // TODO: Validate/set "Raises Collision Events" flag
- // Should this be done for either/both MB (PhysicsShape) and/or Physics.Material
- // For prior:
- // Use PhysicsShape.MaterialTemplate and/or...
- // Use the IInheritPhysicsMaterialProperties and check both (a) OverrideRaisesCollisionEvents and (b) Template
- // get the PhysicsMaterialTemplate (a ScriptableObject but maybe temp?) and set RaisesCollisionEvents
- // dstManager.GetComponentData<PhysicsShape>()
- //
- // For latter:
- // Physics.Material has a "Flags" value that should be Material.MaterialFlags.EnableCollisionEvents
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement