SteamVR_Skeleton_PoserEditor.cs 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using UnityEditor;
  6. using UnityEngine;
  7. namespace Valve.VR
  8. {
  9. [CustomEditor(typeof(SteamVR_Skeleton_Poser))]
  10. public class SteamVR_Skeleton_PoserEditor : Editor
  11. {
  12. private const string leftDefaultAssetName = "vr_glove_left_model_slim";
  13. private const string rightDefaultAssetName = "vr_glove_right_model_slim";
  14. private SerializedProperty skeletonMainPoseProperty;
  15. private SerializedProperty skeletonAdditionalPosesProperty;
  16. private SerializedProperty showLeftPreviewProperty;
  17. private SerializedProperty showRightPreviewProperty;
  18. private SerializedProperty previewLeftInstanceProperty;
  19. private SerializedProperty previewRightInstanceProperty;
  20. private SerializedProperty previewLeftHandPrefab;
  21. private SerializedProperty previewRightHandPrefab;
  22. private SerializedProperty previewPoseSelection;
  23. private SerializedProperty poseEditorExpanded;
  24. private SerializedProperty blendEditorExpanded;
  25. private SerializedProperty poserScale;
  26. private SerializedProperty blendingBehaviourArray;
  27. Texture handTexL;
  28. Texture handTexR;
  29. private SteamVR_Skeleton_Poser poser;
  30. private bool PoseChanged = false;
  31. protected void OnEnable()
  32. {
  33. skeletonMainPoseProperty = serializedObject.FindProperty("skeletonMainPose");
  34. skeletonAdditionalPosesProperty = serializedObject.FindProperty("skeletonAdditionalPoses");
  35. showLeftPreviewProperty = serializedObject.FindProperty("showLeftPreview");
  36. showRightPreviewProperty = serializedObject.FindProperty("showRightPreview");
  37. previewLeftInstanceProperty = serializedObject.FindProperty("previewLeftInstance");
  38. previewRightInstanceProperty = serializedObject.FindProperty("previewRightInstance");
  39. previewLeftHandPrefab = serializedObject.FindProperty("previewLeftHandPrefab");
  40. previewRightHandPrefab = serializedObject.FindProperty("previewRightHandPrefab");
  41. previewPoseSelection = serializedObject.FindProperty("previewPoseSelection");
  42. poseEditorExpanded = serializedObject.FindProperty("poseEditorExpanded");
  43. blendEditorExpanded = serializedObject.FindProperty("blendEditorExpanded");
  44. poserScale = serializedObject.FindProperty("scale");
  45. blendingBehaviourArray = serializedObject.FindProperty("blendingBehaviours");
  46. poser = (SteamVR_Skeleton_Poser)target;
  47. }
  48. protected void LoadDefaultPreviewHands()
  49. {
  50. if (previewLeftHandPrefab.objectReferenceValue == null)
  51. {
  52. string[] defaultLeftPaths = AssetDatabase.FindAssets(string.Format("t:Prefab {0}", leftDefaultAssetName));
  53. if (defaultLeftPaths != null && defaultLeftPaths.Length > 0)
  54. {
  55. string defaultLeftGUID = defaultLeftPaths[0];
  56. string defaultLeftPath = AssetDatabase.GUIDToAssetPath(defaultLeftGUID);
  57. previewLeftHandPrefab.objectReferenceValue = AssetDatabase.LoadAssetAtPath<GameObject>(defaultLeftPath);
  58. if (previewLeftHandPrefab.objectReferenceValue == null)
  59. Debug.LogError("[SteamVR] Could not load prefab: " + leftDefaultAssetName + ". Found path: " + defaultLeftPath);
  60. }
  61. else
  62. Debug.LogError("[SteamVR] Could not load prefab: " + leftDefaultAssetName);
  63. }
  64. if (previewRightHandPrefab.objectReferenceValue == null)
  65. {
  66. string[] defaultRightPaths = AssetDatabase.FindAssets(string.Format("t:Prefab {0}", rightDefaultAssetName));
  67. if (defaultRightPaths != null && defaultRightPaths.Length > 0)
  68. {
  69. string defaultRightGUID = defaultRightPaths[0];
  70. string defaultRightPath = AssetDatabase.GUIDToAssetPath(defaultRightGUID);
  71. previewRightHandPrefab.objectReferenceValue = AssetDatabase.LoadAssetAtPath<GameObject>(defaultRightPath);
  72. if (previewLeftHandPrefab.objectReferenceValue == null)
  73. Debug.LogError("[SteamVR] Could not load prefab: " + rightDefaultAssetName + ". Found path: " + defaultRightPath);
  74. }
  75. else
  76. Debug.LogError("[SteamVR] Could not load prefab: " + rightDefaultAssetName);
  77. }
  78. }
  79. protected void UpdatePreviewHand(SerializedProperty instanceProperty, SerializedProperty showPreviewProperty, SerializedProperty prefabProperty, SteamVR_Skeleton_Pose_Hand handData, SteamVR_Skeleton_Pose sourcePose, bool forceUpdate)
  80. {
  81. GameObject preview = instanceProperty.objectReferenceValue as GameObject;
  82. //EditorGUILayout.PropertyField(showPreviewProperty);
  83. if (showPreviewProperty.boolValue)
  84. {
  85. if (forceUpdate && preview != null)
  86. {
  87. DestroyImmediate(preview);
  88. }
  89. if (preview == null)
  90. {
  91. preview = GameObject.Instantiate<GameObject>((GameObject)prefabProperty.objectReferenceValue);
  92. preview.transform.localScale = Vector3.one * poserScale.floatValue;
  93. preview.transform.parent = poser.transform;
  94. preview.transform.localPosition = Vector3.zero;
  95. preview.transform.localRotation = Quaternion.identity;
  96. SteamVR_Behaviour_Skeleton previewSkeleton = null;
  97. if (preview != null)
  98. previewSkeleton = preview.GetComponent<SteamVR_Behaviour_Skeleton>();
  99. if (previewSkeleton != null)
  100. {
  101. if (handData.bonePositions == null || handData.bonePositions.Length == 0)
  102. {
  103. SteamVR_Skeleton_Pose poseResource = (SteamVR_Skeleton_Pose)Resources.Load("ReferencePose_OpenHand");
  104. DeepCopyPose(poseResource, sourcePose);
  105. EditorUtility.SetDirty(sourcePose);
  106. }
  107. preview.transform.localPosition = Vector3.zero;
  108. preview.transform.localRotation = Quaternion.identity;
  109. preview.transform.parent = null;
  110. preview.transform.localScale = Vector3.one * poserScale.floatValue;
  111. preview.transform.parent = poser.transform;
  112. preview.transform.localRotation = Quaternion.Inverse(handData.rotation);
  113. preview.transform.position = preview.transform.TransformPoint(-handData.position);
  114. for (int boneIndex = 0; boneIndex < handData.bonePositions.Length; boneIndex++)
  115. {
  116. Transform bone = previewSkeleton.GetBone(boneIndex);
  117. bone.localPosition = handData.bonePositions[boneIndex];
  118. bone.localRotation = handData.boneRotations[boneIndex];
  119. }
  120. }
  121. SceneView.RepaintAll();
  122. instanceProperty.objectReferenceValue = preview;
  123. }
  124. }
  125. else
  126. {
  127. if (preview != null)
  128. {
  129. DestroyImmediate(preview);
  130. SceneView.RepaintAll();
  131. }
  132. }
  133. }
  134. protected void ZeroTransformParents(Transform toZero, Transform stopAt)
  135. {
  136. if (toZero == null)
  137. return;
  138. toZero.localPosition = Vector3.zero;
  139. toZero.localRotation = Quaternion.identity;
  140. if (toZero == stopAt)
  141. return;
  142. ZeroTransformParents(toZero.parent, stopAt);
  143. }
  144. protected EVRSkeletalReferencePose defaultReferencePose = EVRSkeletalReferencePose.OpenHand;
  145. protected EVRSkeletalReferencePose forceToReferencePose = EVRSkeletalReferencePose.OpenHand;
  146. protected void SaveHandData(SteamVR_Skeleton_Pose_Hand handData, SteamVR_Behaviour_Skeleton thisSkeleton)
  147. {
  148. handData.position = thisSkeleton.transform.InverseTransformPoint(poser.transform.position);
  149. //handData.position = thisSkeleton.transform.localPosition;
  150. handData.rotation = Quaternion.Inverse(thisSkeleton.transform.localRotation);
  151. handData.bonePositions = new Vector3[SteamVR_Action_Skeleton.numBones];
  152. handData.boneRotations = new Quaternion[SteamVR_Action_Skeleton.numBones];
  153. for (int boneIndex = 0; boneIndex < SteamVR_Action_Skeleton.numBones; boneIndex++)
  154. {
  155. Transform bone = thisSkeleton.GetBone(boneIndex);
  156. handData.bonePositions[boneIndex] = bone.localPosition;
  157. handData.boneRotations[boneIndex] = bone.localRotation;
  158. }
  159. EditorUtility.SetDirty(activePose);
  160. }
  161. protected void DrawHand(bool showHand, SteamVR_Skeleton_Pose_Hand handData, SteamVR_Skeleton_Pose_Hand otherData, bool getFromOpposite)
  162. {
  163. SteamVR_Behaviour_Skeleton thisSkeleton;
  164. SteamVR_Behaviour_Skeleton oppositeSkeleton;
  165. string thisSourceString;
  166. string oppositeSourceString;
  167. if (handData.inputSource == SteamVR_Input_Sources.LeftHand)
  168. {
  169. thisSkeleton = leftSkeleton;
  170. thisSourceString = "Left Hand";
  171. oppositeSourceString = "Right Hand";
  172. oppositeSkeleton = rightSkeleton;
  173. }
  174. else
  175. {
  176. thisSkeleton = rightSkeleton;
  177. thisSourceString = "Right Hand";
  178. oppositeSourceString = "Left Hand";
  179. oppositeSkeleton = leftSkeleton;
  180. }
  181. if (showHand)
  182. {
  183. if (getFromOpposite)
  184. {
  185. bool confirm = EditorUtility.DisplayDialog("SteamVR", string.Format("This will overwrite your current {0} skeleton data. (with data from the {1} skeleton)", thisSourceString, oppositeSourceString), "Overwrite", "Cancel");
  186. if (confirm)
  187. {
  188. Vector3 reflectedPosition = new Vector3(-oppositeSkeleton.transform.localPosition.x, oppositeSkeleton.transform.localPosition.y, oppositeSkeleton.transform.localPosition.z);
  189. thisSkeleton.transform.localPosition = reflectedPosition;
  190. Quaternion oppositeRotation = oppositeSkeleton.transform.localRotation;
  191. Quaternion reflectedRotation = new Quaternion(-oppositeRotation.x, oppositeRotation.y, oppositeRotation.z, -oppositeRotation.w);
  192. thisSkeleton.transform.localRotation = reflectedRotation;
  193. for (int boneIndex = 0; boneIndex < SteamVR_Action_Skeleton.numBones; boneIndex++)
  194. {
  195. Transform boneThis = thisSkeleton.GetBone(boneIndex);
  196. Transform boneOpposite = oppositeSkeleton.GetBone(boneIndex);
  197. boneThis.localPosition = boneOpposite.localPosition;
  198. boneThis.localRotation = boneOpposite.localRotation;
  199. }
  200. handData.thumbFingerMovementType = otherData.thumbFingerMovementType;
  201. handData.indexFingerMovementType = otherData.indexFingerMovementType;
  202. handData.middleFingerMovementType = otherData.middleFingerMovementType;
  203. handData.ringFingerMovementType = otherData.ringFingerMovementType;
  204. handData.pinkyFingerMovementType = otherData.pinkyFingerMovementType;
  205. EditorUtility.SetDirty(poser.skeletonMainPose);
  206. }
  207. }
  208. }
  209. EditorGUIUtility.labelWidth = 120;
  210. SteamVR_Skeleton_FingerExtensionTypes newThumb = (SteamVR_Skeleton_FingerExtensionTypes)EditorGUILayout.EnumPopup("Thumb movement", handData.thumbFingerMovementType);
  211. SteamVR_Skeleton_FingerExtensionTypes newIndex = (SteamVR_Skeleton_FingerExtensionTypes)EditorGUILayout.EnumPopup("Index movement", handData.indexFingerMovementType);
  212. SteamVR_Skeleton_FingerExtensionTypes newMiddle = (SteamVR_Skeleton_FingerExtensionTypes)EditorGUILayout.EnumPopup("Middle movement", handData.middleFingerMovementType);
  213. SteamVR_Skeleton_FingerExtensionTypes newRing = (SteamVR_Skeleton_FingerExtensionTypes)EditorGUILayout.EnumPopup("Ring movement", handData.ringFingerMovementType);
  214. SteamVR_Skeleton_FingerExtensionTypes newPinky = (SteamVR_Skeleton_FingerExtensionTypes)EditorGUILayout.EnumPopup("Pinky movement", handData.pinkyFingerMovementType);
  215. EditorGUIUtility.labelWidth = 0;
  216. if (newThumb != handData.thumbFingerMovementType || newIndex != handData.indexFingerMovementType ||
  217. newMiddle != handData.middleFingerMovementType || newRing != handData.ringFingerMovementType ||
  218. newPinky != handData.pinkyFingerMovementType)
  219. {
  220. /*if ((int)newThumb >= 2 || (int)newIndex >= 2 || (int)newMiddle >= 2 || (int)newRing >= 2 || (int)newPinky >= 2)
  221. {
  222. Debug.LogError("<b>[SteamVR Input]</b> Unfortunately only Static and Free modes are supported in this beta.");
  223. return;
  224. }*/
  225. handData.thumbFingerMovementType = newThumb;
  226. handData.indexFingerMovementType = newIndex;
  227. handData.middleFingerMovementType = newMiddle;
  228. handData.ringFingerMovementType = newRing;
  229. handData.pinkyFingerMovementType = newPinky;
  230. EditorUtility.SetDirty(poser.skeletonMainPose);
  231. }
  232. }
  233. protected void DrawPoseControlButtons()
  234. {
  235. GameObject leftInstance = previewLeftInstanceProperty.objectReferenceValue as GameObject;
  236. leftSkeleton = null;
  237. if (leftInstance != null)
  238. leftSkeleton = leftInstance.GetComponent<SteamVR_Behaviour_Skeleton>();
  239. GameObject rightInstance = previewRightInstanceProperty.objectReferenceValue as GameObject;
  240. rightSkeleton = null;
  241. if (rightInstance != null)
  242. rightSkeleton = rightInstance.GetComponent<SteamVR_Behaviour_Skeleton>();
  243. //only allow saving if a hand is opened for editing
  244. EditorGUI.BeginDisabledGroup(showRightPreviewProperty.boolValue == false && showLeftPreviewProperty.boolValue == false);
  245. GUI.color = new Color(0.9f, 1.0f, 0.9f);
  246. // save both hands at once, or whichever are being edited
  247. bool save = GUILayout.Button(string.Format("Save Pose"));
  248. if (save)
  249. {
  250. if (showRightPreviewProperty.boolValue)
  251. SaveHandData(activePose.rightHand, rightSkeleton);
  252. if (showLeftPreviewProperty.boolValue)
  253. SaveHandData(activePose.leftHand, leftSkeleton);
  254. }
  255. GUI.color = Color.white;
  256. EditorGUI.EndDisabledGroup();
  257. //MIRRORING
  258. //only allow mirroring if both hands are opened for editing
  259. EditorGUI.BeginDisabledGroup(showRightPreviewProperty.boolValue == false || showLeftPreviewProperty.boolValue == false);
  260. EditorGUILayout.Space();
  261. if (GUILayout.Button("Import Pose"))
  262. {
  263. CopyPoseSelect();
  264. }
  265. EditorGUI.EndDisabledGroup();
  266. GUILayout.Space(32);
  267. GUILayout.Label("Reference Pose:");
  268. EditorGUILayout.Space();
  269. forceToReferencePose = (EVRSkeletalReferencePose)EditorGUILayout.EnumPopup(forceToReferencePose);
  270. GUI.color = new Color(1.0f, 0.73f, 0.7f);
  271. bool forcePose = GUILayout.Button("RESET TO REFERENCE POSE");
  272. GUI.color = Color.white;
  273. if (forcePose)
  274. {
  275. bool confirm = EditorUtility.DisplayDialog("SteamVR", string.Format("This will overwrite your current skeleton data. (with data from the {0} reference pose)", forceToReferencePose.ToString()), "Overwrite", "Cancel");
  276. if (confirm)
  277. {
  278. if (forceToReferencePose == EVRSkeletalReferencePose.GripLimit)
  279. {
  280. // grip limit is controller-specific, the rest use a baked pose
  281. if (showLeftPreviewProperty.boolValue)
  282. leftSkeleton.ForceToReferencePose(forceToReferencePose);
  283. if (showRightPreviewProperty.boolValue)
  284. rightSkeleton.ForceToReferencePose(forceToReferencePose);
  285. }
  286. else
  287. {
  288. SteamVR_Skeleton_Pose poseResource = null;
  289. if (forceToReferencePose == EVRSkeletalReferencePose.OpenHand)
  290. poseResource = (SteamVR_Skeleton_Pose)Resources.Load("ReferencePose_OpenHand");
  291. if (forceToReferencePose == EVRSkeletalReferencePose.Fist)
  292. poseResource = (SteamVR_Skeleton_Pose)Resources.Load("ReferencePose_Fist");
  293. if (forceToReferencePose == EVRSkeletalReferencePose.BindPose)
  294. poseResource = (SteamVR_Skeleton_Pose)Resources.Load("ReferencePose_BindPose");
  295. DeepCopyPose(poseResource, activePose);
  296. }
  297. }
  298. }
  299. }
  300. void CopyPoseSelect()
  301. {
  302. string selected = EditorUtility.OpenFilePanel("Open Skeleton Pose ScriptableObject", Application.dataPath, "asset");
  303. selected = selected.Replace(Application.dataPath, "Assets");
  304. if (selected == null) return;
  305. SteamVR_Skeleton_Pose newPose = (SteamVR_Skeleton_Pose)AssetDatabase.LoadAssetAtPath(selected, typeof(SteamVR_Skeleton_Pose));
  306. if (newPose == null)
  307. {
  308. EditorUtility.DisplayDialog("WARNING", "Asset could not be loaded. Is it not a SteamVR_Skeleton_Pose?", "ok");
  309. return;
  310. }
  311. DeepCopyPose(newPose, activePose);
  312. }
  313. void DeepCopyPose(SteamVR_Skeleton_Pose source, SteamVR_Skeleton_Pose dest)
  314. {
  315. int boneNum = SteamVR_Action_Skeleton.numBones;
  316. if (dest.rightHand.bonePositions == null) dest.rightHand.bonePositions = new Vector3[boneNum];
  317. if (dest.rightHand.boneRotations == null) dest.rightHand.boneRotations = new Quaternion[boneNum];
  318. if (dest.leftHand.bonePositions == null) dest.leftHand.bonePositions = new Vector3[boneNum];
  319. if (dest.leftHand.boneRotations == null) dest.leftHand.boneRotations = new Quaternion[boneNum];
  320. EditorUtility.SetDirty(dest);
  321. // RIGHT HAND COPY
  322. dest.rightHand.position = source.rightHand.position;
  323. dest.rightHand.rotation = source.rightHand.rotation;
  324. for (int boneIndex = 0; boneIndex < boneNum; boneIndex++)
  325. {
  326. dest.rightHand.bonePositions[boneIndex] = source.rightHand.bonePositions[boneIndex];
  327. dest.rightHand.boneRotations[boneIndex] = source.rightHand.boneRotations[boneIndex];
  328. EditorUtility.DisplayProgressBar("Copying...", "Copying right hand pose", (float)boneIndex / (float)boneNum / 2f);
  329. }
  330. dest.rightHand.thumbFingerMovementType = source.rightHand.thumbFingerMovementType;
  331. dest.rightHand.indexFingerMovementType = source.rightHand.indexFingerMovementType;
  332. dest.rightHand.middleFingerMovementType = source.rightHand.middleFingerMovementType;
  333. dest.rightHand.ringFingerMovementType = source.rightHand.ringFingerMovementType;
  334. dest.rightHand.pinkyFingerMovementType = source.rightHand.pinkyFingerMovementType;
  335. // LEFT HAND COPY
  336. dest.leftHand.position = source.leftHand.position;
  337. dest.leftHand.rotation = source.leftHand.rotation;
  338. for (int boneIndex = 0; boneIndex < boneNum; boneIndex++)
  339. {
  340. dest.leftHand.bonePositions[boneIndex] = source.leftHand.bonePositions[boneIndex];
  341. dest.leftHand.boneRotations[boneIndex] = source.leftHand.boneRotations[boneIndex];
  342. EditorUtility.DisplayProgressBar("Copying...", "Copying left hand pose", (float)boneIndex / (float)boneNum / 2f);
  343. }
  344. dest.leftHand.thumbFingerMovementType = source.leftHand.thumbFingerMovementType;
  345. dest.leftHand.indexFingerMovementType = source.leftHand.indexFingerMovementType;
  346. dest.leftHand.middleFingerMovementType = source.leftHand.middleFingerMovementType;
  347. dest.leftHand.ringFingerMovementType = source.leftHand.ringFingerMovementType;
  348. dest.leftHand.pinkyFingerMovementType = source.leftHand.pinkyFingerMovementType;
  349. EditorUtility.SetDirty(dest);
  350. forceUpdateHands = true;
  351. EditorUtility.ClearProgressBar();
  352. }
  353. int activePoseIndex = 0;
  354. SerializedProperty activePoseProp;
  355. SteamVR_Skeleton_Pose activePose;
  356. bool forceUpdateHands = false;
  357. public override void OnInspectorGUI()
  358. {
  359. serializedObject.Update();
  360. DrawPoseEditorMenu();
  361. DrawBlendingBehaviourMenu();
  362. serializedObject.ApplyModifiedProperties();
  363. }
  364. bool getRightFromOpposite = false;
  365. bool getLeftFromOpposite = false;
  366. SteamVR_Behaviour_Skeleton leftSkeleton = null;
  367. SteamVR_Behaviour_Skeleton rightSkeleton = null;
  368. void DrawPoseEditorMenu()
  369. {
  370. if (Application.isPlaying)
  371. {
  372. EditorGUILayout.LabelField("Cannot modify pose while in play mode.");
  373. }
  374. else
  375. {
  376. bool createNew = false;
  377. LoadDefaultPreviewHands();
  378. activePoseIndex = previewPoseSelection.intValue;
  379. if (activePoseIndex == 0)
  380. activePoseProp = skeletonMainPoseProperty;
  381. else
  382. activePoseProp = skeletonAdditionalPosesProperty.GetArrayElementAtIndex(activePoseIndex - 1);
  383. //box containing all pose editing controls
  384. GUILayout.BeginVertical("box");
  385. poseEditorExpanded.boolValue = IndentedFoldoutHeader(poseEditorExpanded.boolValue, "Pose Editor");
  386. if (poseEditorExpanded.boolValue)
  387. {
  388. //show selectable menu of all poses, highlighting the one that is selected
  389. EditorGUILayout.Space();
  390. poser.poseNames = new string[skeletonAdditionalPosesProperty.arraySize + 1];
  391. for (int i = 0; i < skeletonAdditionalPosesProperty.arraySize + 1; i++)
  392. {
  393. if (i == 0)
  394. // main pose special case
  395. poser.poseNames[i] = skeletonMainPoseProperty.objectReferenceValue == null ? "[not set]" : skeletonMainPoseProperty.objectReferenceValue.name + " (MAIN)";
  396. else
  397. // additional poses from array
  398. poser.poseNames[i] = skeletonAdditionalPosesProperty.GetArrayElementAtIndex(i - 1).objectReferenceValue == null ? "[not set]" : skeletonAdditionalPosesProperty.GetArrayElementAtIndex(i - 1).objectReferenceValue.name;
  399. }
  400. EditorGUILayout.BeginHorizontal();
  401. int poseSelected = GUILayout.Toolbar(activePoseIndex, poser.poseNames);
  402. if (poseSelected != activePoseIndex)
  403. {
  404. forceUpdateHands = true;
  405. activePoseIndex = poseSelected;
  406. PoseChanged = true;
  407. previewPoseSelection.intValue = activePoseIndex;
  408. serializedObject.ApplyModifiedProperties();
  409. }
  410. EditorGUILayout.BeginVertical(GUILayout.MaxWidth(32));
  411. if (GUILayout.Button("+", GUILayout.MaxWidth(32)))
  412. {
  413. skeletonAdditionalPosesProperty.InsertArrayElementAtIndex(skeletonAdditionalPosesProperty.arraySize);
  414. }
  415. //only allow deletion of additional poses
  416. EditorGUI.BeginDisabledGroup(skeletonAdditionalPosesProperty.arraySize == 0 || activePoseIndex == 0);
  417. if (GUILayout.Button("-", GUILayout.MaxWidth(32)) && skeletonAdditionalPosesProperty.arraySize > 0)
  418. {
  419. skeletonAdditionalPosesProperty.DeleteArrayElementAtIndex(activePoseIndex - 1);
  420. skeletonAdditionalPosesProperty.DeleteArrayElementAtIndex(activePoseIndex - 1);
  421. if (activePoseIndex >= skeletonAdditionalPosesProperty.arraySize + 1)
  422. {
  423. activePoseIndex = skeletonAdditionalPosesProperty.arraySize;
  424. previewPoseSelection.intValue = activePoseIndex;
  425. return;
  426. }
  427. }
  428. EditorGUI.EndDisabledGroup();
  429. EditorGUILayout.EndVertical();
  430. GUILayout.FlexibleSpace();
  431. EditorGUILayout.EndHorizontal();
  432. GUILayout.BeginVertical("box");
  433. // sides of pose editor
  434. GUILayout.BeginHorizontal();
  435. //pose controls
  436. GUILayout.BeginVertical(GUILayout.MaxWidth(200));
  437. GUILayout.Label("Current Pose:");
  438. if (PoseChanged)
  439. {
  440. PoseChanged = false;
  441. forceUpdateHands = true;
  442. if (activePoseIndex == 0)
  443. activePoseProp = skeletonMainPoseProperty;
  444. else
  445. activePoseProp = skeletonAdditionalPosesProperty.GetArrayElementAtIndex(activePoseIndex - 1);
  446. activePose = (SteamVR_Skeleton_Pose)activePoseProp.objectReferenceValue;
  447. }
  448. activePose = (SteamVR_Skeleton_Pose)activePoseProp.objectReferenceValue;
  449. if (activePoseProp.objectReferenceValue == null)
  450. {
  451. if (previewLeftInstanceProperty.objectReferenceValue != null)
  452. DestroyImmediate(previewLeftInstanceProperty.objectReferenceValue);
  453. if (previewRightInstanceProperty.objectReferenceValue != null)
  454. DestroyImmediate(previewRightInstanceProperty.objectReferenceValue);
  455. EditorGUILayout.BeginHorizontal();
  456. activePoseProp.objectReferenceValue = EditorGUILayout.ObjectField(activePoseProp.objectReferenceValue, typeof(SteamVR_Skeleton_Pose), false);
  457. if (GUILayout.Button("Create")) createNew = true;
  458. EditorGUILayout.EndHorizontal();
  459. if (createNew)
  460. {
  461. string fullPath = EditorUtility.SaveFilePanelInProject("Create New Skeleton Pose", "newPose", "asset", "Save file");
  462. if (string.IsNullOrEmpty(fullPath) == false)
  463. {
  464. SteamVR_Skeleton_Pose newPose = ScriptableObject.CreateInstance<SteamVR_Skeleton_Pose>();
  465. AssetDatabase.CreateAsset(newPose, fullPath);
  466. AssetDatabase.SaveAssets();
  467. activePoseProp.objectReferenceValue = newPose;
  468. serializedObject.ApplyModifiedProperties();
  469. }
  470. }
  471. }
  472. else
  473. {
  474. activePoseProp.objectReferenceValue = EditorGUILayout.ObjectField(activePoseProp.objectReferenceValue, typeof(SteamVR_Skeleton_Pose), false);
  475. DrawPoseControlButtons();
  476. UpdatePreviewHand(previewLeftInstanceProperty, showLeftPreviewProperty, previewLeftHandPrefab, activePose.leftHand, activePose, forceUpdateHands);
  477. UpdatePreviewHand(previewRightInstanceProperty, showRightPreviewProperty, previewRightHandPrefab, activePose.rightHand, activePose, forceUpdateHands);
  478. forceUpdateHands = false;
  479. GUILayout.EndVertical();
  480. GUILayout.Space(10);
  481. if (handTexL == null)
  482. handTexL = (Texture)EditorGUIUtility.Load("Assets/SteamVR/Input/Editor/Resources/Icons/HandLeftIcon.png");
  483. if (handTexR == null)
  484. handTexR = (Texture)EditorGUIUtility.Load("Assets/SteamVR/Input/Editor/Resources/Icons/HandRightIcon.png");
  485. //Left Hand
  486. GUILayout.Space(32);
  487. EditorGUILayout.BeginVertical();
  488. EditorGUILayout.BeginVertical("box");
  489. EditorGUILayout.BeginHorizontal();
  490. GUI.color = new Color(1, 1, 1, showLeftPreviewProperty.boolValue ? 1 : 0.25f);
  491. if (GUILayout.Button(handTexL, GUI.skin.label, GUILayout.Width(64), GUILayout.Height(64)))
  492. {
  493. showLeftPreviewProperty.boolValue = !showLeftPreviewProperty.boolValue;
  494. //forceUpdateHands = true;
  495. }
  496. GUI.color = Color.white;
  497. EditorGUIUtility.labelWidth = 48;
  498. EditorGUILayout.LabelField("Left Hand", EditorStyles.boldLabel);
  499. EditorGUIUtility.labelWidth = 0;
  500. GUILayout.FlexibleSpace();
  501. EditorGUILayout.EndHorizontal();
  502. bool showLeft = showLeftPreviewProperty.boolValue;
  503. DrawHand(showLeft, activePose.leftHand, activePose.rightHand, getLeftFromOpposite);
  504. EditorGUILayout.EndVertical();
  505. EditorGUI.BeginDisabledGroup((showLeftPreviewProperty.boolValue && showRightPreviewProperty.boolValue) == false);
  506. getRightFromOpposite = GUILayout.Button("Copy Left pose to Right hand");
  507. EditorGUI.EndDisabledGroup();
  508. EditorGUILayout.EndVertical();
  509. EditorGUILayout.BeginVertical();
  510. EditorGUILayout.BeginVertical("box");
  511. EditorGUILayout.BeginHorizontal();
  512. GUILayout.FlexibleSpace();
  513. EditorGUIUtility.labelWidth = 48;
  514. EditorGUILayout.LabelField("Right Hand", EditorStyles.boldLabel);
  515. EditorGUIUtility.labelWidth = 0;
  516. GUI.color = new Color(1, 1, 1, showRightPreviewProperty.boolValue ? 1 : 0.25f);
  517. if (GUILayout.Button(handTexR, GUI.skin.label, GUILayout.Width(64), GUILayout.Height(64)))
  518. {
  519. showRightPreviewProperty.boolValue = !showRightPreviewProperty.boolValue;
  520. //forceUpdateHands = true;
  521. }
  522. GUI.color = Color.white;
  523. EditorGUILayout.EndHorizontal();
  524. bool showRight = showLeftPreviewProperty.boolValue;
  525. DrawHand(showRight, activePose.rightHand, activePose.leftHand, getRightFromOpposite);
  526. EditorGUILayout.EndVertical();
  527. EditorGUI.BeginDisabledGroup((showLeftPreviewProperty.boolValue && showRightPreviewProperty.boolValue) == false);
  528. getLeftFromOpposite = GUILayout.Button("Copy Right pose to Left hand");
  529. EditorGUI.EndDisabledGroup();
  530. }
  531. /*
  532. if (activePoseProp.objectReferenceValue == null)
  533. {
  534. EditorGUILayout.BeginHorizontal();
  535. EditorGUILayout.PropertyField(activePoseProp);
  536. createNew = GUILayout.Button("Create");
  537. EditorGUILayout.EndHorizontal();
  538. }
  539. else
  540. {
  541. EditorGUILayout.PropertyField(activePoseProp);
  542. DrawDivider();
  543. DrawSaveButtons();
  544. if (PoseChanged)
  545. {
  546. PoseChanged = false;
  547. forceUpdateHands = true;
  548. }
  549. UpdatePreviewHand(previewLeftInstanceProperty, showLeftPreviewProperty, previewLeftHandPrefab, activePose.leftHand, forceUpdateHands);
  550. UpdatePreviewHand(previewRightInstanceProperty, showRightPreviewProperty, previewRightHandPrefab, activePose.rightHand, forceUpdateHands);
  551. }
  552. activePoseProp.objectReferenceValue = newPose;
  553. serializedObject.ApplyModifiedProperties();
  554. }
  555. }
  556. */
  557. GUILayout.EndVertical();
  558. EditorGUILayout.EndVertical();
  559. GUILayout.EndHorizontal();
  560. EditorGUI.BeginChangeCheck();
  561. EditorGUILayout.BeginHorizontal();
  562. EditorGUIUtility.labelWidth = 120;
  563. poserScale.floatValue = EditorGUILayout.FloatField("Preview Pose Scale", poserScale.floatValue);
  564. if (poserScale.floatValue <= 0) poserScale.floatValue = 1;
  565. EditorGUIUtility.labelWidth = 0;
  566. GUILayout.FlexibleSpace();
  567. EditorGUILayout.EndHorizontal();
  568. if (EditorGUI.EndChangeCheck())
  569. {
  570. forceUpdateHands = true;
  571. }
  572. }
  573. GUILayout.EndVertical();
  574. }
  575. }
  576. bool SelectablePoseButton(string name, bool selected)
  577. {
  578. if (selected)
  579. {
  580. GUI.color = new Color(0.7f, 0.73f, 0.8f);
  581. GUILayout.Button(name, GUILayout.ExpandWidth(false));
  582. GUI.color = Color.white;
  583. return false;
  584. }
  585. else
  586. {
  587. return GUILayout.Button(name, GUILayout.ExpandWidth(false));
  588. }
  589. }
  590. Texture[] handMaskTextures;
  591. void DrawBlendingBehaviourMenu()
  592. {
  593. if (handMaskTextures == null)
  594. {
  595. handMaskTextures = new Texture[] { (Texture)EditorGUIUtility.Load("Assets/SteamVR/Input/Editor/Resources/Icons/handmask_Palm.png"),
  596. (Texture)EditorGUIUtility.Load("Assets/SteamVR/Input/Editor/Resources/Icons/handmask_Thumb.png"),
  597. (Texture)EditorGUIUtility.Load("Assets/SteamVR/Input/Editor/Resources/Icons/handmask_Index.png"),
  598. (Texture)EditorGUIUtility.Load("Assets/SteamVR/Input/Editor/Resources/Icons/handmask_Middle.png"),
  599. (Texture)EditorGUIUtility.Load("Assets/SteamVR/Input/Editor/Resources/Icons/handmask_Ring.png"),
  600. (Texture)EditorGUIUtility.Load("Assets/SteamVR/Input/Editor/Resources/Icons/handmask_Pinky.png")
  601. };
  602. }
  603. GUILayout.Space(10);
  604. GUILayout.BeginVertical("box");
  605. blendEditorExpanded.boolValue = IndentedFoldoutHeader(blendEditorExpanded.boolValue, "Blending Editor");
  606. if (blendEditorExpanded.boolValue)
  607. {
  608. //show selectable menu of all poses, highlighting the one that is selected
  609. EditorGUILayout.Space();
  610. for (int i = 0; i < blendingBehaviourArray.arraySize; i++)
  611. {
  612. SerializedProperty blender = blendingBehaviourArray.GetArrayElementAtIndex(i);
  613. SerializedProperty blenderName = blender.FindPropertyRelative("name");
  614. SerializedProperty blenderEnabled = blender.FindPropertyRelative("enabled");
  615. SerializedProperty blenderInfluence = blender.FindPropertyRelative("influence");
  616. SerializedProperty blenderPose = blender.FindPropertyRelative("pose");
  617. SerializedProperty blenderType = blender.FindPropertyRelative("type");
  618. SerializedProperty blenderUseMask = blender.FindPropertyRelative("useMask");
  619. SerializedProperty blenderValue = blender.FindPropertyRelative("value");
  620. SerializedProperty blenderMask = blender.FindPropertyRelative("mask").FindPropertyRelative("values");
  621. SerializedProperty blenderPreview = blender.FindPropertyRelative("previewEnabled");
  622. GUILayout.Space(10);
  623. float bright = blenderEnabled.boolValue ? 0.6f : 0.9f; // grey out box when disabled
  624. if (EditorGUIUtility.isProSkin) bright = 1;
  625. GUI.color = new Color(bright, bright, bright);
  626. GUILayout.BeginVertical("box");
  627. GUI.color = Color.white;
  628. blenderPreview.boolValue = IndentedFoldoutHeader(blenderPreview.boolValue, blenderName.stringValue, 1);
  629. //SerializedProperty blenderValue = blender.FindProperty("value");
  630. EditorGUIUtility.labelWidth = 64;
  631. EditorGUILayout.BeginHorizontal();
  632. DrawBlenderLogo(blenderType);
  633. EditorGUILayout.PropertyField(blenderEnabled);
  634. GUILayout.FlexibleSpace();
  635. EditorGUI.BeginDisabledGroup(i == 0);
  636. if (GUILayout.Button("Move Up"))
  637. {
  638. blendingBehaviourArray.MoveArrayElement(i, i - 1);
  639. }
  640. EditorGUI.EndDisabledGroup();
  641. EditorGUI.BeginDisabledGroup(i == blendingBehaviourArray.arraySize - 1);
  642. if (GUILayout.Button("Move Down"))
  643. {
  644. blendingBehaviourArray.MoveArrayElement(i, i + 1);
  645. }
  646. EditorGUI.EndDisabledGroup();
  647. GUILayout.Space(6);
  648. GUI.color = new Color(0.9f, 0.8f, 0.78f);
  649. if (GUILayout.Button("Delete"))
  650. {
  651. if (EditorUtility.DisplayDialog("", "Do you really want to delete this Blend Behaviour?", "Yes", "Cancel"))
  652. {
  653. blendingBehaviourArray.DeleteArrayElementAtIndex(i);
  654. return;
  655. }
  656. }
  657. GUI.color = Color.white;
  658. EditorGUILayout.EndHorizontal();
  659. if (blenderPreview.boolValue)
  660. {
  661. EditorGUILayout.PropertyField(blenderName);
  662. EditorGUILayout.BeginHorizontal();
  663. //EditorGUILayout.BeginVertical();
  664. EditorGUILayout.BeginVertical();
  665. EditorGUILayout.Slider(blenderInfluence, 0, 1);
  666. blenderPose.intValue = EditorGUILayout.Popup("Pose", blenderPose.intValue, poser.poseNames);
  667. GUILayout.Space(20);
  668. EditorGUILayout.PropertyField(blenderType);
  669. if (Application.isPlaying)
  670. {
  671. GUILayout.Space(10);
  672. GUI.color = new Color(0, 0, 0, 0.3f);
  673. EditorGUILayout.LabelField("", GUI.skin.box, GUILayout.Height(20), GUILayout.ExpandWidth(true));
  674. GUI.color = Color.white;
  675. Rect fillRect = GUILayoutUtility.GetLastRect();
  676. EditorGUI.DrawRect(fillRectHorizontal(fillRect, blenderValue.floatValue), Color.green);
  677. }
  678. EditorGUILayout.EndVertical();
  679. EditorGUILayout.BeginVertical(GUILayout.MaxWidth(100));
  680. EditorGUILayout.PropertyField(blenderUseMask);
  681. if (blenderUseMask.boolValue)
  682. {
  683. DrawMaskEnabled(blenderMask);
  684. }
  685. else
  686. {
  687. DrawMaskDisabled(blenderMask);
  688. }
  689. EditorGUILayout.EndVertical();
  690. EditorGUILayout.EndHorizontal();
  691. DrawDivider();
  692. EditorGUIUtility.labelWidth = 0;
  693. if (blenderType.intValue == (int)SteamVR_Skeleton_Poser.PoseBlendingBehaviour.BlenderTypes.Manual)
  694. {
  695. EditorGUILayout.Slider(blenderValue, 0, 1);
  696. }
  697. if (blenderType.intValue == (int)SteamVR_Skeleton_Poser.PoseBlendingBehaviour.BlenderTypes.AnalogAction)
  698. {
  699. SerializedProperty blenderAction = blender.FindPropertyRelative("action_single");
  700. SerializedProperty blenderSmooth = blender.FindPropertyRelative("smoothingSpeed");
  701. EditorGUILayout.PropertyField(blenderAction);
  702. EditorGUILayout.PropertyField(blenderSmooth);
  703. }
  704. if (blenderType.intValue == (int)SteamVR_Skeleton_Poser.PoseBlendingBehaviour.BlenderTypes.BooleanAction)
  705. {
  706. SerializedProperty blenderAction = blender.FindPropertyRelative("action_bool");
  707. SerializedProperty blenderSmooth = blender.FindPropertyRelative("smoothingSpeed");
  708. EditorGUILayout.PropertyField(blenderAction);
  709. EditorGUILayout.PropertyField(blenderSmooth);
  710. }
  711. }
  712. GUILayout.EndVertical();
  713. }
  714. EditorGUILayout.BeginHorizontal();
  715. if (GUILayout.Button("+", GUILayout.MaxWidth(32)))
  716. {
  717. int i = blendingBehaviourArray.arraySize;
  718. blendingBehaviourArray.InsertArrayElementAtIndex(i);
  719. blendingBehaviourArray.GetArrayElementAtIndex(i).FindPropertyRelative("name").stringValue = "New Behaviour";
  720. blendingBehaviourArray.GetArrayElementAtIndex(i).FindPropertyRelative("enabled").boolValue = true;
  721. blendingBehaviourArray.GetArrayElementAtIndex(i).FindPropertyRelative("influence").floatValue = 1;
  722. blendingBehaviourArray.GetArrayElementAtIndex(i).FindPropertyRelative("previewEnabled").boolValue = true;
  723. serializedObject.ApplyModifiedProperties();
  724. poser.blendingBehaviours[i].mask.Reset();
  725. }
  726. GUILayout.FlexibleSpace();
  727. EditorGUILayout.EndHorizontal();
  728. }
  729. GUILayout.EndVertical();
  730. }
  731. Rect fillRectHorizontal(Rect r, float f)
  732. {
  733. r.xMax--;
  734. r.yMax--;
  735. r.xMin++;
  736. r.yMin++;
  737. r.width *= f;
  738. return r;
  739. }
  740. void DrawBlenderLogo(SerializedProperty blenderType)
  741. {
  742. Texture icon = null;
  743. if (blenderType.intValue == (int)SteamVR_Skeleton_Poser.PoseBlendingBehaviour.BlenderTypes.Manual)
  744. {
  745. icon = (Texture)EditorGUIUtility.Load("Assets/SteamVR/Input/Editor/Resources/Icons/BlenderBehaviour_Manual_Icon.png");
  746. }
  747. if (blenderType.intValue == (int)SteamVR_Skeleton_Poser.PoseBlendingBehaviour.BlenderTypes.AnalogAction)
  748. {
  749. icon = (Texture)EditorGUIUtility.Load("Assets/SteamVR/Input/Editor/Resources/Icons/BlenderBehaviour_Analog_Icon.png");
  750. }
  751. if (blenderType.intValue == (int)SteamVR_Skeleton_Poser.PoseBlendingBehaviour.BlenderTypes.BooleanAction)
  752. {
  753. icon = (Texture)EditorGUIUtility.Load("Assets/SteamVR/Input/Editor/Resources/Icons/BlenderBehaviour_Boolean_Icon.png");
  754. }
  755. GUILayout.Label(icon, GUILayout.MaxHeight(32), GUILayout.MaxWidth(32));
  756. }
  757. Color maskColorEnabled = new Color(0.3f, 1.0f, 0.3f, 1.0f);
  758. Color maskColorDisabled = new Color(0, 0, 0, 0.5f);
  759. Color maskColorUnused = new Color(0.3f, 0.7f, 0.3f, 0.3f);
  760. void DrawMaskDisabled(SerializedProperty mask)
  761. {
  762. Texture m = (Texture)EditorGUIUtility.Load("Assets/SteamVR/Input/Editor/Resources/Icons/handmask.png");
  763. GUI.color = maskColorUnused;
  764. GUILayout.Label(m, GUILayout.MaxHeight(100), GUILayout.MaxWidth(100));
  765. GUI.color = Color.white;
  766. }
  767. void DrawMaskEnabled(SerializedProperty mask)
  768. {
  769. GUILayout.Label("", GUILayout.Height(100), GUILayout.Width(100));
  770. Rect maskRect = GUILayoutUtility.GetLastRect();
  771. for (int i = 0; i < 6; i++)
  772. {
  773. GUI.color = mask.GetArrayElementAtIndex(i).boolValue ? maskColorEnabled : maskColorDisabled;
  774. GUI.Label(maskRect, handMaskTextures[i]);
  775. GUI.color = new Color(0, 0, 0, 0.0f);
  776. if (GUI.Button(GetFingerAreaRect(maskRect, i), ""))
  777. {
  778. mask.GetArrayElementAtIndex(i).boolValue = !mask.GetArrayElementAtIndex(i).boolValue;
  779. }
  780. GUI.color = Color.white;
  781. //maskVal
  782. }
  783. }
  784. /// <summary>
  785. /// Defines area of mask icon to be buttons for each finger
  786. /// </summary>
  787. Rect GetFingerAreaRect(Rect source, int i)
  788. {
  789. Rect outRect = source;
  790. if (i == 0)
  791. {
  792. outRect.xMin = Mathf.Lerp(source.xMin, source.xMax, 0.4f); // left edge
  793. outRect.xMax = Mathf.Lerp(source.xMin, source.xMax, 0.8f); // right edge
  794. outRect.yMin = Mathf.Lerp(source.yMin, source.yMax, 0.5f); // top edge
  795. outRect.yMax = Mathf.Lerp(source.yMin, source.yMax, 1.0f); // bottom edge
  796. }
  797. if (i == 1)
  798. {
  799. outRect.xMin = Mathf.Lerp(source.xMin, source.xMax, 0.0f); // left edge
  800. outRect.xMax = Mathf.Lerp(source.xMin, source.xMax, 0.4f); // right edge
  801. outRect.yMin = Mathf.Lerp(source.yMin, source.yMax, 0.5f); // top edge
  802. outRect.yMax = Mathf.Lerp(source.yMin, source.yMax, 1.0f); // bottom edge
  803. }
  804. if (i == 2)
  805. {
  806. outRect.xMin = Mathf.Lerp(source.xMin, source.xMax, 0.3f); // left edge
  807. outRect.xMax = Mathf.Lerp(source.xMin, source.xMax, 0.425f); // right edge
  808. outRect.yMin = Mathf.Lerp(source.yMin, source.yMax, 0.0f); // top edge
  809. outRect.yMax = Mathf.Lerp(source.yMin, source.yMax, 0.5f); // bottom edge
  810. }
  811. if (i == 3)
  812. {
  813. outRect.xMin = Mathf.Lerp(source.xMin, source.xMax, 0.425f); // left edge
  814. outRect.xMax = Mathf.Lerp(source.xMin, source.xMax, 0.55f); // right edge
  815. outRect.yMin = Mathf.Lerp(source.yMin, source.yMax, 0.0f); // top edge
  816. outRect.yMax = Mathf.Lerp(source.yMin, source.yMax, 0.5f); // bottom edge
  817. }
  818. if (i == 4)
  819. {
  820. outRect.xMin = Mathf.Lerp(source.xMin, source.xMax, 0.55f); // left edge
  821. outRect.xMax = Mathf.Lerp(source.xMin, source.xMax, 0.675f); // right edge
  822. outRect.yMin = Mathf.Lerp(source.yMin, source.yMax, 0.0f); // top edge
  823. outRect.yMax = Mathf.Lerp(source.yMin, source.yMax, 0.5f); // bottom edge
  824. }
  825. if (i == 5)
  826. {
  827. outRect.xMin = Mathf.Lerp(source.xMin, source.xMax, 0.675f); // left edge
  828. outRect.xMax = Mathf.Lerp(source.xMin, source.xMax, 0.8f); // right edge
  829. outRect.yMin = Mathf.Lerp(source.yMin, source.yMax, 0.0f); // top edge
  830. outRect.yMax = Mathf.Lerp(source.yMin, source.yMax, 0.5f); // bottom edge
  831. }
  832. return outRect;
  833. }
  834. void DrawDivider()
  835. {
  836. GUI.color = new Color(0, 0, 0, 0.6f);
  837. EditorGUILayout.Space();
  838. EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);
  839. EditorGUILayout.Space();
  840. GUI.color = Color.white;
  841. }
  842. bool IndentedFoldoutHeader(bool fold, string text, int indent = 1)
  843. {
  844. GUILayout.BeginHorizontal();
  845. GUIStyle boldFoldoutStyle = new GUIStyle(EditorStyles.foldout);
  846. boldFoldoutStyle.fontStyle = FontStyle.Bold;
  847. GUILayout.Space(14f * indent);
  848. fold = EditorGUILayout.Foldout(fold, text, boldFoldoutStyle);
  849. GUILayout.EndHorizontal();
  850. return fold;
  851. }
  852. }
  853. }