예제 #1
0
        /// <summary>
        /// Finds the target.
        /// </summary>
        /// <returns>The target.</returns>
        /// <param name="character">Character.</param>
        /// <param name="fitler">Fitler.</param>
        /// <param name="damageType">Damage type.</param>
        /// <param name="radius">Radius.</param>
        /// <param name="angle">Angle.</param>
        /// <param name="offsetAngle">Offset angle.</param>
        /// <param name="offset">Offset.</param>
        /// <param name="teamIndex">team</param>
        public List <BattleCharacter> FindTarget(
            BattleCharacter character,
            FilterType fitler,
            Layout.LayoutElements.DamageType damageType,
            float radius, float angle, float offsetAngle,
            UVector3 offset, int teamIndex)
        {
            var sqrRadius = radius * radius;

            switch (damageType)
            {
            case Layout.LayoutElements.DamageType.Single:                    //单体直接对目标
                return(new List <BattleCharacter> {
                    character
                });

            case Layout.LayoutElements.DamageType.Rangle:
            {
                var orgin   = character.View.Transform.position + offset;
                var forward = character.View.Transform.forward;

                var q = UQuaternion.Euler(0, angle, 0);

                forward = q * forward;

                var list = new List <BattleCharacter>();
                State.Each <BattleCharacter>((t) =>
                    {
                        //过滤
                        switch (fitler)
                        {
                        case FilterType.Alliance:
                        case FilterType.OwnerTeam:
                            if (teamIndex != t.TeamIndex)
                            {
                                return(false);
                            }
                            break;

                        case FilterType.EmenyTeam:
                            if (teamIndex == t.TeamIndex)
                            {
                                return(false);
                            }
                            break;
                        }
                        //不在目标区域内
                        if ((orgin - t.View.Transform.position).sqrMagnitude > sqrRadius)
                        {
                            return(false);
                        }
                        if (angle < 360)
                        {
                            if (UVector3.Angle(forward, t.View.Transform.forward) > (angle / 2))
                            {
                                return(false);
                            }
                        }
                        list.Add(t);
                        return(false);
                    });
                return(list);
            }
            }

            return(new List <BattleCharacter>());
        }
예제 #2
0
파일: UTest.cs 프로젝트: mengtest/UMath
    // Update is called once per frame
    void Update()
    {
        //return;
        if (rotangle > 360)
        {
            rotangle = 0;
        }
        rotangle += Time.deltaTime * 5f;

        this.mtransfrom.setParent(mparent);
        this.transform.localRotation = Quaternion.Euler(0, rotangle, 0);

        id   = Quaternion.identity;
        idm  = UQuaternion.identity;
        midM = UMatrix4x4.identity;
        mid  = Matrix4x4.identity;

        cForward = this.transform.forward;
        uForward = new UQuaternion(this.transform.rotation.x,
                                   this.transform.rotation.y,
                                   this.transform.rotation.z,
                                   this.transform.rotation.w)
                   * UVector3.forward;

        var inputUv = new UVector3(inputVer.x, inputVer.y, inputVer.z);
        var s       = new UVector3(scale.x, scale.y, scale.z);
        var t       = new UVector3(trans.x, trans.y, trans.z);

        q  = Quaternion.AngleAxis(angle, inputVer);
        mq = UQuaternion.AngleAxis(angle, inputUv);

        qEuler    = Quaternion.Euler(inputVer);
        qToEuler  = qEuler.eulerAngles;
        mqEuler   = UQuaternion.Euler(inputUv);
        mqToEuler = mqEuler.eulerAngles;

        m  = Matrix4x4.TRS(trans, q, scale);
        mm = UMatrix4x4.TRS(t, mq, s);

        Determinant  = m.determinant;
        mDeterminant = mm.Determinant;

        exScale    = mm.Scale;
        exTrans    = mm.Translate;
        exRotation = mm.Rotation;

        lookat  = Quaternion.LookRotation(inputVer);
        mlookat = UQuaternion.LookRotation(inputUv);

        mforwardLookat = mlookat * UVector3.forward;
        forwardLookat  = lookat * Vector3.forward;

        mangle = UQuaternion.LookRotation(inputUv).eulerAngles;
        rangle = Quaternion.LookRotation(inputVer).eulerAngles;


        mlookatMat = UMatrix4x4.LookAt(UVector3.zero, inputUv, UVector3.up);
        lookatMat  = Matrix4x4.TRS(
            Vector3.zero,
            Quaternion.LookRotation(inputVer, Vector3.up),
            Vector3.one);

        var v = this.transform.forward;

        angleY      = MathHelper.CalAngleWithAxisY(new UVector3(v.x, v.y, v.z));
        adm         = MathHelper.DeltaAngle(angleY, angle);
        ad          = Mathf.DeltaAngle(angleY, angle);
        angleDeltaM = MathHelper.MoveTowardsAngle(angleY, angle, adm * Time.deltaTime);
        angleDelta  = Mathf.MoveTowardsAngle(angleY, angle, ad * Time.deltaTime);


        this.mparent.localPosition = this.transform.parent.localPosition.ToUV3();
        this.mparent.localRotation = this.transform.parent.localRotation.ToUQ();
        this.mparent.localScale    = this.transform.parent.localScale.ToUV3();

        this.mtransfrom.localPosition = this.transform.localPosition.ToUV3();
        this.mtransfrom.localRotation = this.transform.localRotation.ToUQ();
        this.mtransfrom.localScale    = this.transform.localScale.ToUV3();

        dir  = this.transform.TransformDirection(Vector3.forward);
        dirU = mtransfrom.TransformDirection(UVector3.forward);

        point  = transform.TransformPoint(Vector3.forward);
        pointU = mtransfrom.TransformPoint(UVector3.forward);
    }