private GameObject GetGameObjectById(int id) { var hierarchy = HierarchyTools.GetHierarchyActiveScene(); hierarchy.gameobjectsDictonary.TryGetValue(id, out var changeGameObject); return(changeGameObject); }
public async Task <Response> CreateResponse(string pathWithoutParams) { Response response = null; if (pathWithoutParams.StartsWith("/json/hierarchy")) { await TaskSwitcher.SwitchToMainThread(); _sceneHierarchyData = HierarchyTools.GetHierarchyActiveScene(); response = new HierarchyResponse(_sceneHierarchyData); } else if (pathWithoutParams.StartsWith("/action")) { response = new ActionResponse(); } else if (pathWithoutParams.StartsWith("/gameObjectInfo")) { response = new GameObjectInfoResponse(_sceneHierarchyData); } else { response = new FileGetResponse(_resourceFileStorage); } response?.SetInfo(_context); return(response); }
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 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 DeleteGameObjectById(int idDeleteObject) { await TaskSwitcher.SwitchToMainThread(); var hierarchy = HierarchyTools.GetHierarchyActiveScene(); hierarchy.gameobjectsDictonary.TryGetValue(idDeleteObject, out var deleteObject); if (deleteObject != null) { UnityEngine.Object.DestroyImmediate(deleteObject.gameObject); } }
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 MoveChildren(int idMove, int idTarget) { await TaskSwitcher.SwitchToMainThread(); var hierarchy = HierarchyTools.GetHierarchyActiveScene(); hierarchy.gameobjectsDictonary.TryGetValue(idMove, out var moveObject); hierarchy.gameobjectsDictonary.TryGetValue(idTarget, out var targetObject); if (moveObject != null) { if (targetObject != null) { moveObject.transform.parent = targetObject.transform; } else { moveObject.transform.parent = null; } } }