pindo 5.13.7 → 5.13.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
- require_relative '../pindo_task'
2
- require_relative '../task_config'
1
+ require 'pindo/module/task/pindo_task'
2
+ require 'pindo/module/task/task_config'
3
3
  require 'pindo/module/pgyer/pgyerhelper'
4
4
 
5
5
  module Pindo
@@ -1,5 +1,5 @@
1
- require_relative '../pindo_task'
2
- require_relative '../task_config'
1
+ require 'pindo/module/task/pindo_task'
2
+ require 'pindo/module/task/task_config'
3
3
 
4
4
  module Pindo
5
5
  module TaskSystem
@@ -1,5 +1,5 @@
1
- require_relative '../pindo_task'
2
- require_relative '../task_config'
1
+ require 'pindo/module/task/pindo_task'
2
+ require 'pindo/module/task/task_config'
3
3
  require 'pindo/module/pgyer/pgyerhelper'
4
4
 
5
5
  module Pindo
@@ -0,0 +1,107 @@
1
+ require 'pindo/module/task/model/unity_task'
2
+ require 'pindo/base/funlog'
3
+
4
+ module Pindo
5
+ module TaskSystem
6
+ # Unity 配置编译模式任务
7
+ # 用于配置 Unity 项目的编译模式(dev/adhoc/release)
8
+ class UnityConfigTask < UnityTask
9
+ attr_reader :deploy_mode
10
+
11
+ def self.task_type
12
+ :unity_config
13
+ end
14
+
15
+ # @param deploy_mode [String] 部署模式 ('dev', 'adhoc', 'release')
16
+ # @param options [Hash] 额外选项
17
+ # - :project_path [String] Unity 项目路径(默认当前目录)
18
+ def initialize(deploy_mode = 'dev', options = {})
19
+ @deploy_mode = deploy_mode
20
+ @unity_exe_path = nil # 将在 do_work 中自动查找
21
+
22
+ # 传递 project_path 给基类
23
+ project_path = options[:project_path] || Dir.pwd
24
+ super("Unity 配置编译模式 (#{deploy_mode})", project_path: project_path, options: options)
25
+ end
26
+
27
+ def validate
28
+ super
29
+
30
+ # 验证 Unity 工程是否存在
31
+ unless unity_helper.unity_project?(@unity_root_path)
32
+ raise Informative, "当前目录不是 Unity 工程:#{@unity_root_path}"
33
+ end
34
+
35
+ # 验证 deploy_mode 参数
36
+ valid_modes = ['dev', 'adhoc', 'release']
37
+ unless valid_modes.include?(@deploy_mode)
38
+ raise Informative, "无效的编译模式: #{@deploy_mode},必须是 #{valid_modes.join(', ')}"
39
+ end
40
+
41
+ true
42
+ end
43
+
44
+ protected
45
+
46
+ def do_work
47
+ # 获取 Unity 版本
48
+ project_unity_version = get_unity_version
49
+
50
+ # 查找 Unity 执行路径
51
+ unless @unity_exe_path
52
+ @unity_exe_path = unity_helper.find_unity_path(
53
+ project_unity_version: project_unity_version,
54
+ force_change_version: false
55
+ )
56
+ end
57
+
58
+ if @unity_exe_path.nil? || @unity_exe_path.empty?
59
+ raise Informative, "无法找到 Unity 执行路径"
60
+ end
61
+
62
+ # 显示 Unity 信息
63
+ puts "项目路径: #{@unity_root_path}"
64
+ puts "Unity 执行路径: #{@unity_exe_path}"
65
+ puts "Unity 版本: #{project_unity_version}"
66
+ puts "编译模式: #{@deploy_mode}\n"
67
+
68
+ # 执行编译模式配置
69
+ result = config_build_mode
70
+
71
+ result
72
+ end
73
+
74
+ # 重写清理方法,提供更精确的参数
75
+ def cleanup_unity_processes
76
+ Funlog.warning("清理 Unity 进程...")
77
+ begin
78
+ Pindo::Unity::UnityProcHelper.cleanup_unity_processes_after_build(
79
+ unity_exe_full_path: @unity_exe_path,
80
+ project_path: @unity_root_path
81
+ )
82
+ rescue => e
83
+ Funlog.warning("清理 Unity 进程失败: #{e.message}")
84
+ end
85
+ end
86
+
87
+ private
88
+
89
+ # 配置编译模式
90
+ def config_build_mode
91
+ # 调用 UnityHelper 的 config_build_mode 方法
92
+ result = unity_helper.config_build_mode(
93
+ unity_exe_full_path: @unity_exe_path,
94
+ project_path: @unity_root_path,
95
+ deploy_mode: @deploy_mode
96
+ )
97
+
98
+ # 返回成功结果
99
+ {
100
+ success: true,
101
+ deploy_mode: @deploy_mode,
102
+ unity_result: result
103
+ }
104
+ end
105
+ end
106
+ end
107
+ end
@@ -1,34 +1,27 @@
1
- require_relative '../pindo_task'
1
+ require 'pindo/module/task/model/unity_task'
2
2
  require 'pindo/base/funlog'
3
3
 
4
4
  module Pindo
5
5
  module TaskSystem
6
- class UnityExportTask < PindoTask
7
- attr_reader :platform, :unity_project_path, :export_path
6
+ # Unity 导出任务
7
+ # 用于将 Unity 项目导出为指定平台(iOS/Android/WebGL)
8
+ class UnityExportTask < UnityTask
9
+ attr_reader :platform, :export_path, :deploy_mode, :is_library_mode
8
10
 
9
11
  def self.task_type
10
12
  :unity_export
11
13
  end
12
14
 
13
- # 重试配置
14
- def self.default_retry_mode
15
- RetryMode::DELAYED
16
- end
17
-
18
- def self.default_retry_count
19
- 2 # 可以重试 2 次
20
- end
21
-
22
- def self.default_retry_delay
23
- 10 # 延迟 10 秒
24
- end
25
-
15
+ # @param platform [String] 目标平台 ('ios', 'android', 'web')
16
+ # @param options [Hash] 额外选项
17
+ # - :project_path [String] Unity 项目路径(默认当前目录)
18
+ # - :export_path [String] 导出路径(nil 表示自动检测)
19
+ # - :deploy_mode [String] 部署模式 ('dev', 'adhoc', 'release'),默认 'dev'
20
+ # - :context [Hash] 上下文信息(如 index_count)
26
21
  def initialize(platform, options = {})
27
22
  @platform = platform
28
- @unity_project_path = options[:project_path] || Dir.pwd
29
23
  @unity_exe_path = nil # 将在 do_work 中自动查找
30
- @unity_helper = nil # 将在 do_work 中自动初始化
31
- @is_library_mode = false # 不再支持库模式
24
+ @is_library_mode = false
32
25
  @index_count = options[:context] ? options[:context][:index_count] : nil
33
26
  @export_path = options[:export_path] # 可由参数传入,nil 表示自动检测
34
27
  @deploy_mode = options[:deploy_mode] || 'dev' # 部署模式:dev/adhoc/release,默认 dev
@@ -44,18 +37,17 @@ module Pindo
44
37
  "Unity 导出 #{platform.upcase}"
45
38
  end
46
39
 
47
- super(name, options)
40
+ # 传递 project_path 给基类
41
+ project_path = options[:project_path] || Dir.pwd
42
+ super(name, project_path: project_path, options: options)
48
43
  end
49
44
 
50
45
  def validate
51
- # 验证 Unity 工程是否存在
52
- unless @unity_helper
53
- @unity_helper = Pindo::Client::UnityHelper.share_instance
54
- end
46
+ super
55
47
 
56
- unless @unity_helper.unity_project?(@unity_project_path)
57
- @error = "当前目录不是 Unity 工程:#{@unity_project_path}"
58
- return false
48
+ # 验证 Unity 工程是否存在
49
+ unless unity_helper.unity_project?(@unity_root_path)
50
+ raise Informative, "当前目录不是 Unity 工程:#{@unity_root_path}"
59
51
  end
60
52
 
61
53
  true
@@ -64,27 +56,26 @@ module Pindo
64
56
  protected
65
57
 
66
58
  def do_work
67
- # 确保 Unity helper 已初始化
68
- @unity_helper ||= Pindo::Client::UnityHelper.share_instance
69
-
70
59
  # 获取 Unity 版本
71
- project_unity_version = @unity_helper.get_unity_version(@unity_project_path)
60
+ project_unity_version = get_unity_version
72
61
 
73
62
  # 查找 Unity 执行路径
74
63
  unless @unity_exe_path
75
- @unity_exe_path = @unity_helper.find_unity_path(
64
+ @unity_exe_path = unity_helper.find_unity_path(
76
65
  project_unity_version: project_unity_version,
77
66
  force_change_version: false
78
67
  )
79
68
  end
80
69
 
81
70
  if @unity_exe_path.nil? || @unity_exe_path.empty?
82
- raise "无法找到 Unity 执行路径"
71
+ raise Informative, "无法找到 Unity 执行路径"
83
72
  end
84
73
 
85
74
  # 显示 Unity 信息
86
- Funlog.info("Unity 版本: #{project_unity_version}")
87
- Funlog.info("Unity 路径: #{@unity_exe_path}")
75
+ puts "项目路径: #{@unity_root_path}"
76
+ puts "Unity 执行路径: #{@unity_exe_path}"
77
+ puts "Unity 版本: #{project_unity_version}"
78
+ puts "部署模式: #{@deploy_mode}\n"
88
79
 
89
80
  # 执行 Unity 导出
90
81
  case @platform
@@ -95,20 +86,34 @@ module Pindo
95
86
  when 'web', 'html'
96
87
  export_web
97
88
  else
98
- raise "Unsupported platform: #{@platform}"
89
+ raise Informative, "不支持的平台: #{@platform}"
90
+ end
91
+ end
92
+
93
+ # 重写清理方法,提供更精确的参数
94
+ def cleanup_unity_processes
95
+ Funlog.warning("清理 Unity 进程...")
96
+ begin
97
+ Pindo::Unity::UnityProcHelper.cleanup_unity_processes_after_build(
98
+ unity_exe_full_path: @unity_exe_path,
99
+ project_path: @unity_root_path
100
+ )
101
+ rescue => e
102
+ Funlog.warning("清理 Unity 进程失败: #{e.message}")
99
103
  end
100
104
  end
101
105
 
102
106
  private
103
107
 
108
+ # 导出 iOS
104
109
  def export_ios
105
110
  platform = 'iOS'
106
111
 
107
112
  # 设置导出路径(如果未指定)
108
113
  if @export_path.nil?
109
114
  # 优先使用 BaseiOS,如果不存在则使用 iOS
110
- base_ios_path = File.join(@unity_project_path, "GoodPlatform", "BaseiOS")
111
- ios_path = File.join(@unity_project_path, "GoodPlatform", "iOS")
115
+ base_ios_path = File.join(@unity_root_path, "GoodPlatform", "BaseiOS")
116
+ ios_path = File.join(@unity_root_path, "GoodPlatform", "iOS")
112
117
 
113
118
  @export_path = if File.exist?(base_ios_path)
114
119
  base_ios_path
@@ -120,6 +125,10 @@ module Pindo
120
125
  # 根据导出路径判断是否为库模式
121
126
  @is_library_mode = @export_path.include?("BaseiOS")
122
127
 
128
+ puts "导出路径: #{@export_path}"
129
+ puts "导出平台: iOS"
130
+ puts "库模式: #{@is_library_mode ? '是' : '否'}\n"
131
+
123
132
  result = execute_unity_build(platform)
124
133
 
125
134
  {
@@ -130,14 +139,15 @@ module Pindo
130
139
  }
131
140
  end
132
141
 
142
+ # 导出 Android
133
143
  def export_android
134
144
  platform = 'Android'
135
145
 
136
146
  # 设置导出路径(如果未指定)
137
147
  if @export_path.nil?
138
148
  # 优先使用 BaseAndroid,如果不存在则使用 Android
139
- base_android_path = File.join(@unity_project_path, "GoodPlatform", "BaseAndroid")
140
- android_path = File.join(@unity_project_path, "GoodPlatform", "Android")
149
+ base_android_path = File.join(@unity_root_path, "GoodPlatform", "BaseAndroid")
150
+ android_path = File.join(@unity_root_path, "GoodPlatform", "Android")
141
151
 
142
152
  @export_path = if File.exist?(base_android_path)
143
153
  base_android_path
@@ -149,6 +159,10 @@ module Pindo
149
159
  # 根据导出路径判断是否为库模式
150
160
  @is_library_mode = @export_path.include?("BaseAndroid")
151
161
 
162
+ puts "导出路径: #{@export_path}"
163
+ puts "导出平台: Android"
164
+ puts "库模式: #{@is_library_mode ? '是' : '否'}\n"
165
+
152
166
  result = execute_unity_build(platform)
153
167
 
154
168
  {
@@ -159,13 +173,18 @@ module Pindo
159
173
  }
160
174
  end
161
175
 
176
+ # 导出 WebGL
162
177
  def export_web
163
178
  platform = 'WebGL'
164
- result = execute_unity_build(platform)
165
179
 
166
180
  # 设置导出路径(如果未指定)
167
181
  # Web 平台只有一个目录
168
- @export_path ||= File.join(@unity_project_path, "GoodPlatform", "WebGL")
182
+ @export_path ||= File.join(@unity_root_path, "GoodPlatform", "WebGL")
183
+
184
+ puts "导出路径: #{@export_path}"
185
+ puts "导出平台: WebGL\n"
186
+
187
+ result = execute_unity_build(platform)
169
188
 
170
189
  {
171
190
  success: true,
@@ -175,41 +194,19 @@ module Pindo
175
194
  }
176
195
  end
177
196
 
197
+ # 执行 Unity 导出
198
+ # Unity 进程管理(检查和清理)已封装在 UnityHelper.export_project 中
178
199
  def execute_unity_build(platform)
179
- # 检查 Unity 进程
180
- @unity_helper.check_unity_processes(
200
+ # 执行导出
201
+ unity_helper.export_project(
181
202
  unity_exe_full_path: @unity_exe_path,
182
- project_path: @unity_project_path
203
+ project_path: @unity_root_path,
204
+ platform: platform,
205
+ isLibrary: @is_library_mode,
206
+ indexNo: @index_count,
207
+ deployMode: @deploy_mode
183
208
  )
184
-
185
- # 执行构建
186
- begin
187
- result = @unity_helper.build_project(
188
- unity_exe_full_path: @unity_exe_path,
189
- project_path: @unity_project_path,
190
- platform: platform,
191
- isLibrary: @is_library_mode,
192
- indexNo: @index_count,
193
- deployMode: @deploy_mode
194
- )
195
-
196
- # 清理 Unity 进程
197
- @unity_helper.cleanup_unity_processes_after_build(
198
- unity_exe_full_path: @unity_exe_path,
199
- project_path: @unity_project_path
200
- )
201
-
202
- result
203
- rescue => e
204
- # 确保清理进程
205
- @unity_helper.cleanup_unity_processes_after_build(
206
- unity_exe_full_path: @unity_exe_path,
207
- project_path: @unity_project_path
208
- ) rescue nil
209
-
210
- raise e
211
- end
212
209
  end
213
210
  end
214
211
  end
215
- end
212
+ end
@@ -0,0 +1,94 @@
1
+ require 'pindo/module/task/model/unity_task'
2
+ require 'pindo/base/funlog'
3
+
4
+ module Pindo
5
+ module TaskSystem
6
+ # Unity 更新必备库任务
7
+ # 用于强制更新 Unity 项目的必备库(NugetForUnity)
8
+ class UnityUpdateTask < UnityTask
9
+ def self.task_type
10
+ :unity_update
11
+ end
12
+
13
+ # @param options [Hash] 额外选项
14
+ # - :project_path [String] Unity 项目路径(默认当前目录)
15
+ def initialize(options = {})
16
+ @unity_exe_path = nil # 将在 do_work 中自动查找
17
+
18
+ # 传递 project_path 给基类
19
+ project_path = options[:project_path] || Dir.pwd
20
+ super("Unity工具库更新", project_path: project_path, options: options)
21
+ end
22
+
23
+ def validate
24
+ super
25
+
26
+ # 验证 Unity 工程是否存在
27
+ unless unity_helper.unity_project?(@unity_root_path)
28
+ raise Informative, "当前目录不是 Unity 工程:#{@unity_root_path}"
29
+ end
30
+
31
+ true
32
+ end
33
+
34
+ protected
35
+
36
+ def do_work
37
+ # 获取 Unity 版本
38
+ project_unity_version = get_unity_version
39
+
40
+ # 查找 Unity 执行路径
41
+ unless @unity_exe_path
42
+ @unity_exe_path = unity_helper.find_unity_path(
43
+ project_unity_version: project_unity_version,
44
+ force_change_version: false
45
+ )
46
+ end
47
+
48
+ if @unity_exe_path.nil? || @unity_exe_path.empty?
49
+ raise Informative, "无法找到 Unity 执行路径"
50
+ end
51
+
52
+ # 显示 Unity 信息
53
+ puts "项目路径: #{@unity_root_path}"
54
+ puts "Unity 执行路径: #{@unity_exe_path}"
55
+ puts "Unity 版本: #{project_unity_version}\n"
56
+
57
+ # 执行必备库更新
58
+ result = force_update_libraries
59
+
60
+ result
61
+ end
62
+
63
+ # 重写清理方法,提供更精确的参数
64
+ def cleanup_unity_processes
65
+ Funlog.warning("清理 Unity 进程...")
66
+ begin
67
+ Pindo::Unity::UnityProcHelper.cleanup_unity_processes_after_build(
68
+ unity_exe_full_path: @unity_exe_path,
69
+ project_path: @unity_root_path
70
+ )
71
+ rescue => e
72
+ Funlog.warning("清理 Unity 进程失败: #{e.message}")
73
+ end
74
+ end
75
+
76
+ private
77
+
78
+ # 强制更新必备库
79
+ def force_update_libraries
80
+ # 调用 UnityHelper 的 force_update_libraries 方法
81
+ result = unity_helper.force_update_libraries(
82
+ unity_exe_full_path: @unity_exe_path,
83
+ project_path: @unity_root_path
84
+ )
85
+
86
+ # 返回成功结果
87
+ {
88
+ success: true,
89
+ unity_result: result
90
+ }
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,155 @@
1
+ require 'pindo/module/task/model/unity_task'
2
+ require 'pindo/base/funlog'
3
+
4
+ module Pindo
5
+ module TaskSystem
6
+ # Unity YooAsset 资源构建任务
7
+ # 用于构建 YooAsset 资源包
8
+ class UnityYooAssetTask < UnityTask
9
+ attr_reader :platform
10
+
11
+ def self.task_type
12
+ :unity_yoo_asset
13
+ end
14
+
15
+ # @param platform [String] 目标平台 ('ios', 'android', 'web')
16
+ # @param options [Hash] 额外选项
17
+ # - :project_path [String] Unity 项目路径(默认当前目录)
18
+ def initialize(platform, options = {})
19
+ @platform = platform
20
+ @unity_exe_path = nil # 将在 do_work 中自动查找
21
+
22
+ name = case platform
23
+ when 'ios', 'ipa'
24
+ "Unity资源Yoo 打包 iOS"
25
+ when 'android', 'apk'
26
+ "Unity资源Yoo 打包 Android"
27
+ when 'web', 'html'
28
+ "Unity资源Yoo 打包 WebGL"
29
+ else
30
+ "Unity资源Yoo 打包 #{platform.upcase}"
31
+ end
32
+
33
+ # 传递 project_path 给基类
34
+ project_path = options[:project_path] || Dir.pwd
35
+ super(name, project_path: project_path, options: options)
36
+ end
37
+
38
+ def validate
39
+ super
40
+
41
+ # 验证 Unity 工程是否存在
42
+ unless unity_helper.unity_project?(@unity_root_path)
43
+ raise Informative, "当前目录不是 Unity 工程:#{@unity_root_path}"
44
+ end
45
+
46
+ true
47
+ end
48
+
49
+ protected
50
+
51
+ def do_work
52
+ # 获取 Unity 版本
53
+ project_unity_version = get_unity_version
54
+
55
+ # 查找 Unity 执行路径
56
+ unless @unity_exe_path
57
+ @unity_exe_path = unity_helper.find_unity_path(
58
+ project_unity_version: project_unity_version,
59
+ force_change_version: false
60
+ )
61
+ end
62
+
63
+ if @unity_exe_path.nil? || @unity_exe_path.empty?
64
+ raise Informative, "无法找到 Unity 执行路径"
65
+ end
66
+
67
+ # 显示 Unity 信息
68
+ puts "项目路径: #{@unity_root_path}"
69
+ puts "Unity 执行路径: #{@unity_exe_path}"
70
+ puts "Unity 版本: #{project_unity_version}"
71
+ puts "目标平台: #{normalize_platform_name(@platform)}\n"
72
+
73
+ # 执行 YooAsset 构建
74
+ result = build_yoo_asset
75
+
76
+ result
77
+ end
78
+
79
+ # 重写清理方法,提供更精确的参数
80
+ def cleanup_unity_processes
81
+ Funlog.warning("清理 Unity 进程...")
82
+ begin
83
+ Pindo::Unity::UnityProcHelper.cleanup_unity_processes_after_build(
84
+ unity_exe_full_path: @unity_exe_path,
85
+ project_path: @unity_root_path
86
+ )
87
+ rescue => e
88
+ Funlog.warning("清理 Unity 进程失败: #{e.message}")
89
+ end
90
+ end
91
+
92
+ private
93
+
94
+ # 构建 YooAsset 资源
95
+ def build_yoo_asset
96
+ platform_name = normalize_platform_name(@platform)
97
+
98
+ # 调用 UnityHelper 的 build_yoo_asset 方法
99
+ result = unity_helper.build_yoo_asset(
100
+ unity_exe_full_path: @unity_exe_path,
101
+ project_path: @unity_root_path,
102
+ platform: platform_name
103
+ )
104
+
105
+ # 如果跳过(YooAsset 不存在),输出警告并显示命令
106
+ if result[:skipped]
107
+ Funlog.warning("项目中未检测到 YooAsset,跳过资源构建")
108
+ print_unity_command
109
+
110
+ return {
111
+ success: true,
112
+ skipped: true,
113
+ platform: @platform,
114
+ reason: result[:reason]
115
+ }
116
+ end
117
+
118
+ # 正常完成
119
+ {
120
+ success: true,
121
+ platform: @platform,
122
+ unity_result: result
123
+ }
124
+ end
125
+
126
+ # 打印将要执行的 Unity 命令
127
+ def print_unity_command
128
+ platform_name = normalize_platform_name(@platform)
129
+
130
+ cmd = "#{@unity_exe_path} -batchmode -quit " \
131
+ "-projectPath #{@unity_root_path} " \
132
+ "-executeMethod Yoo.Editor.YooCommandHelper.BatchBuild " \
133
+ "-platform #{platform_name}"
134
+
135
+ puts "\n本应执行的 Unity 命令:"
136
+ puts cmd
137
+ puts ""
138
+ end
139
+
140
+ # 标准化平台名称
141
+ def normalize_platform_name(platform)
142
+ case platform
143
+ when 'ios', 'ipa'
144
+ 'iOS'
145
+ when 'android', 'apk'
146
+ 'Android'
147
+ when 'web', 'html'
148
+ 'WebGL'
149
+ else
150
+ platform.to_s
151
+ end
152
+ end
153
+ end
154
+ end
155
+ end