예제 #1
0
    public override void OnInspectorGUI()
    {
        //DrawDefaultInspector();
        script = EditorGUILayout.ObjectField("Script", script, typeof(MonoScript), false) as MonoScript;
        if (script != MonoScript.FromMonoBehaviour(editor))
        {
            script = MonoScript.FromMonoBehaviour(editor);
        }
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Select Directory"))
        {
            string path = EditorUtility.OpenFolderPanel("Please select a folder", editor.directory, "");
            if (path.Length > 0)
            {
                editor.directory = path;
                string[] files = ECFile.FileCounts(editor.directory);
                foreach (string f in files)
                {
                    Debug.Log(ECFile.FileName(f) + "." + ECFile.Extension(f));
                }
                Debug.Log(files.Length + " file(s) found.");
            }
            EditorUtility.SetDirty(editor);
        }
        if (editor.FileExists())
        {
            if (GUILayout.Button("Explorer"))
            {
                string path = System.IO.Path.GetFullPath(editor.Path().Replace(@"/", @"\"));
                System.Diagnostics.Process.Start("explorer.exe", "/select," + path);
            }
        }
        GUILayout.EndHorizontal();
        EditorGUILayout.LabelField("Path", EditorStyles.boldLabel);
        editor.directory = EditorGUILayout.TextField("Current Directory: ", editor.directory);
        editor.file      = EditorGUILayout.TextField("Current File Name: ", editor.file);
        editor.extension = EditorGUILayout.TextField("Current Extension: ", editor.extension);

        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Load File"))
        {
            string path = EditorUtility.OpenFilePanel("Please pick a file", editor.directory, editor.extension);
            if (path.Length > 0)
            {
                editor.directory = ECFile.DirectoryName(path);
                editor.file      = ECFile.FileName(path);
                editor.extension = ECFile.Extension(path);
                editor.GetData();
                foreach (string d in editor.value)
                {
                    Debug.Log(d);
                }
            }
            EditorUtility.SetDirty(editor);
        }
        if (editor.FileExists())
        {
            if (GUILayout.Button("Save File"))
            {
                editor.SetData();
            }
        }
        GUILayout.EndHorizontal();

        EditorGUILayout.Space();
        EditorGUILayout.LabelField("Data", EditorStyles.boldLabel);
        editor.separator  = EditorGUILayout.TextField("Separator: ", editor.separator);
        editor.dataLength = EditorGUILayout.IntField("Number of data: ", editor.dataLength, EditorStyles.boldLabel);
        if (editor.data.Length != editor.dataLength)
        {
            editor.ResizeData();
        }
        for (int i = 0; i < editor.data.Length; i++)
        {
            editor.data[i] = EditorGUILayout.TextField(" - Data Name " + (i + 1) + ": ", editor.data[i]);
        }

        if (editor.FileExists())
        {
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Clear File"))
            {
                editor.ClearFile();
            }
            if (GUILayout.Button("Delete File"))
            {
                editor.DeleteFile();
            }
            GUILayout.EndHorizontal();
        }
        else
        {
            if (GUILayout.Button("Create File"))
            {
                if (!editor.DirectoryExists())
                {
                    editor.CreateDirectory();
                }
                editor.CreateFile();
            }
        }
        //GUILayout.BeginHorizontal();
        //data = EditorGUILayout.TextField("Data", data);
        //EditorGUILayout.LabelField("", value);
        //GUILayout.EndHorizontal();
    }
예제 #2
0
    // Update is called once per frame
    void Update()
    {
        if (arduinos.autoConnect != auto[0].isOn)
        {
            arduinos.autoConnect = auto[0].isOn;
        }
        if (networks.autoConnect != auto[1].isOn)
        {
            networks.autoConnect = auto[1].isOn;
        }
        //Arduino
        if (!status[0].text.Equals(arduinos.state.ToString()))
        {
            status[0].text = arduinos.state.ToString();
        }
        switch (connectBtn[0].gameObject.activeSelf)
        {
        case true:
            if (auto[0].isOn || arduinos.state == ConnectionState.CONNECTING || !arduinos.ArduinoExisted())
            {
                connectBtn[0].gameObject.SetActive(false);
            }
            break;

        default:
            if (!auto[0].isOn && arduinos.state != ConnectionState.CONNECTING && arduinos.ArduinoExisted())
            {
                connectBtn[0].gameObject.SetActive(true);
            }
            break;
        }
        switch (arduinos.state)
        {
        case ConnectionState.CONNECTED: btnText[0].text = "Disonnect"; break;

        default: btnText[0].text = "Connect"; break;
        }
        //Network
        if (!status[1].text.Equals(networks.state.ToString()))
        {
            status[1].text = networks.state.ToString();
        }
        switch (connectBtn[1].gameObject.activeSelf)
        {
        case true:
            if (auto[0].isOn || networks.state == ConnectionState.CONNECTING)
            {
                connectBtn[1].gameObject.SetActive(false);
            }
            break;

        default:
            if (!auto[0].isOn && networks.state != ConnectionState.CONNECTING)
            {
                connectBtn[1].gameObject.SetActive(true);
            }
            break;
        }
        if (!networks.HostFound())
        {
            btnText[1].text = "Search";
        }
        else
        {
            switch (networks.state)
            {
            case ConnectionState.CONNECTED: btnText[0].text = "Disonnect"; break;

            default: btnText[0].text = "Connect"; break;
            }
        }
        //Data R/W
        if (quitByExisting == ECFile.FileExists(quitText))
        {
            ECFile.DeleteFile(quitText);
            arduinos.autoConnect = false;
            arduinos.Disconnect();
            networks.autoConnect = false;
            networks.Disconnect();
            Application.Quit();
        }
        else
        {
            if (networks.state == ConnectionState.CONNECTED)
            {
                if (!networks.transferedData.Equals(arduinos.receivedData))
                {
                    networks.DataTransfer(arduinos.receivedData);
                }
            }
            if (arduinos.state == ConnectionState.CONNECTED)
            {
                if (!arduinos.transferedData.Equals(networks.receivedData))
                {
                    arduinos.DataTransfer(networks.receivedData);
                }
            }
        }
        data          = "Received: " + arduinos.receivedData + "\n" + "Transferred: " + networks.receivedData;
        dataText.text = data;
    }
예제 #3
0
    // Update is called once per frame
    void Update()
    {
        if (arduinos.autoConnect != auto[0].isOn)
        {
            arduinos.autoConnect = auto[0].isOn;
        }
        if (fReaders.autoGenFolder != auto[1].isOn)
        {
            fReaders.autoGenFolder = auto[1].isOn;
        }
        //Arduino
        if (!status[0].text.Equals(arduinos.state.ToString()))
        {
            status[0].text = arduinos.state.ToString();
        }
        switch (connectBtn[0].gameObject.activeSelf)
        {
        case true:
            if (auto[0].isOn || arduinos.state == ConnectionState.CONNECTING || !arduinos.ArduinoExisted())
            {
                connectBtn[0].gameObject.SetActive(false);
            }
            break;

        default:
            if (!auto[0].isOn && arduinos.state != ConnectionState.CONNECTING && arduinos.ArduinoExisted())
            {
                connectBtn[0].gameObject.SetActive(true);
            }
            break;
        }
        switch (arduinos.state)
        {
        case ConnectionState.CONNECTED: btnText[0].text = "Disonnect"; break;

        default: btnText[0].text = "Connect"; break;
        }
        //Folder
        switch (connectBtn[1].gameObject.activeSelf)
        {
        case true:
            if (auto[1].isOn || fReaders.ReceiverFound() && fReaders.TransmitterFound())
            {
                connectBtn[1].gameObject.SetActive(false);
                status[1].text = "EXIST";
            }
            break;

        default:
            if (!auto[1].isOn && (!fReaders.ReceiverFound() || !fReaders.TransmitterFound()))
            {
                connectBtn[1].gameObject.SetActive(true);
                status[1].text = "LOST";
            }
            break;
        }
        //Data R/W
        if (quitByExisting == ECFile.FileExists(quitText))
        {
            ECFile.DeleteFile(quitText);
            arduinos.autoConnect = false;
            arduinos.Disconnect();
            Application.Quit();
        }
        else
        {
            if (!fReaders.transferedData.Substring(fReaders.orderLength).Equals(arduinos.receivedData))
            {
                fReaders.DataTransfer(arduinos.receivedData);
            }
            if (arduinos.state == ConnectionState.CONNECTED)
            {
                if (!arduinos.transferedData.Equals(fReaders.receivedData))
                {
                    arduinos.DataTransfer(fReaders.receivedData);
                }
            }
        }
        data          = "Received: " + arduinos.receivedData + "\n" + "Transferred: " + fReaders.receivedData;
        dataText.text = data;
    }