/// <summary> /// 克隆Resources路径下的目标 /// </summary> /// <param name="r_path"></param> /// <returns></returns> public ObjectPoolItem Clone(string r_path) { if (InPathExists(r_path)) { var tPool = m_AllPoolItem[r_path]; var item = tPool.FindIdle; if (item == null) { var game = Instantiate(tPool.Obj); if (game != null) { game.name = tPool.Name; item = new ObjectPoolItem(game, tPool.Parent, r_path); tPool.AddPoolItem(item); } else { DeBug.LogError("注意:要实例化对象为空!"); } } item.Idle = false; return(item); } DeBug.LogError("注意:调用对象池的路径出错!"); return(null); }
/// <summary> /// 查询是否有该对象的基础类,若没有则添加 /// </summary> /// <param name="r_path"></param> /// <returns></returns> private bool InPathExists(string r_path) { if (string.IsNullOrEmpty(r_path)) { Debug.LogError("注意:传入Resources路径为空!"); return(false); } if (m_AllPoolItem.ContainsKey(r_path)) { return(true); } var game = Resources.Load <GameObject>(r_path); if (game == null) { DeBug.LogError($"注意:Resources.Load 加载出错!{r_path}"); return(false); } else { string name = "All" + game.name; var parent = new GameObject(name); parent.transform.parent = transform; parent.SetActive(false); m_ItemsParent.Add(parent); m_AllPoolItem.Add(r_path, new ObjectPoolResources(game, parent.transform)); return(true); } }
/// <summary> /// /// </summary> /// <param name="r_path"></param> /// <returns></returns> public ObjectPoolItem Clone(string r_path) { if (TryExists(r_path)) { ObjectPoolResources tempPool = m_AllPoolItem[r_path]; ObjectPoolItem poolItem = tempPool.FindIdle; if (poolItem == null) { GameObject tempGame = Instantiate(tempPool.Obj); if (tempGame != null) { tempGame.name = tempPool.Name; poolItem = new ObjectPoolItem(tempGame, tempPool.Parent, r_path); tempPool.AddPoolItem(poolItem); } else { DeBug.LogError("注意:要实例化对象为空!"); } } poolItem.Idle = false; return(poolItem); } DeBug.LogError("注意:调用对象池的路径出错!"); return(null); }
/// <summary> /// 添加某个倒计时类 /// </summary> /// <param name="r_time"></param> /// <returns></returns> public void AddTimeLimit(TimeLimit r_item) { if (r_item != null) { timeList.Add(r_item); } else { DeBug.LogError("注意:传入TimeLimit类为空!"); } }
/// <summary> /// 构造赋值对象池中的对象 /// </summary> /// <param name="r_obj"></param> public ObjectPoolItem(GameObject r_obj, Transform r_parent, string r_path) { if (r_obj == null) { DeBug.LogError("传入的对象为空!"); } else { Obj = r_obj; Path = r_path; parent = r_parent; } }
public ObjectPoolResources(GameObject r_obj, Transform r_parent) { if (r_obj == null) { DeBug.LogError(">>>>>> 传入的对象为空!"); } else { Obj = r_obj; Name = r_obj.name; Parent = r_parent; } }
/// <summary> /// 添加某个倒计时类 /// </summary> /// <param name="r_time"></param> /// <returns></returns> public void AddTimeLimit(params TimeLimit[] r_items) { if (r_items?.Length > 0) { for (int i = 0; i < r_items.Length; i++) { AddTimeLimit(r_items[i]); } } else { DeBug.LogError("注意:传入TimeLimit类为空!"); } }
/// <summary> 设置为休闲状态 </summary> public void SetTheIdle() { if (Idle) { Obj.SetActive(false); Form.parent = parent; TransformInit(); DeBug.LogGolden($" {Obj.name} 成功设置为闲置状态!"); } else { Debug.Log("注意:该对象未设置为闲置状态!"); } }
/// <summary> 设置为闲置状态 </summary> public void SetTheIdle() { if (Exists()) { if (!Idle) { DeBug.LogError("注意:该对象未设置为闲置状态!"); Idle = true; } SetActive(false); Trans.SetParent(idleParent); LocalInit(); ResetTags(); } }