private void RemoveTarget(SendArmDataTarget targetData) { targets.Remove(targetData); targetDict.Remove(targetData.target); targetData.target.unitData.fromList.Remove(unitData); if (willRemoveTargets.Contains(targetData)) { willRemoveTargets.Remove(targetData); } }
public void AddTarget(UnitCtl target, int idBegin, int num, bool forced, float speed) { SendArmDataTarget targetData; if (targetDict.TryGetValue(target, out targetData)) { targetData.idBegin = idBegin; targetData.num = num; targetData.forced = forced; targetData.speed = speed; } else { targetData = new SendArmDataTarget(target, idBegin, num, forced, speed); targets.Add(targetData); targetDict.Add(target, targetData); target.unitData.fromList.Add(unitData); } }
public void WillRemoveTarget(SendArmDataTarget targetData) { willRemoveTargets.Add(targetData); }
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(); }