MergeActionNewGameObject.cs 1.5 KB

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