public override void OnEvent(EventData eventData) { int roleId = -1; //获取SubCode,判断是增加还是删除角色 SubCode subCode; object o = null; eventData.Parameters.TryGetValue((byte)ParameterCode.SubCode, out o); subCode = (SubCode)o; eventData.Parameters.TryGetValue((byte)ParameterCode.RoleId, out o); roleId = (int)o; switch (subCode) { case SubCode.SyncPosAndRotation: //同步角色位置和旋转 object posObj = null; object rotObj = null; eventData.Parameters.TryGetValue((byte)ParameterCode.Position, out posObj); eventData.Parameters.TryGetValue((byte)ParameterCode.EulerAngles, out rotObj); Vector3Obj pos = JsonMapper.ToObject <Vector3Obj>(posObj.ToString()); Vector3Obj rotation = JsonMapper.ToObject <Vector3Obj>(rotObj.ToString()); SyncPositonAndRotationResponse(roleId, pos.ToVector3(), rotation.ToVector3()); break; case SubCode.SyncPlayerMoveAnimation: PlayerMoveAnimationModel model = new PlayerMoveAnimationModel(); eventData.Parameters.TryGetValue((byte)ParameterCode.PlayerMoveAnimationModel, out o); model = JsonMapper.ToObject <PlayerMoveAnimationModel>(o.ToString()); SyncPlayerMoveAnimationResponse(roleId, model); break; default: break; } }
public Vector3Obj getNextPos() { Vector3 nectPos = new Vector3(); nectPos = pos.ToVector3() + length * dir.ToVector3(); return(Vector3Obj.ToVector3Obj(nectPos)); }
public static Vector3Obj ToVector3Obj(Vector3 xyz) { Vector3Obj temp = new Vector3Obj(); temp.x = xyz.x; temp.y = xyz.y; temp.z = xyz.z; return(temp); }
void writeUp() { for (int i = 0; i < HSpheres.Count; i++) { for (int j = 0; j < HSpheres[i].Count; j++) { Hxx.HxxUs[i][j].pos = Vector3Obj.ToVector3Obj(HSpheres[i][j].transform.position); } } string strSerializeJSON = JsonConvert.SerializeObject(Hxx.HxxUs); //Debug.Log(strSerializeJSON); File.WriteAllText(infoPath, strSerializeJSON); Debug.Log("writeUp"); }
//发起同步位置和旋转请求 public void SyncPositonAndRotationRequest(Vector3 position, Vector3 eulerAngles) { //向服务器发起请求 Dictionary <byte, object> parameters = new Dictionary <byte, object>(); Vector3Obj posObj = new Vector3Obj(position); Vector3Obj eulerObj = new Vector3Obj(eulerAngles); string jsonPos = JsonMapper.ToJson(posObj); string jsonEuler = JsonMapper.ToJson(eulerObj); parameters.Add((byte)ParameterCode.Position, jsonPos); parameters.Add((byte)ParameterCode.EulerAngles, jsonEuler); parameters.Add((byte)ParameterCode.RoleId, PhotonEngine.Instance.role.ID); parameters.Add((byte)ParameterCode.ChannelID, PhotonEngine.Instance.ChannelId); parameters.Add((byte)ParameterCode.SubCode, SubCode.SyncPosAndRotation); PhotonEngine.Instance.SendRequest(OperationCode.SyncVilligePlayer, parameters); }
public void SyncTransPosAndRotationRequest(Vector3 position, Vector3 eulerAngles) { //向服务器发起请求 Dictionary <byte, object> parameters = new Dictionary <byte, object>(); Vector3Obj posObj = new Vector3Obj(position); Vector3Obj eulerObj = new Vector3Obj(eulerAngles); string jsonPos = JsonMapper.ToJson(posObj); string jsonEuler = JsonMapper.ToJson(eulerObj); parameters.Add((byte)ParameterCode.Position, jsonPos); parameters.Add((byte)ParameterCode.EulerAngles, jsonEuler); parameters.Add((byte)ParameterCode.RoleId, PhotonEngine.Instance.role.ID); parameters.Add((byte)ParameterCode.MasterRoleID, TeamInviteController.Instance.globalMasterID); parameters.Add((byte)ParameterCode.MemberIndex, PhotonEngine.Instance.memeberindex); parameters.Add((byte)ParameterCode.ChannelID, PhotonEngine.Instance.ChannelId); parameters.Add((byte)ParameterCode.SubCode, SubCode.SyncPosAndRotation); PhotonEngine.Instance.SendRequest(OperationCode.Battle, parameters); }
//同步敌人的位置和旋转请求 public void SyncEnermyPosAndRotationRequest(string guid, Vector3 position, Vector3 eulerAngles) { Vector3Obj posObj = new Vector3Obj(position); Vector3Obj eulerObj = new Vector3Obj(eulerAngles); string posJson = JsonMapper.ToJson(posObj); string eulerJson = JsonMapper.ToJson(eulerObj); Dictionary <byte, object> parameters = new Dictionary <byte, object>(); parameters.Add((byte)ParameterCode.EnermyGuid, guid); parameters.Add((byte)ParameterCode.Position, posJson); parameters.Add((byte)ParameterCode.EulerAngles, eulerJson); //其它必要参数:1.channelid , 2.role id, 3.master id, parameters.Add((byte)ParameterCode.ChannelID, PhotonEngine.Instance.ChannelId); parameters.Add((byte)ParameterCode.RoleId, PhotonEngine.Instance.role.ID); parameters.Add((byte)ParameterCode.MasterRoleID, PhotonEngine.Instance.masterid); parameters.Add((byte)ParameterCode.SubCode, SubCode.SyncEnermyPosAndRotation); //发送请求 PhotonEngine.Instance.SendRequest(OperationCode.SyncEnermy, parameters); }
public HxxSpheres(List <Vector3> pts_, List <int> faces_, List <Vector3> vn_, List <Vector3> faceCenters_, int initialNum) { HxxUs = new List <List <Node> >(); facesNum_ = faces_.Count / 3; for (int i = 0; i < facesNum_; i++) { List <Node> theFaceU = new List <Node>(); Vector3 thisFaceCenter = faceCenters_[i]; Vector3 thisNodeHead = thisFaceCenter; Vector3 initialDir = vn_[i]; for (int j = 0; j < initialNum; j++) { Node thisNode = new Node(); thisNode.pos = Vector3Obj.ToVector3Obj(thisNodeHead); thisNode.setTheDir(Vector3Obj.ToVector3Obj(initialDir)); thisNode.length = 0.08f; theFaceU.Add(thisNode); thisNodeHead = thisNode.getNextPos().ToVector3(); } HxxUs.Add(theFaceU); } }
//用服务器发送的数据同步敌人的位置和旋转 void SyncEnermyPosAndRotationResponse(Dictionary <byte, object> parameters) { string guid = ""; object o = null; Vector3Obj posObj = null; Vector3Obj eulerObj = null; parameters.TryGetValue((byte)ParameterCode.Position, out o); posObj = JsonMapper.ToObject <Vector3Obj>(o.ToString()); parameters.TryGetValue((byte)ParameterCode.EulerAngles, out o); eulerObj = JsonMapper.ToObject <Vector3Obj>(o.ToString()); parameters.TryGetValue((byte)ParameterCode.EnermyGuid, out o); guid = o.ToString(); //找到对应的 enermy 进行更新 GameObject enermyGo = null; enermyGoDict.TryGetValue(guid, out enermyGo); if (enermyGo != null) { //Debug.Log("posObj ==" + posObj.ToVector3()); enermyGo.transform.position = posObj.ToVector3(); enermyGo.transform.eulerAngles = eulerObj.ToVector3(); } }
public void setTheDir(Vector3Obj dirInd) { var temp = dirInd.ToVector3(); dir = Vector3Obj.ToVector3Obj(temp.normalized); }
// Update is called once per frame public void Update() { ; if (Input.GetMouseButtonDown(0)) { RaycastHit hit; Vector3 mousePos = Input.mousePosition; Ray ray = Camera.main.ScreenPointToRay(mousePos); if (Physics.Raycast(ray, out hit, 10000)) { Debug.DrawLine(ray.origin, hit.point, Color.red); MeshCollider collider = hit.collider as MeshCollider; if (collider == null || collider.sharedMesh == null) { theChosenFaceIdx = -1; return; } Mesh mesh0 = collider.sharedMesh; Vector3[] vertices = mesh0.vertices; int[] triangles = mesh0.triangles; theChosenFaceIdx = hit.triangleIndex; Vector3 p0 = hit.transform.TransformPoint(vertices[triangles[theChosenFaceIdx * 3]]); Vector3 p1 = hit.transform.TransformPoint(vertices[triangles[theChosenFaceIdx * 3 + 1]]); Vector3 p2 = hit.transform.TransformPoint(vertices[triangles[theChosenFaceIdx * 3 + 2]]); Transform transform = collider.transform; m_spheres[0].transform.position = transform.TransformPoint(p0); m_spheres[1].transform.position = transform.TransformPoint(p1); m_spheres[2].transform.position = transform.TransformPoint(p2); m_spheres[0].GetComponent <Renderer>().material.color = Color.blue; m_spheres[1].GetComponent <Renderer>().material.color = Color.green; m_spheres[2].GetComponent <Renderer>().material.color = Color.red; Debug.Log(theChosenFaceIdx); theChosenFaceSphereNum = HSpheres[theChosenFaceIdx].Count; if (theChosenFaceSphereNum < 1) { theChosenFaceWhichSphereIdx = -1; } else { theChosenFaceWhichSphereIdx = 0; } showUp(); } } if (Input.GetKeyDown(KeyCode.Equals) && theChosenFaceIdx >= 0) { theChosenFaceWhichSphereIdx++; theChosenFaceWhichSphereIdx = theChosenFaceWhichSphereIdx % theChosenFaceSphereNum; Debug.Log(theChosenFaceWhichSphereIdx); if (theChosenFaceSphereNum < 1) { theChosenFaceWhichSphereIdx = -1; } showUp(); Debug.Log("+"); } if (Input.GetKeyDown(KeyCode.Minus) && theChosenFaceIdx >= 0) { theChosenFaceWhichSphereIdx--; theChosenFaceWhichSphereIdx = theChosenFaceWhichSphereIdx % theChosenFaceSphereNum; Debug.Log(theChosenFaceWhichSphereIdx); if (theChosenFaceSphereNum < 1) { theChosenFaceWhichSphereIdx = -1; } showUp(); Debug.Log("-"); } ////////////////////////////////////////////////////////////////// if (Input.GetKeyDown(KeyCode.W) && theChosenFaceIdx >= 0 && theChosenFaceWhichSphereIdx >= 0) { Vector3 pos = HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position; pos.x -= inc1; HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position = pos; showUp(); } if (Input.GetKeyDown(KeyCode.E) && theChosenFaceIdx >= 0 && theChosenFaceWhichSphereIdx >= 0) { Vector3 pos = HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position; pos.x += inc1; HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position = pos; showUp(); } if (Input.GetKeyDown(KeyCode.S) && theChosenFaceIdx >= 0 && theChosenFaceWhichSphereIdx >= 0) { Vector3 pos = HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position; pos.y -= inc1; HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position = pos; showUp(); } if (Input.GetKeyDown(KeyCode.D) && theChosenFaceIdx >= 0 && theChosenFaceWhichSphereIdx >= 0) { Vector3 pos = HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position; pos.y += inc1; HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position = pos; showUp(); Debug.Log("-"); } if (Input.GetKeyDown(KeyCode.X) && theChosenFaceIdx >= 0 && theChosenFaceWhichSphereIdx >= 0) { Vector3 pos = HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position; pos.z -= inc1; HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position = pos; showUp(); Debug.Log("-"); } if (Input.GetKeyDown(KeyCode.C) && theChosenFaceIdx >= 0 && theChosenFaceWhichSphereIdx >= 0) { Vector3 pos = HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position; pos.z += inc1; HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position = pos; showUp(); Debug.Log("-"); } ///////////////////////////////////////////// if (Input.GetKeyDown(KeyCode.Q) && theChosenFaceIdx >= 0 && theChosenFaceWhichSphereIdx >= 0) { Vector3 pos = HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position; pos.x -= inc2; HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position = pos; showUp(); } if (Input.GetKeyDown(KeyCode.R) && theChosenFaceIdx >= 0 && theChosenFaceWhichSphereIdx >= 0) { Vector3 pos = HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position; pos.x += inc2; HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position = pos; showUp(); } if (Input.GetKeyDown(KeyCode.A) && theChosenFaceIdx >= 0 && theChosenFaceWhichSphereIdx >= 0) { Vector3 pos = HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position; pos.y -= inc2; HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position = pos; showUp(); } if (Input.GetKeyDown(KeyCode.F) && theChosenFaceIdx >= 0 && theChosenFaceWhichSphereIdx >= 0) { Vector3 pos = HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position; pos.y += inc2; HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position = pos; showUp(); Debug.Log("-"); } if (Input.GetKeyDown(KeyCode.Z) && theChosenFaceIdx >= 0 && theChosenFaceWhichSphereIdx >= 0) { Vector3 pos = HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position; pos.z -= inc2; HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position = pos; showUp(); Debug.Log("-"); } if (Input.GetKeyDown(KeyCode.V) && theChosenFaceIdx >= 0 && theChosenFaceWhichSphereIdx >= 0) { Vector3 pos = HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position; pos.z += inc2; HSpheres[theChosenFaceIdx][theChosenFaceWhichSphereIdx].transform.position = pos; showUp(); Debug.Log("-"); } //////////////////////////////////////////////////// if (Input.GetKeyDown(KeyCode.F1) && theChosenFaceIdx >= 0 && HSpheres[theChosenFaceIdx].Count > 1) { theChosenFaceWhichSphereIdx = 0; int theLastIdx = Hxx.HxxUs[theChosenFaceIdx].Count - 1; var willbedelete = HSpheres[theChosenFaceIdx][theLastIdx]; HSpheres[theChosenFaceIdx].RemoveAt(theLastIdx); Hxx.HxxUs[theChosenFaceIdx].RemoveAt(theLastIdx); Destroy(willbedelete); theChosenFaceSphereNum = HSpheres[theChosenFaceIdx].Count; showUp(); Debug.Log("delete node"); } if (Input.GetKeyDown(KeyCode.F5) && theChosenFaceIdx >= 0 && HSpheres[theChosenFaceIdx].Count > 0) { theChosenFaceWhichSphereIdx = 0; int theLastIdx = Hxx.HxxUs[theChosenFaceIdx].Count - 1; Node lastNode = Hxx.HxxUs[theChosenFaceIdx][theLastIdx]; Vector3 newNode = lastNode.getNextPos().ToVector3(); Node thisNode = new Node(); thisNode.pos = Vector3Obj.ToVector3Obj(newNode); thisNode.setTheDir(lastNode.dir); thisNode.length = 0.08f; Hxx.HxxUs[theChosenFaceIdx].Add(thisNode); GameObject hs = GameObject.CreatePrimitive(PrimitiveType.Sphere); hs.transform.position = newNode; hs.transform.localScale = new Vector3(0.03f, 0.03f, 0.03f); hs.GetComponent <Renderer>().material.color = Color.white; HSpheres[theChosenFaceIdx].Add(hs); theChosenFaceSphereNum = HSpheres[theChosenFaceIdx].Count; showUp(); Debug.Log("add node"); } if (Input.GetKeyDown(KeyCode.L)) { writeUp(); Application.Quit(); } //if (Time.frameCount % 50 == 0) //{ // writeUp(); //} }
public Node() { pos = new Vector3Obj(); dir = new Vector3Obj(); length = 0.01f; }
public override void OnEvent(EventData eventData) { int roleId = -1; //获取SubCode,判断是增加还是删除角色 SubCode subCode; object o = null; eventData.Parameters.TryGetValue((byte)ParameterCode.SubCode, out o); subCode = (SubCode)o; eventData.Parameters.TryGetValue((byte)ParameterCode.RoleId, out o); roleId = (int)o; switch (subCode) { case SubCode.SyncPosAndRotation: //同步角色位置和旋转 object posObj = null; object rotObj = null; eventData.Parameters.TryGetValue((byte)ParameterCode.Position, out posObj); eventData.Parameters.TryGetValue((byte)ParameterCode.EulerAngles, out rotObj); Vector3Obj pos = JsonMapper.ToObject <Vector3Obj>(posObj.ToString()); Vector3Obj rotation = JsonMapper.ToObject <Vector3Obj>(rotObj.ToString()); SyncTransPosAndRotationResponse(roleId, pos.ToVector3(), rotation.ToVector3()); break; case SubCode.SyncPlayerMoveAnimation: //同步角色移动动画 PlayerMoveAnimationModel model = new PlayerMoveAnimationModel(); eventData.Parameters.TryGetValue((byte)ParameterCode.PlayerMoveAnimationModel, out o); model = JsonMapper.ToObject <PlayerMoveAnimationModel>(o.ToString()); SyncPlayerMoveAnimationResponse(roleId, model); break; case SubCode.SyncPlayerAttackAnimation: //同步角色攻击动画 PlayerAnimationModel playerAnimationModel = new PlayerAnimationModel(); eventData.Parameters.TryGetValue((byte)ParameterCode.PlayerAnimationModel, out o); playerAnimationModel = JsonMapper.ToObject <PlayerAnimationModel>(o.ToString()); SyncPlayerAttackAnimationResponse(roleId, playerAnimationModel); break; case SubCode.SyncEnermySpawn: SyncEnermySpawnResponse(); break; case SubCode.BackToHome: BackToHomeResponse(); break; case SubCode.FightAgain: FightAgainResponse(); break; case SubCode.SyncPlayerHpBar: int hp = 0; int hurtNum = 0; int targetId = 0; eventData.Parameters.TryGetValue((byte)ParameterCode.PlayerHp, out o); hp = (int)o; eventData.Parameters.TryGetValue((byte)ParameterCode.EnermyHurtNum, out o); hurtNum = (int)o; eventData.Parameters.TryGetValue((byte)ParameterCode.TargetId, out o); targetId = (int)o; SyncPlayerHpBarResponse(hp, hurtNum, targetId); break; default: break; } }
//该方法有两种调用场景: //1.用户登录成功,进入城镇 //2.玩家退出副本,返回城镇 void EnterChannelResponse(EventData eventData) { object o = null; Vector3Obj posObj = null; Vector3Obj eulerObj = null; GameObject playerGo = null; string prefabName = girlPrefabName; eventData.Parameters.TryGetValue((byte)ParameterCode.RoleList, out o); if (null != o) { List <Role> roleList = JsonMapper.ToObject <List <Role> >(o.ToString()); if (roleList != null) { //1.组队:只有组队进入副本,在返回城镇时,isTeam才为true if (TeamInviteController.Instance && TeamInviteController.Instance.isTeam) { foreach (Role role in roleList) { if (role.CharacterId == 1) //hard code at present { prefabName = boyPrefabName; } if (role.position != null) { posObj = JsonMapper.ToObject <Vector3Obj>(role.position.ToString()); eulerObj = JsonMapper.ToObject <Vector3Obj>(role.eulerAngles.ToString()); if (Math.Abs(entryPos.x - posObj.ToVector3().x) < 3) { //如果是队长,且与副本入口距离小于3,则稍远离入口,避免刚回城就重新进入副本 if (role.ID == TeamInviteController.Instance.globalMasterID) { posObj.x += 3; } } playerGo = GameObject.Instantiate(Resources.Load("Player/" + prefabName), posObj.ToVector3(), Quaternion.identity) as GameObject; playerGo.transform.eulerAngles = eulerObj.ToVector3(); } else { playerGo = GameObject.Instantiate(Resources.Load("Player/" + prefabName), playerPos.position, Quaternion.identity) as GameObject; } playerGo.GetComponent <Player>().roleId = role.ID; playerGo.GetComponent <Player>().Level = role.Level; playerGo.GetComponent <Player>().Name = role.Name; if (PhotonEngine.Instance.role.ID == role.ID) { playerGo.GetComponent <Player>().isTeam = true; //重新给摄像机赋值,以跟踪当前角色 FollowTarget.Instance.player = playerGo.transform; playerGo.GetComponent <PlayerMove>().isCanControl = true; } playerDict.Remove(role.ID); playerDict.Add(role.ID, playerGo);//把角色添加到集合 } } else //单人:由登录进入城镇,或单人进入副本后返回城镇都判定为单人 { Debug.Log("单人=="); foreach (Role role in roleList) { Debug.Log("role.characterid=" + role.CharacterId); if (role.CharacterId == 1) { prefabName = boyPrefabName; } if (role.position != null) { posObj = JsonMapper.ToObject <Vector3Obj>(role.position.ToString()); eulerObj = JsonMapper.ToObject <Vector3Obj>(role.eulerAngles.ToString()); if (Math.Abs(entryPos.x - posObj.ToVector3().x) < 3) { //如果是当前客户端角色,且与副本入口距离小于3,则稍远离入口,避免刚回城就重新进入副本 if (role.ID == PhotonEngine.Instance.role.ID) { posObj.x += 5; } } playerGo = GameObject.Instantiate(Resources.Load("Player/" + prefabName), posObj.ToVector3(), Quaternion.identity) as GameObject; playerGo.transform.eulerAngles = eulerObj.ToVector3(); } else { playerGo = GameObject.Instantiate(Resources.Load("Player/" + prefabName), playerPos.position, Quaternion.identity) as GameObject; } playerGo.GetComponent <Player>().roleId = role.ID; playerGo.GetComponent <Player>().Level = role.Level; playerGo.GetComponent <Player>().Name = role.Name; playerGo.GetComponent <Player>().isTeam = false; if (playerDict.ContainsKey(role.ID)) { playerDict.Remove(role.ID); //从集合中删除角色 } playerDict.Add(role.ID, playerGo); //把角色添加到集合 if (PhotonEngine.Instance.role.ID == role.ID) { //重新给摄像机赋值,以跟踪当前角色 FollowTarget.Instance.player = playerGo.transform; playerGo.GetComponent <PlayerMove>().isCanControl = true; } } } } } }