public BetterStreamingAssetsTests(string path, bool apkMode)
        {
            if (apkMode && !File.Exists(path))
            {
                Assert.Inconclusive("Build for Android and name output: " + path);
            }

            if (apkMode)
            {
                BetterStreamingAssets.InitializeWithExternalApk(path);
            }
            else
            {
                BetterStreamingAssets.InitializeWithExternalDirectories(".", path);
            }
        }
Exemplo n.º 2
0
        void OnGUI()
        {
            using (new GUILayout.AreaScope(new Rect(0, 0, Screen.width, Screen.height)))
            {
                if (string.IsNullOrEmpty(BetterStreamingAssets.Root))
                {
#if UNITY_EDITOR
                    using (new GUILayout.HorizontalScope())
                    {
                        GUILayout.Label("APK path");
                        EditorApkPath = GUILayout.TextField(EditorApkPath);
                    }

                    if (GUILayout.Button("Use APK (Android like)"))
                    {
                        BetterStreamingAssets.InitializeWithExternalApk(EditorApkPath);
                        Initialize();
                    }

                    if (GUILayout.Button("Use Assets/StreamingAssets directory (iOS/Standalone like)"))
                    {
                        BetterStreamingAssets.Initialize();
                        Initialize();
                    }
                    return;
#else
                    BetterStreamingAssets.Initialize();
                    Initialize();
#endif
                }

                if (m_allStreamingAssets.Length == 0)
                {
                    GUILayout.Label("No streaming assets found in " + BetterStreamingAssets.Root);
                    return;
                }

                GUILayout.Label("Using " + BetterStreamingAssets.Root);

                GUILayout.Label("Discovered streaming assets:");
                using (var scope = new GUILayout.ScrollViewScope(m_assetsScroll, GUILayout.MaxHeight(300)))
                {
                    m_assetsScroll = scope.scrollPosition;
                    foreach (var path in m_allStreamingAssets)
                    {
                        var wasSelected = m_selectedPaths.Contains(path);
                        if (GUILayout.Toggle(wasSelected, path))
                        {
                            if (!wasSelected)
                            {
                                m_selectedPaths.Add(path);
                            }
                        }
                        else
                        {
                            if (wasSelected)
                            {
                                m_selectedPaths.Remove(path);
                            }
                        }
                    }
                }

                const float VerticalSpace = 10.0f;
                GUILayout.Space(VerticalSpace);

                using (new GUILayout.HorizontalScope())
                {
                    GUILayout.Label("Repetition count: " + RepetitionCount, GUILayout.Width(150.0f));
                    RepetitionCount = Mathf.RoundToInt(GUILayout.HorizontalSlider((float)RepetitionCount, 1.0f, 20.0f));
                }

                LogToFile = GUILayout.Toggle(LogToFile, "Log results to file");

                GUILayout.Space(VerticalSpace);

                using (new GUILayout.HorizontalScope())
                {
                    GUILayout.Label("Test modes: ", GUILayout.Width(150.0f));
                    DoTestTypeToggle(TestType.CheckIfExists);
                    DoTestTypeToggle(TestType.LoadBytes);
                }

                GUILayout.Space(VerticalSpace);

                using (new GUILayout.HorizontalScope())
                {
                    GUILayout.Label("Read modes: ", GUILayout.Width(150.0f));
                    DoReadModeToggle(ReadMode.BSA);
                    DoReadModeToggle(ReadMode.WWW);
#if !UNITY_ANDROID || UNITY_EDITOR
                    DoReadModeToggle(ReadMode.Direct);
#endif
                }

                GUI.enabled = m_selectedPaths.Count > 0;
                if (GUILayout.Button("Test Selected Paths (" + m_selectedPaths.Count + ")"))
                {
                    coroutineHost.StartCoroutine(TestAllCoroutine(m_selectedPaths.ToArray(), RepetitionCount, m_readModes, m_testModes, m_results));
                }
                GUI.enabled = true;

                GUILayout.Box(m_status);

                using (var scroll = new GUILayout.ScrollViewScope(m_resultsScroll))
                {
                    m_resultsScroll = scroll.scrollPosition;

                    GUI.skin.label.alignment = TextAnchor.MiddleLeft;
                    GUI.skin.label.clipping  = TextClipping.Clip;

                    foreach (var result in m_results)
                    {
                        using (var layout = new GUILayout.HorizontalScope())
                        {
                            GUILayout.Label(result.path, GUILayout.Width(200));
                            GUILayout.Label(result.readMode.ToString(), GUILayout.Width(160));
                            GUILayout.Label(result.testType.ToString(), GUILayout.Width(160));

                            if (result.error != null)
                            {
                                GUILayout.Label(result.error.GetType().ToString());
                            }
                            else
                            {
                                GUILayout.Label(result.duration.ToString());
                                GUILayout.Label((result.memoryPeak / 1024.0 / 1024.0).ToString("F2") + " MB");
                            }
                        }
                    }

                    GUI.skin.label.clipping  = TextClipping.Overflow;
                    GUI.skin.label.alignment = TextAnchor.MiddleCenter;
                }
            }
        }