/// <summary> /// 加载window /// </summary> /// <param name="name"></param> public void preLoadWindow(GameConfiger game, string name) { GameObject windowPrefab = AssetManager.Instance.loadWindowAsset(game, name); windowPrefab = Instantiate(windowPrefab, CanvasTrans.Root); windowPrefab.SetActive(false); windowsDic.Add(name, windowPrefab.GetComponent <WindowBase>()); }
/// <summary> /// 获取window引用 /// </summary> /// <param name="name">window名字</param> public WindowBase getWindow(GameConfiger game, string name) { if (!windowsDic.ContainsKey(name)) { preLoadWindow(game, name); } WindowBase window = windowsDic[name]; return(window); }
public GameObject loadWindowAsset(GameConfiger game, string name) { string gameName = game.ToString().ToLower(); string prefabName = name.ToLower(); string filePath = gameName + "/" + prefabName; AssetBundle windowAB = loadAsset(gameName, filePath, prefabName); GameObject windowPrefab = windowAB.LoadAsset <GameObject>(prefabName); return(windowPrefab); }
/// <summary> /// 加载widget /// </summary> /// <param name="name"></param> public void preLoadWidget(GameConfiger game, string name) { if (!widgetsDic.ContainsKey(name)) { GameObject widgetPrefab = AssetManager.Instance.loadWindowAsset(game, name); widgetPrefab = Instantiate(widgetPrefab, CanvasTrans.Root); widgetPrefab.SetActive(false); widgetsDic.Add(name, widgetPrefab.GetComponent <WidgetBase>()); if (!widgetsPool.ContainsKey(name)) { widgetsPool.Add(name, new Queue <GameObject>()); } widgetsPool[name].Enqueue(widgetPrefab); } }
/// <summary> /// 打开widget /// </summary> /// <param name="name">widget名字</param> public WidgetBase newWidget(GameConfiger game, string name, params object[] parameters) { if (!widgetsDic.ContainsKey(name)) { preLoadWidget(game, name); } if (widgetsPool[name].Count <= 1) { GameObject widgetPrefab = widgetsPool[name].Dequeue(); GameObject widgetClone = Instantiate(widgetPrefab); widgetsPool[name].Enqueue(widgetPrefab); widgetsPool[name].Enqueue(widgetClone); } WidgetBase widget = widgetsPool[name].Dequeue().GetComponent <WidgetBase>(); //widget.rename(name); widget.show(parameters); return(widget); }
public Sprite loadSpriteAsset(GameConfiger game, string name) { if (assetsRef.ContainsKey(name)) { return(assetsRef[name] as Sprite); } string gameName = game.ToString().ToLower(); string prefabName = name.ToLower(); string filePath = gameName + "/" + prefabName; AssetBundle spriteAB = loadAsset(gameName, filePath, prefabName); string[] str = prefabName.Split('/'); prefabName = str[str.Length - 1]; Texture2D texture2D = spriteAB.LoadAsset <Texture2D>(prefabName); Sprite sprite = Sprite.Create(texture2D, new Rect(0.0f, 0.0f, texture2D.width, texture2D.height), new Vector2(0.5f, 0.5f), 100.0f); assetsRef.Add(name, sprite); return(sprite); }