public override void Execute(TemplateControllerCustom _controller, float _delta = 0) { if (!(_controller is TemplateUnits)) { return; } TemplateUnits units = _controller as TemplateUnits; if (units.targetEnemys.Count > 0) { return; } Collider[] colliders = Physics.OverlapSphere(units.transform.position, this.radius, this.mask); for (int count = 0; count < colliders.Length; count++) { if (!colliders[count].gameObject.activeSelf) { continue; } units.AddTarget(this.type, colliders[count].gameObject); } }
public void AddUnit(TemplateUnits _unit, Color _color, Vector3 _offset) { GameObject uiUnit = Instantiate(this.uiMapPrefab, this.uiMapHolder); GameObject healthBar = Instantiate(this.healthBarPrefab); healthBar.transform.SetParent(transform, false); Image image = uiUnit.GetComponent <Image>(); image.color = _color; MiniMapData data = new MiniMapData { unit = _unit.transform, uiRect = uiUnit.GetComponent <RectTransform>() }; this.minimapData.Add(data); HealthBarLocal healthBarController = healthBar.GetComponent <HealthBarLocal>(); healthBarController.SetTarget(_unit, _offset); healthBar.SetActive(false); this.elements.Add(healthBarController); }
public override void Execute(TemplateControllerCustom _controller, float _delta = 0) { TemplateUnits unit = _controller as TemplateUnits; if (Vector3.Distance(unit.transform.position, unit.agent.destination) > unit.attackDistance || (unit.targetEnemy == null && unit.targetBuild == null)) { return; } if (unit.currAttackCoolDown <= 0) { if (unit.targetEnemy != null) { unit.targetEnemy.ApplyDamage(unit, unit.attackDamage); unit.anim.Play("Attack"); unit.currAttackCoolDown = unit.attackCoolDown; } else if (unit.targetBuild != null) { CityMaster.instance.AttackBuild(unit.attackDamage, unit.targetBuild, unit); unit.currAttackCoolDown = unit.attackCoolDown; } } unit.currAttackCoolDown -= _delta; }
public override void Execute(TemplateControllerCustom _controller, float _delta = 0) { TemplateUnits unit = _controller as TemplateUnits; Vector3 targetPosition = this.vectorZero; if (unit.targetEnemy != null) { targetPosition = unit.targetEnemy.transform.position; } else if (unit.targetBuildData != null && unit.targetBuildData.obj != null) { targetPosition = unit.targetBuildData.obj.transform.position; } else { targetPosition = unit.agent.destination; } Vector3 direction = (targetPosition - unit.transform.position).normalized; direction.y = 0; Quaternion lookRotation = Quaternion.LookRotation(direction); unit.transform.rotation = Quaternion.Slerp(unit.transform.rotation, lookRotation, Time.deltaTime * this.rotationSpeed); }
public override void Execute(TemplateControllerCustom _controller, float _delta = 0) { if (!_controller.gameObject.activeSelf) { return; } TemplateUnits unit = _controller as TemplateUnits; if (unit.targetPosition == vectorZero) { if (checkIsAlive) { if (!CityMaster.instance.IsBuildAlive(this.buildTag)) { return; } } if (CityMaster.instance.HasFreeSlot(this.buildTag)) { ConstructionData data = CityMaster.instance.FindBuild(this.buildTag); unit.targetPosition = data.obj.transform.position; unit.targetPosition.y = _controller.transform.position.y; unit.targetBuild = this.buildTag; unit.targetBuildData = data; unit.agent.SetDestination(unit.targetPosition); } } }
public void AttackBuild(int _damage, string _ID, TemplateUnits _attacker) { ConstructionData data = this.FindBuild(_ID); data.currHealth -= _damage; if (data.currHealth <= 0) { this.DestroyBuild(data); data.currHealth = 0; } data.healthBar.SetHealthBar((float)data.currHealth / (float)data.totalHealth); this.AttackedObj(_ID, _attacker); float healthRangeSize = data.totalHealth / this.colorHealth.Count; int currHealthRange = Mathf.Clamp(Mathf.FloorToInt(data.currHealth / healthRangeSize), 0, this.colorHealth.Count - 1); if (currHealthRange >= this.colorHealth.Count) { currHealthRange = this.colorHealth.Count - 1; } data.currColor = this.colorHealth[currHealthRange]; }
public override void Execute(TemplateControllerCustom _controller, float _delta = 0) { Guards unit = _controller as Guards; if (!CityMaster.instance.HasAttackers()) { if (unit.targetEnemys.Count > 0) { return; } Collider[] colliders = Physics.OverlapSphere(unit.transform.position, this.radius, this.mask); for (int count = 0; count < colliders.Length; count++) { unit.AddTarget(TargetType.Close, colliders[count].gameObject); } return; } if (unit.targetEnemys.Count > 0 && unit.targetEnemys[0].type != TargetType.Attacker) { unit.targetEnemys.Clear(); } TemplateUnits enemy = CityMaster.instance.GetAttacker(); if (enemy != null && !unit.HasTarget(TargetType.Attacker, enemy.gameObject)) { unit.AddTarget(TargetType.Attacker, enemy.gameObject); } }
public void CreateUnit(int _index, bool _checkSize = true) { if (_checkSize && !this.prefabs[_index].HasUnits()) { return; } Vector3 spawn = this.prefabs[_index].RandomSpawn(); GameObject obj = Instantiate(this.prefabs[_index].prefab, spawn, Quaternion.identity); TemplateUnits unit = obj.GetComponent <TemplateUnits>(); unit.Init(); this.units.Add(unit); this.UpdateToolTip(_index); if (_checkSize) { this.prefabs[_index].currUnits.value--; } this.prefabs[_index].uiEvent.Raise(); }
public override void Execute(TemplateControllerCustom _controller, float _delta = 0) { TemplateUnits unit = _controller as TemplateUnits; unit.targetPosition = this.vectorZero; unit.targetBuild = null; unit.targetBuildData = null; }
public override void Execute(TemplateControllerCustom _controller, float _delta = 0) { TemplateUnits unit = _controller as TemplateUnits; if (CityMaster.instance.HideInBuild(unit.targetBuild, unit)) { unit.isHidden = true; unit.gameObject.SetActive(false); } }
public override bool CheckCondition(TemplateControllerCustom _object) { TemplateUnits units = _object as TemplateUnits; if (!units.isAlive) { return(true); } return(false); }
public virtual void ApplyDamage(TemplateUnits _attacker, float _damage) { this.lastAttacker = _attacker; this.currHealth -= _damage; if (!this.isAlive) { this.Die(); } }
public override void Execute(TemplateControllerCustom _controller, float _delta = 0) { TemplateUnits unit = _controller as TemplateUnits; if (unit.targetPosition == vectorZero) { unit.targetPosition = Random.insideUnitSphere * this.data.Radius; unit.targetPosition.y = _controller.transform.position.y; unit.agent.SetDestination(unit.targetPosition); } }
public override bool CheckCondition(TemplateControllerCustom _object) { TemplateUnits guard = _object as TemplateUnits; if (guard.targetEnemys.Count <= 0) { return(true); } return(false); }
public override bool CheckCondition(TemplateControllerCustom _object) { TemplateUnits units = _object as TemplateUnits; if (Vector3.Distance(units.agent.destination, units.transform.position) < units.agent.stoppingDistance && units.targetPosition != vectorZero) { return(true); } return(false); }
public bool HideInBuild(string _ID, TemplateUnits _unit) { ConstructionData data = this.FindBuild(_ID); if (data.currUnits < data.totalUnits) { data.unitsInside.Add(_unit); return(true); } return(false); }
public bool RemoveFromBuild(string _ID, TemplateUnits _unit) { ConstructionData data = this.FindBuild(_ID); if (data.unitsInside.Contains(_unit)) { data.unitsInside.Remove(_unit); return(true); } return(false); }
public override void Execute(TemplateControllerCustom _controller, float _delta = 0) { TemplateUnits unit = _controller as TemplateUnits; if (unit.targetEnemy != null) { if (unit.targetEnemy.isHidden) { unit.targetEnemy = null; unit.targetEnemys.RemoveAt(0); } } }
public override bool CheckCondition(TemplateControllerCustom _object) { if (!Physics.CheckSphere(_object.transform.position, this.radius, this.layerEnemys)) { TemplateUnits unit = _object as TemplateUnits; if (this.CheckHidden && unit.isHidden) { return(false); } return(true); } return(false); }
public override bool CheckCondition(TemplateControllerCustom _object) { TemplateUnits unit = _object as TemplateUnits; if (!Physics.CheckSphere(_object.transform.position, this.radius, this.layerEnemys)) { if (Time.timeSinceLevelLoad - unit.TimeSinceLastEnemy < this.maxTimeWithoutEnemys) { return(false); } return(true); } unit.TimeSinceLastEnemy = Time.timeSinceLevelLoad; return(false); }
public override void Execute(TemplateControllerCustom _controller, float _delta = 0) { TemplateUnits unit = _controller as TemplateUnits; if (unit.lastAttacker != null) { if (!unit.lastAttacker.isAlive) { unit.lastAttacker = null; return; } unit.targetEnemys.Clear(); unit.targetEnemy = unit.lastAttacker; unit.AddTarget(TargetType.Attacker, unit.lastAttacker.gameObject); unit.agent.SetDestination(unit.lastAttacker.transform.position); } }
public void AttackedObj(string _ID, TemplateUnits _unit) { int index = -1; int IDHash = _ID.GetHashCode(); if (!this.attackedDic.ContainsKey(IDHash)) { this.attackedList.Add(new List <TemplateUnits>()); index = this.attackedList.Count - 1; this.attackedDic[IDHash] = index; } else { index = this.attackedDic[IDHash]; } if (this.attackedList.Count > index) { this.attackedList[index].Add(_unit); } }
public override bool CheckCondition(TemplateControllerCustom _object) { TemplateUnits units = _object as TemplateUnits; if (units.targetBuild == null) { return(false); } float distance = Vector3.Distance(units.targetPosition, units.transform.position); if (distance < this.minDistance) { if (this.checkUnitsSlot && !CityMaster.instance.HasFreeSlot(units.targetBuild)) { return(false); } return(true); } return(false); }
public override void Execute(TemplateControllerCustom _controller, float _delta = 0) { if (!_controller.gameObject.activeSelf) { return; } TemplateUnits unit = _controller as TemplateUnits; if (unit.targetPosition == vectorZero) { ConstructionData data = CityMaster.instance.GetClosestBuild(_controller.transform.position); if (data != null) { unit.targetPosition = data.obj.transform.position; unit.targetPosition.y = _controller.transform.position.y; unit.targetBuild = data.ID; unit.targetBuildData = data; unit.agent.SetDestination(unit.targetPosition); } } }
public override void Execute(TemplateControllerCustom _controller, float _delta = 0) { if (!_controller.gameObject.activeSelf) { return; } TemplateUnits unit = _controller as TemplateUnits; if (unit.targetPosition == vectorZero) { if (unit.targetBuild == null) { Vector3 newPosition = unit.transform.forward * Random.Range(this.distance, this.distance); newPosition += unit.transform.right * Random.Range(-this.distance, this.distance); unit.targetPosition = newPosition; unit.targetPosition.y = _controller.transform.position.y; unit.targetBuild = null; unit.agent.SetDestination(unit.targetPosition); } } }
public override void Execute(TemplateControllerCustom _controller, float _delta = 0) { TemplateUnits unit = _controller as TemplateUnits; unit.agent.stoppingDistance = this.stopDistance; }
public override void Execute(TemplateControllerCustom _controller, float _delta = 0) { TemplateUnits unit = _controller as TemplateUnits; UIManager.instance.AddUnit(unit, this.color, unit.offsetUI); }
public override void Execute(TemplateControllerCustom _controller, float _delta = 0) { if (!(_controller is TemplateUnits)) { return; } TemplateUnits unit = _controller as TemplateUnits; if (unit.targetEnemys.Count <= 0) { return; } if (unit.targetEnemys[0].obj == null) { unit.targetEnemys.RemoveAt(0); return; } if (unit.targetEnemys[0].type != TargetType.Construction) { if (unit.targetEnemy == null) { unit.targetEnemy = unit.targetEnemys[0].obj.GetComponent <TemplateUnits>(); unit.agent.SetDestination(unit.targetEnemy.transform.position); return; } if (Vector3.Distance(unit.agent.destination, unit.targetEnemy.transform.position) > Threshold) { unit.agent.SetDestination(unit.targetEnemy.transform.position); } if (!unit.targetEnemy.isAlive) { unit.targetEnemy = null; unit.targetEnemys.RemoveAt(0); } } else { if (unit.targetBuild == null) { ConstructionData data = CityMaster.instance.FindBuildByGameObject(unit.targetEnemys[0].obj); unit.targetBuild = data.ID; unit.targetBuildData = data; unit.agent.SetDestination(unit.targetBuildData.obj.transform.position); } if (!CityMaster.instance.IsBuildAlive(unit.targetBuild)) { unit.targetBuild = null; unit.targetBuildData = null; unit.targetEnemys.RemoveAt(0); } } }
public void SetTarget(TemplateUnits _target, Vector3 _offset) { this.target = _target; this.offset = _offset; }
public override void Execute(TemplateControllerCustom _controller, float _delta = 0) { TemplateUnits unit = _controller as TemplateUnits; unit.anim.SetFloat(this.VariableName, unit.agent.velocity.magnitude); }