Exemplo n.º 1
0
    /// <summary>
    /// Sent when a mouse button (or touch event) gets pressed over the collider (with ‘true’)
    /// and when it gets released (with ‘false’, sent to the same collider even if it’s released elsewhere).
    /// </summary>
    /// <param name="isDown"></param>
    void OnPress(bool isDown)
    {
        if (isDown)
        {
            var        ray = Camera.main.ScreenPointToRay(new Vector3(UICamera.lastTouchPosition.x, UICamera.lastTouchPosition.y));
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                if (SelectTarget.Select(hit.collider.gameObject) == false)
                {
                    // 没有选中目标,就移动
                    if (hit.collider.gameObject.GetComponent <MapNav>())
                    {
                    }
                }
            }
        }

        pressing = isDown;
    }
Exemplo n.º 2
0
    /// <summary>
    /// 释放给定的技能
    /// </summary>
    /// <param name="skillID"></param>
    /// <returns>是否成功释放技能</returns>
    public static bool Fire(uint skillID)
    {
        var skill = SkillManager.Instance.GetSkill(skillID);

        if (skill == null)
        {
            return(false);
        }
        // CD检测
        if (SkillManager.Instance.CoolDown(skillID) > 0)
        {
            return(false);
        }
        //主角检查
        if (MainRole.Instance == null)
        {
            return(false);
        }

        // 如果有选择目标,则检查目标距离,超出范围就跑向目标后再攻击
        GameObject goSelect = null;

        if (SelectTarget.Selected != null)
        {
            var go = SelectTarget.Selected.GetGameObject();
            if (go != null && go.GetComponent <HpProtocol>().hp > 0)
            {
                goSelect = go;
                if (Vector3.Distance(goSelect.transform.position, MainRole.Instance.transform.position) > skill.radius)
                {
                    MainRole.Instance.runToTarget.Target(goSelect, skill.radius, () =>
                    {
                        SkillManager.Fire(skillID);
                    });
                    return(false);
                }
            }
        }

        // 收集目标
        List <GameObject> listSelect = new List <GameObject>();

        listSelect = SkillManager.GetMultiTargets(skill.radius, skill.maxTarget, goSelect);
        if (listSelect.Count == 0)
        {
            // 找到屏幕内最近的目标,自动跑过去
            GameObject goNearest = SkillManager.GetNearestTarget();
            if (goNearest != null)
            {
                MainRole.Instance.runToTarget.Target(goNearest, skill.radius, () =>
                {
                    SkillManager.Fire(skillID);
                });
                return(false);
            }
            else
            {
                Debug.Log("没有攻击目标!");
            }

            return(false);
        }

        // 如果第一个目标不是当前目标,则发送选择目标消息
        if (goSelect == null)
        {
            SelectTarget.Select(listSelect[0]);
        }

        Debug.Log("FireSkill: " + skill);

        // 发送攻击请求
        var cmd = new RequestUseSkillUserCmd_C()
        {
            skillid = skill.id
        };

        foreach (var go in listSelect)
        {
            cmd.hurts.Add(go.GetComponent <Entry>().uid);
        }
        SkillManager.Instance.lastFireTime[skillID] = Time.realtimeSinceStartup;         // 记录施法时戳
        WebSocketClient.Instance.Send(cmd);
        return(true);
    }