MegaFlowSample.cs 883 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. 
  2. using UnityEngine;
  3. [AddComponentMenu("MegaFlow/Sample")]
  4. [ExecuteInEditMode]
  5. public class MegaFlowSample : MonoBehaviour
  6. {
  7. public MegaFlow source;
  8. public int framenum;
  9. public Vector3 velocity;
  10. bool inbounds = false;
  11. [ContextMenu("Help")]
  12. public void Help()
  13. {
  14. Application.OpenURL("http://www.west-racing.com/mf/?page_id=6103");
  15. }
  16. public Vector3 GetVelocity()
  17. {
  18. return GetVelocity(transform.position);
  19. }
  20. public Vector3 GetVelocity(Vector3 pos)
  21. {
  22. if ( source )
  23. {
  24. MegaFlowFrame frame = source.frames[framenum];
  25. if ( frame && frame.GetGridVel != null )
  26. return frame.GetGridVelWorld(pos, ref inbounds);
  27. }
  28. return Vector3.zero;
  29. }
  30. void Update()
  31. {
  32. framenum = Mathf.Clamp(framenum, 0, source.frames.Count - 1);
  33. velocity = GetVelocity();
  34. }
  35. void OnDrawGizmos()
  36. {
  37. Gizmos.DrawIcon(transform.position, "MegaFlowIcon.png", true);
  38. }
  39. }