AvatarLoaderSampleEditor.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using UnityEngine;
  2. using UnityEditor;
  3. using TriLib.Extras;
  4. using UnityEngine.SceneManagement;
  5. namespace TriLibEditor
  6. {
  7. /// <summary>
  8. /// Represents the avatar loader sample scene editor.
  9. /// </summary>
  10. [CustomEditor(typeof(AvatarLoaderSample))]
  11. public class AvatarLoaderSampleEditor : Editor
  12. {
  13. /// <summary>
  14. /// Dialogs title.
  15. /// </summary>
  16. private const string DialogTitle = "TriLib - Configure Sample";
  17. /// <summary>
  18. /// Displays the Option to Configure the Avatar Sample.
  19. /// </summary>
  20. public override void OnInspectorGUI()
  21. {
  22. if (SceneManager.GetActiveScene().name == "AvatarLoader")
  23. {
  24. if (GUILayout.Button("Configure Avatar Loader Sample"))
  25. {
  26. SetupAvatarLoaderSample();
  27. }
  28. }
  29. base.OnInspectorGUI();
  30. }
  31. /// <summary>
  32. /// Setups the Avatar Loader Sample Scene.
  33. /// </summary>
  34. private void SetupAvatarLoaderSample()
  35. {
  36. var avatarLoaderSample = target as AvatarLoaderSample;
  37. if (avatarLoaderSample == null)
  38. {
  39. return;
  40. }
  41. var thirdPersonControllerResults = AssetDatabase.FindAssets("ThirdPersonController t:GameObject");
  42. foreach (var thirdPersonControllerResult in thirdPersonControllerResults)
  43. {
  44. var thirdPersonControllerPrefabPath = AssetDatabase.GUIDToAssetPath(thirdPersonControllerResult);
  45. if (thirdPersonControllerPrefabPath.IndexOf("/ThirdPersonController.prefab", System.StringComparison.Ordinal) > -1)
  46. {
  47. avatarLoaderSample.ThirdPersonControllerPrefab = AssetDatabase.LoadAssetAtPath<GameObject>(thirdPersonControllerPrefabPath);
  48. var freeLookCameraRigResults = AssetDatabase.FindAssets("FreeLookCameraRig t:GameObject");
  49. foreach (var freeLookCameraRigResult in freeLookCameraRigResults)
  50. {
  51. var freeLookCameraRigPath = AssetDatabase.GUIDToAssetPath(freeLookCameraRigResult);
  52. if (freeLookCameraRigPath.IndexOf("/FreeLookCameraRig.prefab", System.StringComparison.Ordinal) > -1)
  53. {
  54. avatarLoaderSample.FreeLookCamPrefab = AssetDatabase.LoadAssetAtPath<GameObject>(freeLookCameraRigPath);
  55. EditorUtility.DisplayDialog(DialogTitle, "Sample configured.", "Ok");
  56. return;
  57. }
  58. }
  59. break;
  60. }
  61. }
  62. EditorUtility.DisplayDialog(DialogTitle, "To configure the Avatar Loader Sample, please download and extract \"Standard Assets\" from Asset Store first.", "Ok");
  63. }
  64. }
  65. }