This repository has been archived on 2025-04-11. You can view files and clone it, but cannot push or open issues or pull requests.
angels-and-demons/Angels and Demons/Assets/Editor/MergeActionDeleteComponent.cs
2018-05-09 20:42:22 -05:00

71 lines
No EOL
1.9 KiB
C#

using UnityEngine;
using UnityEditor;
namespace GitMerge
{
/// <summary>
/// The MergeAction that handles a Component which exists in "their" version but not "ours".
/// </summary>
public class MergeActionDeleteComponent : MergeActionExistence
{
protected Component ourComponent;
protected Component copy;
public MergeActionDeleteComponent(GameObject ours, Component ourComponent)
: base(ours, null)
{
this.ourComponent = ourComponent;
var go = new GameObject("GitMerge Object");
go.SetActiveForMerging(false);
copy = go.AddComponent(ourComponent);
if(GitMergeWindow.automerge)
{
UseOurs();
}
}
protected override void ApplyOurs()
{
if(ourComponent == null)
{
ourComponent = ours.AddComponent(copy);
ObjectDictionaries.SetAsOurObject(ourComponent);
}
}
protected override void ApplyTheirs()
{
if(ourComponent != null)
{
ObjectDictionaries.RemoveOurObject(ourComponent);
Object.DestroyImmediate(ourComponent, true);
}
}
public override void EnsureExistence()
{
UseOurs();
}
public override void OnGUI()
{
GUILayout.Label(copy.GetPlainType());
var defaultOptionColor = merged ? Color.gray : Color.white;
GUI.color = usingOurs ? Color.green : defaultOptionColor;
if(GUILayout.Button("Keep Component"))
{
UseOurs();
}
GUI.color = usingTheirs ? Color.green : defaultOptionColor;
if(GUILayout.Button("Delete Component"))
{
UseTheirs();
}
}
}
}