PhotoTransTargetObject.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class PhotoTransTargetObject : IComparable<PhotoTransTargetObject>
  5. {
  6. public PhotoTransTargetObject(GameObject target, string draw_name, string nameTerm, PhotoTransTargetObject.Type type, Vector2 scaleMinMax)
  7. {
  8. this.obj = target;
  9. if (target != null)
  10. {
  11. this.default_parent = target.transform.parent;
  12. this.init_pos = target.transform.localPosition;
  13. this.init_rotate = target.transform.rotation;
  14. }
  15. this.draw_name = draw_name;
  16. this.nameTerm = nameTerm;
  17. this.type = type;
  18. this.guid = Guid.NewGuid().ToString();
  19. this.attachi_point = PhotoTransTargetObject.AttachPoint.Null;
  20. this.Create(scaleMinMax);
  21. }
  22. public void Create(Vector2 scaleMinMax)
  23. {
  24. if (this.obj == null)
  25. {
  26. return;
  27. }
  28. if (this.rotate_obj == null)
  29. {
  30. this.rotate_obj = PhotoWindowManager.CreateWorldTransformRotate(this.obj, false);
  31. this.rotate_obj.Visible = false;
  32. }
  33. if (this.axis_obj == null)
  34. {
  35. this.axis_obj = PhotoWindowManager.CreateWorldTransformAxis(this.obj, false, false);
  36. this.axis_obj.Visible = false;
  37. this.axis_obj.ScaleMinMax = scaleMinMax;
  38. }
  39. }
  40. public void Delete()
  41. {
  42. if (this.obj == null)
  43. {
  44. return;
  45. }
  46. if (this.axis_obj != null)
  47. {
  48. UnityEngine.Object.DestroyImmediate(this.axis_obj.gameObject);
  49. }
  50. this.axis_obj = null;
  51. if (this.rotate_obj != null)
  52. {
  53. UnityEngine.Object.DestroyImmediate(this.rotate_obj);
  54. }
  55. this.rotate_obj = null;
  56. }
  57. public string Attach(PhotoTransTargetObject.AttachPoint point, bool worldPositionStays, Maid targetMaid)
  58. {
  59. if (this.obj == null)
  60. {
  61. return "設定不可";
  62. }
  63. if (targetMaid == null)
  64. {
  65. if (point != PhotoTransTargetObject.AttachPoint.Null)
  66. {
  67. Debug.LogError("アタッチ先のメイドがみつかりません");
  68. }
  69. point = PhotoTransTargetObject.AttachPoint.Null;
  70. }
  71. this.attachi_point = point;
  72. this.attach_maid_guid = string.Empty;
  73. Transform attachPointTransform = this.default_parent;
  74. if (this.attachi_point != PhotoTransTargetObject.AttachPoint.Null)
  75. {
  76. attachPointTransform = this.GetAttachPointTransform(targetMaid, point);
  77. this.attach_maid_guid = targetMaid.status.guid;
  78. }
  79. string text = string.Empty;
  80. if (targetMaid != null)
  81. {
  82. text = targetMaid.status.charaName.GetFullName(" ") + " : ";
  83. }
  84. text += this.AttachPointToString(point);
  85. if (attachPointTransform == null || attachPointTransform == this.obj.transform.parent)
  86. {
  87. return text;
  88. }
  89. Vector3 position = this.obj.transform.position;
  90. Quaternion rotation = this.obj.transform.rotation;
  91. this.obj.transform.SetParent(attachPointTransform, worldPositionStays);
  92. if (worldPositionStays)
  93. {
  94. this.obj.transform.position = position;
  95. this.obj.transform.rotation = rotation;
  96. }
  97. else
  98. {
  99. this.obj.transform.localPosition = this.init_pos;
  100. this.obj.transform.rotation = this.init_rotate;
  101. }
  102. return text;
  103. }
  104. public Transform GetAttachPointTransform(Maid targetMaid, PhotoTransTargetObject.AttachPoint point)
  105. {
  106. if (PhotoTransTargetObject.subsTable.Count == 0)
  107. {
  108. Func<IKManager.BoneType, string, KeyValuePair<IKManager.BoneType, string>> func = (IKManager.BoneType type, string name) => new KeyValuePair<IKManager.BoneType, string>(type, name);
  109. PhotoTransTargetObject.subsTable.Add(PhotoTransTargetObject.AttachPoint.Null, func(IKManager.BoneType.TopFixed, "設定なし"));
  110. PhotoTransTargetObject.subsTable.Add(PhotoTransTargetObject.AttachPoint.Fix, func(IKManager.BoneType.TopFixed, "固定"));
  111. PhotoTransTargetObject.subsTable.Add(PhotoTransTargetObject.AttachPoint.Root, func(IKManager.BoneType.Root, "原点"));
  112. PhotoTransTargetObject.subsTable.Add(PhotoTransTargetObject.AttachPoint.Head, func(IKManager.BoneType.Head, "頭"));
  113. PhotoTransTargetObject.subsTable.Add(PhotoTransTargetObject.AttachPoint.Neck, func(IKManager.BoneType.Neck, "首元"));
  114. PhotoTransTargetObject.subsTable.Add(PhotoTransTargetObject.AttachPoint.Mune_R, func(IKManager.BoneType.Bust_R, "右胸"));
  115. PhotoTransTargetObject.subsTable.Add(PhotoTransTargetObject.AttachPoint.UpperArm_R, func(IKManager.BoneType.UpperArm_R, "右肩"));
  116. PhotoTransTargetObject.subsTable.Add(PhotoTransTargetObject.AttachPoint.Forearm_R, func(IKManager.BoneType.Forearm_R, "右肘"));
  117. PhotoTransTargetObject.subsTable.Add(PhotoTransTargetObject.AttachPoint.Hand_R, func(IKManager.BoneType.Hand_R, "右手首"));
  118. PhotoTransTargetObject.subsTable.Add(PhotoTransTargetObject.AttachPoint.Thigh_R, func(IKManager.BoneType.Thigh_R, "右足付け根"));
  119. PhotoTransTargetObject.subsTable.Add(PhotoTransTargetObject.AttachPoint.Calf_R, func(IKManager.BoneType.Calf_R, "右膝"));
  120. PhotoTransTargetObject.subsTable.Add(PhotoTransTargetObject.AttachPoint.Foot_R, func(IKManager.BoneType.Foot_R, "右足首"));
  121. PhotoTransTargetObject.subsTable.Add(PhotoTransTargetObject.AttachPoint.Mune_L, func(IKManager.BoneType.Bust_L, "左胸"));
  122. PhotoTransTargetObject.subsTable.Add(PhotoTransTargetObject.AttachPoint.UpperArm_L, func(IKManager.BoneType.UpperArm_L, "左肩"));
  123. PhotoTransTargetObject.subsTable.Add(PhotoTransTargetObject.AttachPoint.Forearm_L, func(IKManager.BoneType.Forearm_L, "左肘"));
  124. PhotoTransTargetObject.subsTable.Add(PhotoTransTargetObject.AttachPoint.Hand_L, func(IKManager.BoneType.Hand_L, "左手首"));
  125. PhotoTransTargetObject.subsTable.Add(PhotoTransTargetObject.AttachPoint.Thigh_L, func(IKManager.BoneType.Thigh_L, "左足付け根"));
  126. PhotoTransTargetObject.subsTable.Add(PhotoTransTargetObject.AttachPoint.Calf_L, func(IKManager.BoneType.Calf_L, "左膝"));
  127. PhotoTransTargetObject.subsTable.Add(PhotoTransTargetObject.AttachPoint.Foot_L, func(IKManager.BoneType.Foot_L, "左足首"));
  128. }
  129. if (targetMaid == null)
  130. {
  131. return null;
  132. }
  133. IKManager maidIKManager = PoseEditWindow.GetMaidIKManager(targetMaid);
  134. return maidIKManager.GetBone(PhotoTransTargetObject.subsTable[point].Key).transform;
  135. }
  136. public string AttachPointToString(PhotoTransTargetObject.AttachPoint point)
  137. {
  138. if (PhotoTransTargetObject.subsTable.Count == 0)
  139. {
  140. this.GetAttachPointTransform(null, PhotoTransTargetObject.AttachPoint.Null);
  141. }
  142. return PhotoTransTargetObject.subsTable[point].Value;
  143. }
  144. public int CompareTo(PhotoTransTargetObject comp_obj)
  145. {
  146. if (this.type != comp_obj.type)
  147. {
  148. int num = (int)comp_obj.type;
  149. return num.CompareTo((int)this.type);
  150. }
  151. string text = string.Empty;
  152. string strB = string.Empty;
  153. if (comp_obj.obj != null)
  154. {
  155. text = comp_obj.obj.name;
  156. }
  157. if (this.obj != null)
  158. {
  159. strB = this.obj.name;
  160. }
  161. return text.CompareTo(strB);
  162. }
  163. public GameObject obj;
  164. public Transform default_parent;
  165. public Vector3 init_pos;
  166. public Quaternion init_rotate;
  167. public string draw_name;
  168. public string nameTerm;
  169. public PhotoTransTargetObject.Type type;
  170. public WorldTransformAxis axis_obj;
  171. public GizmoRender rotate_obj;
  172. public string guid;
  173. public PhotoTransTargetObject.AttachPoint attachi_point;
  174. public string attach_maid_guid = string.Empty;
  175. public Vector3 attachi_local_pos;
  176. public Quaternion attachi_local_rotate;
  177. private static Dictionary<PhotoTransTargetObject.AttachPoint, KeyValuePair<IKManager.BoneType, string>> subsTable = new Dictionary<PhotoTransTargetObject.AttachPoint, KeyValuePair<IKManager.BoneType, string>>();
  178. public enum AttachPoint
  179. {
  180. Null,
  181. Fix,
  182. Root,
  183. Head,
  184. Neck,
  185. Mune_R,
  186. UpperArm_R,
  187. Forearm_R,
  188. Hand_R,
  189. Thigh_R,
  190. Calf_R,
  191. Foot_R,
  192. Mune_L,
  193. UpperArm_L,
  194. Forearm_L,
  195. Hand_L,
  196. Thigh_L,
  197. Calf_L,
  198. Foot_L
  199. }
  200. public enum Type
  201. {
  202. Maid,
  203. BG,
  204. Prefab,
  205. Light
  206. }
  207. }