private async Task <byte[]> ActionChangeTransform(NameValueCollection queryString) { var vector = new Vector3( ParseStringToFloat(queryString.Get("x")), ParseStringToFloat(queryString.Get("y")), ParseStringToFloat(queryString.Get("z"))); await TaskSwitcher.SwitchToMainThread(); var changeGameObject = GetGameObjectById(queryString.Get("id")); var fieldChange = queryString.Get("transformType"); switch (fieldChange) { case "position": changeGameObject.transform.position = vector; break; case "rotation": changeGameObject.transform.rotation = Quaternion.Euler(vector); break; case "scale": changeGameObject.transform.localScale = vector; break; } return(ResponseTools.CreateOkResponse()); }
private async Task <byte[]> ActionChangeTransform(NameValueCollection queryString) { var vector = new Vector3( ParseFloatString(queryString.Get("x")), ParseFloatString(queryString.Get("y")), ParseFloatString(queryString.Get("z"))); await TaskSwitcher.SwitchToMainThread(); var idGameObject = int.Parse(queryString.Get("id")); var hierarchy = HierarchyTools.GetHierarchyActiveScene(); hierarchy.gameobjectsDictonary.TryGetValue(idGameObject, out var changeGameObject); var fieldChange = queryString.Get("transformType"); switch (fieldChange) { case "position": changeGameObject.transform.position = vector; break; case "rotation": changeGameObject.transform.rotation = Quaternion.Euler(vector); break; case "scale": changeGameObject.transform.localScale = vector; break; } return(ResponseTools.CreateOkResponse()); }
public override async Task <ResponseData> MakeResponseData() { var pathWithoutParams = context.AbsolutePath; ResponseData responseData = new ResponseData(); string filePath = pathWithoutParams.Remove(0, 1); if (string.IsNullOrEmpty(filePath)) { filePath = "index.html"; } FileReadResult fileReadResult = await _resourceFileStorage.ReadFileFromResource(filePath); if (!fileReadResult.IsError) { responseData.data = fileReadResult.data; } else { Debug.LogError($"Error load file - {filePath}"); responseData.data = ResponseTools.ConvertStringToResponseData($"Error load file {filePath}"); } return(responseData); }
public override async Task <ResponseData> MakeResponseData() { var idString = context.HttpListenerContext.Request.QueryString.Get("id"); if (string.IsNullOrEmpty(idString)) { throw new Exception("Dont find tag \"id\" in query string"); } var idInt = int.Parse(idString); byte[] finalArray = new byte[0]; if (_sceneHierarchyData == null) { _sceneHierarchyData = HierarchyTools.GetHierarchyActiveScene(); } if (_sceneHierarchyData.gameobjectsDictonary.TryGetValue(idInt, out GameObject go)) { await TaskSwitcher.SwitchToMainThread(); Vector3 position = go.transform.position; Vector3 rotation = go.transform.rotation.eulerAngles; Vector3 scale = go.transform.localScale; GameObjectInfo objectInfo = new GameObjectInfo() { activeSelf = go.activeSelf, name = go.name, position = position, rotation = rotation, scale = scale, }; var json = JsonConvert.SerializeObject(objectInfo, Formatting.Indented, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); finalArray = ResponseTools.ConvertStringToResponseData(json); if (LogToConsoleConfig.IsLogToConsole) { Debug.Log(json); } } else { throw new Exception("Dont find id object " + idInt); } return(new ResponseData() { data = finalArray, }); }
private async Task <byte[]> ActionChangeEnableGameObject(NameValueCollection queryString) { await TaskSwitcher.SwitchToMainThread(); bool activeGameObject = ParseStringToBool(queryString.Get("activeSelf")); var changeGameObject = GetGameObjectById(queryString.Get("id")); changeGameObject.SetActive(activeGameObject); return(ResponseTools.CreateOkResponse()); }
public override async Task <ResponseData> MakeResponseData() { if (_sceneHierarchyData == null) { _sceneHierarchyData = HierarchyTools.GetHierarchyActiveScene(); } var json = JsonConvert.SerializeObject(_sceneHierarchyData, Formatting.Indented); return(new ResponseData() { data = ResponseTools.ConvertStringToResponseData(json) }); }
private async Task <byte[]> ActionDelete(NameValueCollection queryString) { var idString = queryString.Get("id"); if (string.IsNullOrEmpty(idString)) { throw new Exception("Dont find id in ActionDelete action"); } if (int.TryParse(idString, out var idDelete)) { await DeleteGameObjectById(idDelete); return(ResponseTools.CreateOkResponse()); } return(new byte[0]); }
private async Task <ResponseData> OnResponseHandler(HttpServerContext context) { ResponseData responseData = null; try { responseData = await CreateResponse(context); } catch (Exception e) { responseData = new ResponseData { data = ResponseTools.ConvertStringToResponseData(e.Message) }; Debug.LogWarning(e.Message); } return(responseData); }
private async Task <byte[]> ActionMove(NameValueCollection queryString) { var idSourceString = queryString.Get("idSource"); var idDestinationString = queryString.Get("idDestination"); if (string.IsNullOrEmpty(idSourceString)) { throw new Exception("Dont find idSource in ActionMove action"); } if (string.IsNullOrEmpty(idDestinationString)) { throw new Exception("Dont find idDestination in ActionMove action"); } var idSourceInt = int.Parse(idSourceString); var idDestinationInt = int.Parse(idDestinationString); await MoveChildren(idSourceInt, idDestinationInt); return(ResponseTools.CreateOkResponse()); }