public static void HandlePostInstall()
        {
            // Remove from the Editor update loop; we only need this to run once.
            EditorApplication.update -= HandlePostInstall;

            // Check if user just installed or upgraded Poly Toolkit.
            string basePath        = PtUtils.GetPtBaseLocalPath();
            string upgradeFilePath = PtUtils.ToAbsolutePath(basePath + "/upgrade.dat");
            string currentVersion  = "";
            bool   isUpgrade       = false;

            try {
                currentVersion = File.ReadAllText(upgradeFilePath).Trim();
            } catch (Exception) {}

            if (currentVersion == PtSettings.Version.ToString())
            {
                return;
            }
            isUpgrade = !string.IsNullOrEmpty(currentVersion);
            // Show the welcome window.
            WelcomeWindow.ShowWelcomeWindow();
            AssetBrowserWindow.BrowsePolyAssets();
            File.WriteAllText(upgradeFilePath, PtSettings.Version.ToString());

            // In the future, if we need to do any post-upgrade maintenance, we can add it here.
            PtAnalytics.SendEvent(isUpgrade ? PtAnalytics.Action.INSTALL_UPGRADE
      : PtAnalytics.Action.INSTALL_NEW_2, PtSettings.Version.ToString());
        }
예제 #2
0
        static WarnAboutUsingPolyInternal()
        {
            string basePath = PtUtils.GetPtBaseLocalPath();

            List <string> offendingFiles = new List <string>();

            foreach (string asset in AssetDatabase.GetAllAssetPaths())
            {
                // Only check .cs files.
                if (!asset.EndsWith(".cs"))
                {
                    continue;
                }
                // Don't check Poly Toolkit script files.
                if (asset.StartsWith(basePath + "/"))
                {
                    continue;
                }
                // If we got here, this is a user-defined script file. Let's check that it's not using PolyToolkitInternal.
                // Note that the asset database cannot always be trusted; sometimes the assets do not exist.
                string contents;
                try { contents = File.ReadAllText(asset); }
                catch (FileNotFoundException) { continue; }

                // If the user has silenced the warning by adding the special marker, skip this file.
                if (contents.Contains("NO_POLY_TOOLKIT_INTERNAL_CHECK"))
                {
                    continue;
                }

                // This is a pretty naive check but I can't think of any legitimate reason someone would have the string
                // "PolyToolkitInternal" or "PolyToolkitEditor" in their script file. But if they do, they can add
                // NO_POLY_TOOLKIT_INTERNAL_CHECK to the file to silence the warning.
                if (contents.Contains("PolyToolkitInternal") || contents.Contains("PolyToolkitEditor"))
                {
                    offendingFiles.Add(asset);
                }
            }
            if (offendingFiles.Count > 0)
            {
                string errorMessage = ERROR_MESSAGE_HEADER + string.Join("\n", offendingFiles.ToArray());
                Debug.LogError(errorMessage);
                EditorUtility.DisplayDialog(ERROR_MESSAGE_TITLE, errorMessage, "OK");
            }
        }
예제 #3
0
        /// <summary>
        /// Loads a texture file from the Poly Toolkit installation folder given a relative path
        /// from the installation folder to the texture.
        /// </summary>
        /// <param name="relativePath">The relative path were the texture is located. For example,
        /// this could be Editor/Textures/PolyToolkitTitle.png.</param>
        /// <returns>The texture.</returns>
        public static Texture2D LoadTexture2DFromRelativePath(string relativePath)
        {
            string basePath = PtUtils.GetPtBaseLocalPath();

            return(AssetDatabase.LoadAssetAtPath <Texture2D>(Path.Combine(basePath, relativePath)));
        }