示例#1
0
    void PreparationChecker()
    {
        int           numberOfProjectFoldersBeingPrepared = projectsBeingPrepared.Count;
        List <string> projectsDone = new List <string>();

        for (int i = 0; i < numberOfProjectFoldersBeingPrepared; i++)
        {
            string projectFolder   = projectsBeingPrepared[i];
            int    stateOfResource = WebGL_FileSystem.GetPreparationStateOfResource(projectFolder);
            if (stateOfResource == 3)
            {
                projectsDone.Add(projectFolder);
            }
            else if (stateOfResource == 1)
            {
                Debug.Log("ProjectFolder Failed to Download: " + projectFolder);
                //restart download:
                WebGL_FileSystem.PrepareProjectFolderResource(projectFolder);
            }
        }
        for (int i = 0; i < projectsDone.Count; i++)
        {
            projectsBeingPrepared.Remove(projectsDone[i]);
        }
        if (projectsBeingPrepared.Count != numberOfProjectFoldersBeingPrepared)
        {
            if (projectsBeingPrepared.Count == 0)
            {
                CancelInvoke("PreparationChecker");
                postStart();
            }
        }
    }
示例#2
0
    private void Awake()
    {
        gatherProjectFolders();
#if (UNITY_WEBGL) && !UNITY_EDITOR
        for (int i = 0; i < projectFolders.Count; i++)
        {
            string cProject = projectFolders[i];
            if (!WebGL_FileSystem.ResourceReadyCheck(cProject))
            {
                lastPreparedProjectFolderidx = i;
                PrepareProjectFolder(cProject);
                break;
            }
        }
#endif
    }
示例#3
0
    void gatherProjectFolders()
    {
        projectFolders.Clear();
#if (UNITY_WEBGL) && !UNITY_EDITOR
        projectFolders.AddRange(WebGL_FileSystem.GetDirectories(rootFolder));
#else
        if (new DirectoryInfo(rootFolder).Exists)
        {
            projectFolders.AddRange(Directory.GetDirectories(rootFolder));
        }

        if (!new DirectoryInfo(rootFolder).Exists)
        {
            string altProjectFolder = Application.persistentDataPath + "/" + rootFolder;
            if (new DirectoryInfo(altProjectFolder).Exists)
            {
                projectFolders.AddRange(Directory.GetDirectories(altProjectFolder));
            }

            altProjectFolder = Application.streamingAssetsPath + "/" + rootFolder;
            if (new DirectoryInfo(altProjectFolder).Exists)
            {
                projectFolders.AddRange(Directory.GetDirectories(altProjectFolder));
            }
            else
            {
#if UNITY_ANDROID
                if (ZIP_AndroidAssets.isUrl(altProjectFolder))
                {
                    string[] dirList = ZIP_AndroidAssets.retrieveProjectFolders(altProjectFolder);
                    foreach (string dir in dirList)
                    {
                        projectFolders.Add(altProjectFolder + "/" + dir);
                    }
                }
#endif
            }
        }
#endif
    }
示例#4
0
    private bool ResolveProjectFolder(string inProjectFolder, out string outProjectFolder)
    {
        outProjectFolder = null;

#if (UNITY_WEBGL) && !UNITY_EDITOR
        if (WebGL_FileSystem.ResourceReadyCheck(inProjectFolder))
        {
            outProjectFolder = inProjectFolder;
            return(true);
        }
        else
        {
            return(false);
        }
#endif

        if (string.IsNullOrEmpty(inProjectFolder))
        {
            return(false);
        }

        if (new DirectoryInfo(inProjectFolder).Exists)
        {
            outProjectFolder = inProjectFolder;
            return(true);
        }

#if UNITY_ANDROID
        if (ZIP_AndroidAssets.isUrl(inProjectFolder))
        {
            if (ZIP_AndroidAssets.synchronizeProjectFolder(inProjectFolder, out outProjectFolder))
            {
                return(true);
            }
        }
#endif

        return(false);
    }
示例#5
0
    IEnumerator Start()
    {
        //  Preemptively load clips.
        HarmonyRenderer renderer = GetComponent <HarmonyRenderer>();

        if ((renderer == null) || (renderer.clipNames == null))
        {
            yield break;
        }

#if UNITY_WEBGL && !UNITY_EDITOR
        if (WebGL_FileSystem.GetPreparationStateOfResource(renderer.projectFolder) != 3)
        {
            renderer.readyToRender = false;
            PrepareProjectFolder(renderer.projectFolder);
        }
        else
        {
            postStart();
        }
#else
        postStart();
#endif
    }
示例#6
0
    void OnGUI()
    {
        SceneSettings             settings   = FindObjectOfType(typeof(SceneSettings)) as SceneSettings;
        HarmonyAnimation          animation  = FindObjectOfType(typeof(HarmonyAnimation)) as HarmonyAnimation;
        HarmonyRendererController controller = FindObjectOfType(typeof(HarmonyRendererController)) as HarmonyRendererController;

        //  Update font size according to dpi.
        if (!initialized)
        {
            int realFontSize = (Screen.dpi != 0) ? (int)(Screen.dpi * fontMult * fontSize) : fontSize;

            //  Setup styles.
            labelStyle          = new GUIStyle(GUI.skin.GetStyle("label"));
            labelStyle.fontSize = realFontSize;
            labelStyle.wordWrap = false;

            buttonStyle              = new GUIStyle(GUI.skin.GetStyle("button"));
            buttonStyle.fontSize     = realFontSize;
            buttonStyle.stretchWidth = false;

            initialized = true;
        }

        float width  = Screen.width;
        float height = Screen.height;

        //  Add button to go back to main browser scene.
        GUIContent buttonText = new GUIContent("Go Back");
        Rect       buttonRect = GUILayoutUtility.GetRect(buttonText, buttonStyle);

        int buttonWidth  = (int)(buttonRect.width + 1);
        int buttonHeight = (int)(buttonRect.height + 1);

        //  Lower right corner
        buttonRect = new Rect(width - buttonWidth - 5,
                              height - buttonHeight - 5,
                              buttonWidth,
                              buttonHeight);

        if (GUI.Button(buttonRect, buttonText, buttonStyle))
        {
            //  Exit scene.  Delete controller object and enable
            //  browser group hierarchy.

            if (controller != null)
            {
                Destroy(controller.gameObject);
            }
#if UNITY_WEBGL && !UNITY_EDITOR
            WebGL_FileSystem.RemovePreparedResource(settings.projectFolder);
#endif
            settings.viewerGroup.SetActive(false);
            settings.browserGroup.SetActive(true);
        }

        //  If more than 1 clip, add browser for previous/next clip.
        if (settings != null)
        {
            int nClips = settings.clipNames.Length;

            //  Add button for previous clip.
            GUI.enabled = (settings.clipIdx >= 1);
            {
                buttonText = new GUIContent("Prev");
                buttonRect = GUILayoutUtility.GetRect(buttonText, buttonStyle);

                buttonWidth  = (int)(buttonRect.width + 1);
                buttonHeight = (int)(buttonRect.height + 1);

                //  Lower middle side
                buttonRect = new Rect((width / 2) - buttonWidth - 5,
                                      height - ((buttonHeight + 5) * 2),
                                      buttonWidth,
                                      buttonHeight);

                if (GUI.Button(buttonRect, buttonText, buttonStyle))
                {
                    --settings.clipIdx;

                    //  Update clip index and restart animation.
                    if (controller != null)
                    {
                        StartCoroutine(controller.RefreshRendererObject());
                    }
                }
            }

            //  Add button for next clip.
            GUI.enabled = (settings.clipIdx < (nClips - 1));
            {
                buttonText = new GUIContent("Next");
                buttonRect = GUILayoutUtility.GetRect(buttonText, buttonStyle);

                buttonWidth  = (int)(buttonRect.width + 1);
                buttonHeight = (int)(buttonRect.height + 1);

                //  Lower middle side
                buttonRect = new Rect((width / 2) + 5,
                                      height - ((buttonHeight + 5) * 2),
                                      buttonWidth,
                                      buttonHeight);

                if (GUI.Button(buttonRect, buttonText, buttonStyle))
                {
                    ++settings.clipIdx;

                    //  Update clip index and restart animation.
                    if (controller != null)
                    {
                        StartCoroutine(controller.RefreshRendererObject());
                    }
                }
            }

            GUI.enabled = true;
        }

        //  Add button for play/pause animation.
        GUI.enabled = (animation != null);

        buttonText = new GUIContent(((animation == null) || animation.paused == true) ? "Play" : "Pause");
        buttonRect = GUILayoutUtility.GetRect(buttonText, buttonStyle);

        buttonWidth  = (int)(buttonRect.width + 1);
        buttonHeight = (int)(buttonRect.height + 1);

        //  Lower middle side
        buttonRect = new Rect((width - buttonWidth) / 2,
                              height - buttonHeight - 5,
                              buttonWidth,
                              buttonHeight);

        if (GUI.Button(buttonRect, buttonText, buttonStyle))
        {
            if (animation != null)
            {
                //  Pause or Resume animations.
                animation.PauseResumeAnimation();

                //  Change pause state of AudioListener as well.
                AudioListener.pause = animation.paused;
            }
        }

        GUI.enabled = true;

        //  Add label for current clip.
        if (settings != null)
        {
            if (settings.clipIdx >= 0 && settings.clipIdx < settings.clipNames.Length)
            {
                GUIContent labelText = new GUIContent(settings.clipNames[settings.clipIdx]);
                Rect       labelRect = GUILayoutUtility.GetRect(labelText, labelStyle);

                int labelWidth  = (int)labelRect.width;
                int labelHeight = (int)labelRect.height;

                //  Upper middle side.
                labelRect = new Rect((width - labelWidth) / 2,
                                     5,
                                     labelWidth,
                                     labelHeight);

                GUI.Label(labelRect, labelText, labelStyle);
            }
        }
    }
示例#7
0
    private bool ResolveProjectFolder()
    {
        if (string.IsNullOrEmpty(projectFolder))
        {
            return(false);
        }

#if (UNITY_WEBGL) && !UNITY_EDITOR
        if (WebGL_FileSystem.ResourceReadyCheck(projectFolder))
        {
            liveProjectFolder = projectFolder;
            return(true);
        }
        else
        {
            return(false);
        }
#endif

        if (new DirectoryInfo(projectFolder).Exists)
        {
            //this should be activated on webgl as well
            liveProjectFolder = projectFolder;
            return(true);
        }

        //  Try to find a valid directory.  If projectFolder does not exist, append
        //  persistent data path to it and test again.
        if (!new DirectoryInfo(projectFolder).Exists)
        {
            string altProjectFolder = Application.persistentDataPath + "/" + projectFolder;
            if (new DirectoryInfo(altProjectFolder).Exists)
            {
                liveProjectFolder = altProjectFolder;
                return(true);
            }
        }

        //  Try to find a valid directory.  If projectFolder does not exist, append
        //  streaming asset path to it and test again.
        if (!new DirectoryInfo(projectFolder).Exists)
        {
            string altProjectFolder = Application.streamingAssetsPath + "/" + projectFolder;

#if UNITY_ANDROID
            //  streamingAssetsPath is a url (android), download assets locally.
            if (ZIP_AndroidAssets.isUrl(altProjectFolder))
            {
                string tmpProjectFolder;
                if (ZIP_AndroidAssets.synchronizeProjectFolder(altProjectFolder, out tmpProjectFolder))
                {
                    liveProjectFolder = tmpProjectFolder;
                    return(true);
                }
            }
            //  otherwise, a direct path on disk.
            else
#endif
            {
                if (new DirectoryInfo(altProjectFolder).Exists)
                {
                    liveProjectFolder = altProjectFolder;
                    return(true);
                }
            }
        }

        return(false);
    }
示例#8
0
 void PrepareProjectFolder(string projectFolder)
 {
     projectsBeingPrepared.Add(projectFolder);
     WebGL_FileSystem.PrepareProjectFolderResource(projectFolder);
     InvokeRepeating("PreparationChecker", 1, 1);
 }