| . | |
| using System; |
| |
| using UnityEngine; |
| |
| |
| |
| public class DropProjectileOverDistance : MonoBehaviour |
| |
| { |
| |
| private void Awake() |
| |
| { |
| |
| this.m_character = base.GetComponent<Character>(); |
| |
| this.m_nview = base.GetComponent<ZNetView>(); |
| |
| if (this.m_projectilePrefab == null) |
| |
| { |
| |
| base.enabled = false; |
| |
| } |
| |
| } |
| |
| |
| |
| private void FixedUpdate() |
| |
| { |
| |
| if (!this.m_nview.IsValid() || !this.m_nview.IsOwner()) |
| |
| { |
| |
| return; |
| |
| } |
| |
| Vector3 vector = base.transform.position.Horizontal(); |
| |
| this.m_distanceAccumulator += Vector3.Distance(this.lastPosition, vector); |
| |
| Vector3 vector2 = this.lastPosition.DirTo(vector); |
| |
| if (this.lastPosition != vector) |
| |
| { |
| |
| this.lastPosition = vector; |
| |
| } |
| |
| if (this.m_timeToForceSpawn > 0f) |
| |
| { |
| |
| this.m_spawnTimer += Time.deltaTime; |
| |
| if (this.m_spawnTimer > this.m_timeToForceSpawn) |
| |
| { |
| |
| this.SpawnProjectile(base.transform.position, vector2); |
| |
| this.m_distanceAccumulator -= this.m_distancePerProjectile; |
| |
| this.m_distanceAccumulator = Mathf.Max(this.m_distanceAccumulator, 0f); |
| |
| } |
| |
| } |
| |
| if (this.m_distanceAccumulator < this.m_distancePerProjectile) |
| |
| { |
| |
| return; |
| |
| } |
| |
| int num = Mathf.FloorToInt(this.m_distanceAccumulator / this.m_distancePerProjectile); |
| |
| for (int i = 0; i < Mathf.Min(3, num); i++) |
| |
| { |
| |
| this.SpawnProjectile(base.transform.position - vector2 * (float)i, vector2); |
| |
| this.m_distanceAccumulator -= this.m_distancePerProjectile; |
| |
| num--; |
| |
| } |
| |
| this.m_distanceAccumulator -= this.m_distancePerProjectile * (float)num; |
| |
| } |
| |
| |
| |
| private void SpawnProjectile(Vector3 point, Vector3 travelDirection) |
| |
| { |
| |
| this.m_spawnTimer = 0f; |
| |
| if (this.m_projectilePrefab.GetComponent<IProjectile>() == null) |
| |
| { |
| |
| ZLog.LogWarning("Attempted to spawn non-projectile"); |
| |
| } |
| |
| point.y += this.m_spawnHeight; |
| |
| if (this.m_snapToGround) |
| |
| { |
| |
| float num; |
| |
| ZoneSystem.instance.GetSolidHeight(point, out num, 1000); |
| |
| point.y = num; |
| |
| } |
| |
| UnityEngine.Object.Instantiate<GameObject>(this.m_projectilePrefab, point, Quaternion.LookRotation(travelDirection)).GetComponent<IProjectile>().Setup(this.m_character, travelDirection * UnityEngine.Random.Range(this.m_minVelocity, this.m_maxVelocity), -1f, null, null, null); |
| |
| } |
| |
| |
| |
| private void OnDrawGizmosSelected() |
| |
| { |
| |
| Gizmos.color = new Color(0.76f, 0.52f, 0.55f); |
| |
| Gizmos.DrawLine(base.transform.position, base.transform.position + Vector3.up * this.m_spawnHeight); |
| |
| Vector3 vector = base.transform.position + base.transform.forward * this.m_distancePerProjectile; |
| |
| Gizmos.DrawLine(base.transform.position + Vector3.up * 0.5f * this.m_spawnHeight, vector + Vector3.up * 0.5f * this.m_spawnHeight); |
| |
| Gizmos.DrawLine(vector, vector + Vector3.up * this.m_spawnHeight); |
| |
| } |
| |
| |
| |
| public GameObject m_projectilePrefab; |
| |
| |
| |
| public float m_distancePerProjectile = 5f; |
| |
| |
| |
| public float m_spawnHeight = 1f; |
| |
| |
| |
| public bool m_snapToGround; |
| |
| |
| |
| [global::Tooltip("If higher than 0, will force a spawn if nothing has spawned in that amount of time.")] |
| |
| public float m_timeToForceSpawn = -1f; |
| |
| |
| |
| public float m_minVelocity; |
| |
| |
| |
| public float m_maxVelocity; |
| |
| |
| |
| private Character m_character; |
| |
| |
| |
| private ZNetView m_nview; |
| |
| |
| |
| private Vector3 lastPosition; |
| |
| |
| |
| private float m_distanceAccumulator; |
| |
| |
| |
| private float m_spawnTimer; |
| |
| |
| |
| private const int c_MaxSpawnsPerFrame = 3; |
| |
| } |
| |
| |