VR Development Framework
v 1.0.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
PackageBuilder.cs
1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEditor.PackageManager.Requests;
4 using UnityEditor.PackageManager;
5 using UnityEngine;
6 using UnityEditor;
7 
8 namespace AVR.UEditor.Core {
9  public class PackageBuilder
10  {
11  static List<string> PackageQueue = new List<string>();
12 
13  static PackRequest Request;
14 
15  [MenuItem("AVR/Build Tarballs", false, -10)]
16  public static void BuildPackager()
17  {
18  #if AVR_CORE
19  PackageQueue.Add("com.avr.core");
20  #endif
21  #if AVR_AVATAR
22  PackageQueue.Add("com.avr.avatar");
23  #endif
24  #if AVR_MOTION
25  PackageQueue.Add("com.avr.motion");
26  #endif
27  #if AVR_PHYS
28  PackageQueue.Add("com.avr.phys");
29  #endif
30  #if AVR_UI
31  PackageQueue.Add("com.avr.ui");
32  #endif
33  #if AVR_NET
34  PackageQueue.Add("com.avr.net");
35  #endif
36 
37  Debug.Log("Started building "+PackageQueue.Count+" packages.");
38 
39  EditorApplication.update += UpdateBuildProcess;
40  }
41 
42  static void UpdateBuildProcess() {
43  if(PackageQueue.Count<1) {
44  EditorApplication.update -= UpdateBuildProcess;
45  }
46  else if(Request==null || Request.IsCompleted) {
47  BuildTarball(PackageQueue[0]);
48  PackageQueue.RemoveAt(0);
49  }
50  }
51 
52  static void BuildTarball(string source) {
53  source = "Packages/"+source;
54  string destination = Application.dataPath+"/../../tarballs";
55 
56  Debug.Log("Started building " + source + "...");
57  Request = Client.Pack(source, destination);
58  EditorApplication.update += Progress;
59  }
60 
61  static void Progress()
62  {
63  if (Request.IsCompleted)
64  {
65  if (Request.Status == StatusCode.Success)
66  Debug.Log("Tarball created: " + Request.Result.tarballPath);
67  else if (Request.Status >= StatusCode.Failure)
68  Debug.Log(Request.Error.message);
69 
70  EditorApplication.update -= Progress;
71  }
72  }
73  }
74 }
static void BuildTarball(string source)