MergeActionDeleteComponent.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. Debug.Log("ApplyOurs deleting ours GameObject");
  27. if (ourComponent == null)
  28. {
  29. ourComponent = ours.AddComponent(copy);
  30. ObjectDictionaries.SetAsOurObject(ourComponent);
  31. }
  32. }
  33. protected override void ApplyTheirs()
  34. {
  35. Debug.Log("ApplyTheirs deleting their GameObject");
  36. if (ourComponent != null)
  37. {
  38. ObjectDictionaries.RemoveOurObject(ourComponent);
  39. Object.DestroyImmediate(ourComponent, true);
  40. }
  41. }
  42. public override void EnsureExistence()
  43. {
  44. UseOurs();
  45. }
  46. public override void OnGUI()
  47. {
  48. GUILayout.Label(copy.GetPlainType());
  49. var defaultOptionColor = merged ? Color.gray : Color.white;
  50. GUI.color = usingOurs ? Color.green : defaultOptionColor;
  51. if (GUILayout.Button("Keep Component"))
  52. {
  53. UseOurs();
  54. }
  55. GUI.color = usingTheirs ? Color.green : defaultOptionColor;
  56. if (GUILayout.Button("Delete Component"))
  57. {
  58. UseTheirs();
  59. }
  60. }
  61. }
  62. }