public bool Shoot(Bullet bullet, ObjectProperty owner, Transform eyesTransform) { Debug.Assert(null != bullet, "bullet is null!!"); Bullet clone = bullet.Instanciate <Bullet>(); clone.transform.position = transform.position; clone.transform.rotation = transform.rotation; // current look direction default Vector3 lookDir = transform.TransformDirection(Vector3.forward); // Camera direction default if (eyesTransform) { Debug.Assert(null != eyesTransform, "look object is null"); lookDir = eyesTransform.forward; } if (clone.OnFire(owner, lookDir, force)) { // only player if (effectSoundFire && owner.ally != AliasType.NonPlayer) { effectSoundFire.Play(); } } return(true); }
void OnTriggerEnter(Collider col) { ObjectProperty hitUnit = col.gameObject.GetComponent <ObjectProperty>(); Debug.Assert(null != this.owner, "Bullet's Owner is null"); isHit = true; //all projectile colliding game objects should be tagged "Enemy" or whatever in inspector but that tag must be reflected in the below if conditional if (null != hitUnit && hitUnit.ally != this.owner.ally) { //Debug.Log("hit-:" + col.gameObject.name); // Destroy(col.gameObject); // //add an explosion or something // //destroy the projectile that just caused the trigger collision // Destroy(gameObject); Unit obj = hitUnit.gameObject.GetComponent <Unit>(); if (obj && obj.IsAlive) { obj.OnDamage(owner); } this.ReturnToPool(); } else { Facade_Coroutine.DelaySeconds(this, () => { this.ReturnToPool(); }, 3); } }
override public void OnDamage(ObjectProperty skill) { if (!IsAlive) { return; } Debug.Assert(null != skill, "skill is null"); // motion adjust if (!agent.isStopped) { agent.velocity = (agent.velocity.magnitude / 2f) * agent.velocity.normalized; } // demage calculate float impactDamage = DamageCalculate(skill); property.health -= impactDamage; // call die if (property.health <= 0) { OnDie(skill); } else { SetAnimationTrigger("damaged"); } }
public void Reset(AI_Rifle_Enemy Ai) { this.Ai = Ai; this.property = Ai.property; this.target = null; this.destination = Vector3.zero; }
override public void OnDie(ObjectProperty skill) { agent.ResetPath(); _aiEntity.Event = null; agent.isStopped = true; base.OnDie(skill); }
// Fire public bool OnFire(ObjectProperty owner, Vector3 dir, float force) { this.owner = owner; this.force = force; this.direction = dir; isHit = false; return(true); }
void Start() { instance = this; player = GetComponent <AI_Player>(); property = GetComponent <ObjectProperty>(); animator = GetComponent <Animator>(); controller = GetComponent <CharacterController>(); property.Reset(); }
// spawn randowm object in type public PooledObject Spawn(eSpawn type, Vector3 initPos = default(Vector3)) { PooledObject[] objPrefab = null; Transform[] posPrefab = null; switch (type) { case eSpawn.Player: objPrefab = objPrefabPlayer; posPrefab = spots; break; case eSpawn.NonPlayer: objPrefab = objPrefabNPC; posPrefab = spots; break; } int index = Random.Range(0, posPrefab.Length); if (objPrefab != null && posPrefab != null) { const int tryCnt = 5; if (initPos == default(Vector3)) { for (int i = 0; i < tryCnt; ++i) { if (Facade_NavMesh.RandomRangePoint(posPrefab[index].position, 0, 10f, out initPos)) { break; } } } // fails to found the position if (initPos == default(Vector3)) { return(null); } var objSpawn = SpawnObject(objPrefab[Random.Range(0, objPrefab.Length)], initPos); // save for searching in AI ObjectProperty property = objSpawn as ObjectProperty; if (null != property) { All.Add(property); } return(objSpawn); } return(null); }
// raycast test public static RaycastResult IsRaycastHit(ObjectProperty origin, ObjectProperty target, float range, int mask = int.MaxValue) { RaycastHit hit; if (Physics.Raycast(origin.Position, origin.DistanceFrom(target).normalized, out hit, range, mask)) { if (hit.collider.transform == target.transform) { return(RaycastResult.FoundTarget); } return(RaycastResult.BlockedTarget); } return(RaycastResult.Nothing); }
override public void OnAttack(ObjectProperty target) { Debug.Assert(null != target, "target is null"); if (target.isAlive) { SetAnimationTrigger("fire"); // weapon Debug.Assert(null != weapon, "weapon is null!!"); if (weapon.Shoot(bullet, property, weapon.transform)) { //Debug.Log("Shoot!!"); } } }
void OnTriggerEnter(Collider col) { Debug.Log("hit+:" + gameObject.name); ObjectProperty uInfo = col.GetComponent <ObjectProperty>(); if (uInfo) { switch (uInfo.type) { case ObjectType.Bullet: OnDamage(uInfo); break; } } }
public void Enter(Entity e) { AIEntity entity = (AIEntity)e; // avoid from target or own position ObjectProperty scarer = (entity.target) ? entity.target : entity.property; var found = SpawnManager.instance.FindFurthestSpot(scarer); if (found) { entity.Ai.agent.destination = found.transform.position; } // move fast entity.Ai.agent.speed = entity.property.tb.sprintSpeed; entity.target = null; }
// find spot in spawn spots public Transform FindFurthestSpot(ObjectProperty obj) { Vector3 longest = Vector3.zero; Transform pick = null; foreach (var t in spots) { Vector3 v = obj.transform.DistanceFrom(t); if (v.magnitude > longest.magnitude) { longest = v; pick = t; } } return(pick); }
override public void OnDie(ObjectProperty skill) { Debug.Assert(IsAlive, "die again,this unit is already death"); Debug.Log("Die from " + ((null != skill) ? skill.transform.gameObject.name : "")); property.health = 0; property.isAlive = false; SetAnimationTrigger("dying"); // add score if (skill && skill.owner && skill.owner.property.ally != this.property.ally) { GameData.instance.Score += 100; HUD.instance.Event(eNotifyHUD.Kill, 100); } SpawnManager.instance.Remove(this.property); }
// detecting target static public bool DetectTarget(ObjectProperty property, float range, out ObjectProperty target) { Debug.Assert(property != null, "owener property is null"); target = null; Quaternion startingAngle = Quaternion.AngleAxis(-60, Vector3.up); Quaternion stepAngle = Quaternion.AngleAxis(property.tb.stepAngle, Vector3.up); RaycastHit hit; var angle = property.transform.rotation * startingAngle; var pos = property.transform.position; var direction = angle * Vector3.forward; // adjust height for eyes level pos.y += property.tb.eyeLevel; for (var i = 0; i < 24; i++) { if (Physics.Raycast(pos, direction, out hit, range)) { if (debug_on) { Debug.DrawRay(pos, direction * hit.distance, Color.green); } var unit_info = hit.collider.GetComponent <ObjectProperty>(); if (unit_info && unit_info.ally != property.ally) { //Enemy was seen //Debug.Log("- Found out taret:" + unit_info.gameObject.name); target = unit_info; } } else if (debug_on) { Debug.DrawRay(pos, direction * property.tb.sightRange, Color.green); } direction = stepAngle * direction; } return(target != null); }
override public void OnDamage(ObjectProperty skill) { if (!IsAlive) { return; } _aiEntity.triggerDamage = skill; switch ((eEntityState)_aiEntity.Event) { case eEntityState.Runaway: break; case eEntityState.Wander: default: agent.ResetPath(); break; } // for dying procesing base.OnDamage(skill); }
abstract public void OnAttack(ObjectProperty obj);
abstract public void OnDie(ObjectProperty skill);
float DamageCalculate(ObjectProperty attacker) { return(attacker.tb.attack_power); }
void OnEnable() { isHit = false; owner = null; }
public void Remove(ObjectProperty obj) { All.Remove(obj); }
// Calculate distance between this and another public Vector3 DistanceFrom(ObjectProperty obj) { Debug.Assert(null != obj, "object property is null at distanceFrom"); return(obj.Position - Position); }
// Use this for initialization protected void Awake() { property = GetComponent <ObjectProperty>(); }