Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

739 wiersze
23 KiB

  1. -- package.path = ";preload/?.lua"
  2. -- package.path = package.path .. "?;?.lua;preload/?.lua"
  3. -- package.path = package.path .. ";preload/tools/?.lua"
  4. -- package.path = package.path .. ";Editor/?.lua"
  5. -- package.path = package.path .. ";luaScript/?.lua"
  6. -- package.path = package.path .. ";dataconfig/?.lua"
  7. -- package.path = package.path .. ";romFiles/?.lua"
  8. -- package.path = package.path .. ";luaScript/cc/?.lua"
  9. -- package.path = package.path .. ";luaScript/Tools/?.lua"
  10. -- package.path = package.path .. ";luaScript/Tools/Nodes/?.lua"
  11. -- package.path = package.path .. ";luaScript/Tools/Widgets/?.lua"
  12. -- package.path = package.path .. ";luaScript/Tools/Tracks/?.lua"
  13. -- package.path = package.path .. ";luaScript/Tools/Effect/?.lua"
  14. -- package.path = package.path .. ";luaScript/Tools/Other/?.lua"
  15. -- package.path = package.path .. ";luaScript/Tools/Effect/ParticleSystem/?.lua"
  16. -- package.path = package.path .. ";luaScript/Tools/Effect/ParticleSystem/Affector/?.lua"
  17. -- package.path = package.path .. ";luaScript/Tools/Effect/ParticleSystem/Emitter/?.lua"
  18. -- package.path = package.path .. ";luaScript/Protocol/?.lua"
  19. -- package.path = package.path .. ";luaScript/Config/?.lua"
  20. -- package.path = package.path .. ";luaScript/Extension/?.lua"
  21. -- package.path = package.path .. ";luaScript/Map/?.lua"
  22. -- package.path = package.path .. ";luaScript/Views/?.lua"
  23. -- package.path = package.path .. ";luaScript/Config/Languages/?.lua"
  24. -- package.path = package.path .. ";luaScript/Config/ConfigDesc/?.lua"
  25. -- package.path = package.path .. ";luaScript/User/?.lua"
  26. -- package.path = package.path .. ";luaScript/Learning/?.lua"
  27. -- package.path = package.path .. ";luaScript/Learning/Script/?.lua"
  28. -- cc.FileUtils:getInstance():addSearchPath("core")
  29. -- cc.FileUtils:getInstance():addSearchPath("core/preload")
  30. -- cc.FileUtils:getInstance():addSearchPath("core/preload/tools")
  31. -- cc.FileUtils:getInstance():addSearchPath("core/Editor")
  32. -- cc.FileUtils:getInstance():addSearchPath("core/luaScript")
  33. -- cc.FileUtils:getInstance():addSearchPath("core/dataconfig")
  34. -- cc.FileUtils:getInstance():addSearchPath("core/romFiles")
  35. -- cc.FileUtils:getInstance():addSearchPath("core/luaScript/cc")
  36. -- cc.FileUtils:getInstance():addSearchPath("core/luaScript/Tools")
  37. -- cc.FileUtils:getInstance():addSearchPath("core/luaScript/Tools/Other")
  38. -- cc.FileUtils:getInstance():addSearchPath("core/luaScript/Tools/Nodes")
  39. -- cc.FileUtils:getInstance():addSearchPath("core/luaScript/Tools/Widgets")
  40. -- cc.FileUtils:getInstance():addSearchPath("core/luaScript/Tools/Tracks")
  41. -- cc.FileUtils:getInstance():addSearchPath("core/luaScript/Tools/Effect")
  42. -- cc.FileUtils:getInstance():addSearchPath("core/luaScript/Tools/Effect/ParticleSystem")
  43. -- cc.FileUtils:getInstance():addSearchPath("core/luaScript/Tools/Effect/ParticleSystem/Affector")
  44. -- cc.FileUtils:getInstance():addSearchPath("core/luaScript/Tools/Effect/ParticleSystem/Emitter")
  45. -- cc.FileUtils:getInstance():addSearchPath("core/luaScript/Protocol")
  46. -- cc.FileUtils:getInstance():addSearchPath("core/luaScript/Config")
  47. -- cc.FileUtils:getInstance():addSearchPath("core/luaScript/Extension")
  48. -- cc.FileUtils:getInstance():addSearchPath("core/luaScript/Map")
  49. -- cc.FileUtils:getInstance():addSearchPath("core/luaScript/Views")
  50. -- cc.FileUtils:getInstance():addSearchPath("core/luaScript/Config/Languages")
  51. -- cc.FileUtils:getInstance():addSearchPath("core/luaScript/Config/ConfigDesc")
  52. -- cc.FileUtils:getInstance():addSearchPath("core/luaScript/User")
  53. -- cc.FileUtils:getInstance():addSearchPath("core/luaScript/Plugins")
  54. -- cc.FileUtils:getInstance():addSearchPath("core/luaScript/PluginAdvertise")
  55. -- cc.FileUtils:getInstance():addSearchPath("core/luaScript/Learning")
  56. -- cc.FileUtils:getInstance():addSearchPath("core/luaScript/Learning/Script")
  57. require("EditorGlobalFunction")
  58. require("CCBoxNode")
  59. require("NodeEditor")
  60. require("ObstacleTool")
  61. require("CombineEffectEditor")
  62. require("CCNode")
  63. require("CCEffectNode")
  64. require("CCEffectFileEffectNode")
  65. require("CCParticleEffectNode")
  66. require("CCCombineEffect")
  67. require("MapEditor")
  68. require("EditorNodeZorder")
  69. require("AnimEntityInstance")
  70. require("UndoRedoManager")
  71. require("MoveTool")
  72. require("Move2DTool")
  73. require("Move3DTool")
  74. require("preload")
  75. local EditorApp = class("EditorApp", cc.mvc.AppBase)
  76. function EditorApp:ctor()
  77. EditorApp.super.ctor(self);
  78. -- 用来保存C#提供的回调函数
  79. -- NodeEditor提供setPropertyObject
  80. self.cs = {};
  81. -- 当前的编辑器
  82. self.editor = nil;
  83. -- 鼠标移动工具
  84. self.cameraController = require("Camera2DControllerTool"):new();
  85. -- 撤销管理器
  86. self.undoRedoManager = require("UndoRedoManager"):new();
  87. -- 主场景
  88. self.mainScene = nil
  89. -- 主画布
  90. self.mainLayer = nil
  91. -- 主相机
  92. self.mainCamera = nil
  93. -- 移动工具
  94. self.activeMoveTool = require("Move2DTool"):new();
  95. -- 底图
  96. self.background = nil
  97. -- 自定义侦听渲染的listener
  98. self.eventAfterDrawListener = nil
  99. -- 对齐工具
  100. self.alignTool = require("AlignTool"):new();
  101. self.setting =
  102. {
  103. GridColor = cc.c4f(1,1,0,1),
  104. AxisColor = cc.c4f(1,1,1,1),
  105. GridSize = cc.size(100,100),
  106. ResourceSize = cc.size(1280,720),
  107. BackgroundColor = cc.c4b(0,0,0 , 255),
  108. BackgroundImage = "",
  109. ShowFPS = false,
  110. ShowGrid = true,
  111. ShowIPhone5 = false,
  112. ScreenScale = 1,
  113. ScreenScaleMax = 16,
  114. ScreenScaleMin = 0.1,
  115. -- 技能源模型文件
  116. SourceModelFile = "res/default/DefaultModel/DefaultModel.gpb";
  117. -- 技能目标模型文件
  118. TargetModelFile = "res/default/DefaultModel/DefaultModel.gpb";
  119. -- 显示碰撞体的调试信息
  120. ShowCollision = false;
  121. OriginAnchor = cc.p(0.5,0.5),
  122. DisableAudio = false;
  123. -- 默认是否播放UI动画
  124. PlayUIAnimation = false;
  125. }
  126. self.config = {Setting = self.setting};
  127. -- 可见区域
  128. self.visibleRect = require("VisibleRect"):new();
  129. self.cameraNode3D = nil;
  130. end
  131. function EditorApp:createObject(name)
  132. return require(name):new();
  133. end
  134. -- 获取操作的相机
  135. function EditorApp:getMainCameraShakeNode()
  136. return self.mainCamera:getNode();
  137. end
  138. -- 激活一个编辑器
  139. function EditorApp:activateEditor(editorName)
  140. if self.editor then
  141. self.editor:unactivate();
  142. end
  143. self.editor = require(editorName):new();
  144. self.editor:activate();
  145. -- 清空undo redo列表
  146. self.undoRedoManager:clear();
  147. end
  148. function EditorApp:activate2DCamera()
  149. self.mainCamera = cc.Director:getInstance():getActiveCamera();
  150. self.cameraController = require("Camera2DControllerTool"):new();
  151. self.mainLayer:setActiveCamera(nil);
  152. self.cameraController:update();
  153. self.cameraController:refreshSetting();
  154. -- 切换移动工具
  155. self.activeMoveTool:clear();
  156. self.activeMoveTool = require("Move2DTool"):new();
  157. cc.AudioListener:getInstance():setCamera(self.mainCamera);
  158. end
  159. function EditorApp:activate3DCamera()
  160. if not self.cameraNode3D then
  161. -- 创建透视投影相机
  162. local camera = cc.Camera:createPerspective(45 , 1 , 1 , 1000);
  163. cc.Director:getInstance():getActiveCamera():getNode():setScale(1.0);
  164. local cameraNode = cc.Node3D:create("CameraNode3D");
  165. cameraNode:addComponent(camera);
  166. local cameraParentNode = cc.Node3D:create();
  167. cameraParentNode:addChild(cameraNode)
  168. self.mainLayer:addChild(cameraParentNode);
  169. self.cameraNode3D = cameraNode;
  170. end
  171. self.mainLayer:setActiveCamera(self.cameraNode3D:getCamera());
  172. self.mainCamera = self.cameraNode3D:getCamera();
  173. self.mainCamera:setAspectRatio(cc.Director:getInstance():getWinSize().width / cc.Director:getInstance():getWinSize().height);
  174. self.cameraController = require("Camera3DControllerTool"):new();
  175. self.cameraController:update();
  176. self.cameraController:refreshSetting();
  177. -- 切换移动工具
  178. self.activeMoveTool:clear();
  179. self.activeMoveTool = require("Move3DTool"):new();
  180. cc.AudioListener:getInstance():setCamera(self.mainCamera);
  181. end
  182. -- 获取相机
  183. function EditorApp:getActivateCamera()
  184. return self.mainCamera
  185. end
  186. -- 激活一个自定义相机
  187. function EditorApp:activateCustomCamera(camera)
  188. self.mainLayer:setActiveCamera(camera);
  189. self.mainCamera = camera;
  190. self.cameraController = require("Camera3DControllerTool"):new();
  191. self.cameraController:update();
  192. self.cameraController:refreshSetting();
  193. -- 切换移动工具
  194. self.activeMoveTool:clear();
  195. self.activeMoveTool = require("Move3DTool"):new();
  196. cc.AudioListener:getInstance():setCamera(self.mainCamera);
  197. end
  198. function EditorApp:isActiveCamera(camera)
  199. return self.mainCamera == camera;
  200. end
  201. function EditorApp:is3DCamera()
  202. if self.mainLayer:getActiveCamera() == nil or self.mainLayer:getActiveCamera() then
  203. return false;
  204. end
  205. return true;
  206. end
  207. -- 反激活一个编辑器
  208. function EditorApp:unactivateEditor(editorName)
  209. if self.editor and iskindof(self.editor , editorName) then
  210. self.editor:unactivate();
  211. self.editor = nil;
  212. end
  213. -- 清空undo redo列表
  214. self.undoRedoManager:clear();
  215. end
  216. function EditorApp:run()
  217. -- 创建默认场景
  218. self.mainScene = cc.Scene:create();
  219. local layer = cc.Scene:create();
  220. layer:setContentSize(self.setting.ResourceSize);
  221. layer:setAnchorPoint(cc.p(0,0));
  222. self.mainLayer = layer;
  223. self.mainScene:addChild(layer);
  224. -- 默认不使用这个2D相机
  225. self.mainLayer:setActiveCamera(nil);
  226. local background = cc.Layer:create();
  227. self.background = background;
  228. self.mainLayer:addChild(background, EditorNodeZorder.CoordinateNodeZorder);
  229. -- 默认加载通用图
  230. cc.SpriteFrameCache:getInstance():addSpriteFramesWithFile("res/default/default-textures.plist");
  231. cc.SpriteFrameCache:getInstance():addSpriteFramesWithFile("res/ui/zy_tongyong/t_tongyong_1.plist");
  232. cc.SpriteFrameCache:getInstance():addSpriteFramesWithFile("res/ui/zy_tongyong/t_tongyong_2.plist");
  233. -- 默认使用2D相机
  234. self:activate2DCamera();
  235. cc.StreamObject:addIgnoreDir("core");
  236. cc.StreamObject:addIgnoreDir("huanle");
  237. cc.StreamObject:addIgnoreDir("chuannan");
  238. cc.StreamObject:addIgnoreDir("youxianmj");
  239. cc.StreamObject:addIgnoreDir("chongqing");
  240. cc.StreamObject:addIgnoreDir("shuzhou");
  241. cc.Director:getInstance():runWithScene(self.mainScene)
  242. self:refreshSetting();
  243. end
  244. function EditorApp:getOriginOffset()
  245. return cc.p(cc.Director:getInstance():getWinSize().width * self.setting.OriginAnchor.x , cc.Director:getInstance():getWinSize().height * self.setting.OriginAnchor.y);
  246. end
  247. -- 改变编辑器大小
  248. function EditorApp:resize(w , h)
  249. self.mainCamera:setAspectRatio(w/h);
  250. cc.Application:getInstance():applicationScreenSizeChanged(w, h);
  251. cc.Director:getInstance():getOpenGLView():setDesignResolutionSize(w , h , cc.ResolutionPolicy.EXACT_FIT);
  252. self.mainScene:setScale(self.setting.ScreenScale);
  253. -- 通知可见区域更新
  254. self.visibleRect:updateVisibleRect();
  255. --self.mainScene:setContentSize(cc.Director:getInstance():getWinSize());
  256. self.background:setContentSize(cc.Director:getInstance():getWinSize());
  257. --self.mainLayer:setContentSize(cc.Director:getInstance():getWinSize());
  258. self:refreshSetting();
  259. end
  260. -- 创建网格
  261. function EditorApp:refreshSetting()
  262. -- 设置全局缩放
  263. local pDirector = cc.Director:getInstance();
  264. local pEGLView = cc.Director:getInstance():getOpenGLView();
  265. cc.Director:getInstance():getOpenGLView():setDesignResolutionSize(pEGLView:getFrameSize().width , pEGLView:getFrameSize().height , cc.ResolutionPolicy.EXACT_FIT);
  266. --self.mainScene:setScale(self.setting.ScreenScale);
  267. -- 居中
  268. --self.mainLayer:setPosition(self:getOriginOffset());
  269. -- 更新相机控制器
  270. self.cameraController:refreshSetting();
  271. local pDirector = cc.Director:getInstance();
  272. pDirector:setDisplayStats(self.setting.ShowFPS);
  273. -- 是否需要显示碰撞体
  274. if self.setting.ShowCollision == true and self.eventAfterDrawListener == nil then
  275. self.eventAfterDrawListener = cc.EventListenerCustom:create("director_after_draw" , handler(self , self.onUpdate));
  276. cc.Director:getInstance():getEventDispatcher():addEventListenerWithFixedPriority(self.eventAfterDrawListener, 1);
  277. elseif self.setting.ShowCollision == false and self.eventAfterDrawListener ~= nil then
  278. cc.Director:getInstance():getEventDispatcher():removeEventListener(self.eventAfterDrawListener)
  279. self.eventAfterDrawListener = nil
  280. end
  281. local winSize = self.setting.ResourceSize;
  282. local resourceSize = {width = 1280 ; height = 720};
  283. -- 实际比率
  284. local radio = winSize.width / winSize.height;
  285. -- 标准比率
  286. local resourceRadio = resourceSize.width / resourceSize.height;
  287. print("实际分辨率" , winSize.width , winSize.height);
  288. local finalResourceSize;
  289. -- 比16:9还扁,就用标准高度,让宽度变宽
  290. if radio > resourceRadio then
  291. finalResourceSize = {width = resourceSize.height * radio ; height = resourceSize.height};
  292. -- 比16:9高,就固定宽度,让高度变高
  293. else
  294. finalResourceSize = {width = resourceSize.width ; height = resourceSize.width / radio};
  295. end
  296. print("资源分辨率" , finalResourceSize.width , finalResourceSize.height);
  297. -- 改变屏幕大小
  298. self.mainLayer:setContentSize(finalResourceSize);
  299. -- 更新UI尺寸
  300. if self.editor and self.editor.node and self.editor.node.updateSizeAndPosition then
  301. self.editor.node:updateSizeAndPosition();
  302. end
  303. end
  304. function EditorApp:onUpdate()
  305. cc.PhysicsController:getInstance():drawDebug(self.mainCamera:getViewProjectionMatrix())
  306. end
  307. function EditorApp:reload()
  308. if self.effect then
  309. local xmlNode = self.effect:createXmlNode();
  310. self.effect:removeFromParent();
  311. cc.TextureCache:sharedTextureCache():removeUnusedTextures();
  312. self.effect = createEffectFromXmlNode(xmlNode);
  313. self:initEffect(self.effect)
  314. return self.effect;
  315. elseif self.combineEffect then
  316. cc.TextureCache:sharedTextureCache():removeUnusedTextures();
  317. return self.combineEffect;
  318. end
  319. end
  320. -- 生成一个目录
  321. local function visitPath(sourcePath , func , ...)
  322. print("开始生成目录" .. sourcePath)
  323. -- 递归遍历sourcePath的所有目录
  324. for file in lfs.dir(sourcePath) do
  325. if file ~= "." and file ~= ".." then
  326. local f = sourcePath..'/'..file
  327. local attr = lfs.attributes (f , "mode")
  328. if attr == "directory" then
  329. if visitPath(f , func , ...) then
  330. return true;
  331. end
  332. else
  333. if func(f , ...) then
  334. return true;
  335. end
  336. end
  337. end
  338. end
  339. print("生成目录完毕" .. sourcePath)
  340. end
  341. -- 重新保存所有UI
  342. function EditorApp:resaveAllUI()
  343. local function saveui(fileName)
  344. -- 返回pathName , baseName , ext
  345. local pathName , baseName , ext = string.splitFilename(fileName);
  346. print(pathName , baseName , ext);
  347. if ext ~= "ui" then
  348. return false;
  349. end
  350. local function resaveUI()
  351. print("\n\n");
  352. print("正在加载UI:" , fileName);
  353. local node = createNodeFromFile(fileName);
  354. print("正在重新计算PList");
  355. node:recalcAllPList();
  356. print("正在保存UI:" , fileName);
  357. node:saveToFile(fileName);
  358. end
  359. xpcall(resaveUI , function(msg)print("处理界面“" .. fileName .. "”时出错了:" , msg , debug.traceback());alert("处理界面“" .. fileName .. "”时出错了");end);
  360. end
  361. cc.BaseObject:setUpgradingMode(true);
  362. visitPath("res" , saveui);
  363. cc.BaseObject:setUpgradingMode(false);
  364. end
  365. -- 重新保存所有Model
  366. function EditorApp:resaveAllModel()
  367. local function saveui(fileName)
  368. -- 返回pathName , baseName , ext
  369. local pathName , baseName , ext = string.splitFilename(fileName);
  370. print(pathName , baseName , ext);
  371. if ext ~= "gpb" then
  372. return false;
  373. end
  374. local function resaveUI()
  375. print("\n\n");
  376. print("正在加载Model:" , fileName);
  377. local node = cc.ModelNode:create(fileName);
  378. local function onLoad(index)
  379. local skinMesh = node:_getFirstMeshSkin();
  380. if skinMesh then
  381. print("蒙皮骨头数量:" , skinMesh:getJointCount());
  382. if skinMesh:getJointCount() >= 39 then
  383. print("蒙皮骨头数量超过了39个:" , skinMesh:getJointCount());
  384. end
  385. end
  386. node:autorelease();
  387. end
  388. node:runOnLoad(onLoad);
  389. node:retain();
  390. print("正在保存Model:" , fileName);
  391. --node:saveToFile(fileName);
  392. end
  393. xpcall(resaveUI , function()print("处理Effect“" .. fileName .. "”时出错了");alert("处理Effect“" .. fileName .. "”时出错了");end);
  394. end
  395. cc.BaseObject:setUpgradingMode(true);
  396. visitPath("res" , saveui);
  397. cc.BaseObject:setUpgradingMode(false);
  398. end
  399. -- 重新保存所有Effect
  400. function EditorApp:resaveAllEffect()
  401. local function saveui(fileName)
  402. -- 返回pathName , baseName , ext
  403. local pathName , baseName , ext = string.splitFilename(fileName);
  404. print(pathName , baseName , ext);
  405. if ext ~= "effect" then
  406. return false;
  407. end
  408. local function resaveUI()
  409. print("\n\n");
  410. print("正在加载Effect:" , fileName);
  411. local node = createNodeFromFile(fileName);
  412. print("正在保存Effect:" , fileName);
  413. node:saveToFile(fileName);
  414. end
  415. xpcall(resaveUI , function()print("处理Effect“" .. fileName .. "”时出错了");alert("处理Effect“" .. fileName .. "”时出错了");end);
  416. end
  417. cc.BaseObject:setUpgradingMode(true);
  418. visitPath("res" , saveui);
  419. cc.BaseObject:setUpgradingMode(false);
  420. end
  421. -- 重新保存所有CE
  422. function EditorApp:resaveAllCE()
  423. local function saveCE(fileName)
  424. -- 返回pathName , baseName , ext
  425. local pathName , baseName , ext = string.splitFilename(fileName);
  426. print(pathName , baseName , ext);
  427. if ext ~= "ce" then
  428. return false;
  429. end
  430. local function resaveCE()
  431. print("\n\n");
  432. print("正在加载CE:" , fileName);
  433. local node = createCombineEffectFromXmlFile(fileName);
  434. print("正在保存CE:" , fileName);
  435. node:saveToFile(fileName);
  436. end
  437. xpcall(resaveCE , function()print("处理CE“" .. fileName .. "”时出错了");alert("处理CE“" .. fileName .. "”时出错了");end);
  438. end
  439. cc.BaseObject:setUpgradingMode(true);
  440. visitPath("res" , saveCE);
  441. cc.BaseObject:setUpgradingMode(false);
  442. end
  443. -- 重新保存所有Scene
  444. function EditorApp:resaveAllScene()
  445. -- 载入场景文件
  446. local function loadScene(nodeFile)
  447. print("加载场景" , nodeFile);
  448. TimeSpan:enterSpan("loadScene" .. nodeFile);
  449. TimeSpan:enterSpan("createNodeFromFile");
  450. print("加载模型");
  451. LoadingScene = true;
  452. local node = createNodeFromFile(nodeFile);
  453. LoadingScene = false;
  454. node:setCollectAnimationClip(false);
  455. TimeSpan:leaveSpan();
  456. if not EditorMode then
  457. -- 普通模式,屏蔽掉HD内容
  458. local hd = node:findNode("HD");
  459. if hd then
  460. local function onQualityChanged(key , value)
  461. -- 高质量
  462. hd:setVisible(value == 1);
  463. end
  464. hd:bind(app.systemSetting.info , "graphicQuality" , onQualityChanged);
  465. end
  466. end
  467. -- 创建一个题图载入资源
  468. TimeSpan:enterSpan("requireMap");
  469. print("加载障碍块");
  470. local map = require("Map"):new();
  471. local arr = string.split(nodeFile, ".");
  472. map:loadLua(arr[1] .. ".lmap");
  473. TimeSpan:leaveSpan();
  474. TimeSpan:leaveSpan();
  475. return node , map;
  476. end
  477. local function saveui(fileName)
  478. -- 返回pathName , baseName , ext
  479. local pathName , baseName , ext = string.splitFilename(fileName);
  480. print(pathName , baseName , ext);
  481. if ext ~= "scene" then
  482. return false;
  483. end
  484. local function resaveUI()
  485. print("\n\n");
  486. print("正在加载Scene:" , fileName);
  487. local scene , map = loadScene(fileName);
  488. print("正在保存Scene:" , fileName);
  489. scene:saveToFile(fileName);
  490. local arr = string.split(fileName, ".");
  491. map:saveLua(arr[1] .. ".lmap");
  492. map:saveXml(arr[1] .. ".map");
  493. end
  494. xpcall(resaveUI , function(msg)print("处理Scene“" .. fileName .. "”时出错了:" , msg);alert("处理Scene“" .. fileName .. "”时出错了:" .. tostring(msg));end);
  495. end
  496. cc.BaseObject:setUpgradingMode(true);
  497. visitPath("res" , saveui);
  498. cc.BaseObject:setUpgradingMode(false);
  499. end
  500. -- 解析所有的配置,导出所有使用过的资源
  501. function EditorApp:exportAllRes(destPath)
  502. local fileVisitor = cc.ReferanceResourceVisitor:new()
  503. local function exportRes(resFile)
  504. print("资源名字", resFile)
  505. if string.endsWith(resFile, ".gpb") then
  506. local model = cc.ModelNode:create(resFile);
  507. model:visitReferanceResource(fileVisitor)
  508. elseif string.endsWith(resFile, ".scene") then
  509. local object = cc.StreamObject:loadFromFile(resFile)
  510. if object then
  511. object:visitReferanceResource(fileVisitor)
  512. -- 保存地图相关的资源
  513. fileVisitor:visitFile(resFile)
  514. local stringArr = string.split(resFile, ".");
  515. fileVisitor:visitFile(stringArr[1] .. ".lmap")
  516. fileVisitor:visitFile(stringArr[1] .. ".lmap.blocks")
  517. fileVisitor:visitFile(stringArr[1] .. ".map")
  518. end
  519. elseif string.endsWith(resFile, ".ui")
  520. or string.endsWith(resFile, ".ce")
  521. or string.endsWith(resFile, ".effect") then
  522. -- 导出资源本身
  523. local object = cc.StreamObject:loadFromFile(resFile)
  524. if object then
  525. fileVisitor:visitFile(resFile)
  526. object:visitReferanceResource(fileVisitor)
  527. end
  528. elseif string.endsWith(resFile, ".ogg")
  529. or string.endsWith(resFile, ".png")
  530. or string.endsWith(resFile, ".jpg") then
  531. fileVisitor:visitFile(resFile)
  532. elseif string.endsWith(resFile, ".plist") then
  533. local stringArr = string.split(resFile, ".");
  534. fileVisitor:visitFile(resFile)
  535. fileVisitor:visitFile(stringArr[1] .. ".png")
  536. end
  537. end
  538. local function visitOneData(cf)
  539. if table.nums(cf) <= 0 then
  540. return
  541. end
  542. for i, v in pairs(cf) do
  543. if type(v) == "string" and v ~= "" then
  544. local strs = string.split(v, ";")
  545. for ii, vv in pairs(strs) do
  546. exportRes(vv)
  547. end
  548. end
  549. end
  550. end
  551. local function parseXmlFile(fileName)
  552. print("解析xml文件", fileName)
  553. -- 读取整个文件数据
  554. local file = io.open(fileName , "rb");
  555. local fileData = file:read("*a");
  556. file:close();
  557. -- 解析数据
  558. local function onElementStart(name, atts)
  559. visitOneData(atts)
  560. end
  561. -- 这里不能使用xml.eval来解析,android下面,如果下载的文件不是xml格式的,则会宕机
  562. local result , err = tiny.eval(fileData, onElementStart)
  563. if not result then
  564. print("xml文件解析失败", fileName)
  565. return;
  566. end
  567. end
  568. local function parseLuaFile(fileName)
  569. print("处理lua文件", fileName)
  570. local file = io.open(fileName , "rb");
  571. local fileData = file:read("*a");
  572. file:close();
  573. local uiFile = nil
  574. -- 导出UI
  575. for w in string.gmatch(fileData, '"([%w_/]+)%.ui"') do
  576. uiFile = w .. ".ui"
  577. exportRes(uiFile)
  578. end
  579. -- 导出技能
  580. for w in string.gmatch(fileData, '"([%w_/]+)%.ce"') do
  581. uiFile = w .. ".ce"
  582. exportRes(uiFile)
  583. end
  584. -- 导出光效
  585. for w in string.gmatch(fileData, '"([%w_/]+)%.effect"') do
  586. uiFile = w .. ".effect"
  587. exportRes(uiFile)
  588. end
  589. -- 导出模型
  590. for w in string.gmatch(fileData, '"([%w_/]+)%.gpb"') do
  591. uiFile = w .. ".gpb"
  592. exportRes(uiFile)
  593. end
  594. -- 导出plist
  595. for w in string.gmatch(fileData, '"([%w_/]+)%.plist"') do
  596. uiFile = w .. ".plist"
  597. exportRes(uiFile)
  598. end
  599. -- 导出png
  600. for w in string.gmatch(fileData, '"([%w_/]+)%.png"') do
  601. uiFile = w .. ".png"
  602. exportRes(uiFile)
  603. end
  604. -- 导出jpg
  605. for w in string.gmatch(fileData, '"([%w_/]+)%.jpg"') do
  606. uiFile = w .. ".jpg"
  607. exportRes(uiFile)
  608. end
  609. -- 导出声音
  610. for w in string.gmatch(fileData, '"([%w_/]+)%.ogg"') do
  611. uiFile = w .. ".ogg"
  612. exportRes(uiFile)
  613. end
  614. -- 字体
  615. for w in string.gmatch(fileData, '"([%w_/]+)%.fnt"') do
  616. uiFile = w .. ".fnt"
  617. exportRes(uiFile)
  618. end
  619. end
  620. -- 遍历dataconfig目录的所有文件
  621. visitPath("dataconfig", parseXmlFile);
  622. visitPath("luaScript", parseLuaFile);
  623. visitPath("preload", parseLuaFile);
  624. --exportRes("res/animation/XJL_1/XJL_1.effect")
  625. fileVisitor:saveAllRes(destPath)
  626. print("导出资源路径", destPath)
  627. alert("资源导出完毕")
  628. end
  629. return EditorApp;