DynamicBoneColliderBase.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System;
  2. using System.IO;
  3. using UnityEngine;
  4. public abstract class DynamicBoneColliderBase : MonoBehaviour
  5. {
  6. public virtual string TypeName
  7. {
  8. get
  9. {
  10. return string.Empty;
  11. }
  12. }
  13. public virtual bool Collide(ref Vector3 particlePosition, float particleRadius)
  14. {
  15. return false;
  16. }
  17. public virtual void Serialize(BinaryWriter f_bw, int f_nVersion)
  18. {
  19. if (base.transform.name.IndexOf("_HIT_", 0) != 0)
  20. {
  21. NDebug.MessageBox("確認", base.transform.name + " 名の先頭に _HIT_ を付加して保存します。");
  22. base.transform.name = "_HIT_" + base.transform.name;
  23. }
  24. f_bw.Write(base.transform.parent.name);
  25. f_bw.Write(base.transform.name);
  26. f_bw.Write(base.transform.localPosition.x);
  27. f_bw.Write(base.transform.localPosition.y);
  28. f_bw.Write(base.transform.localPosition.z);
  29. f_bw.Write(base.transform.localRotation.x);
  30. f_bw.Write(base.transform.localRotation.y);
  31. f_bw.Write(base.transform.localRotation.z);
  32. f_bw.Write(base.transform.localRotation.w);
  33. f_bw.Write(base.transform.localScale.x);
  34. f_bw.Write(base.transform.localScale.y);
  35. f_bw.Write(base.transform.localScale.z);
  36. f_bw.Write((int)this.m_Direction);
  37. f_bw.Write(this.m_Center.x);
  38. f_bw.Write(this.m_Center.y);
  39. f_bw.Write(this.m_Center.z);
  40. f_bw.Write((int)this.m_Bound);
  41. }
  42. public virtual void Deserialize(BinaryReader f_br, int f_nVersion, Transform f_trBodyBoneRoot)
  43. {
  44. string name = f_br.ReadString();
  45. Transform transform = CMT.SearchObjName(f_trBodyBoneRoot, name, true);
  46. if (transform == null)
  47. {
  48. NDebug.Assert("物理体親ボーンがありません。", false);
  49. }
  50. base.transform.SetParent(transform, false);
  51. base.transform.name = f_br.ReadString();
  52. base.transform.localPosition = new Vector3(f_br.ReadSingle(), f_br.ReadSingle(), f_br.ReadSingle());
  53. base.transform.localRotation = new Quaternion(f_br.ReadSingle(), f_br.ReadSingle(), f_br.ReadSingle(), f_br.ReadSingle());
  54. base.transform.localScale = new Vector3(f_br.ReadSingle(), f_br.ReadSingle(), f_br.ReadSingle());
  55. this.m_Direction = (DynamicBoneColliderBase.Direction)f_br.ReadInt32();
  56. this.m_Center.Set(f_br.ReadSingle(), f_br.ReadSingle(), f_br.ReadSingle());
  57. this.m_Bound = (DynamicBoneColliderBase.Bound)f_br.ReadInt32();
  58. }
  59. [Tooltip("The axis of the capsule's height.")]
  60. public DynamicBoneColliderBase.Direction m_Direction = DynamicBoneColliderBase.Direction.Y;
  61. [Tooltip("The center of the sphere or capsule, in the object's local space.")]
  62. public Vector3 m_Center = Vector3.zero;
  63. [Tooltip("Constrain bones to outside bound or inside bound.")]
  64. public DynamicBoneColliderBase.Bound m_Bound;
  65. public enum Direction
  66. {
  67. X,
  68. Y,
  69. Z
  70. }
  71. public enum Bound
  72. {
  73. Outside,
  74. Inside
  75. }
  76. }