Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. using Unity.Burst;
  2. using Unity.Entities;
  3. using Unity.Physics.Authoring;
  4. using UnityEngine;
  5. using UnityEngine.Assertions;
  6.  
  7. namespace UGS {
  8. /// <summary>
  9. /// Tag component for causing things to stick.
  10. /// Could I also do this with a Physics.Material "Custom Flags" or "Collision Filter" ?
  11. /// </summary>
  12. [BurstCompile]
  13. public struct StickCause : IComponentData {
  14. public float radius; // to calculate contact point
  15. }
  16.  
  17. public sealed class StickCauseMB : MonoBehaviour, IConvertGameObjectToEntity {
  18.  
  19. public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem) {
  20. if (!enabled)
  21. return;
  22.  
  23. var physicsShape = GetComponent<PhysicsShape>();
  24. Assert.IsNotNull(physicsShape, this.ToString());
  25. var componentData = new StickCause { radius = physicsShape.ConvexRadius * transform.localScale.x }; // assumes uniform scaling
  26. dstManager.AddComponentData(entity, componentData);
  27.  
  28. Assert.IsTrue(GetComponent<PhysicsShape>().RaisesCollisionEvents, this.ToString()); // Causes dependency on Unity.Physics.Authoring in our asmdef
  29.  
  30. // TODO: Validate/set "Raises Collision Events" flag
  31. // Should this be done for either/both MB (PhysicsShape) and/or Physics.Material
  32. // For prior:
  33. // Use PhysicsShape.MaterialTemplate and/or...
  34. // Use the IInheritPhysicsMaterialProperties and check both (a) OverrideRaisesCollisionEvents and (b) Template
  35. // get the PhysicsMaterialTemplate (a ScriptableObject but maybe temp?) and set RaisesCollisionEvents
  36. // dstManager.GetComponentData<PhysicsShape>()
  37. //
  38. // For latter:
  39. // Physics.Material has a "Flags" value that should be Material.MaterialFlags.EnableCollisionEvents
  40. }
  41.  
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement