Example #1
0
    void OnEnable()
    {
        webCamList.ClearOptions();
        WebCamDevice[] devices  = WebCamTexture.devices;
        List <string>  nameList = new List <string>();

        for (int i = 0; i < devices.Length; i++)
        {
            nameList.Add(devices[i].name);
        }
        webCamList.AddOptions(nameList);
        webCamList.value = 0;
        webCamManager.Play(webCamPreview);

        if (codeStarComm.IsOpen)
        {
            codeStarPort.interactable = false;
            codeStarConnect.gameObject.SetActive(false);
            codeStarDisconnect.gameObject.SetActive(true);
        }
        else
        {
            codeStarPort.interactable = true;
            codeStarConnect.gameObject.SetActive(true);
            codeStarDisconnect.gameObject.SetActive(false);
        }
        codeStarPort.options.Clear();
        codeStarComm.StartSearch();
    }
Example #2
0
    private void OnConnectClick()
    {
        popupCanvas.gameObject.SetActive(true);
        settingCommSocket.gameObject.SetActive(true);
        okCommSocket.interactable = true;
        portList.options.Clear();

        commSerial.StartSearch();
    }
Example #3
0
    public override void OnInspectorGUI()
    {
        this.serializedObject.Update();

#if UNITY_STANDALONE
        CommSerial socket = (CommSerial)target;
        GUI.enabled = !socket.IsOpen;

#if (UINTY_STANDALONE_WIN || UNITY_EDITOR_WIN)
        EditorGUILayout.LabelField(string.Format("Port Name: {0}", socket.device.name));
#elif (UINTY_STANDALONE_OSX || UNITY_EDITOR_OSX)
        EditorGUILayout.LabelField(string.Format("Port Name: {0}", socket.device.address));
#endif
        EditorGUILayout.BeginHorizontal();
        int      index = -1;
        string[] list  = new string[socket.foundDevices.Count];
        for (int i = 0; i < list.Length; i++)
        {
            list[i] = socket.foundDevices[i].name;
            if (socket.device.Equals(socket.foundDevices[i]))
            {
                index = i;
            }
        }
        index = EditorGUILayout.Popup(" ", index, list);
        if (index >= 0)
        {
            socket.device = new CommDevice(socket.foundDevices[index]);
        }
        if (GUILayout.Button("Search", GUILayout.Width(60f)) == true)
        {
            socket.StartSearch();
        }
        EditorGUILayout.EndHorizontal();

        GUI.enabled = true;
#else
        EditorGUILayout.HelpBox("This component only can work on standalone platform(windows, osx, linux..)", MessageType.Error);
#endif

        EditorGUILayout.PropertyField(baudrate, new GUIContent("Baudrate"));
        EditorGUILayout.PropertyField(dtrReset, new GUIContent("DTR Reset"));

        foldout = EditorGUILayout.Foldout(foldout, "Events");
        if (foldout)
        {
            EditorGUILayout.PropertyField(OnOpen, new GUIContent("OnOpen"));
            EditorGUILayout.PropertyField(OnClose, new GUIContent("OnClose"));
            EditorGUILayout.PropertyField(OnOpenFailed, new GUIContent("OnOpenFailed"));
            EditorGUILayout.PropertyField(OnErrorClosed, new GUIContent("OnErrorClosed"));
            EditorGUILayout.PropertyField(OnStartSearch, new GUIContent("OnStartSearch"));
            EditorGUILayout.PropertyField(OnStopSearch, new GUIContent("OnStopSearch"));
        }

        this.serializedObject.ApplyModifiedProperties();
    }
    public override void OnInspectorGUI()
    {
        this.serializedObject.Update();

        GUI.enabled = false;
        EditorGUILayout.PropertyField(script, true, new GUILayoutOption[0]);
        GUI.enabled = true;

#if UNITY_STANDALONE
#if UNITY_5_6_OR_NEWER
#if NET_2_0
        CommSerial socket = (CommSerial)target;
        GUI.enabled = !socket.IsOpen;

#if UNITY_EDITOR_WIN
        EditorGUILayout.LabelField(string.Format("Port Name: {0}", socket.device.name));
#elif UNITY_EDITOR_OSX
        EditorGUILayout.LabelField(string.Format("Port Name: {0}", socket.device.address));
#endif
        EditorGUILayout.BeginHorizontal();
        int      index = -1;
        string[] list  = new string[socket.foundDevices.Count];
        for (int i = 0; i < list.Length; i++)
        {
            list[i] = socket.foundDevices[i].name;
            if (deviceName.stringValue.Equals(socket.foundDevices[i].name))
            {
                index = i;
            }
        }
        int newIndex = EditorGUILayout.Popup(" ", index, list);
        if (newIndex != index)
        {
            CommDevice newDevice = socket.foundDevices[newIndex];
            deviceName.stringValue    = newDevice.name;
            deviceAddress.stringValue = newDevice.address;
            deviceArgs.ClearArray();
            deviceArgs.arraySize = newDevice.args.Count;
            for (int i = 0; i < newDevice.args.Count; i++)
            {
                SerializedProperty arg = deviceArgs.GetArrayElementAtIndex(i);
                arg.stringValue = newDevice.args[i];
            }
        }

        if (GUILayout.Button("Search", GUILayout.Width(60f)) == true)
        {
            socket.StartSearch();
        }
        EditorGUILayout.EndHorizontal();

        GUI.enabled = true;
#else
        EditorGUILayout.HelpBox("You must set as '.Net 2.0' for API Compatibility Level in PlayerSetting.", MessageType.Error);
#endif
#else
        CommSerial socket = (CommSerial)target;
        GUI.enabled = !socket.IsOpen;

#if UNITY_EDITOR_WIN
        EditorGUILayout.LabelField(string.Format("Port Name: {0}", socket.device.name));
#elif UNITY_EDITOR_OSX
        EditorGUILayout.LabelField(string.Format("Port Name: {0}", socket.device.address));
#endif
        EditorGUILayout.BeginHorizontal();
        int      index = -1;
        string[] list  = new string[socket.foundDevices.Count];
        for (int i = 0; i < list.Length; i++)
        {
            list[i] = socket.foundDevices[i].name;
            if (deviceName.stringValue.Equals(socket.foundDevices[i].name))
            {
                index = i;
            }
        }
        int newIndex = EditorGUILayout.Popup(" ", index, list);
        if (newIndex != index)
        {
            CommDevice newDevice = socket.foundDevices[newIndex];
            deviceName.stringValue    = newDevice.name;
            deviceAddress.stringValue = newDevice.address;
            deviceArgs.ClearArray();
            deviceArgs.arraySize = newDevice.args.Count;
            for (int i = 0; i < newDevice.args.Count; i++)
            {
                SerializedProperty arg = deviceArgs.GetArrayElementAtIndex(i);
                arg.stringValue = newDevice.args[i];
            }
        }

        if (GUILayout.Button("Search", GUILayout.Width(60f)) == true)
        {
            socket.StartSearch();
        }
        EditorGUILayout.EndHorizontal();

        GUI.enabled = true;
#endif
#else
        EditorGUILayout.HelpBox("This component only can work on standalone platform(windows, osx, linux..)", MessageType.Error);
#endif

        EditorGUILayout.PropertyField(baudrate, new GUIContent("Baudrate"));
        EditorGUILayout.PropertyField(dtrReset, new GUIContent("DTR Reset"));

        foldout = EditorGUILayout.Foldout(foldout, "Events");
        if (foldout)
        {
            EditorGUILayout.PropertyField(OnOpen, new GUIContent("OnOpen"));
            EditorGUILayout.PropertyField(OnClose, new GUIContent("OnClose"));
            EditorGUILayout.PropertyField(OnOpenFailed, new GUIContent("OnOpenFailed"));
            EditorGUILayout.PropertyField(OnErrorClosed, new GUIContent("OnErrorClosed"));
            EditorGUILayout.PropertyField(OnStartSearch, new GUIContent("OnStartSearch"));
            EditorGUILayout.PropertyField(OnStopSearch, new GUIContent("OnStopSearch"));
        }

        this.serializedObject.ApplyModifiedProperties();
    }