Esempio n. 1
0
        /// <summary>
        /// Main GUI update
        /// </summary>
        void OnGUI()
        {
            // If this is the first iteration since the window is opened, do the needed initializzations
            if (firstCycle)
            {
                Start();
            }
            // Check if for some reason the updater is not initialized, this eventuality tends to happen if some code gets recompiled while the window is open
            if (updater == null)
            {
                updater = new TSUpdater();
            }

            TSFunctions.DrawHeader(position.width, 10);

            section = (MultiWindowSection)GUILayout.Toolbar((int)section, Enum.GetNames(typeof(MultiWindowSection)), EditorStyles.toolbarButton, GUI.ToolbarButtonSize.Fixed);

            MainAreaScrollPos = EditorGUILayout.BeginScrollView(MainAreaScrollPos);
            GUILayout.Space(10);
            // Based on the section selected draw only the gui of said section
            switch (section)
            {
            case MultiWindowSection.Settings:
                DrawSettings();
                break;

            case MultiWindowSection.Updater:
                DrawUpdater();
                break;

            case MultiWindowSection.Credits:
                DrawCredits();
                break;

            default:
                EditorGUILayout.LabelField("Something went wrong, maybe you should contact the creator and report this");
                break;
            }
            EditorGUILayout.EndScrollView();

            TSFunctions.DrawFooter();
        }
Esempio n. 2
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
        }