SCImage3DInspector.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using UnityEngine;
  2. using UnityEditor;
  3. [CustomEditor(typeof(SCImage3D))]
  4. public class SCImage3DInspector : Editor
  5. {
  6. protected SCImage3D scImage3D;
  7. protected SerializedProperty imageTexture;
  8. protected SerializedProperty imageColor;
  9. protected SerializedProperty imageMaterial;
  10. protected SerializedProperty raycastTarget;
  11. protected SerializedProperty customColliderSize;
  12. [MenuItem("GameObject/SC3DUI/SCImage3D", priority = 0)]
  13. private static void Init()
  14. {
  15. var obj = Instantiate(Resources.Load<SCImage3D>(typeof(SCImage3D).Name));
  16. obj.name = (typeof(SCImage3D).Name);
  17. if (obj)
  18. {
  19. var parent = Selection.activeGameObject;
  20. obj.transform.SetParent(parent ? parent.transform : null, obj.transform);
  21. Selection.activeGameObject = obj.gameObject;
  22. }
  23. }
  24. protected virtual void OnEnable()
  25. {
  26. scImage3D = target as SCImage3D;
  27. imageTexture = serializedObject.FindProperty("m_Texture");
  28. imageColor = serializedObject.FindProperty("m_Color");
  29. imageMaterial = serializedObject.FindProperty("m_Material");
  30. raycastTarget = serializedObject.FindProperty("m_RaycastTarget");
  31. customColliderSize = serializedObject.FindProperty("m_CustomColliderSize");
  32. }
  33. public override void OnInspectorGUI()
  34. {
  35. serializedObject.Update();
  36. base.OnInspectorGUI();
  37. serializedObject.ApplyModifiedProperties();
  38. if (scImage3D != null)
  39. {
  40. scImage3D.UpdateSize();
  41. scImage3D.UpdateMaterial();
  42. scImage3D.UpdateRaycaster();
  43. }
  44. }
  45. }