public void DestroyObstacle() { Utilities.DebugLog("TerrainObstacle.DestroyObstacle ()"); if (this.destroyedPrefab) { GameObject destroyedObstacleGameObject = (GameObject)Instantiate(this.destroyedPrefab, this.gameObject.transform.position, this.gameObject.transform.rotation); TerrainObstacle destroyedObstacle = destroyedObstacleGameObject.GetComponent <TerrainObstacle> (); float obstacleScaleSign = Mathf.Sign(this.transform.localScale.x); destroyedObstacle.transform.localScale = new Vector3(obstacleScaleSign * destroyedObstacle.transform.localScale.x, destroyedObstacle.transform.localScale.y, destroyedObstacle.transform.localScale.z); // Enable/disable pathfinding obstruction PolyNavObstacle polyNavObstacle = destroyedObstacleGameObject.GetComponent <PolyNavObstacle> (); if (polyNavObstacle) { polyNavObstacle.enabled = this.shouldStopUnitMovementWhenDestroyed; } this.isIntact = false; this.shouldRemoveFromListAndDestroyOnNextUpdate = true; destroyedObstacle.shouldAddToListOnNextUpdate = true; } else { SpriteRenderer spriteRenderer = this.gameObject.GetComponent <SpriteRenderer> (); if (spriteRenderer) { spriteRenderer.color = new Color(1f, 1f, 1f, .2f); // 20% transparent } this.isIntact = false; } }
public void TakeDamage(float damage) { Utilities.DebugLog("TerrainObstacle.TakeDamage ()"); this.health -= damage; if (this.health <= 0) { if (this.shouldCauseExplosionWhenDestroyed) { if (this.tcScript) { GameObject explosion = (GameObject)Instantiate(this.tcScript.explosionPrefab, this.transform.position, Quaternion.identity); ParticleSystem particleSystem = explosion.GetComponent <ParticleSystem> (); if (particleSystem) { particleSystem.startSize = this.radius * PARTICLE_RADIUS; } //explosion.transform.position = new Vector2(explosion.transform.position.x + PROJECTILE_CREATION_POINT_OFFSET.x, explosion.transform.position.y + PROJECTILE_CREATION_POINT_OFFSET.y); //Destroy (explosion, 1.0f); // Deal splash damage Utilities.DebugLog("Deal splash damage"); //this.tcScript.DealDamageToUnitsWithinRange (this.gameObject.transform.position, BALLISTIC_PROJECTILE_SPLASH_DAMAGE_RANGE + obstacle.radius, this.attack * BALLISTIC_PROJECTILE_SPLASH_DAMAGE_PERCENTAGE * 20.0f); this.tcScript.DealDamageWithFalloffToUnitsWithinRange(this.gameObject.transform.position, BALLISTIC_PROJECTILE_SPLASH_DAMAGE_RANGE + this.radius * 1.5f, damage * 20.0f, this.gameObject); } } // Enable/disable pathfinding obstruction PolyNavObstacle polyNavObstacle = this.gameObject.GetComponent <PolyNavObstacle> (); polyNavObstacle.enabled = this.shouldStopUnitMovementWhenDestroyed; this.DestroyObstacle(); } }
// Use this for initialization void Start() { m_Obstacle = GetComponent<PolyNavObstacle>(); m_Collider = GetComponent<Collider2D>(); Debug.Assert(m_Obstacle != null && m_Collider != null); }
///Adds a PolyNavObstacle to the map. public void AddObstacle( PolyNavObstacle navObstacle ){ if (!navObstacles.Contains(navObstacle)){ navObstacles.Add(navObstacle); generateFlag = true; } }
///Removes a PolyNavObstacle to the map. public void RemoveObstacle(PolyNavObstacle navObstacle) { if (navObstacles.Contains(navObstacle)) { navObstacles.Remove(navObstacle); regenerateFlag = true; } }
///Adds a PolyNavObstacle to the map. public void AddObstacle(PolyNavObstacle navObstacle) { if (!navObstacles.Contains(navObstacle)) { navObstacles.Add(navObstacle); regenerateFlag = true; } }
///Adds a PolyNavObstacle to the map. public void AddObstacle(PolyNavObstacle navObstacle) { navObstacle.gameObject.layer = obstaclesLayer; if (!navObstacles.Contains(navObstacle)) { navObstacles.Add(navObstacle); GenerateMap(); } }
void MonitorObstacle(PolyNavObstacle obstacle, bool active) { if (obstaclesMask == (obstaclesMask | 1 << obstacle.gameObject.layer)) { if (active) { AddObstacle(obstacle); } else { RemoveObstacle(obstacle); } } }
// Use this for initialization void Start() { Utilities.DebugLog("TerrainObstacle.Start ()"); // Enable/disable pathfinding obstruction PolyNavObstacle polyNavObstacle = this.gameObject.GetComponent <PolyNavObstacle> (); if (polyNavObstacle) { polyNavObstacle.enabled = this.shouldStopUnitMovementWhenIntact; } Camera mainCamera = Camera.main; this.tcScript = mainCamera.GetComponent <TacticalCombat> (); }
static int RemoveObstacle(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); PolyNav2D obj = (PolyNav2D)ToLua.CheckObject <PolyNav2D>(L, 1); PolyNavObstacle arg0 = (PolyNavObstacle)ToLua.CheckObject <PolyNavObstacle>(L, 2); obj.RemoveObstacle(arg0); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
void Start() { //Turns each tile with a collider attached to it into an obstacle on the nav mesh foreach (TileEditor.Tile tile in FindObjectsOfType <TileEditor.Tile>()) { Collider2D col = tile.GetComponent <Collider2D>(); if (col != null) { if (col.gameObject.layer != 10) { PolyNavObstacle ob = tile.gameObject.AddComponent <PolyNavObstacle>(); ob.extraOffset = extraOffset; } } } }
public override void OnInspectorGUI() { serializedObject.Update(); MonoBehaviour mono = (MonoBehaviour)target; ProceduralWall scriptTarget = mono.GetComponent <ProceduralWall>(); PolyNavObstacle pObstacle = mono.GetComponent <PolyNavObstacle>(); CompositeCollider2D collider = mono.GetComponent <CompositeCollider2D>(); base.OnInspectorGUI(); if (GUILayout.Button("Build Wall")) { scriptTarget.Generate(); } serializedObject.ApplyModifiedProperties(); }
/// <summary> /// Instantiation of spawn logic per Transport /// </summary> private void Start() { // Grab the spawn point for this unit. _spawnController = gameObject.GetComponent <TransportSpawnController>(); _spawnPoint = _spawnController.GetSpawnPoint(); _destination = _spawnController.GetDestination(); _payloadMultiplier = _spawnController.PayloadMultiplier; _spawnController.TearDown(); _navMapRef = FindObjectOfType <PolyNav2D>(); _myObstacle = gameObject.GetComponent <PolyNavObstacle>(); // Move to spawn location. transform.position = _spawnPoint; // Apply movement towards destination. MoveToDestination(); }
// check if there is a vison blocker between the target and this object bool HasVisionBlock(Transform target) { if (ignoreVisionBlock) { return(false); } float dist = Vector3.Distance(transform.position, target.position); Vector3 dir = target.transform.position - transform.position; dir.Normalize(); RaycastHit2D[] hits = Physics2D.RaycastAll(transform.position, dir, dist); foreach (RaycastHit2D hit in hits) { Transform hitTrans = hit.transform; if (hit.collider.isTrigger || hitTrans == transform) { continue; } ObjectIdentity oi = hitTrans.GetComponent <ObjectIdentity> (); if (oi) { return(oi.isVisionBlocker()); } if (hit.collider && hit.collider.isTrigger == false && hit.collider.GetComponent <SFPolygon>()) { return(true); } PolyNavObstacle obstacle = hitTrans.GetComponent <PolyNavObstacle> (); if (obstacle) { return(true); } } return(false); }
// check if there is a vison blocker between the target and this object bool HasVisionBlock(Transform target) { float dist = Vector2.Distance(transform.position, target.position); Vector2 dir = target.transform.position - transform.position; dir.Normalize(); // assume at most 10 objects would in between RaycastHit2D[] hits = new RaycastHit2D[10]; Physics2D.Raycast (transform.position, dir, raycastFilter, hits, dist); foreach (RaycastHit2D hit in hits) { Transform hitTrans = hit.transform; if (hitTrans == target || hitTrans == null) { continue; } if (hit.collider && hit.collider.gameObject.layer == LayerMask.NameToLayer("HighWall")) { return(true); } // defined vision blocker ObjectIdentity oi = hitTrans.GetComponent <ObjectIdentity> (); if (oi && oi.isVisionBlocker()) { return(true); } // defined polynavobstacle PolyNavObstacle obstacle = hitTrans.GetComponent <PolyNavObstacle> (); if (obstacle) { return(true); } } return(false); }
private void Start() { float fireSize = hasLargeFire ? 0.3f : 0.1f; if (particles != null) { GameObject parts = Instantiate(particles, transform); parts.transform.localPosition = Vector3.zero; parts.transform.localScale = new Vector3(fireSize, fireSize, fireSize); } else { Debug.Log("No particles associated with this debris controller."); } if (isPolyNav == true) { _myObstacle = gameObject.GetComponent <PolyNavObstacle>(); _navMapRef = FindObjectOfType <PolyNav2D>(); _navMapRef.AddObstacle(_myObstacle); } }
// Handle collisions void OnTriggerEnter2D(Collider2D other) { Utilities.DebugLog("Projectile.OnTriggerEnter2D ()"); if (this.currentState == ProjectileState.PROJECTILE_STATE_ACTIVE) { // Check collision between projectile and Unit Unit unit = other.gameObject.GetComponent <Unit> (); if (unit) { if (unit.isPlayerControlled != this.isPlayerControlled && (!this.isBallisticProjectile || this.percentTravelled > 0.9f) && unit.currentState != Unit.UnitState.UNIT_STATE_PREPARING_FOR_CLOSE_COMBAT && unit.currentState != Unit.UnitState.UNIT_STATE_CLOSE_COMBAT && unit.currentState != Unit.UnitState.UNIT_STATE_DEAD && unit.currentState != Unit.UnitState.UNIT_STATE_DISABLED) { // For bazooka only, decrease damage as it approaches its max range float attackStrength = this.attack; if (this.isBazooka) { attackStrength = attackStrength * ((1.0f - this.percentTravelled) * 0.5f + 0.5f); } unit.TakeDamage(attackStrength); if (this.tcScript) { this.tcScript.projectilesList.Remove(this); } DestroyProjectileAccordingToType(); } } // Check collision between projectile and obstacle TerrainObstacle obstacle = other.gameObject.GetComponent <TerrainObstacle> (); if (obstacle) { if (obstacle.isDestructible && (!this.isBallisticProjectile || this.percentTravelled > 0.9f) && (!this.isBazooka || this.distanceTravelled > 1.0f /*50.0f*/)) { // Stop projectile if applicable if ((obstacle.isIntact && obstacle.shouldStopExplosivesWhenIntact && this.isBallisticProjectile && this.fullBallisticShift * 1.0f < obstacle.height * 2.5f) || (obstacle.isIntact && obstacle.shouldStopFireWhenIntact && this.isFlamethrower) || (obstacle.isIntact && obstacle.shouldStopBulletsWhenIntact && !this.isBallisticProjectile && !this.isFlamethrower) || (!obstacle.isIntact && obstacle.shouldStopExposivesWhenDestroyed && this.isBallisticProjectile) || (!obstacle.isIntact && obstacle.shouldStopFireWhenDestroyed && this.isFlamethrower) || (!obstacle.isIntact && obstacle.shouldStopBulletsWhenDestroyed && !this.isBallisticProjectile && !this.isFlamethrower)) { DestroyProjectileAccordingToType(); } // Cause damage to obstacle if applicable if ((obstacle.isIntact && !obstacle.isImmuneToExplosiveDamage && this.isBallisticProjectile && this.fullBallisticShift * 1.0f < obstacle.height * 2.5f) || (obstacle.isIntact && !obstacle.isImmuneToFireDamage && this.isFlamethrower) || (obstacle.isIntact && !obstacle.isImmuneToBulletDamage && !this.isBallisticProjectile && !this.isFlamethrower)) { obstacle.TakeDamage(this.attack); } } } else { // Check collision between projectile and non-TerrainObstacle PolyNavObstacle PolyNavObstacle polyNavObstacle = other.gameObject.GetComponent <PolyNavObstacle> (); if (polyNavObstacle) { //DestroyProjectileAccordingToType (); float GENERIC_POLYNAV_OBSTACLE_HEIGHT = 200.0f; if ((!this.isBallisticProjectile || this.percentTravelled > 0.9f) && (!this.isBazooka || this.distanceTravelled > 1.0f /*50.0f*/)) { // Stop projectile if applicable if ((this.isBallisticProjectile && this.fullBallisticShift * 1.0f < GENERIC_POLYNAV_OBSTACLE_HEIGHT * 2.5f) || (this.isFlamethrower) || (!this.isBallisticProjectile && !this.isFlamethrower)) { DestroyProjectileAccordingToType(); } } } } } }
///Removes a PolyNavObstacle to the map. public void RemoveObstacle(PolyNavObstacle navObstacle) { navObstacles.Remove(navObstacle); generateFlag = true; }
///Removes a PolyNavObstacle to the map. public void RemoveObstacle(PolyNavObstacle navObstacle) { navObstacles.Remove(navObstacle); GenerateMap(); }
public static void setMoveCollider(Transform who, bool onOff) { PolyNavObstacle col = who.GetComponentInChildren <PolyNavObstacle>(true); col.enabled = onOff; }
// Use this for initialization void Start() { _comp = GetComponent <CompositeCollider2D>(); _obstacle = GetComponent <PolyNav.PolyNavObstacle>(); }