using System; using UnityEngine; using System.Collections; using System.Collections.Generic; using SimpleJSON; using MVR.FileManagementSecure; using System.Text.RegularExpressions; using System.Linq; using Leap.Unity.Query; using Leap.Unity; using MVR.Hub; using UnityEngine.UI; using UnityEngine.Events; using Oculus.Platform.Models; using static Leap.Unity.MultiTypedList; namespace DLPlugin { /* DependencyViewer is a script for finding all dependencies in the scene, and their sub dependencies. You can scan current scene or select VAM preset (.vap)/.json file. Select dependency from list of root dependencies, and look each case of its usage. You can download Hub dependencies for ANY package (even Paid)! By DemonLord. License [CC BY] v2.1 */ public class DependencyViewer : MVRScript { private JSONStorableStringChooser deps; private RectTransform fullWidthUIContent; private List fullWidthUIElements; private UIDynamicButton loadPresetButton; private UIDynamicPopup depsUI; private UIDynamicTextField tfUI; private string[] packages; private string selfName; private string allDep; private string fileName; private string filePackageName; private JSONClass jsNow; private Dictionary> paths = new Dictionary>(); private Dictionary varNames = new Dictionary(); private bool fromMetaJson; private float wait; private HubDownloader packageDownloader; private GameObject myPackageDownloaderUIObject; private HubDownloaderUI hubDownloader; private HubDownloaderUI myHubDownloader; private float counter = 0; private List sliders = new List(); private bool scanned; private int toFind; private Text myHubDownloaderHeaderText; private int pendingResourceDownloads = 0; private string lastPath = ""; public struct VarItem { public string name; public string license; public bool isLatest; public string scenePath; public bool havePackage; public bool isSubDependency; public HubResourcePackageUI uiNew; public HubResourcePackageUI uiFinded; } public override void Init() { try { //SuperController.LogMessage("DependencyViewer "); packageDownloader = SuperController.singleton.packageDownloader; hubDownloader = SuperController.singleton.transform.Find("WorldScaleAdjust/HUD/Browsers/Canvas/HubDownloaderUI").GetComponent(); fullWidthUIElements = new List(); loadPresetButton = CreateButton("Load Json", true); loadPresetButton.transform.SetAsFirstSibling(); loadPresetButton.button.onClick.AddListener(() => { List shortCuts = new List(); ShortCut shortCut = new ShortCut(); shortCut.displayName = "Saves\\scene"; shortCut.path = "Saves\\scene"; shortCuts.Add(shortCut); shortCut = new ShortCut(); shortCut.displayName = "Custom"; shortCut.path = "Custom"; shortCuts.Add(shortCut); shortCut = new ShortCut(); shortCut.displayName = "Custom\\Atom\\Person"; shortCut.path = "Custom\\Atom\\Person"; shortCuts.Add(shortCut); shortCuts.AddRange(FileManagerSecure.GetShortCutsForDirectory("", false, false, false, false)); SuperController.singleton.GetMediaPathDialog((string s) => LoadJson(s), "json|vap", "Saves", false, true, false, null, false, shortCuts, true, true); }); ColorBlock colors = loadPresetButton.button.colors; colors.normalColor = new Color(0.5f, 1f, 0.5f, 1); colors.highlightedColor = new Color(0.4f, 0.8f, 0.4f, 1); colors.pressedColor = new Color(0.3f, 0.5f, 0.3f, 1); loadPresetButton.button.colors = colors; UIDynamicButton b1 = CreateButton("Check Current scene"); b1.button.onClick.AddListener(CheckCurrentScene); b1.button.colors = colors; UIDynamicButton b2 = CreateButton("Rescan"); b2.button.onClick.AddListener(RescanCurrent); colors.normalColor = new Color(1f, 1f, 0.5f, 1); colors.highlightedColor = new Color(0.8f, 0.8f, 0.5f, 1); colors.pressedColor = new Color(0.7f, 0.7f, 0.4f, 1); b2.button.colors = colors; UIDynamicButton b3 = CreateButton("Check Download Dependencies",true); b3.button.onClick.AddListener(CheckDownloadDependencies); colors.normalColor = new Color(1f, 0.6f, 0.9f, 1); colors.highlightedColor = new Color(0.8f, 0.4f, 0.7f, 1); colors.pressedColor = new Color(0.6f, 0.3f, 0.55f, 1); b3.button.colors = colors; } catch (Exception e) { SuperController.LogError("DependencyViewer: " + e); } } public override void InitUI() { base.InitUI(); if (!(UITransform != null)) { return; } MVRScriptUI componentInChildren = UITransform.GetComponentInChildren(); if (componentInChildren.fullWidthUIContent == null) { return; } fullWidthUIContent = componentInChildren.fullWidthUIContent; foreach (Transform fullWidthUIElement in fullWidthUIContent) { fullWidthUIElement.gameObject.SetActive(value: true); fullWidthUIElement.SetParent(componentInChildren.fullWidthUIContent, worldPositionStays: false); } List list2 = new List { "Start Info" }; deps = new JSONStorableStringChooser("Dependencies", list2, "Start Info", "Dependencies", SelectDependency); depsUI = CreateFullWidthFilterablePopup(deps); depsUI.labelWidth *= 1.3f; allDep = "DependencyViewer is a script for finding all dependencies in the scene, and their sub dependencies.\n\n" + "You can scan current scene or select VAM preset (.vap)/.json file. " + "Select dependency from list of root dependencies, and look each case of its usage.\n\n" + "To remove sub dependency you need to remove their root dependency, because only it appears in scene.\n\n" + "Script traces each occurrence of \":/\" string in json code.\n\n" + "All Dependencies tab has root dependencies, and generate their sub dependencies iteratively" + " (it looks inside meta.json file of that package, and for each of its main dependencies, looks inside their package recursively).\n\n" + "Update v2.1\n" + "Downloads show only unique dependencies, and \"shifted\" sub dependencies are not require to be downloaded for current scan.\n" + "Update v2\n" + "Now you can download Hub dependencies for ANY package (even Paid)!\n" + "(Load json -> package -> meta.json)\n\n" + "When you scan \"meta.json\" file, dependencies will be shown exactly from that file. " + "And when downloading [NOTFOUND] packages, their sub dependencies will not be shown!\n\n" + "For [V.1->2] case, will try download old version, because scanned file require exact version, not latest (mainly because of scripts)." + "\n\nBy DemonLord [CC-BY]."; tfUI = CreateFullWidthTextField(new JSONStorableString("All Dependencies", allDep)); tfUI.height = 990; //SuperController.LogMessage(allDep); } void Update() { if (myHubDownloader != null && myHubDownloader.panel.gameObject.activeSelf) { if (myHubDownloader.downloadInfoText != null) { if (pendingResourceDownloads > 0) { myHubDownloader.downloadInfoText.text = "Queued downloads count: " + pendingResourceDownloads; } else { myHubDownloader.downloadInfoText.text = "No queued downloads"; } } } if (wait != 0 ) { if (wait + 1 < Time.time) { wait = Time.time; counter++; if (myHubDownloaderHeaderText != null) { myHubDownloaderHeaderText.text = "Packages (" + myHubDownloader.GetComponentsInChildren().Length + ")"; } HubResourcePackageUI[] c2 = hubDownloader.GetComponentsInChildren(true); if (c2 != null) { try { string nameV; string[] spl; //SuperController.LogMessage("c2.Length " + c2.Length); JSONClass js = new JSONClass(); js["filename"] = "a.b.1.var"; VarItem vi; bool needSubDep = false; int lastNeedSubDepSiblingIndex = 0; foreach (HubResourcePackageUI ui in c2) { if (!ui.gameObject.activeSelf) continue; if (needSubDep) { if (ui.isDependencyIndicator.activeSelf) { ui.transform.SetParent(myHubDownloader.packagesContainer, false); ui.transform.SetSiblingIndex(lastNeedSubDepSiblingIndex); ui.licenseTypeText.text = Colorize(ui.licenseTypeText.text).Replace("green", "lime").Replace("red", "#E70000"); ui.fileSizeText.text = "" + ui.fileSizeText.text + ""; lastNeedSubDepSiblingIndex++; continue; } else needSubDep = false; } nameV = ui.nameText.text; spl = nameV.Split('.'); if (spl.Length != 3) continue; nameV = spl[0] + '.' + spl[1] + '.' + "latest"; if (varNames.ContainsKey(nameV) && !ui.nameText.text.EndsWith("latest")) { vi = varNames[nameV]; varNames.Remove(nameV); varNames[ui.nameText.text] = vi; } nameV = ui.nameText.text; if (varNames.ContainsKey(nameV)) { vi = varNames[nameV]; if (vi.uiFinded != null) { if (vi.uiFinded.nameText.text.EndsWith("latest") && vi.uiFinded.nameText.text != nameV) { int n = vi.uiFinded.transform.GetSiblingIndex(); ui.transform.SetParent(myHubDownloader.packagesContainer, false); vi.uiFinded.connectedItem = new HubResourcePackage(js, null, false); vi.uiFinded.gameObject.SetActive(value: false); ui.transform.SetSiblingIndex(n); ui.resourceButton.interactable = true; Button button = Instantiate(ui.resourceButton, ui.resourceButton.transform.parent, false); Destroy(ui.resourceButton.gameObject); ui.resourceButton = button; ui.resourceButton.onClick.AddListener(() => { SuperController.singleton.hubBrowser.OpenDetail(ui.nameText.text, true); //SuperController.LogMessage("nameV2 " + ui.nameText.text); }); ui.connectedItem.downloadQueuedCallback = (HubResourcePackage.DownloadQueuedCallback)Delegate.Combine(new HubResourcePackage.DownloadQueuedCallback(ResourceDownloadQueued), ui.connectedItem.downloadQueuedCallback); ui.connectedItem.downloadCompleteCallback = (HubResourcePackage.DownloadCompleteCallback)Delegate.Combine(new HubResourcePackage.DownloadCompleteCallback(ResourceDownloadComplete), ui.connectedItem.downloadCompleteCallback); ui.connectedItem.downloadErrorCallback = (HubResourcePackage.DownloadErrorCallback)Delegate.Combine(new HubResourcePackage.DownloadErrorCallback(ResourceDownloadError), ui.connectedItem.downloadErrorCallback); ui.licenseTypeText.text = Colorize(ui.licenseTypeText.text).Replace("green", "lime").Replace("red", "#E70000"); ui.fileSizeText.text = "" + ui.fileSizeText.text + ""; ui.isDependencyIndicator.SetActive(varNames[nameV].isSubDependency); vi.uiFinded = ui; varNames[nameV] = vi; } else if (vi.uiFinded.nameText.text == nameV && ui.transform.parent == hubDownloader.packagesContainer) { ui.connectedItem = new HubResourcePackage(js, null, false); ui.gameObject.SetActive(value: false); } } if (vi.uiNew != null) { toFind--; int n = vi.uiNew.transform.GetSiblingIndex(); ui.transform.SetParent(myHubDownloader.packagesContainer, false); Destroy(vi.uiNew.gameObject); vi.uiNew = null; ui.transform.SetSiblingIndex(n); ui.resourceButton.interactable = true; Button button = Instantiate(ui.resourceButton, ui.resourceButton.transform.parent, false); Destroy(ui.resourceButton.gameObject); ui.resourceButton = button; ui.resourceButton.onClick.AddListener(() => { SuperController.singleton.hubBrowser.OpenDetail(ui.nameText.text, true); //SuperController.LogMessage("nameV1 " + ui.nameText.text); }); ui.connectedItem.downloadQueuedCallback = (HubResourcePackage.DownloadQueuedCallback)Delegate.Combine(new HubResourcePackage.DownloadQueuedCallback(ResourceDownloadQueued), ui.connectedItem.downloadQueuedCallback); ui.connectedItem.downloadCompleteCallback = (HubResourcePackage.DownloadCompleteCallback)Delegate.Combine(new HubResourcePackage.DownloadCompleteCallback(ResourceDownloadComplete), ui.connectedItem.downloadCompleteCallback); ui.connectedItem.downloadErrorCallback = (HubResourcePackage.DownloadErrorCallback)Delegate.Combine(new HubResourcePackage.DownloadErrorCallback(ResourceDownloadError), ui.connectedItem.downloadErrorCallback); ui.licenseTypeText.text = Colorize(ui.licenseTypeText.text).Replace("green", "lime").Replace("red", "#E70000"); if (!ui.isDependencyIndicator.activeSelf) { if(!vi.havePackage && !fromMetaJson) { needSubDep = true; lastNeedSubDepSiblingIndex = n+1; //SuperController.LogMessage("needSubDep " + ui.nameText.text); } } else ui.isDependencyIndicator.SetActive(value: false); ui.fileSizeText.text = "" + ui.fileSizeText.text + ""; ui.isDependencyIndicator.SetActive(varNames[nameV].isSubDependency); vi.uiFinded = ui; varNames[nameV] = vi; } } else { ui.connectedItem = new HubResourcePackage(js, null, false); ui.gameObject.SetActive(value: false); } } } catch (Exception e) { SuperController.LogMessage("Update " + e); } } foreach (Slider s in sliders) { if (s != null) { s.value = counter / 20f; } } if (toFind == 0) { toFind = -1; counter = 17; } } if (counter == 10) { foreach (Slider s in sliders) { if (s != null) { s.transform.Find("Fill Area/Fill").GetComponent().color = new Color(1f, 0.478f, 0.478f, 1f); s.transform.Find("Text").GetComponent().text = "<- Try open link"; } } } if (counter >= 20) { wait = 0; } } } protected void ResourceDownloadQueued(HubResourcePackage hrp) { pendingResourceDownloads++; } protected void ResourceDownloadComplete(HubResourcePackage hrp, bool alreadyHad) { pendingResourceDownloads--; } protected void ResourceDownloadError(HubResourcePackage hrp, string err) { pendingResourceDownloads--; } private string GetScenePath(string path) { foreach (string s2 in SuperController.singleton.GetFilesAtPath(path)) { if (s2.EndsWith(".json")) return s2; } foreach (string s in FileManagerSecure.GetDirectories(path)) { return GetScenePath(s); } return null; } private void CheckDownloadDependencies() { try { if (scanned) { myPackageDownloaderUIObject.SetActive(true); return; } if (varNames.Count > 0 && packageDownloader != null) { scanned = true; wait = Time.time; sliders.Clear(); counter = 0; packageDownloader.ClearTrackedPackages(); foreach (var item in varNames) { if (item.Value.uiNew != null) Destroy(item.Value.uiNew.gameObject); } if (myHubDownloader != null) { foreach (var item in myHubDownloader.packagesContainer.GetComponents()) { Destroy(item); } } if (myPackageDownloaderUIObject == null) { HubDownloaderUI c0 = SuperController.singleton.GetComponentInChildren(true); myPackageDownloaderUIObject = Instantiate(c0.gameObject, this.manager.scriptUIParent, false); myHubDownloaderHeaderText = myPackageDownloaderUIObject.transform.Find("InnerPanel/HubDownloads/DownloadsHeader/Package").GetComponent(); HubDownloaderUI c1 = myPackageDownloaderUIObject.GetComponentInChildren(); if (c1 != null) { c1.panel = myPackageDownloaderUIObject.GetComponent(); c1.panel.anchoredPosition = new Vector2(c1.panel.anchoredPosition.x, c1.panel.anchoredPosition.y + 50); c1.panel.sizeDelta = new Vector2(c1.panel.sizeDelta.x, c1.panel.sizeDelta.y + 220); c1.packagesContainer = c1.transform.Find("InnerPanel/HubDownloads/Downloads/Viewport/Content").GetComponent(); c1.infoText = c1.transform.Find("InnerPanel/InfoText").GetComponent(); c1.downloadInfoText = c1.transform.Find("InnerPanel/DownloadInfoText").GetComponent(); /* SuperController.LogMessage("c11 "); c1.openPanelButton = CDD.button; c1.openPanelButton.onClick.AddListener(() => { if (c1.panel != null) { c1.panel.gameObject.SetActive(value: true); } });*/ c1.closePanelButton = c1.transform.Find("InnerPanel/CloseButton").GetComponent