PhotoTransTargetObject.cs 7.4 KB

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