////////////////////////////////////////////////////////////RegisterCallback//////////////////////////////////////////////////////////////////////////////////// static void Msg_ReqObject(JsonData json, DToolClient client) { string path = json["p"].ToString(); int instanceID = json["i"].AsInt; GameObject go = FindObject(path, client, instanceID); if (go == null) { return; } int active = 0; if (go.activeSelf) { active = 1; } JsonData jsonData = new JsonData(); jsonData["p"] = path; jsonData["i"] = go.GetInstanceID(); jsonData["a"] = active; jsonData["px"] = go.transform.position.x; jsonData["py"] = go.transform.position.y; jsonData["pz"] = go.transform.position.z; jsonData["rx"] = go.transform.eulerAngles.x; jsonData["ry"] = go.transform.eulerAngles.y; jsonData["rz"] = go.transform.eulerAngles.z; jsonData["sx"] = go.transform.localScale.x; jsonData["sy"] = go.transform.localScale.y; jsonData["sz"] = go.transform.localScale.z; client.SendToServer((int)DTool_CTS.DTool_CTS_UpdateObject, jsonData.ToJson()); }
static GameObject FindObject(string path, DToolClient client, int instanceID) { GameObject go = null; bool isFind = client.mSceneGameObjects.TryGetValue(instanceID, out go); if (isFind) { return(go); } go = GameObject.Find(path); if (go == null) { int index = path.IndexOf('/'); if (index <= -1) { return(null); } string headPath = path.Substring(0, index); GameObject root = GameObject.Find(headPath); if (root == null) { return(null); } path = path.Substring(index + 1); Transform t = root.transform.Find(path); if (t == null) { return(null); } go = t.gameObject; } return(go); }
static void Msg_ReqMemory(JsonData json, DToolClient client) { JsonData jsonRoot = new JsonData(); jsonRoot["trm"] = ToCommasNumber(UnityEngine.Profiling.Profiler.GetTotalReservedMemoryLong()); // 总堆内存; jsonRoot["tam"] = ToCommasNumber(UnityEngine.Profiling.Profiler.GetTotalAllocatedMemoryLong()); // 已占用内存; jsonRoot["turm"] = ToCommasNumber(UnityEngine.Profiling.Profiler.GetTotalUnusedReservedMemoryLong()); // 空闲中内存; jsonRoot["mhs"] = ToCommasNumber(UnityEngine.Profiling.Profiler.GetMonoHeapSizeLong()); // 总Mono堆内存; jsonRoot["mus"] = ToCommasNumber(UnityEngine.Profiling.Profiler.GetMonoUsedSizeLong()); // 已占用Mono堆内存; client.SendToServer((int)DTool_CTS.DTool_CTS_Memory, jsonRoot.ToJson()); }
static void Msg_ReqActive(JsonData json, DToolClient client) { string path = json["p"].ToString(); int instanceID = json["i"].AsInt; int active = 0; if (!int.TryParse(json["a"].ToString(), out active)) { return; } GameObject go = FindObject(path, client, instanceID); if (go == null) { return; } go.SetActive(active > 0); }
static void Msg_ReqUpdateHierarchy(JsonData json, DToolClient client) { client.logic.UpdateHierarchy(); }
static void Msg_ReqObjMemory(JsonData json, DToolClient client) { int objType = 0; if (!int.TryParse(json["t"].ToString(), out objType)) { return; } MemoryObjType mot = (MemoryObjType)objType; Type tp = typeof(UnityEngine.Object); switch (mot) { case MemoryObjType.MemoryObjType_RenderTexture: tp = typeof(RenderTexture); break; case MemoryObjType.MemoryObjType_Texture2D: tp = typeof(Texture2D); break; case MemoryObjType.MemoryObjType_CubeMap: tp = typeof(Cubemap); break; case MemoryObjType.MemoryObjType_Mesh: tp = typeof(Mesh); break; case MemoryObjType.MemoryObjType_AnimationClip: tp = typeof(AnimationClip); break; } JsonData rootJson = new JsonData(); JsonData arrayJson = new JsonData(); long totalSize = 0; UnityEngine.Object[] objs = Resources.FindObjectsOfTypeAll(tp); for (int i = 0; i < objs.Length; ++i) { JsonData jsonData = new JsonData(); jsonData["t"] = objType; UnityEngine.Object obj = objs[i]; switch (mot) { case MemoryObjType.MemoryObjType_RenderTexture: { RenderTexture rt = obj as RenderTexture; jsonData["n"] = rt.name; jsonData["w"] = rt.width; jsonData["h"] = rt.height; jsonData["d"] = rt.depth; jsonData["f"] = (int)rt.format; } break; case MemoryObjType.MemoryObjType_Texture2D: { Texture2D tex = obj as Texture2D; jsonData["n"] = tex.name; jsonData["w"] = tex.width; jsonData["h"] = tex.height; jsonData["m"] = tex.mipmapCount; jsonData["f"] = (int)tex.format; } break; case MemoryObjType.MemoryObjType_CubeMap: { Cubemap cubmap = obj as Cubemap; jsonData["n"] = cubmap.name; jsonData["w"] = cubmap.width; jsonData["h"] = cubmap.height; jsonData["f"] = (int)cubmap.format; jsonData["m"] = cubmap.mipmapCount; } break; case MemoryObjType.MemoryObjType_Mesh: { Mesh mesh = obj as Mesh; jsonData["n"] = mesh.name; jsonData["r"] = mesh.isReadable; jsonData["v"] = mesh.vertexCount; jsonData["smc"] = mesh.subMeshCount; JsonData smdata = new JsonData(); jsonData["sm"] = smdata; for (int s = 0; s < mesh.subMeshCount; ++s) { smdata.Add((int)mesh.GetIndexCount(s)); } } break; case MemoryObjType.MemoryObjType_AnimationClip: { AnimationClip clip = obj as AnimationClip; jsonData["n"] = clip.name; jsonData["l"] = clip.length; jsonData["il"] = clip.isLooping ? 1 : 0; } break; } long msz = UnityEngine.Profiling.Profiler.GetRuntimeMemorySizeLong(obj); jsonData["sz"] = msz; totalSize += msz; arrayJson.Add(jsonData); } if (arrayJson.IsArray) { rootJson["a"] = arrayJson; } rootJson["s"] = totalSize; client.SendToServer((int)DTool_CTS.DTool_CTS_ObjMemory, rootJson.ToJson()); }