MergeActionDeleteComponent.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using UnityEngine;
  2. using UnityEditor;
  3. namespace GitMerge
  4. {
  5. /// <summary>
  6. /// The MergeAction that handles a Component which exists in "their" version but not "ours".
  7. /// </summary>
  8. public class MergeActionDeleteComponent : MergeActionExistence
  9. {
  10. protected Component ourComponent;
  11. protected Component copy;
  12. public MergeActionDeleteComponent(GameObject ours, Component ourComponent)
  13. : base(ours, null)
  14. {
  15. this.ourComponent = ourComponent;
  16. var go = new GameObject("GitMerge Object");
  17. go.SetActiveForMerging(false);
  18. copy = go.AddComponent(ourComponent);
  19. if (GitMergeWindow.automerge)
  20. {
  21. UseOurs();
  22. }
  23. }
  24. protected override void ApplyOurs()
  25. {
  26. if (ourComponent == null)
  27. {
  28. ourComponent = ours.AddComponent(copy);
  29. ObjectDictionaries.SetAsOurObject(ourComponent);
  30. }
  31. }
  32. protected override void ApplyTheirs()
  33. {
  34. if (ourComponent != null)
  35. {
  36. ObjectDictionaries.RemoveOurObject(ourComponent);
  37. Object.DestroyImmediate(ourComponent, true);
  38. }
  39. }
  40. public override void EnsureExistence()
  41. {
  42. UseOurs();
  43. }
  44. public override void OnGUI()
  45. {
  46. GUILayout.Label(copy.GetPlainType());
  47. var defaultOptionColor = merged ? Color.gray : Color.white;
  48. GUI.color = usingOurs ? Color.green : defaultOptionColor;
  49. if (GUILayout.Button("Keep Component"))
  50. {
  51. UseOurs();
  52. }
  53. GUI.color = usingTheirs ? Color.green : defaultOptionColor;
  54. if (GUILayout.Button("Delete Component"))
  55. {
  56. UseTheirs();
  57. }
  58. }
  59. }
  60. }