Unity Git项目添加子模块

在 当前仓库根目录下执行命令

git submodule add https://github.com/xxx/child.git

检查仓库状态

git status

更新子库

git submodule update --remote

下拉父仓库Git并保住子库也更新

git pull --recurse-submodules

推荐使用 Githubdesktop工具

这样你可以更清楚的看到自己子库关联状态

在Unity本使用脚本调用Git

csharp 复制代码
public static void NewGitCommand( string arguments, string WorkingDirectory = "./" )
    {
        string gitPath = "git";
        ProcessStartInfo startInfo = new ProcessStartInfo( gitPath, arguments )
        {
            WindowStyle = ProcessWindowStyle.Hidden,
            UseShellExecute = false,
            ErrorDialog = false,
            CreateNoWindow = true,
            RedirectStandardError = true,
            RedirectStandardInput = true,
            RedirectStandardOutput = true,
            LoadUserProfile = true,
            WorkingDirectory = WorkingDirectory
        };
        var p = new Process { StartInfo = startInfo };
        p.OutputDataReceived += new DataReceivedEventHandler( ( object sender, DataReceivedEventArgs eventArgs ) =>
        {
            if ( !string.IsNullOrEmpty( eventArgs.Data ) )
            {
                Debug.Log(eventArgs.Data);
            }
        } );
        p.ErrorDataReceived += new DataReceivedEventHandler( ( object sender, DataReceivedEventArgs eventArgs ) =>
        {
            if ( !string.IsNullOrEmpty( eventArgs.Data ) )
            {
                Debug.Log( eventArgs.Data );
            }
        } );
        p.Start();
        p.BeginOutputReadLine();
        p.WaitForExit();
        p.Close();
        p.Dispose(); 
    }

案例

csharp 复制代码
   public static void InitOrUpdateSubmodule()
    {
        //Log.PINK( "Begin Update Submodule ======>" );
        NewGitCommand( "submodule update --init --recursive" );
        NewGitCommand( "pull" );
        NewGitCommand( "submodule update" );
        NewGitCommand( "submodule update --remote" );
        AssetDatabase.Refresh();
        //Log.PINK( "End Update Submodule ======>" );
    }
相关推荐
技术小结-李爽15 分钟前
【工具】git安装及配置
git
xcLeigh2 小时前
Unity基础:Light灯光组件入门——Directional Light、Point Light与Spotlight
unity·游戏引擎·教程
技术小结-李爽6 小时前
【工具】git与gitee和gitlab和github等等有什么区别?
git·gitee·gitlab
郝学胜-神的一滴7 小时前
[简化版 GAMES 104] 现代游戏引擎 04:从0到1构建你的游戏世界
c++·游戏·unity·游戏引擎·软件工程·unreal engine
为伴只为你11 小时前
将已有git工程转为使用LFS
git
x-cmd13 小时前
AI 时代的 Git 革命:多 Agent 并发开发的新基础设施
git·ai·agent·代码管理·开发者工具·多智能体协作·worktree
是嘟嘟啊1 天前
【Unity DOTS】EntityCommandBuffer 与 JobHandle
unity·ecs·dots·unity dots·job·burst·burstjob
xcLeigh1 天前
Unity基础:Camera相机组件详解——透视投影与正交投影的区别
数码相机·unity·游戏引擎
玖玥拾1 天前
Unity3D RPG 入门项目(二)移动 Bug 修复、环绕相机、NPC 任务系统、UI 穿透处理
unity·游戏引擎
Yasin Chen1 天前
Unity UGUI RectMask2D 原理
unity·游戏引擎