// Update is called once per frame void Update() { KBEngine.Entity entity = KBEngineApp.app.player(); KBEngine.Avatar avatar = null; if (entity != null && entity.className == "Avatar") { avatar = (KBEngine.Avatar)entity; } if (avatar != null) { text_pos.text = avatar.position.x.ToString("#.0") + "," + avatar.position.z.ToString("#.0"); foreach (Skill sk in SkillBox.inst.skills) { sk.updateTimer(Time.deltaTime);//更新技能的冷却时间 } } if (Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100.0f, 1 << LayerMask.NameToLayer("CanAttack"))) { UI_Target ui_target = World.instance.getUITarget(); ui_target.GE_target = hit.collider.GetComponent <GameEntity>(); ui_target.UpdateTargetUI(); string name = Utility.getPreString(ui_target.GE_target.name); if (name == "NPC" && !MenuBox.hasMenu()) { Int32 id = Utility.getPostInt(ui_target.GE_target.name); NPC _npc = (NPC)KBEngineApp.app.findEntity(id); if (_npc != null) { UInt32 dialogID = _npc.dialogID; avatar.dialog(id, dialogID); } } } } //更新消耗品计时器 ConsumeLimitCD.instance.Update(Time.deltaTime); }
public void OnTabSelected() { UI_Target ui_target = World.instance.getUITarget(); GameEntity ge = null; if (ui_target != null && ui_target.GE_target != null) { ge = ui_target.GE_target; } KBEngine.Entity entity = KBEngineApp.app.player(); KBEngine.Avatar avatar = null; if (entity != null && entity.className == "Avatar") { avatar = (KBEngine.Avatar)entity; } if (avatar == null) { return; } UnityEngine.GameObject[] objs = UnityEngine.GameObject.FindObjectsOfType <UnityEngine.GameObject>(); float mindis = 10000; UnityEngine.GameObject minObj = null; foreach (UnityEngine.GameObject obj in objs) { if (obj.layer != LayerMask.NameToLayer("CanAttack") || obj.GetComponent <GameEntity>() == null || obj.GetComponent <GameEntity>().hp == 0) { continue; } float dis = Vector3.Distance(avatar.position, obj.transform.position); if (mindis > dis && (ge == null || ge != null && ge != obj.GetComponent <GameEntity>())) { mindis = dis; minObj = obj; } } if (minObj != null) { ui_target.GE_target = minObj.GetComponent <GameEntity>(); ui_target.UpdateTargetUI(); } }
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(); }