Beispiel #1
0
 public string ConvertObjects()
 {
     arrayBuild jsonMessage = new arrayBuild();
     foreach (GameObject thisObject in objects)
     {
         string longName = thisObject.transform.tag;
         float rotation = thisObject.transform.rotation.z;
         jsonMessage.AddObject(longName, thisObject.transform.position.x, thisObject.transform.position.y, rotation, 3);
         
     }
     string message = jsonMessage.serializeArray();
     return message;
 }
Beispiel #2
0
	//Call to send the level to the clients
	public void sendLevel()
	{
       

		//Gets all objects with the tag "Level"
		Debug.Log ("Getting all tagged objects");
		GameObject[] allObjects = GameObject.FindGameObjectsWithTag("Level");

        //Create class for JSON message
        arrayBuild jsonMessage = new arrayBuild();
		
		//Convert to proper list
		Debug.Log ("Converting to proper listing");
		foreach (GameObject thisObject in allObjects)
		{
			//Gets Objects proper name without all the duplicate issues
			string longName = thisObject.transform.name;
			string shortName;
			
			//If the object has "duplicate" text added to object name
			if( (longName.IndexOf(' ') + 1) != 0 )
			{
				shortName = longName.Substring(0, longName.IndexOf(' '));
			}
			else{
				shortName = longName;
			}

            //Get the objects status. THIS WILL BE ADDED ONTO LATER.
            Debug.Log("STATUSES HAVE NOT BEEN IMPLEMENTED TO GRAB STATUS FROM OBJECT. STATUSES DOES WORK ON OBJECTS THOUGH.");
            int status = 0;

            //Awful way to get status
            /*
            if(shortName.CompareTo("GravitySwitch") == 0)
            {
                gravityWheelControl getStatus = thisObject.gameObject.GetComponent(gravityWheelControl);
                thisObject.GetComponent(SpriteRenderer).name;
            }
            */

            //Get the objects rotation.
            float rotation = thisObject.transform.rotation.z;

            //Compile it all to a single string. OBSELETE BUT WILL BE USED FOR DEBUGGING FOR NOW.
            //string result = "SL:" + shortName + ":" + thisObject.transform.position.x + ":" + thisObject.transform.position.y;
            //Debug.Log(result);

            //Add object to list. DOES NOT USE PROPER GRIDS YET.
            jsonMessage.AddObject(shortName, (int)thisObject.transform.position.x, (int)thisObject.transform.position.y, rotation, 1);
		}


		/*
         * SEND END LEVEL OBJECT
        */

        GameObject endObject = GameObject.FindGameObjectWithTag("Exit");

        //Gets Objects proper name without all the duplicate issues
        string endlongName = endObject.transform.name;
        string endshortName;

        //If the object has "duplicate" text added to object name
        if ((endlongName.IndexOf(' ') + 1) != 0)
        {
            endshortName = endlongName.Substring(0, endlongName.IndexOf(' '));
        }
        else
        {
            endshortName = endlongName;
        }

        //Get the objects status. THIS WILL BE ADDED ONTO LATER.
        int endstatus = 0;

        //Get the objects rotation. THIS WILL BE ADDED ONTO LATER.
        float endrotation = endObject.transform.rotation.z;

        //Compile it all to a single string
        //string endresult = "SL:" + endshortName + ":" + endObject.transform.position.x + ":" + endObject.transform.position.y;
        //Debug.Log(endresult);

        //Add object to list
        jsonMessage.AddObject(endshortName, (int)endObject.transform.position.x, (int)endObject.transform.position.y, endrotation, 3);
        

        /*
         * SEND ARRAY
        */

        /*
        //Serialize array
        string message = jsonMessage.serializeArray();
        Debug.Log("Serialized output: " + message);

        //Sends jsonMessage to client
        
        Debug.Log("Sending Array of Messages");
        input.text = message;
        SendReadyToBeginMessage(0);
        input.text = "";
        */

        //Save level to file
        string message = jsonMessage.serializeArray();
        saveLevel(message);

		
	}