SteamVR_Skeleton_PoserEditor.cs 48 KB

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