Пример #1
0
    protected override void OnInit()
    {
        limit = host.fireBoll.limit;
        Vector3 pos = parent.position;

        pos.y += parent.BoxCollider.y / 2;
        if (host.config.IsRatioOffset)
        {
            Offset = new Vector3(parent.BoxCollider.x * Offset.x, parent.BoxCollider.y * Offset.y, parent.BoxCollider.z * Offset.z);
        }
        this.gameObject.transform.position = pos + this.Offset;

        this.targetPos = this.gameObject.transform.position + (Quaternion.Euler(this.Angle) * parent.transform.forward) * MaxDistance;
        this.gameObject.transform.LookAt(this.targetPos);//向目标飞行

        ColliderEventComponent colliderEvent = this.gameObject.AddComponent <ColliderEventComponent>();

        colliderEvent.isTrigger       = true;
        colliderEvent.onTriggerEnter += OnTriggerEnter;
    }
Пример #2
0
    protected override void OnInit()
    {
        target = host.fireBoll.ro;
        //Debug.Log(target.transform.position);
        limit = host.fireBoll.limit;
        if (!target)
        {
            return;
        }

        Vector3 pos = parent.position;

        pos.y += parent.BoxCollider.y / 2;
        if (host.config.IsActOnTarget)
        {
            pos = target.transform.position;
        }
        if (host.config.IsRatioOffset)
        {
            Offset = new Vector3(parent.BoxCollider.x * Offset.x, parent.BoxCollider.y * Offset.y, parent.BoxCollider.z * Offset.z);
        }
        this.gameObject.transform.position = pos + this.Offset + this.gameObject.transform.forward * host.config.Distance;
        MaxDistance = Vector3.Distance(target.position, this.gameObject.transform.position) - target.BoxCollider.z / 2;
        //Vector3 forward = (target.position - this.gameObject.transform.position).normalized;
        //forward.y = 0;

        //this.targetPos = this.gameObject.transform.position + (Quaternion.Euler(this.Angle) * forward) * MaxDistance;
        //this.targetPos.y = target.position.y + target.BoxCollider.y / 2;
        this.targetPos = target.transform.position;
        this.gameObject.transform.LookAt(this.targetPos);//向目标飞行

        float speed = host.config.Speed;

        if (speed <= 0)
        {
            speed = 1;
        }

        //路径点
        Vector3[]            paths    = new Vector3[] { this.targetPos / 2, this.targetPos };
        DG.Tweening.PathType pathtype = DG.Tweening.PathType.Linear;
        if (host.PathType != Model.PathType.Linear)
        {
            pathtype = DG.Tweening.PathType.CatmullRom;
            switch (host.PathType)
            {
            case Model.PathType.CatmullRom:
                paths[0].y = this.gameObject.transform.position.y + host.OffsetMaxY;
                break;

            case Model.PathType.LeftCatmullRom:
                paths[0].x -= host.OffsetMaxY;
                break;

            case Model.PathType.RightCatmullRom:
                paths[0].x += host.OffsetMaxY;
                break;
            }
        }
        Debug.Log(paths);
        Debug.Log(MaxDistance + "/" + host.config.Speed + "=" + MaxDistance / host.config.Speed);
        DG.Tweening.Tween tween = null;
        if (pathtype == DG.Tweening.PathType.Linear)
        {
            tween = this.gameObject.transform.DOPath(new Vector3[] { targetPos }, MaxDistance / host.config.Speed, pathtype).SetLookAt(0.001f);
        }
        else
        {
            tween = this.gameObject.transform.DOPath(paths, MaxDistance / host.config.Speed, pathtype).SetLookAt(0.001f);
        }
        tween.OnComplete(() => target.mActionPerformer.StartAction(host.farther.config, EventPart.FIREBALLHIT, host.farther.High));

        ColliderEventComponent colliderEvent = this.gameObject.AddComponent <ColliderEventComponent>();

        colliderEvent.isTrigger       = true;
        colliderEvent.onTriggerEnter += OnTriggerEnter;
    }