当前位置:   article > 正文

Unity自动保存场景脚本

unity 保存脚本

1 自动保存场景脚本,是一个js脚本,放到Editor文件夹下,在任务栏的Window下就可以看到SimpleSave了,点击后会打开一个小窗口,这个窗口必须一直存在前台,关闭就会停止.

saveTime : 是30秒保存一次

  1. import UnityEditor;
  2. class SimpleAutoSave extends EditorWindow {
  3. var saveTime : float = 30;
  4. var nextSave : float = 0;
  5. @MenuItem("Window/SimpleSave")
  6. static function Init() {
  7. var window : SimpleAutoSave =
  8. EditorWindow.GetWindowWithRect(
  9. SimpleAutoSave,
  10. Rect(0,0,165,40));
  11. window.Show();
  12. }
  13. function OnEnable(){
  14. nextSave = EditorApplication.timeSinceStartup + saveTime;
  15. }
  16. function OnGUI() {
  17. EditorGUILayout.LabelField("Save Each:", saveTime + " Secs");
  18. var timeToSave : int = nextSave - EditorApplication.timeSinceStartup;
  19. EditorGUILayout.LabelField("Next Save:", timeToSave.ToString() + " Sec");
  20. this.Repaint();
  21. if(EditorApplication.timeSinceStartup > nextSave) {
  22. var path = EditorApplication.currentScene;
  23. try{
  24. EditorApplication.SaveScene(path);
  25. }
  26. catch(error){
  27. }
  28. nextSave = EditorApplication.timeSinceStartup + saveTime;
  29. }
  30. }
  31. }
  32. 复制代码

转载于:https://juejin.im/post/5b3ac88cf265da63252c2eaf

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号