Example #1
0
        /// <summary>
        /// Initializations needed when first opening the window
        /// </summary>
        public void Start()
        {
            firstCycle = false;

            // Gets the inspector level from editorPrefs, if for some reason is not present it just defaults to normal and writes it (should never happen if i remembered to do the first time window)
            if (EditorPrefs.HasKey(TSConstants.TSEPInspectorLevel))
            {
                inspectorLevel = (InspectorLevel)EditorPrefs.GetInt(TSConstants.TSEPInspectorLevel);
            }
            else
            {
                inspectorLevel = InspectorLevel.Normal;
                EditorPrefs.SetInt(TSConstants.TSEPInspectorLevel, (int)InspectorLevel.Normal);
            }

            // Loads the settings file if exists, creates a default one if not
            if (File.Exists(TSConstants.SettingsJSONPath))
            {
                TSSettings settings = JsonUtility.FromJson <TSSettings>(File.ReadAllText(TSConstants.SettingsJSONPath));
                sectionStyle         = (SectionStyle)settings.sectionStyle;
                sectionColor         = settings.sectionColor;
                isAutoUpdateDisabled = settings.disableUpdates;
            }
            else
            {
                TSSettings settings = new TSSettings();
                settings.sectionStyle   = (int)SectionStyle.Bubbles;
                settings.sectionColor   = new Color(1, 1, 1, 1);
                settings.disableUpdates = false;
                File.WriteAllText(TSConstants.SettingsJSONPath, JsonUtility.ToJson(settings));
            }
        }
        /// <summary>
        /// Default constructor
        /// </summary>
        public OrderedSectionGroup()
        {
            TSSettings settings = JsonUtility.FromJson <TSSettings>(File.ReadAllText(TSConstants.SettingsJSONPath));

            sectionStyle = (SectionStyle)settings.sectionStyle;
            switch (sectionStyle)
            {
            case SectionStyle.Bubbles:
                buttonStyle = "button";
                break;

            case SectionStyle.Foldout:
                buttonStyle = new GUIStyle("button");
                break;

            case SectionStyle.Box:
                buttonStyle                  = new GUIStyle("box");
                buttonStyle.alignment        = TextAnchor.MiddleCenter;
                buttonStyle.stretchWidth     = true;
                buttonStyle.normal.textColor = Color.white;
                buttonStyle.fontStyle        = FontStyle.Bold;
                break;
            }

            sectionBgColor = settings.sectionColor;
            sections       = new List <OrderedSection>();
        }
Example #3
0
        /// <summary>
        /// Default section constructor
        /// </summary>
        /// <param name="sectionTitle">Title of the section</param>
        /// <param name="open">If is open or closed upon creation</param>
        /// <param name="content">Delegate function for drawing the section content</param>
        /// <param name="changesCheck">Delegate fucntion for checks that need to be done knowing if the box is open or enabled at all</param>
        public Section(GUIContent sectionTitle, bool open, SectionContent content, ChangesCheck changesCheck)
        {
            this.sectionTitle = sectionTitle;
            this.isOpen       = open;
            this.content      = content;
            this.changesCheck = changesCheck;

            TSSettings settings = JsonUtility.FromJson <TSSettings>(File.ReadAllText(TSConstants.SettingsJSONPath));

            sectionStyle        = (SectionStyle)settings.sectionStyle;
            this.sectionBgColor = settings.sectionColor;
        }
Example #4
0
        /// <summary>
        /// Main constructor
        /// </summary>
        /// <param name="sectionTitle">Title of the section</param>
        /// <param name="open">Is the section expanded?</param>
        /// <param name="enabled">IS the section enabled?</param>
        /// <returns></returns>
        public OrderedSection(GUIContent sectionTitle, bool open, bool enabled)
        {
            this.sectionTitle = sectionTitle;
            this.isOpen       = open;
            this.isEnabled    = enabled;
            pushState         = 0;

            isUp   = false;
            isDown = false;

            TSSettings settings = JsonUtility.FromJson <TSSettings>(File.ReadAllText(TSConstants.SettingsJSONPath));

            sectionStyle        = (SectionStyle)settings.sectionStyle;
            this.sectionBgColor = settings.sectionColor;
        }
Example #5
0
        /// <summary>
        /// Draws the settings GUI
        /// </summary>
        private void DrawSettings()
        {
            EditorGUI.BeginChangeCheck();
            inspectorLevel = (InspectorLevel)EditorGUILayout.EnumPopup(TSConstants.TSWindowLabels.InspectorLevel, inspectorLevel);
            if (EditorGUI.EndChangeCheck())
            {
                EditorPrefs.SetInt(TSConstants.TSEPInspectorLevel, (int)inspectorLevel);
            }

            EditorGUI.BeginChangeCheck();
            updater.updateStream = (UpdateStream)EditorGUILayout.EnumPopup(TSConstants.TSWindowLabels.UpdateStream, updater.updateStream);
            if (EditorGUI.EndChangeCheck())
            {
                LocalVersionJSON local = JsonUtility.FromJson <LocalVersionJSON>(File.ReadAllText(TSConstants.LocalJSONPath));
                local.beta = updater.updateStream == UpdateStream.Beta;
                File.WriteAllText(TSConstants.LocalJSONPath, JsonUtility.ToJson(local));
                updater.Reset();
            }

            EditorGUI.BeginChangeCheck();
            sectionStyle         = (SectionStyle)EditorGUILayout.EnumPopup(TSConstants.TSWindowLabels.SectionStyle, sectionStyle);
            sectionColor         = EditorGUILayout.ColorField(TSConstants.TSWindowLabels.Color, sectionColor);
            isAutoUpdateDisabled = EditorGUILayout.Toggle(TSConstants.TSWindowLabels.DisableAutoUpdates, isAutoUpdateDisabled);
            if (EditorGUI.EndChangeCheck())
            {
                TSSettings settings = JsonUtility.FromJson <TSSettings>(File.ReadAllText(TSConstants.SettingsJSONPath));
                settings.sectionStyle   = (int)sectionStyle;
                settings.sectionColor   = sectionColor;
                settings.disableUpdates = isAutoUpdateDisabled;
                File.WriteAllText(TSConstants.SettingsJSONPath, JsonUtility.ToJson(settings));
                exampleSection = new Section(new GUIContent("Example Section"), true, delegate(MaterialEditor m){ EditorGUILayout.LabelField("Example content"); }, delegate(bool a, bool b){});
            }


            GUILayout.Space(20);
            if (exampleSection == null)
            {
                exampleSection = new Section(new GUIContent("Example Section"), true, delegate(MaterialEditor m){ EditorGUILayout.LabelField("Example content"); }, delegate(bool a, bool b){});
            }
            exampleSection.DrawSection(null);
        }
Example #6
0
        /// <summary>
        /// Coroutine that downloads the update file and installs it
        /// </summary>
        /// <returns></returns>
        public IEnumerator <float> DownloadUpdate()
        {
            if (state == UpdaterState.Ready)
            {
                // Creates a web request to the github repository based on the selected update stream
                if (updateStream == UpdateStream.Beta)
                {
                    request = new UnityWebRequest("https://github.com/Cibbi/Toony-standard/archive/" + githubBetaJSON.sha + ".zip");
                    file    = new DownloadHandlerFile(Application.dataPath + "/toonyStandard.zip");
                }
                else
                {
                    request = new UnityWebRequest(githubReleaseJSON.assets[0].browser_download_url);
                    file    = new DownloadHandlerFile(Application.dataPath + "/toonyStandard.unitypackage");
                }

                request.method          = UnityWebRequest.kHttpVerbGET;
                file.removeFileOnAbort  = true;
                request.downloadHandler = file;
                request.SendWebRequest();
                state = UpdaterState.Downloading;
                // Main check cycle that waits for the downloaded file, like the update check execution is paused every cycle to not block
                // normal window execution
                while (state == UpdaterState.Downloading)
                {
                    yield return(0.5f);

                    // Executed if the request is done
                    if (request.isDone)
                    {
                        state = UpdaterState.Downloaded;

                        TSSettings settings = JsonUtility.FromJson <TSSettings>(File.ReadAllText(TSConstants.SettingsJSONPath));

                        // If the update stream is the beta one the downloaded file is a zip file, meaning that we have to extract it manually, fortunately a guy called Yallie made a simple
                        // extraction class that handles the basic stuff needed here, check him over https://github.com/yallie/unzip
                        if (updateStream == UpdateStream.Beta)
                        {
                            string localFolder = TSConstants.LocalShaderFolder;
                            Unzip  zip         = new Unzip(Application.dataPath + "/toonyStandard.zip");
                            // Deleting the old Toony standard version
                            if (Directory.Exists(TSConstants.LocalShaderFolder))
                            {
                                Directory.Delete(TSConstants.LocalShaderFolder, true);
                            }
                            // For each file in the zip we change the github repository path with the more user friendly one used on the releases, and then extract that file in that path
                            foreach (string fileName in zip.FileNames)
                            {
                                string newDir = fileName.Replace("Toony-standard-" + githubBetaJSON.sha, localFolder);
                                if (!Directory.Exists(Path.GetDirectoryName(newDir)))
                                {
                                    Directory.CreateDirectory(Path.GetDirectoryName(newDir));
                                }
                                zip.Extract(fileName, newDir);
                            }
                            // Disposing of the zip, this is important cause without doing it the zip file cannot be deleted afterwards
                            zip.Dispose();
                            // Creation of the updated version.json file for this beta version, cause the one that comes in the zip does not contain the sha of the commit used when checking updates
                            // Since it's impossible to know a commit sha before doing such commit.
                            LocalVersionJSON local = new LocalVersionJSON();
                            local.beta      = true;
                            local.betaSha   = githubBetaJSON.sha;
                            local.version   = "beta";
                            local.lastCheck = DateTime.Now.ToString();
                            File.WriteAllText(TSConstants.LocalJSONPath, JsonUtility.ToJson(local));
                            // The asset database is refreshed to be sure that the zip file is actually detected from the asset database for its deletion
                            File.Delete(Application.dataPath + "/toonyStandard.zip");
                            AssetDatabase.Refresh(ImportAssetOptions.ImportRecursive);
                        }
                        // If the update stream is the release one the downloaded file is the latest unitypackage that can be found here https://github.com/Cibbi/Toony-standard/releases
                        // Since it's a unitypackage its installation is relatively easy, but we still delete the old version first for safety
                        else
                        {
                            if (Directory.Exists(TSConstants.LocalShaderFolder))
                            {
                                Directory.Delete(TSConstants.LocalShaderFolder, true);
                            }
                            AssetDatabase.ImportPackage(Application.dataPath + "/toonyStandard.unitypackage", false);
                            AssetDatabase.Refresh();
                            AssetDatabase.DeleteAsset("Assets/toonyStandard.unitypackage");
                        }

                        File.WriteAllText(TSConstants.OldSettingsJSONPath, JsonUtility.ToJson(settings));
                    }
                    // Executed if the request got an error response
                    if (request.isNetworkError || request.isHttpError)
                    {
                        Debug.Log("Toony Standard: network error during downlaod, please retry later");
                    }
                }
            }
        }
Example #7
0
        /// <summary>
        /// Static contructor that runs on editor load and starts the update check
        /// </summary>
        static TSStartup()
        {
            bool update;

            TSConstants.InitializeFolderReferences();


            //checks if there's old configuration settings that needs to be reimported
            if (File.Exists(TSConstants.OldSettingsJSONPath))
            {
                TSSettings settings = JsonUtility.FromJson <TSSettings>(File.ReadAllText(TSConstants.OldSettingsJSONPath));
                File.WriteAllText(TSConstants.SettingsJSONPath, JsonUtility.ToJson(settings));
                File.Delete(TSConstants.OldSettingsJSONPath);
                AssetDatabase.Refresh();
            }

            if (File.Exists(TSConstants.SettingsJSONPath))
            {
                TSSettings settings = JsonUtility.FromJson <TSSettings>(File.ReadAllText(TSConstants.SettingsJSONPath));
                update = !settings.disableUpdates;
            }
            else
            {
                TSSettings settings = new TSSettings();
                settings.sectionStyle   = (int)SectionStyle.Bubbles;
                settings.sectionColor   = new Color(1, 1, 1, 1);
                settings.disableUpdates = false;
                File.WriteAllText(TSConstants.SettingsJSONPath, JsonUtility.ToJson(settings));
                update = true;
            }

            if (!EditorPrefs.HasKey(TSConstants.TSEPNotFirstTime))
            {
                int windowWidth            = 500;
                int windowHeight           = 500;
                TSFirstTimeWindow ftWindow = EditorWindow.CreateInstance <TSFirstTimeWindow>();
                ftWindow.minSize      = new Vector2(windowWidth, windowHeight);
                ftWindow.maxSize      = new Vector2(windowWidth, windowHeight);
                ftWindow.titleContent = new GUIContent("Welcome to Toony Standard!");
                ftWindow.ShowUtility();
            }

            if (update)
            {
                updater = new TSUpdater();
                updater.StartCoroutine(updater.CheckForUpdate());
                // This will make the update function continously running each update
                EditorApplication.update += Update;
            }
            //temporary code for converting materials for the hdr color fix toggle
            #region TempCode2018Unity
#if !UNITY_2018_1_OR_NEWER
            if (!File.Exists(TSConstants.LocalShaderFolder + "/convert"))
            {
                string     file             = "";
                Material[] projectMaterials = FindAssetsByType <Material>();
                int        mats             = 0;
                foreach (Material m in projectMaterials)
                {
                    if (m.shader.name.Equals("Hidden/Cibbis shaders/toony standard/Opaque") ||
                        m.shader.name.Equals("Hidden/Cibbis shaders/toony standard/Cutout") ||
                        m.shader.name.Equals("Hidden/Cibbis shaders/toony standard/Fade") ||
                        m.shader.name.Equals("Hidden/Cibbis shaders/toony standard/Transparent"))
                    {
                        mats++;
                        file += m.name + " shader: " + m.shader + "\n";
                        m.SetFloat("_NeedsFix", 1);
                    }
                }
                File.WriteAllText(TSConstants.LocalShaderFolder + "/convert", "Materials updated: " + mats + "\n" + file);
            }
#else
            if (File.Exists(TSConstants.LocalShaderFolder + "/convert"))
            {
                if (EditorUtility.DisplayDialog("Toony Standard", "Welcome to unity 2018! Unfortunately this upgrade slightly modified the aspect of all HDR enabled colors of Toony standard materials, Do you want to convert them back now? (you can decide to not do it and convert single materials later on)", "Yes do it", "I will check later myself"))
                {
                    Material[]      projectMaterials  = FindAssetsByType <Material>();
                    List <Material> selectedMaterials = new List <Material>();
                    foreach (Material m in projectMaterials)
                    {
                        if ((m.shader.name.Equals("Hidden/Cibbis shaders/toony standard/Opaque") ||
                             m.shader.name.Equals("Hidden/Cibbis shaders/toony standard/Cutout") ||
                             m.shader.name.Equals("Hidden/Cibbis shaders/toony standard/Fade") ||
                             m.shader.name.Equals("Hidden/Cibbis shaders/toony standard/Transparent") ||
                             m.shader.name.Equals("Hidden/Cibbis shaders/toony standard/OpaqueOutlined") ||
                             m.shader.name.Equals("Hidden/Cibbis shaders/toony standard/CutoutOutlined") ||
                             m.shader.name.Equals("Hidden/Cibbis shaders/toony standard/Dither") ||
                             m.shader.name.Equals("Hidden/Cibbis shaders/toony standard/DitherOutlined")) &&
                            (m.GetFloat("_NeedsFix") == 1f))
                        {
                            Debug.Log("Material \"" + m.name + "\" with shader: " + m.shader.name + " will be converted");
                            selectedMaterials.Add(m);
                            m.SetFloat("_NeedsFix", 0);
                        }
                    }
                    MaterialProperty[] mt = MaterialEditor.GetMaterialProperties(selectedMaterials.ToArray());
                    if (mt != null)
                    {
                        foreach (MaterialProperty m in mt)
                        {
                            if (m.flags == MaterialProperty.PropFlags.HDR)
                            {
                                m.colorValue = m.colorValue.linear;
                            }
                        }
                        Debug.Log("Conveted " + selectedMaterials.Count + " materials");
                        EditorUtility.DisplayDialog("Toony Standard", "Successfully updated " + selectedMaterials.Count + " materials!", "Ok");
                    }
                    else
                    {
                        EditorUtility.DisplayDialog("Toony Standard", "Successfully updated " + selectedMaterials.Count + " materials! Wait what? Really? Come on use my shader at least once!", "Ok");
                    }
                }
                else
                {
                    EditorUtility.DisplayDialog("Toony Standard", "If you select a 2017 imported material wou will have the option to convert colors of that material in the inspector.", "Ok");
                }
                File.Delete(TSConstants.LocalShaderFolder + "/convert");
            }
#endif
            #endregion
        }