Exemplo n.º 1
0
        public Dictionary <string, string> GetDictionary(JSONClass N)
        {
            Dictionary <string, string> d = new Dictionary <string, string>();

            foreach (string key in N.GetKeys())
            {
                d.Add(key, N[key]);
            }
            return(d);
        }
Exemplo n.º 2
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!");
                }
            }
        }