public void Update() { m_time_counter += Time.deltaTime; m_totol_time_counter += Time.deltaTime; if (FlyMode == FlyModeType.Linear) { Vector3 curt = CalcPos(m_time_counter); UpdateRotation(curt); transform.localPosition = curt; } if (m_time_counter >= m_curt_fly_time) { if (PrefabFxEnd != null) { FxBase fb = FxPool.Instance.Alloc(PrefabFxEnd, null); fb.transform.localPosition = CurtEnd; } } if (m_totol_time_counter >= FlyTime) { m_active_in_pool = false; BulletViewPool.Instance.Free(this); } else if (m_time_counter >= m_curt_fly_time) { ++m_end_index; m_time_counter = 0; m_curt_fly_time = Vector3.Distance(m_end[m_end_index], m_end[m_end_index - 1]) / Speed; if (FlyMode == FlyModeType.Laser) { transform.localPosition = CurtStart; UpdateRotation(CurtEnd); if (m_fb != null) { FxPool.Instance.Free(m_fb); m_fb = null; } if (PrefabFxFly != null) { m_fb = FxPool.Instance.Alloc(PrefabFxFly, null); m_fb.transform.localPosition = CurtStart; m_fb.transform.localRotation = transform.localRotation; m_fb.ScaleBody(Vector3.Distance(CurtStart, CurtEnd)); } } if (OnReachTarget != null) { OnReachTarget(this, m_end_index); } } }
public void Active(Vector3 s, Creature[] targets) { m_active_in_pool = true; gameObject.SetActive(true); m_start = s; m_end = GetTargetPos(targets); m_end_index = 0; m_time_counter = 0; m_totol_time_counter = 0; m_fly_time = 0; Vector3 prev = s; for (int i = 0; i < m_end.Length; ++i) { m_fly_time += Vector3.Distance(prev, m_end[i]) / Speed; prev = m_end[i]; } m_curt_fly_time = Vector3.Distance(s, m_end[0]) / Speed; transform.localPosition = s; if (FlyMode == FlyModeType.Laser) { UpdateRotation(CurtEnd); if (PrefabFxFly != null) { m_fb = FxPool.Instance.Alloc(PrefabFxFly, null); m_fb.transform.localPosition = transform.localPosition; m_fb.transform.localRotation = transform.localRotation; m_fb.ScaleBody(Vector3.Distance(CurtStart, CurtEnd)); } } else if (FlyMode == FlyModeType.Linear) { Vector3 curt = CalcPos(0.02f); UpdateRotation(curt); if (PrefabFxFly != null) { m_fb = FxPool.Instance.Alloc(PrefabFxFly, gameObject); } } OnReachTarget = null; }