示例#1
0
        private void CloseClientThread()
        {
            EWUnityExtensions.Log("##### ExerWorldPlugin close tcp connection ");
            if (clientThread != null)
            {
                try {
                    if (tcpclient != null)
                    {
                        tcpclient.GetStream().Dispose();
                    }
                } catch (Exception) {
                }

                try {
                    tcpclient.Close();
                } catch (Exception) {
                }

                try {
                    clientThread.Abort();
                } catch {
                    EWUnityExtensions.LogWarning("##### ExerWorldPlugin ExerLinker: client close Error");
                }
            }
            else
            {
                EWUnityExtensions.LogWarning("##### ExerWorldPlugin ExerLinker: clientThread was null");
            }
        }
示例#2
0
 public static void SetCurrentValue(string _controlName, float value)
 {
     try {
         allControls[_controlName].SetCurrentValue(value);
     } catch (UnityException e) {
         EWUnityExtensions.LogWarning("Could not find value for control named '" + _controlName + "', Exception: " + e);
     }
 }
示例#3
0
        // static methods

        public static float GetCurrentValue(string _controlName)
        {
            try {
                return(allControls[_controlName].currentValue);
            } catch (UnityException e) {
                EWUnityExtensions.LogWarning("Could not find value for control named '" + _controlName + "', Exception: " + e);
                return(0);
            }
        }
示例#4
0
        public void AutoBootLinker()
        {
            string pathToExerWorldLinker = "";
            string exectuableName        = "";

                        #if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
            exectuableName = "ExerWorldLinker.exe";
                        #endif

            pathToExerWorldLinker = "";

            if (Application.platform == RuntimePlatform.OSXPlayer)
            {
                pathToExerWorldLinker = "" + Application.dataPath + "/../../";
            }
            else
            {
                pathToExerWorldLinker = "" + Application.dataPath + "/../";
            }

            pathToExerWorldLinker += "ExerWorldLinker/";

            string pathtoExerWorldLinkerWithExecutable = pathToExerWorldLinker + exectuableName;
            EWUnityExtensions.Log("Try to start ExerWorldLinker here:" + "'" + pathToExerWorldLinker + "'");

            #if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
            try {
                procLinker = new Process();
                procLinker.StartInfo.FileName         = pathtoExerWorldLinkerWithExecutable;
                procLinker.StartInfo.WorkingDirectory = pathToExerWorldLinker;

                // procLinker.StartInfo.Arguments = ...

                // Stop the process from opening a new window
                // TODO / FIXME nice to have but seems to block sth inside of exer.world's linker
                // procLinker.StartInfo.RedirectStandardOutput = true;
                // procLinker.StartInfo.UseShellExecute = false;
                // procLinker.StartInfo.CreateNoWindow = true;

                procLinker.Start();
                hasLinkerStarted = true;

                // GainFocus();
                StartCoroutine(GainFocusDelayed(0.1f));
            } catch (Exception e) {
                EWUnityExtensions.LogWarning("Could not start ExerWorld's Linker from " + pathToExerWorldLinker + "\n" + e);
            }
            #endif
        }
示例#5
0
        public static float GetCurrentValueMulti(string _controlNameMulti, string _exerworldId)
        {
            string wholeName = MakeMultiValueName(_controlNameMulti, _exerworldId);

            // TODO not dry bääh
            if (ControlInputMulti.allMultiControls.ContainsKey(wholeName))
            {
                return(ControlInputMulti.allMultiControls[wholeName].currentValue);
            }
            else
            {
                EWUnityExtensions.LogWarning("Could not find value for control named '" + wholeName + "'");
                return(0);
            }
        }
示例#6
0
        void Update()
        {
            float curTime = Time.realtimeSinceStartup;

            // check if ControlInputs have to be created (needed for multiinputs which can dynamically grow)

            foreach (CreateQueueEntry entry in createQueue)
            {
                ControlInput parent        = entry.ciParent;
                string       multiId       = entry.multiId;
                string       multiFullName = entry.name;

                if (ControlInputMulti.allMultiControls.ContainsKey(multiFullName) == false)
                {
                    EWUnityExtensions.Log("Create new multi val controlinput child for '" + multiFullName + "'");
                    ControlInputMulti ciChild = this.gameObject.AddComponent <ControlInputMulti> ();
                    ciChild.multiId = multiId;
                    ciChild.RegisterMulti(multiFullName);
                    ciChild.multiParent = parent;
                    ControlInput.MultiInputEntry multiEntry = new ControlInput.MultiInputEntry();
                    multiEntry.multiId      = multiId;
                    multiEntry.name         = multiFullName;
                    multiEntry.controlInput = ciChild;
                    parent.multiInputs.Add(multiEntry);
                    ciChild.SetCurrentValue(entry.initVal);
                }
                else
                {
                    EWUnityExtensions.LogWarning("'" + multiFullName + "' already created!");
                }
            }
            createQueue.Clear();


            // TODO: restart client if closed... look for server (rendevous/zeroconf ? )
            if (IsConnectionLost() && (curTime - timeLastConnectionTry) > cooldownConnectionTry)
            {
                timeLastConnectionTry = curTime;
                EWUnityExtensions.Log("Try to connect to server '" + linker_ip + ":" + linker_tcp_port + "'");
                connectThread = new Thread(ConnectToServer);
                connectThread.Start();
            }

            foreach (var kV in inValues)
            {
                EWUnityExtensions.Log("in Values => " + kV.Key + " -> " + kV.Value);
            }
        }
示例#7
0
        // start read thread, it will read the data from the connection, if available
        void StartClientThread()
        {
            //No need to get data if there is no connection
            if (IsConnectionLost())
            {
                //no connection, no data
                EWUnityExtensions.LogWarning("##### ExerWorldPlugin StartClientThread, Unable to start client thread because no connection was established beforehand");
                return;
            }

            if (clientThread != null)
            {
                clientThread.Abort();
            }
            clientThread = new Thread(HandleStreamLoop);
            clientThread.Start();
        }
示例#8
0
        // NOTE: only for multi value fields
        public static Dictionary <string, float> GetCurrentMultiValues(string _controlName)
        {
            Dictionary <string, float> multiValDict = new Dictionary <string, float> ();

            try {
                ControlInput ci = allControls[_controlName];
                if (ci.isMultiInput)
                {
                    foreach (MultiInputEntry entry in ci.multiInputs)
                    {
                        multiValDict[entry.multiId] = entry.controlInput.GetCurrentValue();
                    }
                }
            } catch (UnityException e) {
                EWUnityExtensions.LogWarning("Could not find value for control named '" + _controlName + "', Exception: " + e);
            }

            return(multiValDict);
        }
示例#9
0
 void OnApplicationQuit()
 {
     EWUnityExtensions.LogWarning("##### ExerWorldPlugin OnApplicationQuit called");
     CloseClientThread();
 }
示例#10
0
        private void UpdateValues(string[] lines)
        {
            // EWUnityExtensions.Log("Update values: " + lines[0]);

            // TODO: actually only one line is needed ...
            // for (int i=0; i < lines.Length ; i++) {
            string line = lines [0];

            if (debugShowData)
            {
                EWUnityExtensions.Log("Line to parse is '" + line + "'");
            }

            JSONNode rootNode = JSON.Parse(line);
            // EWUnityExtensions.Log ("input interpreted as Json has values # " + rootNode.Count);
            JSONNode values = (JSONNode)rootNode ["values"];

            if (values != null)
            {
                // EWUnityExtensions.Log ("=> values has => # " + values.Count);
            }


            for (int j = 0; j < inNames.Length; j++)
            {
                string inValName = inNames [j];

                JSONNode valueArray = values [j];

                // TODO: parse the values and split them appropriately. inputs can be look:
                //			[[], [], [], [], [0.990325079762794], [-0.2852937250435257]]
                //      OR	[[0.990325079762794,0.123], [], [], [], [], [-0.2852937250435257]]
                //      OR	[[], [], [], [], [], []]
                //		OR	[[0.123], [0.123], [0.123], [0.123], [0.123], [0.123]]


                bool foundFitting = false;
                if (this.debugShowData)
                {
                    // EWUnityExtensions.Log("# controlInputs to update: " + ControlInput.allControlsList.Count);
                }

                foreach (ControlInput ci in ControlInput.allControlsList)
                {
                    if (ci.controlName == inValName)
                    {
                        float avg_val = 0;

                        for (int ik = 0; ik < valueArray.Count; ik++)
                        {
                            JSONNode val = valueArray [ik];

                            bool isJsonClass = val is JSONClass;
                            bool isJsonData  = val is SimpleJSON.JSONData;


                            if (debugShowData)
                            {
                                EWUnityExtensions.Log("val has count # " + val.Count + " and is json class ? " + isJsonClass);
                            }
                            if (isJsonClass && ci.isMultiInput)
                            {
                                JSONClass valDict = (JSONClass)val;
                                if (debugShowData)
                                {
                                    EWUnityExtensions.Log("valDict has children: #" + valDict.Count);
                                }
                                foreach (string key in valDict.GetKeys())
                                {
                                    float childVal = float.Parse(valDict [key]);
                                    if (debugShowData)
                                    {
                                        EWUnityExtensions.Log("=> found key " + key + " with value " + childVal);
                                    }
                                    string            multiFullName = ControlInputMulti.MakeMultiValueName(ci.controlName, key);
                                    ControlInputMulti ciChild       = null;
                                    if (ControlInputMulti.allMultiControls.ContainsKey(multiFullName) == false)
                                    {
                                        CreateQueueEntry entry = new CreateQueueEntry();
                                        entry.ciParent = ci;
                                        entry.multiId  = key;
                                        entry.name     = multiFullName;
                                        entry.initVal  = childVal;
                                        createQueue.Add(entry);
                                    }
                                    else
                                    {
                                        ciChild = ControlInputMulti.allMultiControls [multiFullName];
                                        ciChild.SetCurrentValue(childVal);
                                    }
                                }
                            }
                            else if (isJsonData)
                            {
                                avg_val += val.AsFloat;
                            }
                            else
                            {
                                EWUnityExtensions.LogWarning("Unknown json type" + val.ToString() + " " + val.GetType() + ", isMulti ? " + ci.isMultiInput);
                            }
                        }

                        ci.SetCurrentValue(avg_val);

                        foundFitting = true;
                        break;
                    }
                }


                if (foundFitting)
                {
                    // EWUnityExtensions.Log("Found fitting control!");
                }
                else
                {
                    // EWUnityExtensions.Log("Found NOOOO fitting control!");
                }
            }
        }