//перерегестрирует обьект в новом секторе public void ChackRect(IPhysicItem item) { var top = WorldPosToOffsetTile(item.GetTopLeftPos()); var bottom = WorldPosToOffsetTile(item.GetBottomRightPos()); var topSector = GetSector(top); var bottomSector = GetSector(bottom); Vector2Int[] sectros = GetSectors(topSector, bottomSector); //1е проверяем сменились ли сектора если да то удаляемся и регистрируемся if (item.PhysicsSectors != null && !CompareSectors(item.PhysicsSectors, sectros)) { //if (item.View.name != "Player(Clone)") // Debug.LogError(item.View.name); RemovePhysicItem(item); item.PhysicsSectors = sectros; AddPhysicItem(item); } else { if (item.PhysicsSectors == null) { // if (item.View.name != "Player(Clone)") // Debug.LogError(item.View.name); item.PhysicsSectors = sectros; AddPhysicItem(item); } } }
public void SetPos(Vector2Int pos) { spawnPos = pos; viewReciver = GetComponent <UnitViewReciver>(); pysicItem = viewReciver.pysicItem; transform.position = new Vector3(pos.x * TileDataProvider.TileSize, pos.y * TileDataProvider.TileSize + 3, transform.position.z); pysicItem.SetPosition(transform.position); }
void Start() { viewReciver = GetComponent <UnitViewReciver>(); pysicItem = viewReciver.pysicItem; lightPoint = new LightPoint(); lightPoint.SetSize(32); }
public void Init(IPhysicItem pysicItem, IView view) { this.pysicItem = pysicItem; var t = Random.Range(0, 100); if (t < 50) { direcr *= -1; } }
private void OnCollision(IPhysicItem item) { var ai = item.View.GetComponent <AiController>(); if (ai != null) { ai.behaviour.pysicItem.AddVelocity(pysicItem.velocity.normalized * 4); ai.Damage(10); IgoPoolManager.Spawn <BloodEffect>(ai.transform.position, Quaternion.identity); Destroy(gameObject); } }
//удаляет обьект из системы public void RemovePhysicItem(IPhysicItem item) { if (item.PhysicsSectors != null) { for (int i = 0; i < item.PhysicsSectors.Length; i++) { int x = item.PhysicsSectors[i].x; int y = item.PhysicsSectors[i].y; physicSectors[x][y].Remove(item); } } item.PhysicsSectors = null; }
public void Init(Vector2Int pos) { spawnPos = pos; viewReciver = GetComponent <UnitViewReciver>(); pysicItem = viewReciver.pysicItem; transform.position = new Vector3(pos.x * TileDataProvider.TileSize, pos.y * TileDataProvider.TileSize + 3, transform.position.z); pysicItem.SetPosition(transform.position); pysicItem.OnCollision += OnCollision; maxHp = 100; currHp = 100; // TargetManager.Player = this; }
//проверка на колизии обьекта вызовит OnCollision у обьектов которые пересеклись public void ChackCollision(IPhysicItem item) { //var aX1 = item.GetTopLeftPos().x var sectors = item.PhysicsSectors; for (int i = 0; i < sectors.Length; i++) { var sector = sectors[i]; var objects = physicSectors[sector.x][sector.y]; for (int j = 0; j < objects.Count; j++) { var otherItem = objects[j]; if (otherItem != item && CollisionPhysicItems(item, otherItem)) { item.OnCollision.TryCall(otherItem); otherItem.OnCollision.TryCall(item); } } } }
void OnCollision(IPhysicItem item) { var bagItem = item.View.GetComponent <IPoolBagItem>(); if (bagItem != null) { model.GetBag().AddBagItem(bagItem.GetBagItem()); IgoPoolManager.Unspawn(item.View.gameObject); return; } var ai = item.View.GetComponent <AiController>(); if (ai != null) { if (Time.time - oldAiCollisionT > 0.5f) { oldAiCollisionT = Time.time; var direcr = Mathf.Sign(transform.position.x - ai.transform.position.x); var vect = transform.position - ai.transform.position; pysicItem.AddVelocity(-pysicItem.velocity); pysicItem.AddVelocity(vect.normalized * 14);//new Vector2(direcr*7, 8)); ai.GetComponent <UnitViewReciver>().PlayAttck(); Damage(5); TweenAlpha(0.2f, true); CooldownManager.AddCooldown(0.5f, null, () => { TweenAlpha(0.2f, false); }); } ; // ai.behaviour.Jamp(); return; } }
//добавляет public void AddPhysicItem(IPhysicItem item) { // string print = ""; for (int i = 0; i < item.PhysicsSectors.Length; i++) { int x = item.PhysicsSectors[i].x; int y = item.PhysicsSectors[i].y; // int count = 0; if (physicSectors.ContainsKey(x) && physicSectors[x].ContainsKey(y)) { physicSectors[x][y].Add(item); } if (physicSectors.ContainsKey(x) && !physicSectors[x].ContainsKey(y)) { physicSectors[x].Add(y, new List <IPhysicItem>() { item }); } if (!physicSectors.ContainsKey(x)) { physicSectors.Add(x, new Dictionary <int, List <IPhysicItem> >()); physicSectors[x].Add(y, new List <IPhysicItem>() { item }); } // count = physicSectors[x][y].Count; //print += string.Format("x = {0}, y = {1} count = {2}; ", x, y, count); } //Debug.LogError(print); }
void Awake() { pysicItem = new PhysicItem(this); pysicItem.SetGravity(gravity); }
void Awake() { pysicItem = new PhysicItem(this); }
public void Init(IPhysicItem pysicItem, IView view) { this.pysicItem = pysicItem; UpdateDirect(); }
public void Init(IPhysicItem pysicItem, IView view) { this.pysicItem = pysicItem; this.view = (MinerView)view; }
//проверяет пересекаются ли 2 квадрата public bool CollisionPhysicItems(IPhysicItem a, IPhysicItem b) { return(a.GetRect().Overlaps(b.GetRect())); }