コード例 #1
0
        IEnumerator addForceParabolaGo(Vector3 srcPos, float skillRange)
        {
            float idxRand = Random.Range(0, 0.2f);

            yield return(new WaitForSeconds(idxRand));

            float currentDist = Vector3.Distance(this.transform.position, srcPos);
            float randValue   = Random.Range(0, 5.0f);
            // print("==="+ randValue);
            Vector3 t = (transform.position - srcPos).normalized;

            m_endPos    = srcPos + (transform.position - srcPos).normalized * (currentDist + trackParam.range + randValue);
            m_endPos.y  = transform.position.y;
            m_endPos2   = m_endPos + (transform.position - srcPos).normalized * (trackParam.range / 4);
            m_endPos2.y = transform.position.y;
            //直接散开
            float idxDis = Random.Range(0, 1.0f);

            m_pathAll[0] = transform.position;
            m_pathAll[1] = new Vector3((m_endPos.x - transform.position.x) / 2 + transform.position.x, trackParam.high + idxDis,
                                       (m_endPos.z - transform.position.z) / 2 + transform.position.z + idxDis);
            m_pathAll[2] = m_endPos;
            //计算角度
            Vector3   a     = new Vector3(0, 0, 1);
            Vector3   b     = transform.position - srcPos;
            float     angle = HMath.angle(0, 0, b.z, b.x);
            Hashtable args  = new Hashtable();

            //设置路径的点
            args.Add("path", m_pathAll);
            //设置类型为线性,线性效果会好一些。
            //args.Add("easeType", iTween.EaseType.easeOutQuad);
            args.Add("easeType", iTween.EaseType.linear);
            //设置寻路的速度
            args.Add("speed", trackParam.speedTrack);
            //args.Add("delay", 0.2f);
            //是否先从原始位置走到路径中第一个点的位置
            // args.Add("movetopath", true);
            //是否让模型始终面朝当面目标的方向,拐弯的地方会自动旋转模型
            //如果你发现你的模型在寻路的时候始终都是一个方向那么一定要打开这个
            //args.Add("orienttopath", true);

            //处理移动过程中的事件。
            //开始发生移动时调用AnimationStart方法,5.0表示它的参数
            args.Add("onstart", "AnimationStart");
            args.Add("onstartparams", angle);

            //移动结束时调用,参数和上面类似
            args.Add("oncomplete", "AnimationEnd");
            args.Add("oncompleteparams", "end");
            args.Add("oncompletetarget", gameObject);
            //移动中调用,参数和上面类似
            //args.Add("onupdate", "AnimationUpdate");
            //args.Add("onupdatetarget", gameObject);
            //args.Add("onupdateparams", true);
            //让模型开始寻路
            iTween.MoveTo(this.gameObject, args);
        }
コード例 #2
0
        float GetAngle(Vector3 from, Vector3 to)
        {
            float angle = HMath.angle(from.x, from.z, to.x, to.z);

            if (angle < 0)
            {
                angle += 360;
            }
            return(angle);
        }
コード例 #3
0
        override public void Play()
        {
            isPlay = true;
            from   = fromTransform.position;
            to     = toTransform.position;


            localTo           = to - from;
            content.position  = from;
            time              = localTo.magnitude / speed;
            backtime          = time / 4;
            arrowScale        = localTo.magnitude / 2;
            arrow.eulerAngles = new Vector3(0F, 0F, HMath.angle(0, 0, localTo.x, localTo.y));
            arrow.localScale  = new Vector3(0, Mathf.Clamp(0, 0, 2F), 1);

            _time = 0;
            StopAllCoroutines();
            StartCoroutine(Playing());
        }
コード例 #4
0
        public Vector3[] GetAnchorPoints()
        {
            if (isChange == false)
            {
                return(anchorPointsSource);
            }
            isChange = false;

            Vector3 center = transform.position;
            Vector3 size   = transform.lossyScale;
            float   angle  = -transform.eulerAngles.y;

            anchorPointsSource[0] = new Vector3(size.x * -0.5F, 0F, size.z * -0.5F);
            anchorPointsSource[1] = new Vector3(size.x * 0.5F, 0F, size.z * 0.5F);
            anchorPointsSource[2] = new Vector3(size.x * -0.5F, 0F, size.z * 0.5F);
            anchorPointsSource[3] = new Vector3(size.x * 0.5F, 0F, size.z * -0.5F);

            size.x += extended;
            size.z += extended;

            anchorPoints[0] = new Vector3(size.x * -0.5F, 0F, size.z * -0.5F);
            anchorPoints[1] = new Vector3(size.x * 0.5F, 0F, size.z * 0.5F);
            anchorPoints[2] = new Vector3(size.x * -0.5F, 0F, size.z * 0.5F);
            anchorPoints[3] = new Vector3(size.x * 0.5F, 0F, size.z * -0.5F);

            min.x = min.z = 9999999F;
            max.x = max.z = -9999999F;
            for (int i = 0; i < anchorPoints.Length; i++)
            {
                Vector3 point      = anchorPoints[i];
                float   anglePoint = HMath.angle(0f, 0f, point.x, point.z);
                float   angleEnd   = angle + anglePoint;
                float   length     = point.magnitude;
                float   radian     = HMath.angleToRadian(angleEnd);

                point.x         = HMath.radianPointX(radian, length, 0f);
                point.z         = HMath.radianPointY(radian, length, 0f);
                point          += center;
                anchorPoints[i] = point;
                if (point.x < min.x)
                {
                    min.x = point.x;
                }
                if (point.z < min.z)
                {
                    min.z = point.z;
                }
                if (point.x > max.x)
                {
                    max.x = point.x;
                }
                if (point.z > max.z)
                {
                    max.z = point.z;
                }


                point                 = anchorPointsSource[i];
                anglePoint            = HMath.angle(0f, 0f, point.x, point.z);
                angleEnd              = angle + anglePoint;
                length                = point.magnitude;
                radian                = HMath.angleToRadian(angleEnd);
                point.x               = HMath.radianPointX(radian, length, 0f);
                point.z               = HMath.radianPointY(radian, length, 0f);
                point                += center;
                anchorPointsSource[i] = point;
            }

            anchorPoints2[0] = anchorPoints[1];
            anchorPoints2[1] = anchorPoints[2];
            anchorPoints2[2] = anchorPoints[0];
            anchorPoints2[3] = anchorPoints[3];

            return(anchorPoints);
        }
コード例 #5
0
        protected override void OnUpdate()
        {
            base.OnUpdate();
            if (state == UnitPathState.None)
            {
                return;
            }

            if (needAround)
            {
                if (state == UnitPathState.Moveing)
                {
                    RelationType relation = unitData.GetRelation(unitData.to.legionId);
                    if (relation == RelationType.Enemy)
                    {
                        path.group.Around(unitData, transform.position);
                    }
                }
                else if (state == UnitPathState.Around)
                {
                    if (Vector3.Distance(transform.position, aroundPoint) < aroundAtkRadius)
                    {
                        state            = UnitPathState.AroundAtk;
                        unitAgent.action = "attack";

                        unitData.to.aroundList.Add(unitData);
                    }
                }
            }


            if (_freezed == false)
            {
                if (_distanceFrom <= 5)
                {
                    _distanceFrom = Vector3.Distance(transform.position, unitData.from.unit.transform.position);
                }

                if (_distanceFrom > 5)
                {
                    unitAgent.angel = HMath.AngleBetweenForward2Vector(rigibody.velocity);
                }
            }


            if (state == UnitPathState.Moveing || state == UnitPathState.Around)
            {
                unitAgent.anchorAngle.eulerAngles = new Vector3(0f, unitAgent.angel, 0f);
            }
            else if (state == UnitPathState.AroundAtk)
            {
                Vector3 pos = transform.position;
                Vector3 o   = unitData.to.unit.transform.position;
                unitAgent.angel = HMath.angle(pos.z, pos.x, o.z, o.x);
            }

            if (state == UnitPathState.Around || state == UnitPathState.AroundAtk)
            {
                RelationType relation = unitData.GetRelation(unitData.to.legionId);
                if (relation != RelationType.Enemy)
                {
                    In(false);
                }
            }

            if (unitData != null)
            {
                if (_moveSpeed != unitData.moveSpeed)
                {
                    _moveSpeed = unitData.moveSpeed;
                    //TODO 查询路线BUG
                    OnSpeedChange();
                }

                if (_freezed != unitData.freezedMoveSpeed)
                {
                    _freezed = unitData.freezedMoveSpeed;

                    if (_freezed)
                    {
                        m_steeringAgent.enabled = false;
                        rigibody.velocity       = Vector3.zero;
                    }
                    else
                    {
                        m_steeringAgent.enabled = true;
                    }
                }

                if (_freezed)
                {
                    if (unitAgent.action != "die")
                    {
                        unitAgent.speed = 0;
                    }
                    else
                    {
                        unitAgent.speed = 1;
                    }
                }
                else
                {
                    if (unitAgent.action == "walk" && unitData.moveSpeed <= 0)
                    {
                        unitAgent.speed = 0;
                    }
                    else
                    {
                        unitAgent.speed = 1;
                    }
                }
            }


            if (state == UnitPathState.Die)
            {
                dieTime += Time.deltaTime;
                if (transform.position.y < -1 || dieTime > dieTimeMax)
                {
                    War.hunManager.Play(unitCtl.unitData.colorId, transform.position.SetY(0));

                    SoliderPoolItem soliderPoolItem = GetComponent <SoliderPoolItem>();
                    if (soliderPoolItem != null)
                    {
                        soliderPoolItem.Release();
                    }
                    else
                    {
                        DestroyObject(gameObject);
                    }
                }
            }
        }
コード例 #6
0
        IEnumerator Playing()
        {
            bool isBack = false;

            while (isPlay)
            {
                if (isBack == false)
                {
                    if (_time == 0)
                    {
                        hand.position    = from;
                        _arrowScale      = arrowScale * _t;
                        arrow.localScale = new Vector3(_arrowScale, 1, 1);
                        yield return(new WaitForSeconds(delayBegin * 0.4f));

                        hand.localScale = Vector3.one * 0.8f;
                        yield return(new WaitForSeconds(delayBegin * 0.1f));

                        circle.localScale = Vector3.one * 0.8f;
                        yield return(new WaitForSeconds(delayBegin * 0.5f));

                        circleView.gameObject.transform.position = new Vector3(0, -10, -1000);
                        circleView.gameObject.SetActive(true);
                    }

                    _time          += Time.deltaTime;
                    _t              = _time / time;
                    hand.position   = Vector3.Lerp(from, to, _t);
                    circle.position = hand.position;

                    _arrowScale      = arrowScale * _t;
                    arrow.localScale = new Vector3(_arrowScale, 1, 1);
                    if (_t >= 1)
                    {
                        _time  = 0;
                        _t     = 0;
                        isBack = true;
                    }

                    if (from != fromTransform.position || to != toTransform.position)
                    {
                        from = fromTransform.position;
                        to   = toTransform.position;

                        localTo          = to - from;
                        content.position = from;

                        arrowScale        = localTo.magnitude / 2;
                        arrow.eulerAngles = new Vector3(0F, 0F, HMath.angle(0, 0, localTo.x, localTo.y));
                        time = localTo.magnitude / speed;
                    }
                }
                else
                {
                    if (_time == 0)
                    {
                        yield return(new WaitForSeconds(delayEnd));

                        _arrowScale       = arrowScale * _t;
                        arrow.localScale  = new Vector3(_arrowScale, 1, 1);
                        circle.localScale = Vector3.one;
                    }


                    _time        += Time.deltaTime;
                    _t            = _time / backtime;
                    hand.position = Vector3.Lerp(to, from, _t);

                    if (_t >= 1)
                    {
                        _time  = 0;
                        _t     = 0;
                        isBack = false;


                        circleView.gameObject.SetActive(false);
                        yield return(new WaitForSeconds(0.1f));

                        circle.position   = from;
                        circle.localScale = Vector3.one;
                        yield return(new WaitForSeconds(0.25f));
                    }
                }

                yield return(new WaitForEndOfFrame());
            }
        }
コード例 #7
0
        IEnumerator Playing()
        {
            bool isBack = false;

            while (isPlay)
            {
                if (isBack == false)
                {
                    if (_time == 0)
                    {
                        hand.position    = from;
                        _arrowScale      = arrowScale * _t;
                        arrow.localScale = new Vector3(_arrowScale, Mathf.Clamp(_arrowScale, 0, 2F), 1);
                        yield return(new WaitForSeconds(delayBegin * 0.4f));

                        hand.localScale = Vector3.one * 0.8f;
                        yield return(new WaitForSeconds(delayBegin * 0.1f));

                        circle.localScale = Vector3.one * 0.9f;
                        yield return(new WaitForSeconds(delayBegin * 0.5f));
                    }

                    _time            += Time.deltaTime;
                    _t                = _time / time;
                    hand.position     = Vector3.Lerp(from, to, _t);
                    circle.localScale = Vector3.Lerp(Vector3.one * 0.9f, Vector3.one * 0.4f, _t);

                    _arrowScale      = arrowScale * _t;
                    arrow.localScale = new Vector3(_arrowScale, Mathf.Clamp(_arrowScale, 0, 2F), 1);
                    if (_t >= 1)
                    {
                        _time  = 0;
                        _t     = 0;
                        isBack = true;
                    }

                    if (from != fromTransform.position || to != toTransform.position)
                    {
                        from = fromTransform.position;
                        to   = toTransform.position;

                        localTo          = to - from;
                        content.position = from;

                        arrowScale        = localTo.magnitude / 2;
                        arrow.eulerAngles = new Vector3(0F, 0F, HMath.angle(0, 0, localTo.x, localTo.y));
                        time = localTo.magnitude / speed;

                        target.position = to;
                    }
                }
                else
                {
                    if (_time == 0)
                    {
                        yield return(new WaitForSeconds(delayEnd));

                        _arrowScale       = arrowScale * _t;
                        arrow.localScale  = new Vector3(_arrowScale, Mathf.Clamp(_arrowScale, 0, 2F), 1);
                        circle.localScale = Vector3.one;
                    }


                    _time          += Time.deltaTime;
                    _t              = _time / backtime;
                    hand.position   = Vector3.Lerp(to, from, _t);
                    hand.localScale = Vector3.one * (1 + Mathf.Abs(Mathf.Abs(0.5f - _t) - 0.5f));

                    if (_t >= 1)
                    {
                        _time  = 0;
                        _t     = 0;
                        isBack = false;
                    }
                }

                yield return(new WaitForEndOfFrame());
            }
        }
コード例 #8
0
ファイル: BSendArming.cs プロジェクト: PenpenLi/abcabcabc.mg
        protected override void OnUpdate()
        {
            base.OnUpdate();

            if (!sendArmData.sending)
            {
                return;
            }
            if (!War.isGameing)
            {
                return;
            }
            if (_forced == false && unitData.freezedSendArm)
            {
                return;
            }
            if (unitData.unitNum <= 0 || unitData.death)
            {
                Stop();
                return;
            }


            armOnceWidth = legionData.soliderData.armOnceWidth;
            radius       = legionData.soliderData.radius;
            gapV         = legionData.soliderData.gapV;
            gapH         = radius * 2;
            if (gapV < 0)
            {
                gapV = gapH;
            }
            if (armOnceWidth < 0)
            {
                armOnceWidth = 8;
            }
            onceCount = Mathf.FloorToInt(armOnceWidth / gapH);


            targetCount = sendArmData.targets.Count;
            for (int j = 0; j < targetCount; j++)
            {
                SendArmDataTarget targetData = sendArmData.targets[j];

                int count = Mathf.Min(targetData.num, onceCount);
                count = Mathf.Min(count, unitData.unitNum);
                //Debug.Log ("j=" + j + " count=" + count + "  targetData.num=" + targetData.num);
                if (count <= 0)
                {
                    sendArmData.WillRemoveTarget(targetData);
                    continue;
                }

                if (count > 8)
                {
                    count = 8;
                }

                if (Time.time > targetData.nextTime)
                {
                    PathGroup pathGroup = War.scene.GetPathCache(onceCount, transform, targetData.target.transform);
                    isInitPathCache = pathGroup != null;
                    List <UnitPath> unitPathList  = new List <UnitPath>();
                    UnitPathGroup   unitPathGroup = null;
                    if (!isInitPathCache)
                    {
                        GameObject groupGO = War.factory.CreatePathGroup();
                        groupGO.transform.position = transform.position;
                        unitPathGroup = groupGO.GetComponent <UnitPathGroup>();
                    }

                    float moveSpeed = 1f;
                    for (int i = 0; i < count; i++)
                    {
                        int pathIndex = (int)((i + 1) / 2) * (i % 2 == 0 ? 1 : -1);

                        targetData.num      += -1;
                        sendArmData.sendNum += -1;
                        unitData.AddUnitNum(-1);

//											GameObject soliderGO = War.factory.CreateSolider(unitData.legionId);
                        GameObject soliderGO       = War.soliderPool.Get();
                        UnitData   soliderUnitData = legionData.soliderData.Clone();
                        soliderUnitData.id   = targetData.idBegin++;
                        soliderUnitData.from = unitData;
                        soliderUnitData.to   = targetData.target.unitData;
                        unitData.soliderPropContainer.UnitApp(soliderUnitData);
                        legionData.soliderPropContainer.UnitApp(soliderUnitData);
                        legionData.soliderInitPropContainer.UnitApp(soliderUnitData, true);

                        soliderGO.AddEComponent(soliderUnitData);
                        soliderUnitData.Init();
                        if (targetData.forced)
                        {
                            soliderUnitData.moveSpeed = targetData.speed;
                        }
                        UnitAgent unitAgent = soliderGO.GetComponent <UnitAgent>();
                        unitAgent.Walk();
                        unitAgent.angel = HMath.angle(transform.position.z, transform.position.x, targetData.target.transform.position.z, targetData.target.transform.position.x);


                        soliderGO.name = "War_Solider-" + soliderUnitData.id;


                        UnitPath unitPath = soliderGO.GetComponent <UnitPath>();
                        unitPath.index               = pathIndex;
                        unitPath.maxSpeed            = targetData.forced ? targetData.speed : soliderUnitData.moveSpeed;
                        soliderGO.transform.position = transform.position;

                        if (isInitPathCache)
                        {
                            unitPathList.Add(unitPath);
                        }
                        else
                        {
                            unitPathGroup.list.Add(unitPath);
                        }



                        moveSpeed = unitPath.maxSpeed;
                        if (targetData.forced)
                        {
                            soliderUnitData.moveSpeed = moveSpeed;
                            soliderUnitData.Props[PropId.InitMoveSpeed] = moveSpeed;
                        }

                        soliderUnitData.to.AddFromLegionUnit(soliderUnitData.legionId, 1);

                        SoliderPoolItem soliderPoolItem = soliderGO.GetComponent <SoliderPoolItem>();
                        if (soliderPoolItem != null)
                        {
                            soliderPoolItem.Rest();
                        }
                    }

                    //				Debug.Log(string.Format("<color=green>isInitPathCache={0}</color>", isInitPathCache));
                    if (isInitPathCache)
                    {
                        pathGroup = War.scene.GetPathCache(onceCount, transform, targetData.target.transform);
                        int unitPathListCount = unitPathList.Count;
                        pathGroup = pathGroup.Clone(unitPathListCount);

                        for (int i = 0; i < unitPathListCount; i++)
                        {
                            unitPathList[i].SetPath(pathGroup.paths[i]);
                        }
                    }
                    else
                    {
                        unitPathGroup.gap       = gapH;
                        unitPathGroup.pathNum   = count;
                        unitPathGroup.onceCount = onceCount;
                        unitPathGroup.MoveTo(unitCtl, targetData.target);
                    }

                    if (float.IsNaN(moveSpeed) || moveSpeed <= 0)
                    {
                        moveSpeed = 1f;
                    }
                    targetData.nextTime = Time.time + (gapV + sendArmData.sendUnitSpeed) / moveSpeed;
                }
            }

            sendArmData.ExeRemoveTargets();
        }