MergeActionNewComponent.cs 1.8 KB

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