示例#1
0
    public void AdvancedSettings()
    {
        GUILayout.Label("Discovery settings", EditorStyles.boldLabel);
        EditorGUI.indentLevel++;

        manager.DiscoverTries = EditorGUILayout.IntField("Number of tries", manager.DiscoverTries);

        blacklistedFoldout = EditorGUI.Foldout(GUILayoutUtility.GetRect(40f, 40f, 16f, 16f, EditorStyles.foldout), blacklistedFoldout, "Blacklisted ports", true, EditorStyles.foldout);
        if (blacklistedFoldout)
        {
            GUILayout.BeginVertical();

            GUILayout.BeginHorizontal();
            GUILayout.Space(EditorGUI.indentLevel * 15 + 4);;

            GUILayout.Label("Serial port", "OL Titleleft");
            GUILayout.Label("", "OL Titleright", GUILayout.MaxWidth(35));
            GUILayout.EndHorizontal();

            foreach (string blackList in manager.BlackListedPorts)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Space(EditorGUI.indentLevel * 15 + 4);
                GUILayout.Label(blackList, olLight);
                if (GUILayout.Button("×", "OL Titleright", GUILayout.MaxWidth(35)))
                {
                    manager.BlackListedPorts.Remove(blackList);
                    return;
                }
                GUILayout.EndHorizontal();
            }

            GUILayout.BeginHorizontal();
            GUILayout.Space(EditorGUI.indentLevel * 15 + 4);
            EditorGUI.indentLevel--;
            newBlackListedPort = EditorGUILayout.TextField("", newBlackListedPort, olInput, GUILayout.ExpandWidth(true));
            if (GUILayout.Button("Add", "TE Toolbarbutton", GUILayout.MaxWidth(35)))
            {
                if (newBlackListedPort == "")
                {
                    return;
                }
                manager.BlackListedPorts.Add(newBlackListedPort);
            }
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
        }

        GUILayout.Label("Debug", EditorStyles.boldLabel);
        EditorGUI.indentLevel++;
        GUILayout.BeginHorizontal();
        GUILayout.BeginVertical();
        //  SetGUIBackgroundColor("#4FC3F7");
        if (GUILayout.Button("Get port state"))
        {
            manager.GetPortState();
        }
        GUILayout.EndVertical();

        GUILayout.BeginVertical();
        //  SetGUIBackgroundColor("#ef5350");
        if (GUILayout.Button("Clear console"))
        {
            var logEntries  = System.Type.GetType("UnityEditorInternal.LogEntries,UnityEditor.dll");
            var clearMethod = logEntries.GetMethod("Clear", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
            clearMethod.Invoke(null, null);
        }
        // SetGUIBackgroundColor();
        GUILayout.EndVertical();
        GUILayout.EndHorizontal();


        GUILayout.Label("Update Uduino", EditorStyles.boldLabel);
        EditorGUI.indentLevel++;
        GUILayout.BeginHorizontal();
        GUILayout.BeginVertical();
        EditorGUI.indentLevel--;
        EditorGUI.indentLevel--;
        EditorGUI.indentLevel--;
        EditorGUILayout.HelpBox("Current version: " + UduinoVersion.getVersion(), MessageType.None);

        GUILayout.EndVertical();

        GUILayout.BeginVertical();
        // SetGUIBackgroundColor("#4FC3F7");
        if (GUILayout.Button("Check for update"))
        {
            string       url        = "http://marcteyssier.com/data/uduino/last-version.txt";
            WebRequest   myRequest  = WebRequest.Create(url);
            WebResponse  myResponse = myRequest.GetResponse();
            Stream       myStream   = myResponse.GetResponseStream();
            StreamReader myReader   = new StreamReader(myStream);
            string       s          = myReader.ReadToEnd();
            myReader.Close();
            isUpToDateChecked = true;
            if (s == UduinoVersion.getVersion())
            {
                isUpToDate = true;
            }
            else
            {
                isUpToDate = false;
            }
        }

        // SetGUIBackgroundColor();
        GUILayout.EndVertical();
        GUILayout.EndHorizontal();
        if (isUpToDateChecked)
        {
            if (isUpToDate)
            {
                EditorGUILayout.HelpBox("Uduino is up to date", MessageType.Info, true);
            }
            else
            {
                EditorGUILayout.HelpBox("Uduino is not up to date. Download the last version on the Asset Store.", MessageType.Error, true);
            }
        }

        EditorGUILayout.Separator();
    }
    public void AdvancedSettings()
    {
        GUILayout.Label("General Serial settings", EditorStyles.boldLabel);
        EditorGUI.indentLevel++;

        Manager.defaultArduinoBoardType = EditorGUILayout.Popup("Board Type", Manager.defaultArduinoBoardType, BoardsTypeList.Boards.ListToNames());
        Manager.readTimeout             = EditorGUILayout.IntField("Read timeout", Manager.readTimeout);
        Manager.writeTimeout            = EditorGUILayout.IntField("Write timeout", Manager.writeTimeout);
        Manager.autoRead = EditorGUILayout.Toggle("Auto read", Manager.autoRead);

        EditorGUI.indentLevel--;

        GUILayout.Label("Discovery settings", EditorStyles.boldLabel);
        EditorGUI.indentLevel++;
        Manager.autoDiscover  = EditorGUILayout.Toggle("Discover on play", Manager.autoDiscover);
        Manager.DiscoverTries = EditorGUILayout.IntField("Discovery tries", Manager.DiscoverTries);

        blacklistedFoldout = EditorGUI.Foldout(GUILayoutUtility.GetRect(40f, 40f, 16f, 16f, EditorStyles.foldout), blacklistedFoldout, "Blacklisted ports", true, EditorStyles.foldout);
        if (blacklistedFoldout)
        {
            GUILayout.BeginVertical();

            GUILayout.BeginHorizontal();
            GUILayout.Space(EditorGUI.indentLevel * 15 + 4);;

            GUILayout.Label("Serial port", "OL Titleleft");
            GUILayout.Label("", "OL Titleright", GUILayout.MaxWidth(35));
            GUILayout.EndHorizontal();

            foreach (string blackList in Manager.BlackListedPorts)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Space(EditorGUI.indentLevel * 15 + 4);
                GUILayout.Label(blackList, olLight);
                if (GUILayout.Button("×", "OL Titleright", GUILayout.MaxWidth(35)))
                {
                    Manager.BlackListedPorts.Remove(blackList);
                    EditorUtility.SetDirty(target);
                    return;
                }
                GUILayout.EndHorizontal();
            }

            GUILayout.BeginHorizontal();
            GUILayout.Space(EditorGUI.indentLevel * 15 + 4);
            EditorGUI.indentLevel--;
            newBlackListedPort = EditorGUILayout.TextField("", newBlackListedPort, olInput, GUILayout.ExpandWidth(true));
            if (GUILayout.Button("Add", "TE Toolbarbutton", GUILayout.MaxWidth(35)))
            {
                if (newBlackListedPort != "")
                {
                    Manager.BlackListedPorts.Add(newBlackListedPort);
                }
                newBlackListedPort = "";
                EditorUtility.SetDirty(target);
            }
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
            EditorGUI.indentLevel++;
        }

        GUILayout.Label("On disconnect", EditorStyles.boldLabel);
        GUILayout.BeginHorizontal();
        Manager.stopAllOnQuit = EditorGUILayout.Toggle("Reset pins", Manager.stopAllOnQuit);
        GUILayout.EndHorizontal();


        GUILayout.Label("Debug", EditorStyles.boldLabel);
        EditorGUI.indentLevel++;
        GUILayout.BeginHorizontal();
        GUILayout.BeginVertical();
        //  SetGUIBackgroundColor("#4FC3F7");
        if (GUILayout.Button("Get port state"))
        {
            Manager.GetPortState();
        }
        GUILayout.EndVertical();

        GUILayout.BeginVertical();
        //  SetGUIBackgroundColor("#ef5350");
        if (GUILayout.Button("Clear console"))
        {
            var logEntries  = System.Type.GetType("UnityEditorInternal.LogEntries,UnityEditor.dll");
            var clearMethod = logEntries.GetMethod("Clear", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
            clearMethod.Invoke(null, null);
        }
        // SetGUIBackgroundColor();
        GUILayout.EndVertical();
        GUILayout.EndHorizontal();

        GUILayout.Label("Update Uduino", EditorStyles.boldLabel);
        EditorGUI.indentLevel++;
        GUILayout.BeginHorizontal();
        GUILayout.BeginVertical();
        EditorGUI.indentLevel--;
        EditorGUI.indentLevel--;
        EditorGUI.indentLevel--;
        EditorGUILayout.HelpBox("Current version: " + UduinoVersion.getVersion(), MessageType.None);

        GUILayout.EndVertical();

        GUILayout.BeginVertical();
        // SetGUIBackgroundColor("#4FC3F7");
        if (GUILayout.Button("Check for update"))
        {
            string       url        = "http://marcteyssier.com/uduino/version";
            WebRequest   myRequest  = WebRequest.Create(url);
            WebResponse  myResponse = myRequest.GetResponse();
            Stream       myStream   = myResponse.GetResponseStream();
            StreamReader myReader   = new StreamReader(myStream);
            checkVersion = myReader.ReadToEnd();
            myReader.Close();
            isUpToDateChecked = true;
            if (checkVersion == UduinoVersion.getVersion())
            {
                isUpToDate = true;
            }
            else
            {
                isUpToDate = false;
            }
        }

        // SetGUIBackgroundColor();
        GUILayout.EndVertical();
        GUILayout.EndHorizontal();
        if (isUpToDateChecked)
        {
            if (isUpToDate)
            {
                EditorGUILayout.HelpBox("Uduino is up to date (" + checkVersion + ")", MessageType.Info, true);
            }
            else
            {
                EditorGUILayout.HelpBox("Uduino is not up to date. Download the version  (" + checkVersion + ") on the Asset Store.", MessageType.Error, true);
            }
        }

        EditorGUILayout.Separator();
    }