예제 #1
0
        void ConstructText(GlyphData glyphdata, GameObject glyphprefabs, int counts)
        {
            float sizing;

            float.TryParse(string.Format(glyphdata.size), out sizing);
            sizing = sizing * SIZE_UNIT_SCALE_FACTOR;
            Debug.Log("SIZE OF THE OBJECT" + sizing);

            if (Marker == glyphdata.marker)
            {
                LoadTextGlyph("text");
                GameObject TextInstance = InstantiateGlyph(textPrefab, glyphprefabs.transform);
                String     _sensor_name = "";
                TextMesh   textMesh     = TextInstance.GetComponent(typeof(TextMesh)) as TextMesh;
                //TextInstance.transform.localScale = new Vector3(sizing, sizing, sizing);

                if (glyphdata.one_glyph == "1")
                {
                    foreach (GlyphData f in glyphdata.Fields)
                    {
                        _sensor_name += f.sensor_name + " (" + f.channel + ") : " + f.normal_value + "\n";
                    }
                    textMesh.text = _sensor_name;
                    Debug.Log(" Mark " + glyphdata.mark + " Text: " + textMesh.text + " oneglyph kah? " + glyphdata.one_glyph);
                    textMesh.characterSize = 0.4f;
                }
                else
                {
                    textMesh.text = glyphdata.sensor_name + " : " + glyphdata.normal_value;
                    //TextInstance.transform.localPosition += new Vector3(counts, 0, 0);
                    Debug.Log("NOT ONEGLYPH Mark " + glyphdata.mark + " Text: " + glyphdata.sensor_name + " oneglyph kah? " + glyphdata.normal_value);
                    textMesh.characterSize = 0.5f;
                }

                textMesh.anchor = TextAnchor.MiddleCenter;
                float   offsetPosY = ((glyphprefabs.transform.position.y - (0.7f)) * SIZE_UNIT_SCALE_FACTOR);
                Vector3 offsetPos  = new Vector3(0, offsetPosY, 0);
                TextInstance.transform.localPosition = offsetPos;
            }
        }
예제 #2
0
        /* Later, need to make it more neat*/
        void ParsingJson(JSONNode response, ref List <GlyphData> m_glyph_data)
        {
            int num_devices = response.AsArray.Count;

            Debug.Log("Number of Device " + num_devices);
            for (int i = 0; i < num_devices; i++)
            {
                int    num_sensors = response[i]["sensor"].AsArray.Count;
                string _one_glyph  = string.Format(response[i].AsObject["as_one_glyph"].Value);

                string    _did    = string.Format(response[i].AsObject["_id"].Value);
                string    _glyph  = string.Format(response[i].AsObject["glyph"].Value);
                GlyphData _root   = new GlyphData(_did, "root");
                string    _marker = string.Format(response[i].AsObject["marker"].Value);

                for (int j = 0; j < num_sensors; j++)
                {
                    String channel;
                    //float channel_value;
                    _did = string.Format(response[i]["sensor"][j].AsObject["_id"].Value);
                    string _sid = string.Format(response[i]["sensor"][j].AsObject["_id"].Value);
                    Debug.Log("jumlah sensor :" + response[i]["sensor"].AsArray.Count);

                    if (_one_glyph == "1")
                    {
                        GlyphData _child = new GlyphData(_did, _sid);
                        //float.TryParse(string.Format(response[i]["sensor"][i]["data"][j].AsObject["value"].Value),out channel_value);
                        _child.channel = string.Format(response[i]["sensor"][j].AsObject["channel"].Value);

                        float data_value;
                        float data_max;
                        float data_min;
                        float opacity;
                        //float set_size;
                        float.TryParse(string.Format(response[i]["sensor"][j].AsObject["data"].Value), out data_value);
                        float.TryParse(string.Format(response[i]["sensor"][j].AsObject["max_val"].Value), out data_max);
                        float.TryParse(string.Format(response[i]["sensor"][j].AsObject["min_val"].Value), out data_min);
                        float.TryParse(string.Format(response[i]["sensor"][j].AsObject["opacity"].Value).Substring(0, string.Format(response[i]["sensor"][j].AsObject["opacity"].Value).Length - 1), out opacity);
                        //float.TryParse(string.Format(response[i]["sensor"][j].AsObject["set_size"].Value),out set_size);

                        if (data_max < data_value)
                        {
                            data_max = data_value;
                        }
                        //Debug.Log("COCACOLOR " + string.Format(response[i]["sensor"][j].AsObject["def_color"].Value));

                        _child.normal_value = data_value.ToString("R");
                        _child.sensor_name  = string.Format(response[i]["sensor"][j].AsObject["sensor_name"].Value);
                        _child.value        = ((data_value - (data_min)) / (data_max - data_min)).ToString("R");
                        Debug.Log("Normalized value " + ((data_value - (data_min)) / (data_max - data_min)).ToString("R"));
                        if (_child.channel == "color")
                        {
                            _child.value = string.Format(response[i]["sensor"][j].AsObject["min_color"].Value) + string.Format(response[i]["sensor"][j].AsObject["max_color"].Value + _child.value);
                            Debug.Log("INI ADALAH VALUE DARI SINGLE " + response[i]["sensor"][j].AsObject["min_color"].Value);
                        }
                        _child.one_glyph = _one_glyph;
                        _root.opacity    = (opacity / 100).ToString("R");
                        //_root.size = central_size;
                        _root.size      = string.Format(response[i]["sensor"][j].AsObject["set_size"].Value);//set_size;
                        _root.def_color = string.Format(response[i]["sensor"][j].AsObject["def_color"].Value);
                        _root.mark      = _glyph;
                        _root.marker    = _marker;
                        _root.Fields.Add(_child);
                    }
                    else
                    {
                        _root = new GlyphData(_did, _sid);
                        float data_value;
                        float data_max;
                        float data_min;
                        float opacity;
                        //float set_size;
                        float.TryParse(string.Format(response[i]["sensor"][j].AsObject["data"].Value), out data_value);
                        float.TryParse(string.Format(response[i]["sensor"][j].AsObject["max_val"].Value), out data_max);
                        float.TryParse(string.Format(response[i]["sensor"][j].AsObject["min_val"].Value), out data_min);
                        //float.TryParse(string.Format(response[i]["sensor"][j].AsObject["set_size"].Value),out set_size);
                        float.TryParse(string.Format(response[i]["sensor"][j].AsObject["opacity"].Value).Substring(0, string.Format(response[i]["sensor"][j].AsObject["opacity"].Value).Length - 1), out opacity);

                        if (data_max < data_value)
                        {
                            data_max = data_value;
                        }

                        _root.normal_value = data_value.ToString("R");
                        _root.sensor_name  = string.Format(response[i]["sensor"][j].AsObject["sensor_name"].Value);
                        _root.value        = ((data_value - (data_min)) / (data_max - data_min)).ToString("R");
                        Debug.Log("Normalized value ROOT " + ((data_value - (data_min)) / (data_max - data_min)).ToString("R"));
                        _root.mark      = string.Format(response[i]["sensor"][j].AsObject["glyph"].Value);
                        _root.marker    = _marker;
                        _root.def_color = string.Format(response[i]["sensor"][j].AsObject["def_color"].Value);
                        _root.opacity   = (opacity / 100).ToString("R");
                        //_root.size = central_size;
                        _root.size = string.Format(response[i]["sensor"][j].AsObject["set_size"].Value);
                        //set_size;
                        Debug.Log("OPACITY " + _root.opacity);
                        _root.channel = string.Format(response[i]["sensor"][j].AsObject["channel"].Value);
                        if (_root.channel == "color")
                        {
                            _root.value = string.Format(response[i]["sensor"][j].AsObject["min_color"].Value) + string.Format(response[i]["sensor"][j].AsObject["max_color"].Value + _root.value);
                        }
                        m_glyph_data.Add(_root);
                    }
                }

                if (_one_glyph == "1")
                {
                    _root.one_glyph = _one_glyph;
                    m_glyph_data.Add(_root);
                }
            }
            //float sizing;
            //float.TryParse(string.Format(glyphdata.size), out sizing);
            //TextInstance.transform.localScale = new Vector3(sizing, sizing, sizing);
            gameObject.transform.localEulerAngles = new Vector3(90, 90, 0);
            gameObject.transform.localPosition    = new Vector3(0.8f * SIZE_UNIT_SCALE_FACTOR, 0, 0);
        }
예제 #3
0
        void ConstructGlyph(GlyphData glyphdata, int counts, string ruler)
        {
            float val = 1.0f;
            float sizing;

            float.TryParse(string.Format(glyphdata.size), out sizing);

            sizing = sizing * SIZE_UNIT_SCALE_FACTOR;

            Debug.Log("GLYPH : " + glyphdata.mark);
            Debug.Log("COUNTS : " + counts);


            if (Marker == glyphdata.marker)
            {
                LoadGlyph(glyphdata.mark);
                GameObject glyphInstance = InstantiateGlyph(glyphPrefab, gameObject.transform);

                glyphInstance.transform.localScale = new Vector3(sizing, sizing, sizing); //it'll be changed later!
                SetChannelValue(glyphInstance, "color", glyphdata.def_color);

                //Debug.Log("COLOR MARKER :"+ glyphdata.opacity);
                //Debug.Log("COLOR MARKER :"+ glyphdata.def_color);
                //Debug.Log("VALUE :"+ glyphdata.value);


                if (glyphdata.one_glyph == "1")
                {
                    //Debug.Log("SIZE VALUE of ONE MARKER:"+ sizing);
                    //Debug.Log("SIZE VALUE of ONE MARKER:"+ glyphInstance.transform.localScale);

                    foreach (GlyphData f in glyphdata.Fields)
                    {
                        float.TryParse(string.Format(f.value), out val);
                        if (ruler == "1")
                        {
                            if (f.channel == "height")
                            {
                                SetChannelValue(glyphInstance, "opacity", "0.1");
                            }
                            else
                            {
                                glyphInstance.SetActive(false);
                            }
                        }
                        else
                        {
                            if (f.channel == "height")
                            {
                                glyphInstance.transform.localPosition += new Vector3(0, (SIZE_UNIT_SCALE_FACTOR * ((sizing / 2f) * -1f)), 0);
                            }
                            else
                            {
                                Debug.Log("AS ONE GLYPH :" + f.channel + " VALUE " + f.value);
                                SetChannelValue(glyphInstance, f.channel, f.value);
                            }
                        }
                    }
                }
                else
                {
                    Debug.Log("SIZE VALUE of MULTIPLE MARKER:" + glyphInstance.transform.localScale);
                    float.TryParse(string.Format(glyphdata.value), out val);
                    if (ruler == "1")
                    {
                        if (glyphdata.channel == "height")
                        {
                            SetChannelValue(glyphInstance, "opacity", "0.1");
                        }
                        else
                        {
                            glyphInstance.SetActive(false);
                        }
                    }
                    else
                    {
                        SetChannelValue(glyphInstance, glyphdata.channel, glyphdata.value);
                        if (glyphdata.channel == "height")
                        {
                            glyphInstance.transform.localPosition += new Vector3(0, (SIZE_UNIT_SCALE_FACTOR * ((sizing / 2f) * -1f)), 0);
                        }
                    }

                    glyphInstance.transform.localPosition += new Vector3(SIZE_UNIT_SCALE_FACTOR * counts, 0, 0);
                }

                if (ruler != "1")
                {
                    SetChannelValue(glyphInstance, "opacity", glyphdata.opacity);
                    ConstructText(glyphdata, glyphInstance, counts);
                }
            }
        }