Exemple #1
0
 private void Clear()
 {
     this.Post(new EntityDisposed(this));
     UnityToEntityBridge.Unregister(this);
     EntityController.FinishDeleteEntity(this);
     _components.Clear();
     Id   = -1;
     Name = "Destroyed";
     ClearParent();
     if (_tags != null)
     {
         _tagPool.Store(_tags);
         _tags = null;
     }
 }
Exemple #2
0
        private void HandleLoader(EquipmentChanged arg, ModelLoaderComponent loader)
        {
            if (!loader.OnlyActiveWhileEquipped)
            {
                return;
            }
            var entity = arg.Owner;

            if (arg.Owner == null && loader.LoadedComponents.Count > 0)
            {
                UnityToEntityBridge.Unregister(entity);
                for (int i = 0; i < loader.LoadedComponents.Count; i++)
                {
                    entity.Remove(loader.LoadedComponents[i]);
                }
                loader.LoadedComponents.Clear();
                loader.LoadedModel = null;
            }
            else if (arg.Owner != null && loader.LoadedModel == null)
            {
                var parent = arg.Slot.EquipTr;
                var model  = ItemPool.Spawn(loader.ModelName);
                if (parent != null)
                {
                    model.transform.SetParentResetPos(parent);
                }
                loader.LoadedModel = new CachedGenericComponent <IRenderingComponent>(model.GetComponent <IRenderingComponent>());
                if (loader.LoadedModel == null)
                {
                    ItemPool.Despawn(model.gameObject);
                    return;
                }

                UnityToEntityBridge.RegisterToEntity(model.gameObject, entity);
                loader.LoadedComponents.Add(entity.Add(new RenderingComponent(loader.LoadedModel.Value)).GetType());
                loader.LoadedComponents.Add(entity.Add(new TransformComponent(model.Transform)).GetType());
                loader.LoadedComponents.Add(
                    entity.Add(new FloatingTextStatusComponent(model.Transform, new Vector3(0, 1.5f, 0))).GetType());
                var rb = model.GetComponent <Rigidbody>();
                if (rb != null)
                {
                    loader.LoadedComponents.Add(entity.Add(new RigidbodyComponent(rb)).GetType());
                }
            }
        }
 public bool TryStore(Entity entity)
 {
     if (_poolDict.TryGetValue(entity.Get <TypeId>().Id, out var stack))
     {
         if (!stack.IsFull)
         {
             UnityToEntityBridge.Unregister(entity);
             entity.Get <RenderingComponent>().Clear();
             entity.Remove(typeof(SpriteAnimationComponent));
             entity.Tags.Clear();
             entity.Post(new ProjectileDespawned(entity));
             entity.Pooled = true;
             entity.ClearParent();
             stack.Add(entity);
             return(true);
         }
     }
     //entity.Destroy();
     return(false);
 }