protected virtual void Update() { if (_keepAvatar == null) { return; } else { if (_keepAvatar.position != transform.position) { if (_keepAvatar.isPlayer()) { ClampRotation(); _keepAvatar.position = transform.position; _keepAvatar.direction = transform.eulerAngles; } else { RefreshStatus(); } RefreshSmallMap(); } } }
void CreatePlayer() { Debug.Log("SyncManager::CreatePlayer.count:" + GameData.Instance.RoomPlayers.Count); for (int i = 0; i < GameData.Instance.RoomPlayers.Count; i++) { KBEngine.Avatar player = GameData.Instance.RoomPlayers[i]; TSVector position = new TSVector(player.position.x, player.position.y, player.position.z); TSVector direciton = new TSVector(0, 180, 0); //Debug.Log("SyncManager::CreatePlayer.player.position:"+ player.position + ",direciton:"+ player.direction); GameObject perfab = SyncedInstantiate(playerPerfab, position, TSQuaternion.Euler(direciton)); Debug.Log("SyncManager::CreatePlayer.player.renderObj:" + (perfab == null ? "Null" : perfab.name) + ",position:" + perfab.transform.position + ",direction:" + perfab.transform.eulerAngles); perfab.name = player.className + "_" + player.id; PlayerBehaviour playerScript = perfab.AddComponent <PlayerBehaviour>(); playerScript.owner = player; player.renderObj = perfab; playerBehaviours.Add(player.id, playerScript); if (player.isPlayer()) { cameraTransform.GetComponent <CamerFllown>().AttachTarget(perfab.transform); cameraTransform.transform.parent = perfab.transform; } } }
public void RecvGetRoomInfo() { Debug.Log(" RoomPanel::RecvGetRoomInfo." + GameData.Instance.RoomPlayers.Count); int i = 0; for (; i < GameData.Instance.RoomPlayers.Count; i++) { KBEngine.Avatar avatar = GameData.Instance.RoomPlayers[i]; Int32 win = avatar.component1.winScore; Int32 fail = avatar.component1.lossScore; Debug.Log(" avatar." + avatar.id + ",isPlayer:" + avatar.isPlayer()); Transform trans = prefabs[i]; Text text = trans.Find("Text").GetComponent <Text>(); string str = "名字:" + avatar.id + "\r\n"; str += "阵营:" + (!avatar.isPlayer() ? "红" : "蓝") + "\r\n"; str += "胜利:" + win.ToString() + " "; str += "失败:" + fail.ToString() + "\r\n"; if (avatar.isPlayer()) { str += "【我自己】"; } if (avatar.id == GameData.Instance.CurrentRoom.room_creater) { str += "【房主】"; } text.text = str; if (avatar.isPlayer()) { trans.GetComponent <Image>().color = Color.blue; } else { trans.GetComponent <Image>().color = Color.red; } } for (; i < 6; i++) { Transform trans = prefabs[i]; Text text = trans.Find("Text").GetComponent <Text>(); text.text = "【等待玩家】"; trans.GetComponent <Image>().color = Color.gray; } }
public void onAvatarEnterWorld(UInt64 rndUUID, Int32 eid, KBEngine.Avatar avatar) { if (!avatar.isPlayer()) { return; } Debug.Log("loading scene..."); }
public void onAvatarEnterWorld(UInt64 rndUUID, Int32 eid, KBEngine.Avatar avatar) { if (!avatar.isPlayer()) { return; } //UI.inst.info("loading scene...(加载场景中...)"); Debug.Log("loading scene...(加载场景中...)"); }
public void onAvatarEnterWorld(UInt64 rndUUID, Int32 eid, KBEngine.Avatar avatar) { Debug.Log("onAvatarEnterWorld"); if (!avatar.isPlayer()) { return; } sNetworkOutOfWorld.inst.info("loading scene...(加载场景中...)"); Debug.Log("loading scene..."); }
void AvatarEnterWorld(KBEngine.Entity entity) { KBEngine.Avatar selfAvatar = entity as KBEngine.Avatar; GameObject selfGO = Instantiate(avatarPrefab); selfAvatar.renderObj = selfGO; selfGO.transform.eulerAngles = selfAvatar.direction; selfGO.transform.Find("Name").GetComponent <TextMesh>().text = selfAvatar.name; selfGO.name = selfAvatar.name; selfGO.transform.position = selfAvatar.position; if (selfAvatar.isPlayer()) { selfGO.transform.Find("Name").GetComponent <TextMesh>().color = Color.red; selfGO.AddComponent <Rigidbody>(); selfGO.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationZ; } else { selfGO.transform.Find("Name").GetComponent <TextMesh>().color = Color.green; Destroy(selfGO.transform.Find("CameraView/FirstView").gameObject); Destroy(selfGO.transform.Find("CameraView/ThirdView").gameObject); } selfGO.GetComponent <PlayerController>().KeepAvatar = selfAvatar; //UI小地图 GameUIcontroller.SmallMap.Find(selfAvatar.track + "").gameObject.SetActive(true); GameUIcontroller.SmallMap.Find(selfAvatar.track + "/Name").GetComponent <Text>().text = selfAvatar.name; GameUIcontroller.SmallMap.Find(selfAvatar.track + "/Percent").GetComponent <Text>().text = "0%"; GameUIcontroller.ViewParent[selfAvatar.track] = selfGO.transform.Find("CameraView/OthersView"); if (selfAvatar.isPlayer()) { GameUIcontroller.SmallMap.Find(selfAvatar.track + "/View").gameObject.SetActive(false); GameUIcontroller.SmallMap.Find(selfAvatar.track + "/Name").GetComponent <Text>().color = Color.red; GameUIcontroller.SmallMap.Find(selfAvatar.track + "/Percent").GetComponent <Text>().color = Color.red; } avatarsDict.Add(selfAvatar.id, selfAvatar); }
public void onAvatarEnterWorld(UInt64 rndUUID, Int32 eid, KBEngine.Avatar avatar) { if (!avatar.isPlayer()) { return; } UI.inst.info("loading scene...(加载场景中...)"); Debug.Log("loading scene..."); // TriggerEvent((int)EVENT_ID.EVENT_CREAT_PLAYER); }
private void OnGUI() { if (owner.isPlayer()) { GUI.contentColor = Color.green; GUI.Label(new Rect(0, Screen.height - 20, 400, 100), "id: " + owner.id); GUI.Label(new Rect(0, Screen.height - 35, 400, 100), "frameCount: " + FrameCount); GUI.Label(new Rect(0, Screen.height - 50, 400, 100), "position: " + tsRigidBody.position); GUI.Label(new Rect(0, Screen.height - 65, 400, 100), "velocity: " + tsRigidBody.velocity); GUI.Label(new Rect(0, Screen.height - 80, 400, 100), "angularVelocity: " + tsRigidBody.angularVelocity); GUI.Label(new Rect(0, Screen.height - 95, 400, 100), "force: " + force); } else { GUI.contentColor = Color.yellow; GUI.Label(new Rect(Screen.width - 200, Screen.height - 20, 400, 100), "id: " + owner.id); GUI.Label(new Rect(Screen.width - 200, Screen.height - 35, 400, 100), "frameCount: " + FrameCount); GUI.Label(new Rect(Screen.width - 200, Screen.height - 50, 400, 100), "position: " + tsRigidBody.position); GUI.Label(new Rect(Screen.width - 200, Screen.height - 65, 400, 100), "velocity: " + tsRigidBody.velocity); GUI.Label(new Rect(Screen.width - 200, Screen.height - 80, 400, 100), "angularVelocity: " + tsRigidBody.angularVelocity); GUI.Label(new Rect(Screen.width - 200, Screen.height - 95, 400, 100), "force: " + force); } }
public void onAvatarEnterWorld(UInt64 rndUUID, Int32 eid, KBEngine.Avatar avatar) { if (!avatar.isPlayer()) { return; } UI.inst.info("loading scene...(加载场景中...)"); Debug.Log("loading scene..."); object speed = avatar.getDefinedPropterty("moveSpeed"); if (speed != null) { set_moveSpeed(avatar, speed); } object state = avatar.getDefinedPropterty("state"); if (state != null) { set_state(avatar, state); } object modelScale = avatar.getDefinedPropterty("modelScale"); if (modelScale != null) { set_modelScale(avatar, modelScale); } object name = avatar.getDefinedPropterty("name"); if (name != null) { set_entityName(avatar, (string)name); } object hp = avatar.getDefinedPropterty("HP"); if (hp != null) { set_HP(avatar, hp); } }
public void onAvatarEnterWorld(UInt64 rndUUID, Int32 eid, KBEngine.Avatar avatar) { if (!avatar.isPlayer()) { return; } createPlayer(); //UI.inst.info("loading scene...(加载场景中...)"); Debug.Log("loading scene..."); //object speed = avatar.moveSpeed; //if (speed != null) // set_moveSpeed(avatar, speed); set_state(avatar, avatar.state); set_entityName(avatar, avatar.name); set_HP(avatar, avatar.HP, avatar.HP_Max); set_HP_Max(avatar, avatar.HP_Max, avatar.HP); //设置头像属性 UnityEngine.GameObject ptarget = UnityEngine.GameObject.FindGameObjectWithTag("TargetPlayer"); if (ptarget) { ui_targetPlayer = ptarget.GetComponent <UI_Target>(); } if (ui_targetPlayer) { ui_targetPlayer.GE_target = player.GetComponent <GameEntity>(); ui_targetPlayer.UpdateTargetUI(); } //end UnityEngine.GameObject canvas = UnityEngine.GameObject.FindGameObjectWithTag("Canvas"); UnityEngine.GameObject panel_state = null; if (canvas.transform.Find("Panel - State") != null) { panel_state = canvas.transform.Find("Panel - State").gameObject; } if (panel_state != null) { UI_AvatarState avaterState = panel_state.GetComponent <UI_AvatarState>(); object attack_max = avatar.attack_Max; if (attack_max != null) { avaterState.setAttackMax((Int32)attack_max); } object attack_min = avatar.attack_Min; if (attack_min != null) { avaterState.setAttackMin((Int32)attack_min); } object defence = avatar.defence; if (defence != null) { avaterState.setDefence((Int32)defence); } object rating = avatar.rating; if (rating != null) { avaterState.setRating((Int32)rating); } object dodge = avatar.dodge; if (dodge != null) { avaterState.setDodge((Int32)dodge); } object strength = avatar.strength; if (strength != null) { avaterState.setStrength((Int32)strength); } object dexterity = avatar.dexterity; if (dexterity != null) { avaterState.setDexterity((Int32)dexterity); } object stamina = avatar.stamina; if (stamina != null) { avaterState.setStamina((Int32)stamina); } object exp = avatar.exp; if (exp != null) { avaterState.setExp((UInt64)exp); } object level = avatar.level; if (level != null) { avaterState.setLevel((UInt16)level); } } object equipWeapon = avatar.equipWeapon; if (equipWeapon != null) { set_equipWeapon(avatar, (Int32)equipWeapon); } SkillBox.inst.initSkillDisplay(); }
/// <summary> /// 在场景中生成飞船 /// </summary> /// <param name="id"></param> /// <param name="team"></param> /// <param name="spid"></param> private void SpawnShip(KBEngine.Avatar avatar) { // 获取预设的出生点 Transform spawnPoints = GameObject.FindWithTag("SpwanPoints").transform; // 出生点坐标 Transform spawnTrans; int team = 1; int spid = avatar.isPlayer() ? 0 : 1; if (team == 1) { spawnTrans = spawnPoints.GetChild(0).GetChild(spid - 1); } else { spawnTrans = spawnPoints.GetChild(1).GetChild(spid - 1); } if (spawnTrans == null) { Debug.LogError("SpawnShip 出生点错误!"); return; } // 获取飞船 prefab GameObject battleControllerObject = GameObject.FindWithTag("BattleController"); if (battleControllerObject == null) { Debug.LogError("场景中缺失 BattleController 对象!"); return; } BattleController battleController = battleControllerObject.GetComponent <BattleController>(); GameObject[] shipPrefabs = battleController.characterPrefabs; if (shipPrefabs.Length < 2) { Debug.LogError("飞船预设数量不够!"); return; } // 产生飞船 GameObject shipObj = (GameObject)Object.Instantiate(shipPrefabs[team - 1]); shipObj.name = avatar.id.ToString(); shipObj.transform.position = spawnTrans.position; shipObj.transform.rotation = spawnTrans.rotation; // 构造 Ship 对象 Ship ship = new Ship(); ship.playerController = shipObj.GetComponent <PlayerController>(); ship.team = team; // 保存到场景的 Ship 列表中 ShipDict.Add(avatar.id.ToString(), ship); // 角色操控处理 // if (id == GameMgr.instance.id) // { // ship.playerController.ControlMode = PlayerController.CharacterControlMode.Player; // // // 设置摇杆操作控制的角色 // GameObject inputManagerObject = GameObject.FindWithTag("InputManager"); // if (inputManagerObject == null) // { // Debug.LogError("场景中缺失 InputManager 对象!"); // return; // } // // InputManager inputManager = inputManagerObject.GetComponent<InputManager>(); // inputManager.Player = ship.playerController; // } // else // { // ship.playerController.ControlMode = PlayerController.CharacterControlMode.Net; // } }