InspectableGameObjectRef.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using BansheeEngine;
  7. namespace BansheeEditor
  8. {
  9. public class InspectableGameObjectRef : InspectableObjectBase
  10. {
  11. private GameObject propertyValue;
  12. private GUIGameObjectField guiField;
  13. private bool isInitialized;
  14. public InspectableGameObjectRef(string title, InspectableFieldLayout layout, SerializableProperty property)
  15. : base(title, layout, property)
  16. {
  17. }
  18. private void Initialize(int layoutIndex)
  19. {
  20. if (property.Type == SerializableProperty.FieldType.GameObjectRef)
  21. {
  22. guiField = new GUIGameObjectField(property.InternalType, new GUIContent(title));
  23. guiField.OnChanged += OnFieldValueChanged;
  24. layout.AddElement(layoutIndex, guiField);
  25. }
  26. isInitialized = true;
  27. }
  28. protected override bool IsModified()
  29. {
  30. if (!isInitialized)
  31. return true;
  32. GameObject newPropertyValue = property.GetValue<GameObject>();
  33. if (propertyValue != newPropertyValue)
  34. return true;
  35. return base.IsModified();
  36. }
  37. protected override void Update(int layoutIndex)
  38. {
  39. base.Update(layoutIndex);
  40. if (!isInitialized)
  41. Initialize(layoutIndex);
  42. propertyValue = property.GetValue<GameObject>();
  43. if (guiField != null)
  44. guiField.Value = propertyValue;
  45. }
  46. private void OnFieldValueChanged(GameObject newValue)
  47. {
  48. property.SetValue(newValue);
  49. }
  50. }
  51. }