void Awake() { // Find a reference to the path and steering agent m_pathAgent = GetComponent <PathAgentComponent>(); m_steeringAgent = GetComponent <SteeringAgentComponent>(); m_pathGroup = GetComponent <UnitPathGroup>(); }
protected override void OnAwake() { base.OnAwake(); m_pathAgent = GetComponent <PathAgentComponent>(); m_steeringAgent = GetComponent <SteeringAgentComponent>(); rigibody = GetComponent <Rigidbody>(); }
void Awake() { // Find a reference to the path and steering agent m_pathAgent = GetComponent <PathAgentComponent>(); m_steeringAgent = GetComponent <SteeringAgentComponent2D> () as ISteeringAgent; if (m_steeringAgent == null) { m_steeringAgent = GetComponent <SteeringAgentComponent> () as ISteeringAgent; } }
public void SetPath(Path path) { if (unitData == null) { // OnRelease(); // SoliderPoolItem soliderPoolItem = GetComponent<SoliderPoolItem>(); // // Debug.LogErrorFormat("<color=red>SetPath unitData=null gameObject={0}, gameObject.activeSelf={1} isRelease={2}, isPut={3}, needRest={4}</color>", gameObject, gameObject.activeSelf, soliderPoolItem.isRelease, soliderPoolItem.isPut, soliderPoolItem.needRest); return; } if (m_steeringAgent == null) { m_pathAgent = GetComponent <PathAgentComponent>(); m_steeringAgent = GetComponent <SteeringAgentComponent>(); rigibody = GetComponent <Rigidbody>(); } from = unitData.from.unit; to = unitData.to.unit; state = UnitPathState.Moveing; this.path = path; path.unitPath = this; // float timeTotal0 = path.s0 / maxSpeed; // float speed = path.s / timeTotal0; _moveSpeed = unitData.moveSpeed; // m_steeringAgent.m_maxSpeed = speed; // m_steeringAgent.m_slowingDistance = speed / 2F; // m_steeringAgent.m_arrivalDistance = 0.5F * speed / 2F > 2f ? 2F : 0.5F * speed / 2F; // if(m_steeringAgent.m_arrivalDistance < 0.5) m_steeringAgent.m_arrivalDistance = 0.5F; //TODO OnSpeedChange(); // m_steeringAgent.SteerAlongPath( path.points.ToArray(), m_pathAgent.PathManager.PathTerrain ); m_steeringAgent.SteerAlongPath(path.points.ToArray(), null); }
IEnumerator SetMoveTo(UnitCtl from, UnitCtl to) { yield return(new WaitForSeconds(0.3f)); GameObject go = GameObject.Instantiate(prefab); go.transform.SetParent(War.scene.rootSoliders); go.transform.position = from.transform.position; WE_UnitPathGroup unitPathGroup = go.GetComponent <WE_UnitPathGroup>(); PathAgentComponent pathAgent = go.GetComponent <PathAgentComponent>(); pathAgent.m_pathManager = War.pathManager; go.SetActive(true); // unitPathGroup.gap = gapH; // unitPathGroup.pathNum = count; // unitPathGroup.onceCount = onceCount; unitPathGroup.sPathFinded += OnFind; unitPathGroup.MoveTo(from, to); }
void Awake() { // Find a reference to the path and steering agent m_pathAgent = GetComponent<PathAgentComponent>(); m_steeringAgent = GetComponent<SteeringAgentComponent>(); }
public IEnumerator InitPathCache() { if (_initPathCache) { yield break; } _initPathCache = true; Dictionary <int, bool> onceCountHas = new Dictionary <int, bool>(); int count = buildList.Count; float totalCount = count * count * War.sceneData.legionDict.Count; float totalIndex = 0; float rate = 0; foreach (KeyValuePair <int, LegionData> legionKVP in War.sceneData.legionDict) { LegionData legionData = legionKVP.Value; if (legionData.type != LegionType.Player && !legionData.aiSendArm) { totalIndex += count * count; rate = totalIndex / totalCount; War.sceneCreate.SetSceneLoaderProgress(rate); yield return(new WaitForSeconds(count * 0.2f)); continue; } float radius = legionData.soliderData.radius; float gap = radius * 2; int onceCount = Mathf.FloorToInt(8 / gap); if (onceCountHas.ContainsKey(onceCount)) { totalIndex += count * count; rate = totalIndex / totalCount; War.sceneCreate.SetSceneLoaderProgress(rate); yield return(new WaitForSeconds(count * 0.2f)); continue; } onceCountHas.Add(onceCount, true); // Debug.Log(string.Format("<color=yellow>legionData.legionId={0}, buildList.Count={1}, onceCount={2}</color>", legionData.legionId, count, onceCount)); for (int i = 0; i < count; i++) { Transform from = buildList[i].transform; for (int j = 0; j < count; j++) { totalIndex++; if (i == j) { continue; } Transform to = buildList[j].transform; GameObject groupGO = War.factory.CreatePathGroup(); UnitPathGroup pathGroup = groupGO.GetComponent <UnitPathGroup>(); PathAgentComponent pathAgent = groupGO.GetComponent <PathAgentComponent>(); pathAgent.m_pathManager = War.pathManager; groupGO.transform.position = from.position; pathGroup.isInitCache = true; pathGroup.gap = gap; pathGroup.onceCount = onceCount; pathGroup.MoveTo(from, to); // Debug.Log(string.Format("<color=yellow>i={0}, j={1}, onceCount={2}</color>", i, j, onceCount)); rate = totalIndex / totalCount; yield return(new WaitForEndOfFrame()); War.sceneCreate.SetSceneLoaderProgress(rate); // Debug.Log("rate=" + rate); yield return(new WaitForEndOfFrame()); } } rate = totalIndex / totalCount; War.sceneCreate.SetSceneLoaderProgress(rate); yield return(new WaitForEndOfFrame()); } War.sceneCreate.OnInitPathCacheComplete(); }