private void ActivateIcon(Minion minion) { if (minionIcons.TryGetValue(minion.Type, out Sprite icon)) { MapIcon mapIcon = mapIconPool.Get(); mapIcon.Icon = icon; mapIcon.Target = minion; } }
public T GetObject <T>() where T : class { IObjectPool pool = ObjectPool.GetObjectPool <T>(); if (pool != null) { return(pool.Get <T>()); } return(null); }
public IProjectile Get(Vector3 position, Quaternion rotation) { IProjectile proj = _pool.Get(); Component comp = proj as Component; comp.transform.position = position; comp.transform.rotation = rotation; return(proj); }
/// <summary> /// 获取对象 /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public T GetObject <T>() where T : IPooledObject { IObjectPool objectPool = GetObjectPool <T>(); if (objectPool == null) { objectPool = RegisterObjectPool <T>(); } return((T)objectPool.Get()); }
/// <summary> /// 获取对象 /// </summary> /// <param name="type"></param> /// <returns></returns> public IPooledObject GetObject(Type type) { IObjectPool objectPool = GetObjectPool(type); if (objectPool == null) { objectPool = RegisterObjectPool(type); } return(objectPool.Get()); }
/// <summary> /// 返回某个对象,如果不存在则返回参数value /// </summary> /// <param name="pool">对象池</param> /// <param name="key">键值</param> /// <param name="value">如果对象池不存在对应键的数据,则返回此值</param> /// <returns></returns> public static object GetOrAdd(this IObjectPool pool, object key, object value) { if (!pool.Contains(key)) { return(value); } else { return(pool.Get(key)); } }
/// <summary> /// 返回某个对象,如果不存在则调用函数委托获取值,并将值存入对象池后返回 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="pool">对象池</param> /// <param name="key">键值</param> /// <param name="func">如果对象池不存在对应键的数据,则从此函数委托获取新值并存入对象池后返回</param> /// <returns></returns> public static T GetOrAdd <T>(this IObjectPool pool, object key, Func <T> func) { if (!pool.Contains(key)) { T value = func.Invoke(); pool.Add(key, value); return(value); } else { return((T)pool.Get(key)); } }
public Object GetObject(Type t) { IObjectPool p = null; if (!poolDict.ContainsKey(t)) { p = CreateCommonPool(t); RegisterPool(t, p); } p = poolDict[t]; return(p.Get()); }
public virtual void Spawn(Vector3 from, Vector3 to, int level) { SoundPlayer.Play("rocket_shot"); var entity = _pool.Get(); var moveComponent = entity.GetComponent <Move>(); moveComponent.Init(new [] { from, to }, level, ProcessReachTarget); }
public T GetObject <T>() where T : class { var t = typeof(T); IObjectPool p = null; if (!poolDict.ContainsKey(t)) { p = CreateCommonPool <T>(); RegisterPool(t, p); } p = poolDict[t]; return(p.Get() as T); }
/// <summary> /// 从连接池中获得一个数据库连接 /// </summary> /// <returns></returns> public static IDbConnection GetConnectionFromPool(DbConnectionInfo dbConnectionInfo) { string connStr = dbConnectionInfo.ConnectionString; if (_connectionPoolDict.TryGetValue(connStr, out IObjectPool <IDbConnection> pool)) { return(pool.Get()); } else { IObjectPool <IDbConnection> newPool = _dbConnectionPoolGenerator(connStr, GetProvider(dbConnectionInfo.DatabaseType)); _connectionPoolDict.TryAdd(connStr, newPool); return(newPool.Get()); } }
public IAspect Get(IEntity entity) { var aspect = _aspectPool.Get(); aspect.Init(entity); aspect.Deleted += AspectDeleted; if (aspect.IsInChannel(_channelManager.Channel, "all")) { _channelAspects.AddLast(aspect); } _aspects.AddLast(aspect); return(aspect); }
public T Get <T>(CharacterBase target, Model.BattleStatus.Skill.SkillInfo skillInfo) where T : SkillVFX { if (target is null) { return(null); } var position = target.transform.position; var size = target.SizeType == SizeType.XS ? SizeType.S : SizeType.M; var elemental = skillInfo.ElementalType; if (skillInfo.SkillCategory == SkillCategory.AreaAttack) { size = SizeType.L; //FIXME 현재 무속성 범위공격 이펙트는 존재하지 않기때문에 임시처리. if (elemental == ElementalType.Normal) { elemental = ElementalType.Fire; } var pos = ActionCamera.instance.Cam.ScreenToWorldPoint( new Vector2((float)Screen.width / 2, 0)); position.x = pos.x + 0.5f; position.y = Stage.StageStartPosition; } var skillName = $"{skillInfo.SkillCategory}_{size}_{elemental}".ToLower(); if (skillInfo.SkillCategory == SkillCategory.BlowAttack && skillInfo.SkillTargetType == SkillTargetType.Enemies) { skillName = $"{skillInfo.SkillCategory}_m_{elemental}_area".ToLower(); } else { position.x -= 0.2f; position.y += 0.32f; } var go = _pool.Get(skillName, false, position) ?? _pool.Get(skillName, true, position); return(GetEffect <T>(go, target)); }
public IEntity Get(string name = "", string[] channels = null) { var entity = _entityPool.Get(); entity.Name = name; if (channels == null || channels.Length == 0) { entity.Channels.Add(_channelManager.Channel); } else { foreach (var c in channels) { entity.Channels.Add(c); } } entity.Deleted += CleanupDeleted; Entities[entity.ID] = entity; return(entity); }
public GameObject RequestInstance() { return(pool.Get()); }
public GameObject GetPooledObject() { return(objectPool.Get()); }
/// <summary> /// 返回某个对象,如果不存在则返回null /// </summary> /// <param name="key"></param> /// <returns></returns> public object Get(object key) { IObjectPool pool = this.GetObjectPool(); return(pool == null ? null : pool.Get(key)); }
public T RequestComponent() { return(pool.Get()); }
/// <summary> /// 刷新所有 /// </summary> public void Refresh(V[] datas) { if (_pool == null || _lifeNodes == null || _parser == null) { return; } if (datas != null) { _refreshTask?.Stop(); //仍存在的节点数量 int lifeCount = _lifeNodes.Count; //需要新增的节点数 int readyToAddCount = datas.Length - lifeCount; if (readyToAddCount >= 0) { //已存在直接解析数据赋值 for (int i = 0; i < lifeCount; i++) { _parser.Parse(_lifeNodes[i], datas[i]); } //需补的 创建节点并解析赋值 if (_optimize) { _refreshTask = Task.CreateTask(CreateWithPerFrame(lifeCount, datas)); } else { for (int i = lifeCount; i < datas.Length; i++) { T node = _pool.Get(); _parser.Parse(node, datas[i]); _lifeNodes.Add(node); } } } else { //已存在的直接解析数据赋值 for (int i = 0; i < datas.Length; i++) { _parser.Parse(_lifeNodes[i], datas[i]); } //多余的 移除节点 for (int i = lifeCount - 1; i >= datas.Length; i--) { _pool.Remove(_lifeNodes[i]); _lifeNodes.RemoveAt(i); } } } else { _lifeNodes.ForEach(node => _pool.Remove(node)); _lifeNodes.Clear(); } }