void LoadObject(string _name, NetworkViewID _viewID, Vector3 _pos, Vector3 _angles, Vector3 _scale, string _filename, string _id) { //on regarde si l'object n'existe pas déjà foreach (NAObject o in NA.app.listObjects) { if (o.id == _id) { return; } } Debug.Log("RPC LoadObject " + _name + " " + _filename); // créer un objet vide pour la synchro, puis ajouter l'objet téléchargé en child NAObject n = new NAObject(NA.app.goRootSpace, _name, _pos, _angles, _scale, _filename, _viewID); n.id = _id; NA.app.listObjects.Add(n); n.Download(); }
void OnGUI() { GUI.color = new Color(0, 0, 0, 0.5f); GUI.DrawTexture(new Rect(0, 0, Screen.width, 30), texWhite); GUI.color = Color.white; //GUI.Label(new Rect(0,0,400,30), "NewAtlantisNew Client - SAIC workshop"); GUI.Label(new Rect(0, 0, 400, 30), "New Atlantis Client v0.31"); /*strSpace = GUI.TextField (new Rect (300, 0, 200, 30), strSpace); * if (GUI.Button (new Rect(500,0, 100, 30), "Connect")) * { * Connect(strSpace); * return; * } * if (GUI.Button (new Rect(600,0,100,30), "Disconnect")) * { * Disconnect(); * return; * } * */ /*if (GUI.Button (new Rect (700, 0, 50, 30), "pause")) * { * Time.timeScale = 0f; * } * if (GUI.Button (new Rect (750, 0, 50, 30), "play")) * { * Time.timeScale = 1f; * }*/ /* * GUI.Label (new Rect(0, 30, 200, 30), "ip=" + Network.player.ipAddress); * strIP = GUI.TextField(new Rect(100, 30, 100, 30), strIP); * if (GUI.Button (new Rect (200, 30, 100, 30), "start server")) * { * Network.InitializeServer(32, 25002, false); * CreateNetworkAvatar(); * } * * if (GUI.Button (new Rect (300, 30, 100, 30), "connect to server")) * { * Network.Connect(strIP, 25002); * //CreateNetworkAvatar(); * } * */ if (bStartPopup) { float popupx = Screen.width / 2 - 200; float popupy = Screen.height / 2 - 200; GUI.Box(new Rect(popupx, popupy, 400, 400), "Welcome to the New Atlantis"); popupy += 30; foreach (string space in spaces) { if (GUI.Button(new Rect(popupx, popupy, 400, 30), space)) { strSpace = space; Connect(space); } popupy += 30; } popupy += 30; if (GUI.Button(new Rect(popupx, popupy, 400, 30), "close")) { bStartPopup = false; } } //toolbar bGUI = GUI.Toggle(new Rect(0, 60, 100, 30), bGUI, "GUI"); /* * int camx = Screen.width - 100; * int camy = 0; * GUI.Label (new Rect(camx, camy, 100, 30), "Cameras : "); * camy += 30; * foreach (GameObject c in cameras) * { * if (selectedCamera == c.camera) * GUI.color = Color.red; * else * GUI.color = Color.white; * string name = c.name; * if (c.gameObject.transform.parent != null) * name = c.gameObject.transform.parent.gameObject.name; * if (GUI.Button (new Rect(camx,camy,100,30), name)) * { * selectedCamera.enabled = false; * selectedCamera.GetComponent<AudioListener>().enabled = false; * selectedCamera = c.camera; * selectedCamera.enabled = true; * selectedCamera.GetComponent<AudioListener>().enabled = true; * } * camy +=30; * GUI.color = Color.white; * } */ //bottom toolbar int bottomy = Screen.height - 30; GUI.color = new Color(0, 0, 0, 0.5f); GUI.DrawTexture(new Rect(0, bottomy, Screen.width, 30), texWhite); GUI.color = Color.white; //GUI.color = goMainLight.activeSelf ? Color.red : Color.white; /*if (GUI.Button (new Rect(0, bottomy, 100, 30), "light")) * { * goMainLight.SetActive(!goMainLight.activeSelf); * } * GUI.color = mainCamera.light.enabled ? Color.red : Color.white; * if (GUI.Button (new Rect(100, bottomy, 100, 30), "headlight")) * { * mainCamera.light.enabled = !mainCamera.light.enabled; * } */ //right toolbar /*GUI.color = new Color (0, 0, 0, 0.5f); * GUI.DrawTexture (new Rect (Screen.width-100, 0, 100, Screen.height), texWhite); * GUI.color = Color.white; * int lightx = Screen.width-100; * int lighty = Screen.height/2; * GUI.Label(new Rect(lightx, lighty, 200, 30), "Lights"); * lighty += 30; * Light[] lights = Light.FindObjectsOfType (typeof(Light)) as Light[]; * foreach (Light l in lights) * { * GUI.color = l.enabled ? Color.red : Color.white; * if (l.name.Contains("Creature")) * continue; * if (l.name.Contains("Area")) * continue; * if (GUI.Button (new Rect(lightx, lighty, 100, 30), l.name)) * { * l.enabled = !l.enabled; * } * //lightx +=100; * lighty += 30; * } */ GUI.color = bPushObjects?Color.red:Color.white; /*if (GUI.Button (new Rect(0, Screen.height-30, 100, 30), "push objects")) * { * bPushObjects = !bPushObjects; * } * * if (GUI.Button (new Rect(100, Screen.height-30, 100, 30), "augment water")) * { * VerySpecialCase(); * } */ GUI.color = bChat?Color.red:Color.white; if (GUI.Button(new Rect(200, 0, 100, 30), "chat")) { bChat = !bChat; } GUI.color = bNetwork?Color.red:Color.white; if (GUI.Button(new Rect(300, 0, 100, 30), "network")) { bNetwork = !bNetwork; } GUI.color = bCameras?Color.red:Color.white; if (GUI.Button(new Rect(400, 0, 100, 30), "cameras")) { bCameras = !bCameras; } GUI.color = bLights?Color.red:Color.white; if (GUI.Button(new Rect(500, 0, 100, 30), "lights")) { bLights = !bLights; } GUI.color = bSpace?Color.red:Color.white; if (GUI.Button(new Rect(600, 0, 100, 30), "space")) { bSpace = !bSpace; } GUI.color = bOptions?Color.red:Color.white; if (GUI.Button(new Rect(700, 0, 100, 30), "options")) { bOptions = !bOptions; } GUI.color = bAbout?Color.red:Color.white; if (GUI.Button(new Rect(800, 0, 100, 30), "about")) { bAbout = !bAbout; } //to do : list of objects ? GUI.color = Color.white; if (bGUI) { strFile = GUI.TextField(new Rect(400, 30, 200, 30), strFile); /*if (GUI.Button (new Rect(600,30, 100, 30), "load local")) * { * currentLocal = new NAObject ("local", new Vector3 (5, 5, 5), Vector3.zero, strFile); * currentLocal.DownloadLocal(); * } */ /*if (GUI.Button (new Rect(0,60,100,30), "download all")) * { * DownloadAll(); * } */ if (GUI.Button(new Rect(300, 60, 50, 30), "x-")) { currentSelection.go.transform.position += new Vector3(-1, 0, 0); } if (GUI.Button(new Rect(350, 60, 50, 30), "x+")) { currentSelection.go.transform.position += new Vector3(1, 0, 0); } if (GUI.Button(new Rect(400, 60, 50, 30), "y-")) { currentSelection.go.transform.position += new Vector3(0, -1, 0); } if (GUI.Button(new Rect(450, 60, 50, 30), "y+")) { currentSelection.go.transform.position += new Vector3(0, 1, 0); } if (GUI.Button(new Rect(500, 60, 50, 30), "z-")) { currentSelection.go.transform.position += new Vector3(0, 0, -1); } if (GUI.Button(new Rect(550, 60, 50, 30), "z+")) { currentSelection.go.transform.position += new Vector3(0, 0, 1); } if (GUI.Button(new Rect(600, 60, 50, 30), "ry+")) { currentSelection.go.transform.eulerAngles += new Vector3(0, 10, 0); } if (GUI.Button(new Rect(650, 60, 50, 30), "ry-")) { currentSelection.go.transform.eulerAngles += new Vector3(0, -10, 0); } //downloads state int y = 100; foreach (NAObject o in listObjects) { if (o == currentSelection) { GUI.color = Color.red; } else { GUI.color = Color.white; } GUI.Label(new Rect(0, y, 200, 30), o.name); GUI.Label(new Rect(200, y, 200, 30), o.file); if (o.www != null) { GUI.Label(new Rect(400, y, 100, 30), "downloading"); } else { GUI.Label(new Rect(400, y, 100, 30), "" + o.downloaded / 1000 + " KB"); } //GUI.Label(new Rect(400,y,100,30), o.GetStatus()); if (o.go != null) { if (GUI.Button(new Rect(500, y, 50, 30), "select")) { if (currentSelection == o) { currentSelection = null; } else { currentSelection = o; } } if (GUI.Button(new Rect(550, y, 50, 30), "save")) { o.position = o.go.transform.position; o.angles = o.go.transform.eulerAngles; SetObjectPosition(o.id, o.position.x, o.position.y, o.position.z); } if (GUI.Button(new Rect(600, y, 50, 30), "delete")) { o.position = o.go.transform.position; o.angles = o.go.transform.eulerAngles; SetObjectSpace(o.id, "trash"); //move to trash GameObject.Destroy(o.go); o.go = null; } /*if (GUI.Button (new Rect(700, y, 100, 30), "grab")) * { * o.go.transform.parent = selectedCamera.transform; * o.go.transform.localPosition = new Vector3(0,0,1); * } */ } //GUI.Label(new Rect(300,y,200,30), o.name); y += 30; GUI.color = Color.white; } int x = 0; } if (bChat) { mGuiWinRectChat = GUI.Window(1, mGuiWinRectChat, WindowFunctionChat, "CHAT"); } if (bNetwork) { mGuiWinRectNetwork = GUI.Window(2, mGuiWinRectNetwork, WindowFunctionNetwork, "NETWORK"); } if (bCameras) { mGuiWinRectCameras = GUI.Window(3, mGuiWinRectCameras, WindowFunctionCameras, "CAMERAS"); } if (bLights) { mGuiWinRectLights = GUI.Window(4, mGuiWinRectLights, WindowFunctionLights, "LIGHTS"); } if (bSpace) { mGuiWinRectSpace = GUI.Window(5, mGuiWinRectSpace, WindowFunctionSpace, "SPACES"); } if (bOptions) { mGuiWinRectOptions = GUI.Window(6, mGuiWinRectOptions, WindowFunctionOptions, "OPTIONS"); } if (bAbout) { mGuiWinRectAbout = GUI.Window(7, mGuiWinRectAbout, WindowFunctionAbout, "ABOUT"); } }
void ParseXML(string str) { Debug.Log("parsing XML..."); xml = new XmlDocument(); xml.XmlResolver = null; try { xml.LoadXml(str); } catch (XmlException e) { //Console.WriteLine(e.Message); } xpn = xml.CreateNavigator(); XPathNodeIterator xpni = xpn.Select("/space"); if (xpni == null) { Debug.Log("no space node"); return; } xpni.MoveNext(); if (xpni.Current == null) { return; } XPathNodeIterator xpnic = xpni.Current.SelectChildren(XPathNodeType.Element); if (xpnic == null) { return; } while (xpnic.MoveNext()) { if (xpnic.Current.Name.Equals("object")) { Hashtable httags = null; string name = xpnic.Current.GetAttribute("name", ""); string filename = xpnic.Current.GetAttribute("filename", ""); string id = xpnic.Current.GetAttribute("id", ""); float x = float.Parse(xpnic.Current.GetAttribute("x", "")); float y = float.Parse(xpnic.Current.GetAttribute("y", "")); float z = float.Parse(xpnic.Current.GetAttribute("z", "")); float ax = float.Parse(xpnic.Current.GetAttribute("ax", "")); float ay = float.Parse(xpnic.Current.GetAttribute("ay", "")); float az = float.Parse(xpnic.Current.GetAttribute("az", "")); if (filename.Contains("2.9")) { continue; } NAObject n = new NAObject(name, new Vector3(x, y, z), new Vector3(ax, ay, az), filename); n.id = id; listObjects.Add(n); } } }