Component.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. namespace BansheeEngine
  4. {
  5. /// <summary>
  6. /// Base class for all components. Components represent primary logic elements in the scene. They are attached to
  7. /// scene objects.
  8. /// </summary>
  9. public class Component : GameObject
  10. {
  11. // Internal use only
  12. protected Component()
  13. { }
  14. /// <summary>
  15. /// Returns the scene object this component is attached to.
  16. /// </summary>
  17. public SceneObject SceneObject
  18. {
  19. get { return Internal_GetSceneObject(mCachedPtr); }
  20. }
  21. /// <summary>
  22. /// Calculates bounds of the visible content for this component.
  23. /// </summary>
  24. /// <param name="box">Bounds in world space represented as an axis aligned bounding box.</param>
  25. /// <param name="sphere">Bounds in world space represented as a sphere.</param>
  26. /// <returns>True if the bounds have non-zero volume, false otherwise.</returns>
  27. internal protected virtual bool CalculateBounds(out AABox box, out Sphere sphere)
  28. {
  29. Vector3 pos = SceneObject.Position;
  30. box = new AABox(pos, pos);
  31. sphere = new Sphere(pos, 0.0f);
  32. return false;
  33. }
  34. [MethodImpl(MethodImplOptions.InternalCall)]
  35. internal static extern Component Internal_AddComponent(SceneObject parent, Type type);
  36. [MethodImpl(MethodImplOptions.InternalCall)]
  37. internal static extern Component Internal_GetComponent(SceneObject parent, Type type);
  38. [MethodImpl(MethodImplOptions.InternalCall)]
  39. internal static extern Component[] Internal_GetComponents(SceneObject parent);
  40. [MethodImpl(MethodImplOptions.InternalCall)]
  41. internal static extern Component Internal_RemoveComponent(SceneObject parent, Type type);
  42. [MethodImpl(MethodImplOptions.InternalCall)]
  43. internal static extern SceneObject Internal_GetSceneObject(IntPtr nativeInstance);
  44. }
  45. }