using System; using System.Collections; using System.Collections.Generic; using System.IO; using UnityEngine; public class CloudPoint : MonoBehaviour { // Start is called before the first frame update private GameObject pointCloud; private List headAvatarList; private List headMeshFilterList; public Material matVertex; public VyncCelect _VyncCloud; public int offsetZ=2; public float headPointSize=0;//0.005 public float bodyPointSize=0;//0.01f public TextMesh _fpsText; public TextMesh _SizeText; public string ip; // public WebRtcManager _WebRtcManager; void Start() { headAvatarList=new List(); headMeshFilterList=new List(); pointCloud = new GameObject ("avatar"); pointCloud.transform.position = new Vector3(-1.063f, -0.427f, -1.688f); pointCloud.transform.parent = transform; _VyncCloud = VyncCelect.GetInstance(); _VyncCloud.HOST = ip; _VyncCloud.StartThread(); _fpsText.gameObject.SetActive(false); _SizeText.gameObject.SetActive(false); StartCoroutine("renderCloud"); } void OnDestroy() { Debug.Log("OnDestroy"); StopCoroutine("renderCloud"); if(_VyncCloud!=null) _VyncCloud.destory(); // _WebRtcManager.leaveRoom(); } private bool isLost; public void clear(bool vis) { if(!isLost&&!vis||vis==isLost) return; isLost = vis; pointCloud.SetActive(vis); } private bool init=false; private void Update() { _VyncCloud.offsetZ = offsetZ; _VyncCloud.headPointSize = headPointSize; _VyncCloud.bodyPointSize = bodyPointSize; _fpsText.text = _VyncCloud.timeDelay.ToString()+"ms Fps:"+1000/_VyncCloud.timeDelay; _SizeText.text ="SNCount:"+_VyncCloud._curDeviceSN_Array_NUM+ " curSN:" + _VyncCloud._curDeviceSN_NUM; } public void initSocket() { if (init) { // _WebRtcManager.MicrophoneMute(); } if (init) { // _WebRtcManager.SpeakerMute(); } if (init) { // _WebRtcManager.ToggleMic1(); } if (!init) { init = true; #if UNITY_ANDROID // _WebRtcManager.initSocket(ip); // Invoke("initUser",2); #endif } } public void initUser() { return; #if UNITY_ANDROID // _WebRtcManager.loginUser(_VyncCloud._curDeviceSN_NUM); Invoke("jionORcreateRoom",2); #endif } public void jionORcreateRoom() { #if UNITY_ANDROID // _WebRtcManager.createOrJoinRoom(); #endif } IEnumerator renderCloud() { while (true) { if (!_VyncCloud.isUpdatae) { //Debug.Log("初始没完成 "); yield return null; continue; } if (headAvatarList.Count > _VyncCloud.headPointGroups) { for (int i=_VyncCloud.headPointGroups;imeshInd&&headAvatarList[meshInd] != null) { //Debug.Log("xjytest:loadhead_"+meshInd.ToString()+" headAvatarList:"+headAvatarList.Count); CreateMesh(meshInd, headMeshFilterList[meshInd].mesh); } else { // Debug.Log("xjytest:head_"+meshInd.ToString()+" headAvatarList:"+headAvatarList.Count); GameObject obj = new GameObject("head_" + meshInd.ToString()); MeshFilter _MeshFilter = obj.AddComponent(); MeshRenderer _MeshRenderer= obj.AddComponent(); headAvatarList.Add(obj); headMeshFilterList.Add(_MeshFilter); obj.transform.parent = pointCloud.transform; obj.transform.localPosition=new Vector3(0,0,0); _MeshFilter.mesh = CreateMesh(meshInd); _MeshRenderer.material = matVertex; _MeshRenderer.material.SetMatrix("_Transform", transform.localToWorldMatrix); } // matVertex.SetFloat("_Size", pointSize); } private int[] indecies; private Vector3[] myPoints; private Color[] myColors; private int indexnum = 0; Mesh CreateMesh(int id,Mesh _mesh = null) { indexnum++; if (_mesh == null) { _mesh = new Mesh(); indecies = new int[_VyncCloud.limitPoints]; for (int i = 0; i < _VyncCloud.limitPoints; ++i) { indecies[i] = i; } //WriteIntoTxt(_VyncCloud.fileStr); } // Debug.Log("xjytest:_VyncCloud.headpostionList:"+_VyncCloud.headpostionList.Count+"_VyncCloud.headcolorList[id]:"+_VyncCloud.headcolorList.Count+" xjytest id: "+id+" meshid:"+_mesh.name+indexnum); _mesh.vertices =_VyncCloud.headpostionList[id]; _mesh.colors = _VyncCloud.headcolorList[id]; _mesh.SetIndices(indecies, MeshTopology.Triangles, 0); return _mesh; } }