Пример #1
0
    /// <summary>
    /// 开始移动
    /// </summary>
    public override void Begin()
    {
        // 加载特效预设
        effectObject = PoolLoader.Instance().Load(effectKey, EffectsFactory.EffectPackName, parent);
        if (effectObject == null)
        {
            throw new Exception("特效为空, 加载失败.");
        }
        //effectObject = Instantiate(effectObject);
        // 设置数据
        effectObject.transform.localScale = scale;
        effectObject.transform.position   = position;
        effectObject.layer = layer;
        // 开始移动
        // 创建弹道
        ballistic = BallisticFactory.Single.CreateBallistic(effectObject, position, targetObj.transform.position - position, targetObj, speed, 1, trajectoryType: flyType);

        ballistic.OnKill = (ballistic1, target) =>
        {
            effectObject.RemoveComponents(typeof(Ballistic));
            PoolLoader.Instance().CircleBack(effectObject);
        };
        // 运行完成
        ballistic.OnComplete = (a, b) =>
        {
            if (completeCallback != null)
            {
                completeCallback();
            }
            a.Kill();
            //Destroy();
        };
    }
Пример #2
0
    /// <summary>
    /// 根据类型获取目标点
    /// </summary>
    /// <param name="ball">当前移动对象</param>
    /// <param name="ballisticTarget">对象弹道判断类</param>
    /// <returns>目标点</returns>
    private static Vector3 GetTargetPos(Ballistic ball, BallisticArriveTarget ballisticTarget)
    {
        Vector3 result = Vector3.zero;

        if (ball != null && ballisticTarget != null)
        {
            if (ballisticTarget is BallisticArriveTargetForFreeFly)
            {
                result = ball.Direction.normalized * ((BallisticArriveTargetForFreeFly)ballisticTarget).FreeFlyMaxLength;
            }
            else if (ballisticTarget is BallisticArriveTargetForObj)
            {
                var objTarget = ballisticTarget as BallisticArriveTargetForObj;
                if (objTarget.TargetObj != null)
                {
                    result = objTarget.TargetObj.transform.position;
                }
                else
                {
                    result = objTarget.LasttimePos;
                }
            }
            else if (ballisticTarget is BallisticArriveTargetForPosition)
            {
                result = ((BallisticArriveTargetForPosition)ballisticTarget).TargetPosition;
            }
        }

        return(result);
    }
Пример #3
0
    /// <summary>
    /// 是否到达目标
    /// </summary>
    /// <param name="ball">弹道对象</param>
    /// <returns>是否到达</returns>
    public override bool IsArrivedTarget(Ballistic ball)
    {
        var result = false;

        if (ball != null && TargetObj != null)
        {
            // 判断位置+半径是否到达目标
            if (TargetObj != null)
            {
                if ((ball.Position - TargetObj.transform.position).magnitude <= ball.Speed * Time.deltaTime)
                {
                    LasttimePos = TargetObj.transform.position;
                    result      = true;
                }
            }
            else
            {
                if ((ball.Position - LasttimePos).magnitude <= ball.Speed * Time.deltaTime)
                {
                    result = true;
                }
            }
        }

        return(result);
    }
Пример #4
0
    void Start()
    {
        ballistic = GetComponent <Ballistic>();

        rot = -90;
        Utils.TrackWithCamera(transform);

        StartCoroutine(Script1());
    }
Пример #5
0
        public void AttackCallback()
        {
            var arrow = EntityFactory.Instance.CreateArrow().GetComponent <Rigidbody>();

            arrow.GetComponent <Arrow>().Owner = Entity;
            arrow.position = Spawn.position;
            var origin  = Spawn.position;
            var target  = Entity.Engaging.Target.Position;
            var yOffset = Entity.Engaging.Target.Agent.height * 0.75f;

            arrow.velocity = Ballistic.ComputeInitialVelocity(origin, target, yOffset);
        }
Пример #6
0
        private Vector3 ComputeVelocity(Projectile projectile)
        {
            var origin = Spawn.position;
            var offset = new Vector3(Random.Range(-0.2f, 0.2f), Random.Range(0.0f, 0.45f));

            // TODO for movie only !!!
            // offset.y = .4f;


            var target  = projectile.Target.position + offset;
            var speed   = projectile.speed;
            var gravity = projectile.UseGravity;

            return(Ballistic.ComputeInitialVelocity(origin, target, speed, gravity));
        }
Пример #7
0
    /// <summary>
    /// 是否到达目标
    /// </summary>
    /// <param name="ball">弹道对象</param>
    /// <returns>是否到达</returns>
    public override bool IsArrivedTarget(Ballistic ball)
    {
        var result = false;

        if (ball != null)
        {
            // 判断位置+半径是否到达目标
            var nowDir = (TargetPosition - ball.Position);
            if (nowDir.magnitude <= ball.Speed * Time.deltaTime)
            {
                result = true;
            }
        }
        // TODO
        Debug.DrawRay(TargetPosition, Vector3.up * 10);
        return(result);
    }
Пример #8
0
    /// <summary>
    /// 是否到达目标
    /// </summary>
    /// <param name="ball">弹道对象</param>
    /// <returns>是否到达</returns>
    public override bool IsArrivedTarget(Ballistic ball)
    {
        var result = false;

        if (ball != null)
        {
            // 累加移动距离
            if (prePostion != Vector3.zero)
            {
                moveDistance += (ball.Position - prePostion).magnitude;
                if (moveDistance >= FreeFlyMaxLength)
                {
                    result = true;
                }
            }
            else
            {
                prePostion = ball.Position;
            }
        }

        return(result);
    }
Пример #9
0
 /// <summary>
 /// 是否到达目标
 /// </summary>
 /// <param name="ball">弹道对象</param>
 /// <returns>是否到达</returns>
 public abstract bool IsArrivedTarget(Ballistic ball);