Exemple #1
0
        protected override void OnUpdate()
        {
            base.OnUpdate();

            if (unitData == null)
            {
                return;
            }

            if (!unitData.death && unitData.hp <= 0)
            {
                unitData.death = true;
            }

            if (_death != unitData.death)
            {
                _death = unitData.death;
                if (_death)
                {
                    SoliderPoolItem soliderPoolItem = GetComponent <SoliderPoolItem>();
                    UnitPath        unitPath        = GetComponent <UnitPath>();
                    unitPath.state = UnitPathState.Die;
                    if (unitData.isHitFly)
                    {
                        unitAgent.HitFly();
                        if (soliderPoolItem != null)
                        {
                            //							soliderPoolItem.DelayRelease(3F);
                            soliderPoolItem.Release();
                        }
                        else
                        {
                            delayDestory.delayTime = 3F;
                            delayDestory.enabled   = true;
                        }
                    }
                    else
                    {
                        if (soliderPoolItem != null)
                        {
                            soliderPoolItem.Release();
                        }
                        else
                        {
                            delayDestory.delayTime = 0F;
                            delayDestory.enabled   = true;
                        }
                    }
                }
            }
        }
        public void OnSteeringRequestSucceeded()
        {
            if (unitPath && unitPath.state == UnitPathState.Die)
            {
                return;
            }
            RelationType relation = unitData.GetRelation(unitData.to.legionId);

            if (relation == RelationType.Enemy)
            {
                if (unitPath.needAround)
                {
                    if (unitPath.state == UnitPathState.Ining)
                    {
                        unitPath.HitFly();
                    }
                }
                else
                {
                    unitData.to.unit.GetComponent <BBuildShake>().Play();
                    Die();
                }
            }
            else
            {
                delayDestory = GetComponent <DelayDestory>();
                if (unitData != null && unitData.to != null)
                {
//					War.textEffect.PlayHP(unitData.hp, unitData.to.unit);
                    unitData.to.hp += unitData.hp;
                }


                SoliderPoolItem soliderPoolItem = GetComponent <SoliderPoolItem>();
                if (soliderPoolItem != null)
                {
                    soliderPoolItem.Release();
                }
                else
                {
                    delayDestory.delayTime = 0F;
                    delayDestory.enabled   = true;
                }
            }
        }
Exemple #3
0
        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();
        }