Inheritance: MonoBehaviour, IPointerDownHandler
Example #1
0
    public UI_Target getUITarget()
    {
        if (ui_target == null)
        {
            UnityEngine.GameObject target = UnityEngine.GameObject.FindGameObjectWithTag("Target");
            if (target)
            {
                ui_target = target.GetComponent <UI_Target>();
            }
        }

        return(ui_target);
    }
Example #2
0
    // 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);
    }
Example #3
0
    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();
        }
    }
Example #4
0
    // Use this for initialization
    void Start()
    {
        UnityEngine.GameObject target = UnityEngine.GameObject.FindGameObjectWithTag("Target");
        if (target)
        {
            ui_target = target.GetComponent <UI_Target>();
        }

        KBEngine.Event.registerOut("addSpaceGeometryMapping", this, "addSpaceGeometryMapping");
        KBEngine.Event.registerOut("onAvatarEnterWorld", this, "onAvatarEnterWorld");
        KBEngine.Event.registerOut("onEnterWorld", this, "onEnterWorld");
        KBEngine.Event.registerOut("onLeaveWorld", this, "onLeaveWorld");
        KBEngine.Event.registerOut("set_position", this, "set_position");
        KBEngine.Event.registerOut("set_direction", this, "set_direction");
        KBEngine.Event.registerOut("updatePosition", this, "updatePosition");
        KBEngine.Event.registerOut("set_name", this, "set_entityName");
        KBEngine.Event.registerOut("set_state", this, "set_state");
        KBEngine.Event.registerOut("set_HP", this, "set_HP");
        KBEngine.Event.registerOut("set_HP_Max", this, "set_HP_Max");
        KBEngine.Event.registerOut("recvDamage", this, "recvDamage");
        KBEngine.Event.registerOut("onReqItemList", this, "onReqItemList");
        KBEngine.Event.registerOut("set_equipWeapon", this, "set_equipWeapon");
        KBEngine.Event.registerOut("setSkillButton", this, "setSkillButton");
    }
Example #5
0
    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();
    }
Example #6
0
    public UI_Target getUITarget()
    {
        if (ui_target == null)
        {
            UnityEngine.GameObject target = UnityEngine.GameObject.FindGameObjectWithTag("Target");
            if (target)
            {
                ui_target = target.GetComponent<UI_Target>();
            }
        }

        return ui_target;
    }
Example #7
0
    // Use this for initialization
    void Start()
    {
        UnityEngine.GameObject target = UnityEngine.GameObject.FindGameObjectWithTag("Target");
        if (target)
        {
            ui_target = target.GetComponent<UI_Target>();
        }

        KBEngine.Event.registerOut("addSpaceGeometryMapping", this, "addSpaceGeometryMapping");
        KBEngine.Event.registerOut("onAvatarEnterWorld", this, "onAvatarEnterWorld");
        KBEngine.Event.registerOut("onEnterWorld", this, "onEnterWorld");
        KBEngine.Event.registerOut("onLeaveWorld", this, "onLeaveWorld");
        KBEngine.Event.registerOut("set_position", this, "set_position");
        KBEngine.Event.registerOut("set_direction", this, "set_direction");
        KBEngine.Event.registerOut("updatePosition", this, "updatePosition");
        KBEngine.Event.registerOut("set_name", this, "set_entityName");
        KBEngine.Event.registerOut("set_state", this, "set_state");
        KBEngine.Event.registerOut("set_HP", this, "set_HP");
        KBEngine.Event.registerOut("set_HP_Max", this, "set_HP_Max");
        KBEngine.Event.registerOut("recvDamage", this, "recvDamage");
        KBEngine.Event.registerOut("onReqItemList", this, "onReqItemList");
        KBEngine.Event.registerOut("set_equipWeapon", this, "set_equipWeapon");
        KBEngine.Event.registerOut("setSkillButton", this, "setSkillButton");
    }
Example #8
0
    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.getDefinedProperty("moveSpeed");
        //if (speed != null)
        //    set_moveSpeed(avatar, speed);

        object state = avatar.getDefinedProperty("state");
        if (state != null)
            set_state(avatar, state);

        //object modelScale = avatar.getDefinedProperty("modelScale");
        //if (modelScale != null)
        //    set_modelScale(avatar, modelScale);

        object name = avatar.getDefinedProperty("name");
        if (name != null)
            set_entityName(avatar, (string)name);

        object hp = avatar.getDefinedProperty("HP");
        if (hp != null)
            set_HP(avatar, hp);

        object hpMax = avatar.getDefinedProperty("HP_Max");
        if (hpMax != null)
            set_HP_Max(avatar, hpMax);

        //设置头像属性
        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.getDefinedProperty("attack_Max");
            if (attack_max != null)
                avaterState.setAttackMax((Int32)attack_max);

            object attack_min = avatar.getDefinedProperty("attack_Min");
            if (attack_min != null)
                avaterState.setAttackMin((Int32)attack_min);

            object defence = avatar.getDefinedProperty("defence");
            if (defence != null)
                avaterState.setDefence((Int32)defence);

            object rating = avatar.getDefinedProperty("rating");
            if (rating != null)
                avaterState.setRating((Int32)rating);

            object dodge = avatar.getDefinedProperty("dodge");
            if (dodge != null)
                avaterState.setDodge((Int32)dodge);

            object strength = avatar.getDefinedProperty("strength");
            if (strength != null)
                avaterState.setStrength((Int32)strength);

            object dexterity = avatar.getDefinedProperty("dexterity");
            if (dexterity != null)
                avaterState.setDexterity((Int32)dexterity);

            object stamina = avatar.getDefinedProperty("stamina");
            if (stamina != null)
                avaterState.setStamina((Int32)stamina);

            object exp = avatar.getDefinedProperty("exp");
            if (exp != null)
                avaterState.setExp((UInt64)exp);

            object level = avatar.getDefinedProperty("level");
            if (level != null)
                avaterState.setLevel((UInt16)level);
        }

        object equipWeapon = avatar.getDefinedProperty("equipWeapon");
        if (equipWeapon != null)
            set_equipWeapon(avatar, (Int32)equipWeapon);

        SkillBox.inst.initSkillDisplay();
    }
Example #9
0
    public void AttackSkill(int skillId)
    {
        KBEngine.Entity entity = KBEngineApp.app.player();
        KBEngine.Avatar avatar = null;
        if (entity != null && entity.className == "Avatar")
        {
            avatar = (KBEngine.Avatar)entity;
        }
        if (avatar == null)
        {
            return;
        }

        UI_Target ui_target = World.instance.getUITarget();

        if (ui_target != null && ui_target.GE_target != null)
        {
            string name     = ui_target.GE_target.name;
            Int32  entityId = Utility.getPostInt(name);

            if (avatar != null)
            {
                int errorCode = avatar.useTargetSkill(skillId, entityId);
                if (errorCode == 1)
                {
                    UI_ErrorHint._instance.errorShow("目标太远");
                    //逼近目标
                    UnityEngine.GameObject renderEntity = (UnityEngine.GameObject)entity.renderObj;
                    renderEntity.GetComponent <MoveController>().moveTo(ui_target.GE_target.transform, SkillBox.inst.get(skillId).canUseDistMax - 1, skillId);
                }
                if (errorCode == 2)
                {
                    UI_ErrorHint._instance.errorShow("技能冷却");
                }
                if (errorCode == 3)
                {
                    UI_ErrorHint._instance.errorShow("目标已死亡");
                }
            }
        }
        else
        {
            if (skillId == 3)//治疗自己
            {
                if (avatar != null)
                {
                    int errorCode = avatar.useTargetSkill(skillId, avatar.id);
                    if (errorCode == 2)
                    {
                        UI_ErrorHint._instance.errorShow("技能冷却");
                    }
                    if (errorCode == 3)
                    {
                        UI_ErrorHint._instance.errorShow("目标已死亡");
                    }
                }
            }
            else
            {
                UI_ErrorHint._instance.errorShow("未选择目标");
            }
        }
    }