Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.76 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using MySql.Data.MySqlClient;
  5.  
  6. public class PrefabHandler : MonoBehaviour {
  7.  
  8. public string SQL_DATABASE_NAME = "";
  9. public string SQL_USERNAME = "";
  10. public string SQL_PASSWORD = "";
  11. public string SQL_PORT = "";
  12. public string SQL_HOST = "";
  13.  
  14. private string connectionString = null;
  15. MySql.Data.MySqlClient.MySqlConnection cnn;
  16.  
  17.  
  18. private string goName;
  19. private int goID;
  20. private int goTransformX;
  21. private int goTransformY;
  22. private int goTransformZ;
  23. private int goRotateX;
  24. private int goRotateY;
  25. private int goRotateZ;
  26.  
  27.  
  28.  
  29. public void Start ()
  30. {
  31.  
  32. connectionString = "Data Source=" + SQL_HOST + "," + SQL_PORT + ";" + "Initial Catalog=" + SQL_DATABASE_NAME + ";" + "User ID=" + SQL_USERNAME + ";" + "Password=" + SQL_PASSWORD + ";";
  33.  
  34. cnn = new MySql.Data.MySqlClient.MySqlConnection(connectionString);
  35.  
  36.     try {
  37.         Debug.Log("Connecting to MySQL");
  38.         cnn.Open();
  39.         MySql.Data.MySqlClient.MySqlBulkLoader ObjectLoader = new MySql.Data.MySqlClient.MySqlBulkLoader(cnn);
  40.  
  41.         //*CREATE TABLE GameObjects (Name VARCHAR(100) NOT NULL, GameObjectID INTEGER, TransformX INTEGER, TransformY INTEGER, TransformZ INTEGER, RotateX INTEGER, RotateY INTEGER, RotateZ INTEGER); */
  42.         //*INSERT INTO GameObjects (Name, GameObjectID, TransformX, TransformY, TransformZ, RotateX, RotateY, RotateZ) VALUES ( "" , , , , , , , ); */
  43.         //*EX: INSERT INTO GameObjects (Name, GameObjectID, TransformX, TransformY, TransformZ, RotateX, RotateY, RotateZ) VALUES ( "Skeleton" , 1, 295, 10, 120, 0, 80, 0); */
  44.  
  45.  
  46.         string sql = "SELECT Name,GameObjectID,TransformX,TransformY,TransformZ,RotateX,RotateY,RotateZ FROM GameObjects";
  47.  
  48.         MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand(sql, cnn);
  49.  
  50.         MySql.Data.MySqlClient.MySqlDataReader goInfo = cmd.ExecuteReader();
  51.  
  52.        
  53.             while(goInfo.Read())
  54.             {
  55.                 goName = (string)goInfo[0];
  56.                 goID = (int)goInfo[1];
  57.                 goTransformX = (int)goInfo[2];
  58.                 goTransformY = (int)goInfo[3];
  59.                 goTransformZ = (int)goInfo[4];
  60.                 goRotateX = (int)goInfo[5];
  61.                 goRotateY = (int)goInfo[6];
  62.                 goRotateZ = (int)goInfo[7];
  63.             }
  64.  
  65.             //Skeleton Spawner
  66.             if(goID == 1)
  67.             {
  68.             GameObject go = (GameObject)Instantiate(Resources.Load("Skeleton"),new Vector3(goTransformX,goTransformY,goTransformZ)
  69.                                                 ,Quaternion.Euler(goRotateX,goRotateY,goRotateZ));
  70.             }
  71.        
  72.         goInfo.Close();
  73.         cnn.Close();
  74.     }
  75.     catch
  76.     {
  77.         Debug.Log("Failed Connection");
  78.     }
  79.  
  80.  
  81. }
  82.  
  83.  
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement