mirror of
https://github.com/MrUnknownDE/vcc-tools.git
synced 2026-05-04 22:26:06 +02:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7bc0eee024 | |||
| 48134f2a03 | |||
| 00ab946aa0 | |||
| 992e67eee2 |
+142
-34
@@ -13,6 +13,9 @@ public class GitPanel : EditorWindow
|
||||
private bool isGitInstalled = true;
|
||||
private bool hasRepo = false;
|
||||
|
||||
private bool settingsCorrect = true;
|
||||
private string settingsWarning = "";
|
||||
|
||||
private string currentBranchName = "unknown";
|
||||
private string[] availableBranches = new string[0];
|
||||
private int selectedBranchIndex = 0;
|
||||
@@ -20,11 +23,14 @@ public class GitPanel : EditorWindow
|
||||
private string[] changedFiles = new string[0];
|
||||
private Vector2 scrollPositionChanges;
|
||||
private Vector2 scrollPositionHistory;
|
||||
|
||||
// STATISCH: Damit RunGitCommand darauf zugreifen kann und das Log beim Neuladen erhalten bleibt!
|
||||
private static string gitLogOutput = "";
|
||||
private Vector2 scrollPositionLog;
|
||||
|
||||
private int selectedTab = 0;
|
||||
private string[] tabNames = { "Changes", "History" };
|
||||
|
||||
// NEU: Settings & Override
|
||||
private bool showSettings = false;
|
||||
private string webUrlOverride = "";
|
||||
private string prefsKey = "";
|
||||
@@ -36,15 +42,13 @@ public class GitPanel : EditorWindow
|
||||
public static void ShowWindow()
|
||||
{
|
||||
GitPanel window = GetWindow<GitPanel>("GIT Version Control System");
|
||||
window.minSize = new Vector2(350, 550);
|
||||
window.minSize = new Vector2(380, 650);
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
// Generiert einen einzigartigen Key für dieses spezifische Unity-Projekt
|
||||
prefsKey = $"GitTool_WebUrl_{Application.dataPath.GetHashCode()}";
|
||||
webUrlOverride = EditorPrefs.GetString(prefsKey, "");
|
||||
|
||||
RefreshData();
|
||||
}
|
||||
|
||||
@@ -53,8 +57,9 @@ public class GitPanel : EditorWindow
|
||||
public void RefreshData()
|
||||
{
|
||||
CheckGitInstallation();
|
||||
CheckUnitySettings();
|
||||
|
||||
if (!isGitInstalled) return;
|
||||
|
||||
CheckRepoStatus();
|
||||
|
||||
if (hasRepo)
|
||||
@@ -79,6 +84,33 @@ public class GitPanel : EditorWindow
|
||||
} catch { isGitInstalled = false; }
|
||||
}
|
||||
|
||||
// FIX: Nutzt jetzt die aktuelle Unity-API (VersionControlSettings.mode)
|
||||
private void CheckUnitySettings()
|
||||
{
|
||||
settingsCorrect = true;
|
||||
settingsWarning = "";
|
||||
|
||||
if (VersionControlSettings.mode != "Visible Meta Files")
|
||||
{
|
||||
settingsCorrect = false;
|
||||
settingsWarning += "• Version Control Mode must be 'Visible Meta Files'\n";
|
||||
}
|
||||
|
||||
if (EditorSettings.serializationMode != SerializationMode.ForceText)
|
||||
{
|
||||
settingsCorrect = false;
|
||||
settingsWarning += "• Asset Serialization must be 'Force Text'\n";
|
||||
}
|
||||
}
|
||||
|
||||
private void FixUnitySettings()
|
||||
{
|
||||
VersionControlSettings.mode = "Visible Meta Files";
|
||||
EditorSettings.serializationMode = SerializationMode.ForceText;
|
||||
UnityEngine.Debug.Log("Git-Tool: Unity Project Settings updated for Git compatibility.");
|
||||
RefreshData();
|
||||
}
|
||||
|
||||
private void SetDefaultCommitMessage() { commitMessage = $"Auto-Save: {System.DateTime.Now:yyyy-MM-dd HH:mm:ss}"; }
|
||||
|
||||
private void OnGUI()
|
||||
@@ -88,23 +120,34 @@ public class GitPanel : EditorWindow
|
||||
if (hasRepo) GUILayout.Label($"Active Branch: {currentBranchName}", EditorStyles.miniLabel);
|
||||
GUILayout.Space(5);
|
||||
|
||||
if (!settingsCorrect)
|
||||
{
|
||||
EditorGUILayout.BeginVertical("box");
|
||||
EditorGUILayout.HelpBox("INCOMPATIBLE PROJECT SETTINGS:\n" + settingsWarning, MessageType.Error);
|
||||
GUI.backgroundColor = new Color(1f, 0.5f, 0f);
|
||||
if (GUILayout.Button("Fix Project Settings Now"))
|
||||
{
|
||||
FixUnitySettings();
|
||||
}
|
||||
GUI.backgroundColor = Color.white;
|
||||
EditorGUILayout.EndVertical();
|
||||
GUILayout.Space(10);
|
||||
}
|
||||
|
||||
if (!isGitInstalled) { RenderGitMissingUI(); return; }
|
||||
if (!hasRepo) { RenderInitUI(); return; }
|
||||
|
||||
// --- NEU: SETTINGS FOLDOUT ---
|
||||
showSettings = EditorGUILayout.Foldout(showSettings, "⚙️ Repository Settings");
|
||||
if (showSettings)
|
||||
{
|
||||
EditorGUILayout.BeginVertical("box");
|
||||
GUILayout.Label("Web Override (For custom SSH instances)", EditorStyles.miniBoldLabel);
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
webUrlOverride = EditorGUILayout.TextField("Web URL:", webUrlOverride);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorPrefs.SetString(prefsKey, webUrlOverride.Trim());
|
||||
}
|
||||
EditorGUILayout.HelpBox("e.g. https://git.mrunk.de/mrunknownde/my-repo\nLeaves SSH untouched but fixes browser links.", MessageType.None);
|
||||
EditorGUILayout.EndVertical();
|
||||
GUILayout.Space(5);
|
||||
}
|
||||
@@ -118,7 +161,7 @@ public class GitPanel : EditorWindow
|
||||
|
||||
private void RenderGitMissingUI()
|
||||
{
|
||||
EditorGUILayout.HelpBox("CRITICAL: Git not found. Please install Git and restart Unity.", MessageType.Error);
|
||||
EditorGUILayout.HelpBox("CRITICAL: Git not found.", MessageType.Error);
|
||||
if (GUILayout.Button("Download Git for Windows", GUILayout.Height(30))) Application.OpenURL("https://git-scm.com/download/win");
|
||||
}
|
||||
|
||||
@@ -128,24 +171,23 @@ public class GitPanel : EditorWindow
|
||||
remoteUrlInput = EditorGUILayout.TextField("Remote URL:", remoteUrlInput);
|
||||
if (GUILayout.Button("Initialize Repository", GUILayout.Height(30)))
|
||||
{
|
||||
RunGitCommand("init");
|
||||
RunGitCommand("branch -M main");
|
||||
RunGitCommand("init", true);
|
||||
RunGitCommand("branch -M main", true);
|
||||
if (!string.IsNullOrWhiteSpace(remoteUrlInput)) {
|
||||
RunGitCommand($"remote add origin \"{remoteUrlInput.Trim()}\"");
|
||||
RunGitCommand("pull origin main --allow-unrelated-histories --no-edit");
|
||||
RunGitCommand($"remote add origin \"{remoteUrlInput.Trim()}\"", true);
|
||||
RunGitCommand("pull origin main --allow-unrelated-histories --no-edit", true);
|
||||
}
|
||||
GenerateUnityGitIgnore();
|
||||
AssetDatabase.Refresh();
|
||||
RunGitCommand("add .gitignore");
|
||||
RunGitCommand("commit -m \"Initial commit (GitIgnore)\"");
|
||||
if (!string.IsNullOrWhiteSpace(remoteUrlInput)) RunGitCommand("push -u origin main");
|
||||
RunGitCommand("add .gitignore", true);
|
||||
RunGitCommand("commit -m \"Initial commit (GitIgnore)\"", true);
|
||||
if (!string.IsNullOrWhiteSpace(remoteUrlInput)) RunGitCommand("push -u origin main", true);
|
||||
RefreshData();
|
||||
}
|
||||
}
|
||||
|
||||
private void RenderGitUI()
|
||||
{
|
||||
// --- BRANCH MANAGEMENT ---
|
||||
EditorGUILayout.BeginVertical("box");
|
||||
GUILayout.Label("Branch Management", EditorStyles.boldLabel);
|
||||
|
||||
@@ -155,7 +197,8 @@ public class GitPanel : EditorWindow
|
||||
int newIndex = EditorGUILayout.Popup("Switch Branch:", selectedBranchIndex, availableBranches);
|
||||
if (EditorGUI.EndChangeCheck() && newIndex != selectedBranchIndex)
|
||||
{
|
||||
RunGitCommand($"checkout \"{availableBranches[newIndex]}\"");
|
||||
RunGitCommand($"checkout \"{availableBranches[newIndex]}\"", true);
|
||||
AssetDatabase.Refresh();
|
||||
RefreshData();
|
||||
return;
|
||||
}
|
||||
@@ -168,7 +211,7 @@ public class GitPanel : EditorWindow
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(newBranchName))
|
||||
{
|
||||
RunGitCommand($"checkout -b \"{newBranchName.Trim()}\"");
|
||||
RunGitCommand($"checkout -b \"{newBranchName.Trim()}\"", true);
|
||||
newBranchName = "";
|
||||
RefreshData();
|
||||
GUI.FocusControl(null);
|
||||
@@ -180,26 +223,59 @@ public class GitPanel : EditorWindow
|
||||
EditorGUILayout.EndVertical();
|
||||
|
||||
GUILayout.Space(10);
|
||||
|
||||
// --- COMMIT BEREICH ---
|
||||
commitMessage = EditorGUILayout.TextField(commitMessage, GUILayout.Height(25));
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
|
||||
GUI.backgroundColor = new Color(0.2f, 0.4f, 0.8f);
|
||||
if (GUILayout.Button("✓ Commit & Push", GUILayout.Height(30)))
|
||||
if (GUILayout.Button("✓ Push", GUILayout.Height(30)))
|
||||
{
|
||||
UnityEngine.Debug.Log("Git-Tool: Saving Scenes and Assets before push...");
|
||||
UnityEditor.SceneManagement.EditorSceneManager.SaveOpenScenes();
|
||||
AssetDatabase.SaveAssets();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(commitMessage)) SetDefaultCommitMessage();
|
||||
RunGitCommand("add .");
|
||||
RunGitCommand($"commit -m \"{commitMessage}\"");
|
||||
RunGitCommand("push -u origin HEAD");
|
||||
commitMessage = "";
|
||||
RunGitCommand("add .", true);
|
||||
RunGitCommand($"commit -m \"{commitMessage}\"", true);
|
||||
|
||||
string pushResult = RunGitCommand("push -u origin HEAD", true);
|
||||
if (pushResult.Contains("rejected") || pushResult.Contains("fetch first"))
|
||||
{
|
||||
UnityEngine.Debug.LogError("Git-Tool: PUSH REJECTED! Jemand anderes hat Änderungen hochgeladen. Bitte klicke zuerst auf 'Pull'.");
|
||||
}
|
||||
else
|
||||
{
|
||||
UnityEngine.Debug.Log("Git-Tool: Changes successfully pushed!");
|
||||
commitMessage = "";
|
||||
}
|
||||
RefreshData();
|
||||
}
|
||||
|
||||
GUI.backgroundColor = new Color(0.8f, 0.6f, 0.2f);
|
||||
if (GUILayout.Button("⬇️ Pull", GUILayout.Width(80), GUILayout.Height(30)))
|
||||
{
|
||||
UnityEditor.SceneManagement.EditorSceneManager.SaveOpenScenes();
|
||||
AssetDatabase.SaveAssets();
|
||||
|
||||
string pullResult = RunGitCommand("pull", true);
|
||||
AssetDatabase.Refresh();
|
||||
|
||||
if (pullResult.Contains("CONFLICT"))
|
||||
{
|
||||
UnityEngine.Debug.LogError("Git-Tool: MERGE CONFLICT! Bitte in VS Code auflösen!");
|
||||
EditorUtility.DisplayDialog("Merge Conflict", "Es gibt Konflikte mit den Server-Daten!\n\nGit konnte die Änderungen nicht automatisch zusammenführen. Bitte öffne die roten Dateien in deinem Code-Editor und löse den Konflikt manuell auf.", "OK");
|
||||
}
|
||||
RefreshData();
|
||||
}
|
||||
|
||||
GUI.backgroundColor = new Color(0.8f, 0.3f, 0.3f);
|
||||
if (GUILayout.Button("⎌ Revert All", GUILayout.Width(80), GUILayout.Height(30)))
|
||||
if (GUILayout.Button("⎌ Revert", GUILayout.Width(80), GUILayout.Height(30)))
|
||||
{
|
||||
if (EditorUtility.DisplayDialog("Revert Changes?", "Discard ALL uncommitted changes?", "Yes", "Cancel")) {
|
||||
RunGitCommand("reset --hard HEAD"); RunGitCommand("clean -fd"); RefreshData();
|
||||
RunGitCommand("reset --hard HEAD", true);
|
||||
RunGitCommand("clean -fd", true);
|
||||
AssetDatabase.Refresh();
|
||||
RefreshData();
|
||||
}
|
||||
}
|
||||
GUI.backgroundColor = Color.white;
|
||||
@@ -215,6 +291,17 @@ public class GitPanel : EditorWindow
|
||||
if (changedFiles.Length == 0) GUILayout.Label("No changes.");
|
||||
else RenderFileList(changedFiles);
|
||||
EditorGUILayout.EndScrollView();
|
||||
|
||||
GUILayout.Space(5);
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
GUILayout.Label("GIT CONSOLE", EditorStyles.boldLabel);
|
||||
if (GUILayout.Button("Clear", GUILayout.Width(50))) gitLogOutput = "";
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
scrollPositionLog = EditorGUILayout.BeginScrollView(scrollPositionLog, "box", GUILayout.Height(120));
|
||||
GUIStyle logStyle = new GUIStyle(EditorStyles.label) { wordWrap = true, fontSize = 10 };
|
||||
GUILayout.Label(string.IsNullOrEmpty(gitLogOutput) ? "Ready." : gitLogOutput, logStyle);
|
||||
EditorGUILayout.EndScrollView();
|
||||
}
|
||||
|
||||
private void RenderHistoryUI()
|
||||
@@ -256,7 +343,6 @@ public class GitPanel : EditorWindow
|
||||
|
||||
private void OpenCommitInBrowser(string hash)
|
||||
{
|
||||
// NEU: Override Logik greift zuerst!
|
||||
if (!string.IsNullOrWhiteSpace(webUrlOverride))
|
||||
{
|
||||
string url = webUrlOverride;
|
||||
@@ -266,7 +352,6 @@ public class GitPanel : EditorWindow
|
||||
return;
|
||||
}
|
||||
|
||||
// Standard Fallback Logik (wenn kein Override gesetzt ist)
|
||||
string remoteUrl = RunGitCommand("config --get remote.origin.url").Trim();
|
||||
if (string.IsNullOrEmpty(remoteUrl)) return;
|
||||
|
||||
@@ -277,7 +362,6 @@ public class GitPanel : EditorWindow
|
||||
if (firstColon != -1) remoteUrl = remoteUrl.Remove(firstColon, 1).Insert(firstColon, "/");
|
||||
}
|
||||
if (remoteUrl.EndsWith(".git")) remoteUrl = remoteUrl.Substring(0, remoteUrl.Length - 4);
|
||||
|
||||
Application.OpenURL($"{remoteUrl}/commit/{hash}");
|
||||
}
|
||||
|
||||
@@ -325,10 +409,34 @@ public class GitPanel : EditorWindow
|
||||
if (!File.Exists(path)) File.WriteAllText(path, ".idea\n.vs\nbin\nobj\n/Library\n/Temp\n/UserSettings\n/Configs\n/*.csproj\n/*.sln\n/Logs\n/Packages/*\n!/Packages/manifest.json\n!/Packages/packages-lock.json\n~UnityDirMonSyncFile~*");
|
||||
}
|
||||
|
||||
public static string RunGitCommand(string args) {
|
||||
// FIX: Methode ist wieder static!
|
||||
public static string RunGitCommand(string args, bool logAction = false) {
|
||||
try {
|
||||
ProcessStartInfo si = new ProcessStartInfo("git", args) { WorkingDirectory = Path.GetFullPath(Path.Combine(Application.dataPath, "..")), UseShellExecute = false, RedirectStandardOutput = true, CreateNoWindow = true };
|
||||
using (Process p = Process.Start(si)) { string o = p.StandardOutput.ReadToEnd(); p.WaitForExit(); return o; }
|
||||
ProcessStartInfo si = new ProcessStartInfo("git", args) {
|
||||
WorkingDirectory = Path.GetFullPath(Path.Combine(Application.dataPath, "..")),
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
CreateNoWindow = true
|
||||
};
|
||||
|
||||
using (Process p = Process.Start(si)) {
|
||||
string o = p.StandardOutput.ReadToEnd();
|
||||
string e = p.StandardError.ReadToEnd();
|
||||
p.WaitForExit();
|
||||
string result = o + (string.IsNullOrWhiteSpace(e) ? "" : "\n" + e);
|
||||
|
||||
if (logAction) {
|
||||
string time = System.DateTime.Now.ToString("HH:mm:ss");
|
||||
string entry = $"[{time}] > git {args}\n";
|
||||
if (!string.IsNullOrWhiteSpace(result)) entry += result.Trim() + "\n\n";
|
||||
|
||||
gitLogOutput = entry + gitLogOutput;
|
||||
if (gitLogOutput.Length > 10000) gitLogOutput = gitLogOutput.Substring(0, 10000);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
} catch { return ""; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,19 +44,10 @@ Listen up, because the German Copyright Law (*Urheberrechtsgesetz*) doesn't take
|
||||
|
||||
This tool is installed manually directly into your Unity project.
|
||||
|
||||
### Method 1: Unity Package Manager (Recommended)
|
||||
1. Go to the [Releases page](../../releases/latest) of this repository.
|
||||
2. Download the latest `de.mrunknownde.gittool-vX.X.X.zip` file.
|
||||
3. Extract the ZIP file into a folder on your PC.
|
||||
4. Open your Unity Project.
|
||||
5. Go to `Window` -> `Package Manager`.
|
||||
6. Click the **+** icon in the top left corner and select **Add package from disk...**.
|
||||
7. Navigate to the extracted folder, select the `package.json` file, and click Open.
|
||||
|
||||
### Method 2: Direct Folder Drop
|
||||
1. Download the latest `.zip` release.
|
||||
### Direct Folder Drop
|
||||
1. Download the latest `mrunknownde-vcc-tools-v20xx-xx-xx.zip` release.
|
||||
2. Extract the archive.
|
||||
3. Drag and drop the extracted folder directly into the `Packages` directory inside your Unity project's root folder (using Windows Explorer / File Explorer, not inside the Unity Editor window). Unity will automatically compile the tools.
|
||||
3. Drag and drop the extracted folder directly into the `Assets` directory inside your Unity project's root folder (using Windows Explorer / File Explorer, not inside the Unity Editor window). Unity will automatically compile the tools.
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user