Beispiel #1
0
    private int gameObjectCounter(JSONRootElement v)
    {
        if (v == null)
        {
            return(0);
        }
        int c = 0;

        if (v.elements != null)
        {
            foreach (JSONElement e in v.elements)
            {
                if (e.type == "RTelement" || e.type == "element" || e.type == "RTedge" || e.type == "edge")
                {
                    c++;
                }
            }
        }
        if (v.RTelements != null)
        {
            foreach (JSONElement e in v.RTelements)
            {
                if (e.type == "RTelement" || e.type == "element" || e.type == "RTedge" || e.type == "edge")
                {
                    c++;
                }
            }
        }
        return(c);
    }
Beispiel #2
0
    public void sendMsg(string script, GameObject current_world)
    {
        var generate_geometries = false;

        try
        {
            // SEND POST
            var request = (HttpWebRequest)WebRequest.Create("http://" + m_IpSetting.input_IPAddress.text + ":" + m_IpSetting.input_port.text + "/");
            request.Timeout = 5000;

            byte[] data = data = System.Text.Encoding.ASCII.GetBytes(script);

            request.Method        = "POST";
            request.ContentType   = "text/xml;charset=\"utf-8\"";
            request.ContentLength = data.Length;

            // GET RESPONSE
            using (var stream = request.GetRequestStream())
            {
                stream.Write(data, 0, data.Length);
            }
            changeAlertMessage("Code sent correctly", NormalColor);

            response = (HttpWebResponse)request.GetResponse();

            // let's read the response stream. It is stored in 'responseString' variable
            responseString = new System.IO.StreamReader(response.GetResponseStream()).ReadToEnd();
            Debug.LogWarning("responseString: " + responseString);

            // ### [BEGIN] bsotomayor edit 081219 ###
            generate_geometries = responseString.Contains("elements"); // true if the response contains elements

            // script executed successfully !
            this.view = JsonUtility.FromJson <JSONRootElement>(responseString);
            if (this.view.elements != null)
            {
                Debug.LogWarning("JSON contains " + this.view.elements.Length + " lines");
            }
            else
            {
                Debug.Log("ERROR loc = " + this.view.errormsg.location + " msg:" + this.view.errormsg.message);
                var   msg = "";
                Color c;
                if (this.view.value != "" && this.view.errormsg.message == null)
                { // Textual Value
                    msg = this.view.value;
                    Debug.Log("this.view.value = " + this.view.value);
                    c = new Color(0, 0, 0);
                }
                else
                {
                    if (this.view.errormsg.location == null)
                    { // Error
                        msg = this.view.errormsg.message;
                        Debug.Log("this.view.errormsg.location = 0");
                        c = new Color(220, 0, 0);
                    }
                    else
                    { // SyntaxError
                        msg = this.view.errormsg.message + "\nLocation: " + this.view.errormsg.location;
                        Debug.Log("this.view.errormsg.location = " + this.view.errormsg.location);
                        c = new Color(220, 0, 0);

                        // lets change the caretPosition by the Error location.
                        m_codeEditor.CodeInputPanel.M_Input.caretPosition = (Int16.Parse(this.view.errormsg.location)) - 1;
                    }
                }
                Debug.Log("msg = '" + msg + "' color '" + c.ToString() + "'");
                changeAlertMessage(msg, c);
            }
            // ### [END] bsotomayor edit 081219 ###
        }
        catch (Exception e)
        {
            var msg = "";
            if (e is WebException)
            {
                msg = "Server Error";
            }
            else
            {
                msg = "Error";
            }
            msg += "\n" + e.Message;
            msg += "\n" + e.TargetSite.ToString();
            msg += "\n" + e.Source;

            changeAlertMessage(msg, ErrorColor);
            Debug.Log(msg + "\n" + e.StackTrace.ToString());
        };

        // GENERATE GEOMETRIES
        if (generate_geometries)
        {
            AVAR_Element obj;
            AVAR_Edge    edge;
            int          index_edges = 0;

            float min_z         = 1000.0f;
            int   element_count = 0;

            current_world.transform.position = new Vector3(0, 0, 0);

            //Scale? (if it is possible to do on Pharo, then that's better!) ####
            float maxX = 1.0f;
            float maxZ = 1.0f;

            if (this.view.RTelements != null)
            {
                for (int i = 0; i < this.view.RTelements.Length; i++)
                {
                    //Debug.Log("type: " + this.view.RTelements[i].type);
                    if (this.view.RTelements[i].type == "RTelement") // No es necesario
                    {
                        if (maxX < this.view.RTelements[i].position[0])
                        {
                            maxX = this.view.RTelements[i].position[0];
                        }
                        if (maxZ < this.view.RTelements[i].position[1])
                        {
                            maxZ = this.view.RTelements[i].position[1];
                        }
                    }
                }
            }

            if (this.view.elements != null)
            {
                for (int i = 0; i < this.view.elements.Length; i++)
                {
                    if (this.view.elements[i].type == "camera")
                    {
                        Debug.Log("type :" + this.view.elements[i].type + " | pos:" + this.view.elements[i].position);
                    }
                    else if (this.view.elements[i].type == "element")
                    {
                        if (engine == "NONE")
                        {
                            engine = "WODEN";
                        }
                        Debug.Log("A Woden 'element'");

                        Color col = new Color(
                            this.view.elements[i].color[0],
                            this.view.elements[i].color[1],
                            this.view.elements[i].color[2]);
                        col.a = this.view.elements[i].color[3];

                        obj = new AVAR_Element(
                            this.view.elements[i],
                            positioning,
                            scaling,
                            scale_const, //not necessary
                            col,
                            current_world);

                        // adding other properties
                        // adding interaction
                        // [BEGIN] bsotomayor 081919 (popup interaction for 3D viz)
                        obj.go.AddComponent <InteractiveGameObject>().f_Init(false, this.interactions, this.view.elements[i].model);
                        // [END] bsotomayor 081919 (popup interaction for 3D viz)


                        element_count += 1;
                    }
                    if (this.view.elements[i].type == "edge")
                    {
                        Color col = new Color(
                            this.view.elements[i].color[0],
                            this.view.elements[i].color[1],
                            this.view.elements[i].color[2]
                            );
                        col.a = this.view.elements[i].color[3];
                        edge  = new AVAR_Edge(
                            this.view.elements[i].from_id,
                            this.view.elements[i].to_id,
                            this.view.elements[i].type,
                            0.005f,
                            col,
                            current_world
                            );

                        //if (this.DEBUG)
                        edge.print();

                        index_edges += 1;
                    }
                }
            }
            if (this.view.RTelements != null)
            {
                for (int i = 0; i < this.view.RTelements.Length; i++)
                {
                    if (this.view.RTelements[i].type == "RTelement")
                    {
                        Color col = new Color(
                            this.view.RTelements[i].color[0],
                            this.view.RTelements[i].color[1],
                            this.view.RTelements[i].color[2]
                            );

                        // Roassal2 objects
                        if (engine == "NONE")
                        {
                            engine = "ROASSAL2";
                        }

                        // Create a Roassal2 element
                        obj = new AVAR_Element(
                            this.view.RTelements[i],
                            positioning,
                            scaling,
                            scale_const,
                            col,
                            current_world);

                        // Add popup text for Roassal2 elements
                        // [BEGIN] bsotomayor 081919 (for popup interaction in 2D viz)
                        obj.go.AddComponent <InteractiveGameObject>().f_Init(false, this.interactions, this.view.RTelements[i].model);
                        // [END] bsotomayor 081919 (for popup interaction in 2D viz)
                    }

                    else if (this.view.RTelements[i].type == "RTedge")
                    {
                        Color col = new Color(
                            this.view.RTelements[i].color[0],
                            this.view.RTelements[i].color[1],
                            this.view.RTelements[i].color[2]
                            );

                        edge = new AVAR_Edge(
                            this.view.RTelements[i].to_id,
                            this.view.RTelements[i].from_id,
                            this.view.RTelements[i].type,
                            0.001f,
                            col,
                            current_world
                            );

                        edge.print();
                        edge.transformParent(current_world);
                        index_edges += 1;
                    }
                }
            }
            changeAlertMessage("View loaded correctly", NormalColor);


            if (this.view.value != null)
            { // if text representention of Roassal vars is not null
              //consolePanel.gameObject.SetActive(true);
              //consolePanel.m_text.text= ">> Result:\n" + this.view.value;
                ////consoleText.transform.localScale = this.consoleText_dim;
                ////consolePanel.transform.localScale = this.consolePanel_dim;
                changeAlertMessage(" " + view.value.Replace('\r', '\n'), NormalColor);//   '/r' in pharo , '\n' in C#
            }
            else
            {
                //consolePanel.gameObject.SetActive(false);
                //consoleText.transform.localScale = Vector3.zero;
                //consolePanel.transform.localScale = Vector3.zero;
            }
            //Debug.Log("consoleText.text=" + consolePanel.m_text.text);

            //this.world.transform.position = world_centroid_position; [Not yet]

            //changeAlertMessage("View loaded correctly", new Color(220, 20, 20));

            Vector3 v_shifting = new Vector3(shifting[0], shifting[1], shifting[2]);

            var distance = 1.5f;
            current_world.transform.position = Camera.main.transform.position + Camera.main.transform.forward * distance;
            if (this.view.elements != null)
            {
                current_world.transform.eulerAngles = 180 * Vector3.right;
            }
            else
            {
                current_world.transform.LookAt(2 * current_world.transform.position - Camera.main.transform.position);
            }


            //SetCodeEditor();
        }
        if (current_world.transform.childCount > 0)
        {
            SetCodeEditor();
        }
    }