public bool CanSeeOrHear(Entity source, Entity target, out bool canHear) { var sourcePos = source.GetPosition(); var dir = target.GetPosition() - sourcePos; var ray = new Ray(sourcePos, dir.normalized); var rayLimit = Physics.RaycastNonAlloc(ray, _rayHits, dir.magnitude, UnitCheckMask); _rayHits.SortByDistanceAsc(rayLimit); canHear = true; for (int i = 0; i < rayLimit; i++) { if (_rayHits[i].transform.CompareTag(StringConst.TagEnvironment)) { canHear = false; continue; } var entity = MonoBehaviourToEntity.GetEntity(_rayHits[i].collider); if (entity == null) { continue; } if (entity == source) { continue; } if (entity == target) { return true; } } return true; }
public Entity GetTarget(Entity source, Vector3 dir, float range, TargetType targeting) { //if (GameOptions.ArenaCombat) { // return FindArenaActorInRange(source, range, targeting); //} var sourcePos = source.GetPosition(); var ray = new Ray(sourcePos, dir); var rayLimit = Physics.RaycastNonAlloc(ray, _rayHits, range, UnitCheckMask); _rayHits.SortByDistanceAsc(rayLimit); for (int i = 0; i < rayLimit; i++) { if (_rayHits[i].transform.CompareTag(StringConst.TagEnvironment)) { return null; } var entity = MonoBehaviourToEntity.GetEntity(_rayHits[i].collider); if (entity == null) { continue; } if (entity == source) { continue; } var target = EntityController.GetEntity(entity); if (targeting == TargetType.Enemy && !World.Get<FactionSystem>().AreEnemies(source, target)) { continue; } if (targeting == TargetType.Friendly && !World.Get<FactionSystem>().AreFriends(source, target)) { continue; } return target; } return null; }
private void SpawnModel(Transform parent) { var model = ItemPool.Spawn(_modelName); if (parent != null) { model.transform.SetParentResetPos(parent); } _loadedModel = model.GetComponent <IModelComponent>(); if (_loadedModel == null) { ItemPool.Despawn(model.gameObject); return; } var entity = this.GetEntity(); MonoBehaviourToEntity.RegisterToEntity(model.gameObject, entity); _loadedComponents.Add(entity.Add(new ModelComponent(_loadedModel))); entity.Tr = model.Transform; _loadedComponents.Add(entity.Add(new FloatingTextStatusComponent(model.Transform, new Vector3(0, 1.5f, 0)))); var animTr = model.GetComponent <IAnimTr>(); if (animTr != null) { _loadedComponents.Add(entity.Add(new AnimTr(animTr.AnimTr))); } var rb = model.GetComponent <Rigidbody>(); if (rb != null) { _loadedComponents.Add(entity.Add(new RigidbodyComponent(rb))); } }
private void CheckRayList(Entity entity, int limit) { for (int i = 0; i < limit; i++) { var hitEntity = EntityController.GetEntity(MonoBehaviourToEntity.GetEntityId(_rayHits[i].collider)); if (hitEntity == null || hitEntity == entity) { continue; } entity.Post(new CollisionEvent(entity, hitEntity, _rayHits[i].point, _rayHits[i].normal)); } }
private void Clear() { Post(new EntityDisposed(this)); MonoBehaviourToEntity.Unregister(this); EntityController.FinishDeleteEntity(this); Id = -1; Name = "Destroyed"; ClearParent(); Tr = null; _eventHub.Clear(); Tags.Clear(); Stats.Clear(); }
public void Store(Entity entity) { MonoBehaviourToEntity.Unregister(entity); entity.Remove <RigidbodyComponent>(); entity.Get <ModelComponent>().Model = null; if (_poolDict.TryGetValue(entity.Get <TypeId>().Id, out var stack)) { if (!stack.IsFull) { entity.Pooled = true; entity.ClearParent(); entity.Stats.ClearMods(); stack.Add(entity); return; } } entity.Destroy(); }
//private Entity FindArenaActorInRange(Entity source, float range, TargetType targeting) { // List<Entity> actorList = new List<Entity>(); // switch (targeting) { // case TargetType.Self: // return source; // case TargetType.Friendly: // World.Get<FactionSystem>().FillFactionFriendsList(actorList, source.Get<FactionComponent>().Faction); // break; // default: // World.Get<FactionSystem>().FillFactionEnemiesList(actorList, source.Get<FactionComponent>().Faction); // break; // } // actorList.Shuffle(); // var ranksCanBust = (int) range; // for (int i = 0; i < actorList.Count; i++) { // if (actorList[i].PositionRank <= ranksCanBust) { // return actorList[i]; // } // } // return null; //} private bool CanSeeTarget(int rayLimit, Entity source, Entity target) { _rayHits.SortByDistanceAsc(rayLimit); for (int i = 0; i < rayLimit; i++) { if (_rayHits[i].transform.CompareTag(StringConst.TagEnvironment)) { return false; } var colliderEntity = MonoBehaviourToEntity.GetEntity(_rayHits[i].collider); if (colliderEntity == null || colliderEntity == source) { continue; } if (colliderEntity == target) { return true; } if (World.Get<FactionSystem>().AreEnemies(colliderEntity, source)) { return false; } } return true; }
void OnTriggerEnter(Collider other) { if (!enabled) { return; } var hitEntity = EntityController.GetEntity(MonoBehaviourToEntity.GetEntityId(other)); var entity = EntityController.GetEntity(EntityID); if (hitEntity == null || hitEntity == entity) { return; } if (!entity.Tags.Contain(EntityTags.CanUnityCollide) || !hitEntity.Tags.Contain(EntityTags.CanUnityCollide)) { return; } var hitPnt = other.ClosestPointOnBounds(transform.position); entity.Post(new CollisionEvent(entity, hitEntity, hitPnt, (hitPnt - transform.position).normalized)); }
void OnCollisionEnter(Collision collision) { if (!enabled) { return; } var hitEntity = EntityController.GetEntity(MonoBehaviourToEntity.GetEntityId(collision.collider)); var entity = EntityController.GetEntity(EntityID); if (hitEntity == null || hitEntity == entity) { return; } if (!entity.Tags.Contain(EntityTags.CanUnityCollide) || !hitEntity.Tags.Contain(EntityTags.CanUnityCollide)) { return; } var collisionPnt = collision.contacts[0]; entity.Post(new CollisionEvent(entity, hitEntity, collisionPnt.point, collisionPnt.normal)); }
public void Handle(EquipmentChanged arg) { if (!_onlyActiveWhileEquipped) { return; } if (arg.Owner == null && _loadedComponents.Count > 0) { var entity = this.GetEntity(); MonoBehaviourToEntity.Unregister(entity); for (int i = 0; i < _loadedComponents.Count; i++) { entity.Remove(_loadedComponents[i]); } _loadedComponents.Clear(); _loadedModel = null; } else if (arg.Owner != null && _loadedModel == null) { SpawnModel(arg.Slot.EquipTr); } }
public Entity SpawnProjectile(Entity owner) { var spawnComponent = owner.Get <ActionSpawnComponent>(); var entity = GetProjectile(spawnComponent.Data); entity.Get <DespawnTimer>().StartTimer(); if (string.IsNullOrEmpty(spawnComponent.Prefab)) { return(entity); } owner.FindSpawn(out var spawnPos, out var spawnRot); var spawn = ItemPool.Spawn(UnityDirs.Projectiles, spawnComponent.Prefab, spawnPos, spawnRot); if (spawn == null) { return(entity); } entity.Tr = spawn.Transform; entity.Add(new RigidbodyComponent(spawn.GetComponent <Rigidbody>())); entity.Get <ModelComponent>().Model = spawn.GetComponent <IModelComponent>(); MonoBehaviourToEntity.RegisterToEntity(spawn.gameObject, entity); entity.ParentId = owner.Id; return(entity); }
void Update() { if (!Game.GameActive) { return; } //if (_debug) { // DebugText.UpdatePermText("World Control", "Game Not Active"); //} //if (GenericDraggableController.Dragging) { // if (_debug) { // DebugText.UpdatePermText("World Control", "Dragging"); // } // return; //} _foundControl = false; //_eventData.position = Input.mousePosition; //EventSystem.current.RaycastAll(_eventData, _result); if (PlayerInput.IsCursorOverUI) { SetCurrentNull(); //if (_debug) { // var go = PlayerInput.CurrentInput != null ? PlayerInput.CurrentInput.GameObjectUnderPointer() : null; // DebugText.UpdatePermText("World Control", string.Format("Over UI: {0}", go != null ? go.name : // EventSystem.current.currentSelectedGameObject != null ? EventSystem.current.currentSelectedGameObject.name : " null ?")); //} return; } _mouseRay = Cam.ScreenPointToRay(Input.mousePosition); Entity currentActor = null; var cnt = Physics.RaycastNonAlloc(_mouseRay, _hits, _currentEnemyRayDistance, _worldControlsMask); _hits.SortByDistanceAsc(cnt); for (int i = 0; i < cnt; i++) { var hit = _hits[i]; if (!_foundControl) { if (hit.transform.gameObject == _currentGameObject) { _foundControl = true; continue; } if (hit.distance <= _currentRayDistance) { hit.transform.GetComponentsInChildren(_tempControls); for (int j = 0; j < _tempControls.Count; j++) { if (_tempControls[j] == null) { continue; } if (_tempControls[j].WorldControlActive) { SetNewCurrent(_tempControls[j], hit.transform.gameObject); _foundControl = true; break; } } } } if (currentActor == null) { currentActor = MonoBehaviourToEntity.GetEntity(hit.collider); } if (LayerMasks.Environment.ContainsLayer(hit.transform.gameObject.layer)) { if (_debug) { DebugText.UpdatePermText("World Control", "Environment " + cnt); } break; } } if (currentActor != null) { if (_debug) { DebugText.UpdatePermText("World Control", currentActor.Id.ToString()); } } //RaycastHit hit; //if (Physics.Raycast(_mouseRay, out hit, _enemyDistance, _worldControlsMask)) { // if (hit.transform.gameObject == _currentGameObject) { // _foundControl = true; // } // else { // if (hit.distance <= _rayDistance) { // var newCurrent = hit.transform.GetComponent<IWorldControl>(); // if (newCurrent != null) { // SetNewCurrent(newCurrent, hit.transform.gameObject); // _foundControl = true; // } // } // else { // if (currentActor == null) { // Actor.Actors.TryGetValue(hit.collider, out currentActor); // } // } // } //} UICenterTarget.SetTargetActor(currentActor.GetNode <VisibleNode>()); if (!_foundControl || currentActor != null) { SetCurrentNull(); } if (_debug) { DebugText.UpdatePermText("World Control", string.Format("Current: {0}", _currentGameObject != null ? _currentGameObject.name : "None")); } //if (_current == null && AlternativeUse == null) { // var wasActive = GenericDraggableController.HasTarget; // if (GenericDraggableController.main.CanDrag()) { // UICenterTarget.SetText("Drag"); // } // else if (wasActive){ // UICenterTarget.Clear(); // } //} //else { // GenericDraggableController.ClearTarget(); //} }