public void LoadIcon(string url, LoadCompleteCallback onSuccess, LoadErrorCallback onFail) { LoadItem item = new LoadItem(); item.url = url; item.onSuccess = onSuccess; item.onFail = onFail; _items.Add(item); if(!_started) StartCoroutine(Run()); }
public List <LoadItem> Feed() { List <LoadItem> loader = new List <LoadItem>(); foreach (MonoNamePair script in ScriptList) { //Check if null if (script.Script != null) { LoadItem temp = new LoadItem(); temp.script = script.Script; temp.type = script.Script.GetType(); loader.Add(temp); } } return(loader); }
/// <summary> /// 设置图片(同步加载) /// </summary> /// <param name="image_">是否需要保持引用,等go失效时设置为移除引用?</param> /// <param name="url_"></param> /// <param name="spriteName"></param> /// <param name="refer_"></param> /// <param name="nativeSize_">重置尺寸</param> public void SetSprite(object refer_, Image image_, string url_, string spriteName, bool nativeSize_ = false) { string real_url_ = FormatPath(url_); if (m_itemQueue.Count > 0 && m_image2item.ContainsKey(image_)) { //image在加载队列中,从队列移除 LoadItem item = m_image2item[image_]; RemoveLoadItem(item); } Refer.Assert(refer_); string referId = Refer.Format(refer_); RetainImage(image_, referId); __SetSprite(referId, image_, real_url_, spriteName, nativeSize_); }
LoadItem AddLoadItem(string referId_, Image image_, string url_, string spriteName_, bool nativeSize_) { LoadItem item = null; if (m_itemQueue.Count > 0 && m_image2item.ContainsKey(image_)) { item = m_image2item[image_]; //加载项已存在 } if (item == null) { item = m_itemPool.Pop(); m_itemQueue.Add(item); m_image2item[image_] = item; } item.Init(referId_, image_, url_, spriteName_, nativeSize_); return(item); }
public void CheckLoadQueue(LoadItem loadItem) { IPool pool; if (mPools.TryGetValue(loadItem.id, out pool)) { Object target = pool.GetObject(); pool.RefCount--; if (target == null) { Debug.LogError("获取对象为空"); return; } AddActivePoolInfo(target, pool.id); loadItem.callback(target); } else { Debug.LogError("没找到池子"); } }
private LoadItem ReadItem(XElement ie) { var result = new LoadItem {Value = ie.Attr("code")}; var level = ie.Attr("level"); if (!string.IsNullOrWhiteSpace(level)) { result.Level = (LoadLevel)Enum.Parse(typeof(LoadLevel), level, true); } result.Command = ie.Attr("command"); if (result.Value.EndsWith(".js")) { result.Type = LoadItemType.Script; }else if (result.Value.EndsWith(".css")) { result.Type = LoadItemType.Style; }else if (result.Value.Contains("rel=")) { result.Type = LoadItemType.Link; }else if (result.Value.EndsWith(".html")) { result.Type = LoadItemType.Template; } else { result.Type = LoadItemType.Meta; } return result; }
private decimal PutTwoLessonOnWeek(List <Position> Adding, decimal Load, LoadItem item) { for (int counter = 0; counter < Adding.Count - 1 && Load > 0; counter++) { Position curr = Adding[counter]; Position next = Adding[counter + 1]; ScheduleDay day = Shedule.GetDay(curr.Time); if (!IsHoursNear(curr.Time, next.Time) || !day.LimitLessonsNotExceeded(item.Groups, day.Week, day.Day, 2)) { continue; } if (CanPutToPosition(curr.Time, curr.Room, item) && CanPutToPosition(next.Time, next.Room, item)) { Load = PutLesson(item, curr.Time, curr.Room, Load); Load = PutLesson(item, next.Time, next.Room, Load); } } return(Load); }
protected virtual ScheduleRoom FindRoom(LoadItem item, ScheduleTime time) { //проверяем не привязан ли этот предмет к определенной аудитории var query = GetRoomsBindingDiscipline(item.LessonType, item.Discipline).ToList(); //если предмет не привязан то ищем по всем аудиториям, если же привязан то только по отобранным List <ScheduleRoom> rooms = (query.Count > 0) ? query : Rooms; //выбираем аудиторию, ищем пока не найдется подходящая не занятая foreach (ScheduleRoom room in rooms) { //можно ли в этой аудитории проводить данный вид занятия if (!PossibleAppointLessonRoom(room, item.LessonType)) { continue; // если нельзя то переходим к следующей аудитории } //проверяем накладки по аудитоиям, группам и преподам if (Employments.IsHourFree(item.Teacher, item.Groups, room.Name, time)) { return(room); //больше не ищем аудиторию } } return(null); }
public void OnUpdate() { int handled = 0; while (_items.Count > 0) { LoadItem item = _items[0]; _items.RemoveAt(0); NTexture ntex; if (_pool.ContainsKey(item.url)) { Log.Info("hit " + item.url); ntex = (NTexture)_pool[item.url]; ntex.refCount++; if (item.onSuccess != null) { item.onSuccess(ntex); } } else { try { Bitmap bm = new Bitmap(_basePath + item.url); Texture tex = new Texture(bm.Width, bm.Height, bm.GetPixels()); bm.Dispose(); ntex = new NTexture(tex); ntex.refCount++; if (item.onSuccess != null) { item.onSuccess(ntex); } } catch (Exception err) { //Log.Warning("load texture '" + item.url + "' failed."); ntex = NTexture.Empty; if (item.onFail != null) { item.onFail(err.Message); } } _pool[item.url] = ntex; } handled++; if (handled == WORKLOAD_PER_FRFAME) { break; } } float now = Engine.Timer.GetCurrTime(); if (now - _lastCheckPool > POOL_CHECK_TIME) { _lastCheckPool = now; int cnt = _pool.Count; if (cnt > MAX_POOL_SIZE) { ArrayList toRemove = null; foreach (DictionaryEntry de in _pool) { string key = (string)de.Key; NTexture texture = (NTexture)de.Value; if (texture.refCount == 0) { if (toRemove == null) { toRemove = new ArrayList(); } toRemove.Add(key); texture.Dispose(); //Log.Info("free icon " + de.Key); cnt--; if (cnt <= 8) { break; } } } if (toRemove != null) { foreach (string key in toRemove) { _pool.Remove(key); } } } } }
protected virtual decimal PutLessonsOnFreePositions(IEnumerable <Position> freePositions, decimal Load, int Attempt, LoadItem item) { switch (Attempt) { //первый проход генератора case 1: return(Load / Step == 1 ? PutTwoLessonOnTwoWeek(freePositions.ToList(), Load, item) : PutTwoLessonOnWeek(freePositions.ToList(), Load, item)); //второй проход дорасставить как получится и куда получится case 2: return(PutOneLessonOnOneOrTwoWeek(freePositions.ToList(), Load, item)); default: return(Load); } }
IEnumerator Run() { _started = true; LoadItem item = null; while (true) { if (_items.Count > 0) { item = _items[0]; _items.RemoveAt(0); } else { break; } if (_pool.ContainsKey(item.url)) { //Debug.Log("hit " + item.url); NTexture texture = (NTexture)_pool[item.url]; texture.refCount++; if (item.onSuccess != null) { item.onSuccess(texture); } continue; } WWW www = new WWW(_basePath + item.url + ".ab"); yield return(www); if (string.IsNullOrEmpty(www.error)) { AssetBundle bundle = www.assetBundle; if (bundle == null) { Debug.LogWarning("Run Window->Build FairyGUI example Bundles first."); if (item.onFail != null) { item.onFail(www.error); } continue; } #if UNITY_5 NTexture texture = new NTexture(bundle.LoadAllAssets <Texture2D>()[0]); #else NTexture texture = new NTexture((Texture2D)bundle.mainAsset); #endif texture.refCount++; bundle.Unload(false); _pool[item.url] = texture; if (item.onSuccess != null) { item.onSuccess(texture); } } else { if (item.onFail != null) { item.onFail(www.error); } } } _started = false; }
public void OnExit(LoadItem loadItem) { }
public void OnMouseUp(LoadItem loadItem) { IsMouseMove = false; }
//点击事件 处理 是否道路 public void OnClick(LoadItem loadItem) { }
protected virtual bool CanPutToPosition(ScheduleTime time, ScheduleRoom room, LoadItem item) { ScheduleDay day = Shedule.GetDay(time.Week, time.Day); return(time.WeekNumber <= 4 && time.WeekNumber >= 1 && day != null && day.LimitLessonsNotExceeded(item.Groups, time.Week, time.Day, 1) && Employments.IsHourFree(item.Teacher, item.Groups, room.Name, time)); }
IEnumerator Run() { _started = true; LoadItem item = null; while (true) { if (_items.Count > 0) { item = _items[0]; _items.RemoveAt(0); } else { break; } if (_pool.ContainsKey(item.url)) { //Debug.Log("hit " + item.url); NTexture texture = (NTexture)_pool[item.url]; texture.refCount++; if (item.onSuccess != null) { item.onSuccess(texture); } continue; } string url = _basePath + item.url + ".ab"; #if UNITY_5_4_OR_NEWER #if UNITY_2018_1_OR_NEWER UnityWebRequest www = UnityWebRequestAssetBundle.GetAssetBundle(url); #else UnityWebRequest www = UnityWebRequest.GetAssetBundle(url); #endif #if UNITY_2017_2_OR_NEWER yield return(www.SendWebRequest()); #else yield return(www.Send()); #endif if (!www.isNetworkError && !www.isHttpError) { AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(www); #else WWW www = new WWW(url); yield return(www); if (string.IsNullOrEmpty(www.error)) { AssetBundle bundle = www.assetBundle; #endif if (bundle == null) { Debug.LogWarning("Run Window->Build FairyGUI example Bundles first."); if (item.onFail != null) { item.onFail(www.error); } continue; } #if (UNITY_5 || UNITY_5_3_OR_NEWER) NTexture texture = new NTexture(bundle.LoadAllAssets <Texture2D>()[0]); #else NTexture texture = new NTexture((Texture2D)bundle.mainAsset); #endif texture.refCount++; bundle.Unload(false); _pool[item.url] = texture; if (item.onSuccess != null) { item.onSuccess(texture); } } else { if (item.onFail != null) { item.onFail(www.error); } } } _started = false; } IEnumerator FreeIdleIcons() { yield return(new WaitForSeconds(POOL_CHECK_TIME)); //check the pool every 30 seconds int cnt = _pool.Count; if (cnt > MAX_POOL_SIZE) { ArrayList toRemove = null; foreach (DictionaryEntry de in _pool) { string key = (string)de.Key; NTexture texture = (NTexture)de.Value; if (texture.refCount == 0) { if (toRemove == null) { toRemove = new ArrayList(); } toRemove.Add(key); texture.Dispose(); //Debug.Log("free icon " + de.Key); cnt--; if (cnt <= 8) { break; } } } if (toRemove != null) { foreach (string key in toRemove) { _pool.Remove(key); } } } } }
protected virtual decimal PutOneLessonOnOneOrTwoWeek(List <Position> freePositions, decimal Load, LoadItem item) { foreach (Position position in freePositions) { ScheduleDay day = Shedule.GetDay(position.Time); if (day.LimitLessonsNotExceeded(item.Groups, day.Week, day.Day, 1)) { Load = PutLesson(item, position.Time, position.Room, Load); if (Load > 0 && CanPutToPosition(GetTimeAfterTwoWeek(position.Time), position.Room, item)) { Load = PutLesson(item, GetTimeAfterTwoWeek(position.Time), position.Room, Load); } } if (Load == 0) { break; } } return(Load); }
IEnumerator Run() { _started = true; LoadItem item = null; while (true) { if (_items.Count > 0) // 如果_items有值,取出来第一个,移除第一个 { item = _items[0]; _items.RemoveAt(0); } else // _items没值,直接退出循环,下边是新创建 { break; //退出循环 } //池里包含item.url,取出来图片,引用自增,如果有成功回调,调用一下成功的回调 if (_pool.ContainsKey(item.url)) { NTexture texture = (NTexture)_pool[item.url]; texture.refCount++; if (item.onSuccess != null) { item.onSuccess(texture); } continue; // 继续循环 } //在ab包里加载 WWW www = new WWW(_basePath + item.url + ".ab"); yield return(www); if (string.IsNullOrEmpty(www.error)) { AssetBundle bundle = www.assetBundle; if (bundle == null) { Debug.Log("bundle is null, you need Run Window -> Build FairyGUI example Bundles first."); if (item.onFail != null) { item.onFail(www.error); } continue; } #if UNITY_5 NTexture texture = new NTexture(bundle.LoadAllAssets <Texture2D>()[0]); #else NTexture texture = new NTexture((Texture2D)bundle.mainAsset); #endif texture.refCount++; bundle.Unload(false); _pool[item.url] = texture; if (item.onSuccess != null) { item.onSuccess(texture); } } else { if (item.onFail != null) { item.onFail(www.error); } } } _started = false; }
IEnumerator Run() { started = true; LoadItem tempItem = null; while (true) { if (items.Count > 0) { tempItem = items[0]; items.RemoveAt(0); } else { break; } if (pool.ContainsKey(tempItem.url)) { NTexture tempTexture = (NTexture)pool[tempItem.url]; if (tempTexture == null) { pool.Remove(tempItem.url); } } if (pool.ContainsKey(tempItem.url)) { yield return(null); NTexture tempTexture = (NTexture)pool[tempItem.url]; tempTexture.refCount++; if (tempItem.onSuccess != null) { tempItem.onSuccess(tempTexture); } continue; } AssetBundle bundle = AssetBundle.LoadFromFile(Util.GetTargetAssetBundlesPath(tempItem.url)); yield return(null); if (bundle != null) { NTexture texture = new NTexture(bundle.LoadAllAssets <Texture2D>()[0]); texture.refCount++; pool[tempItem.url] = texture; assetBundleList.Add(tempItem.url, bundle); try { if (tempItem.onSuccess != null) { tempItem.onSuccess(texture); } } catch { started = false; } } else { Debug.LogError("<color=#FF0000>加载资源失败 -----> " + tempItem.url + "</color>"); } } started = false; }
IEnumerator Run() { _started = true; LoadItem item = null; while (true) { if (_item.Count > 0) { item = _item[0]; _item.RemoveAt(0); } else { break; } if (_pool.ContainsKey(item.url)) { NTexture texture = _pool[item.url] as NTexture; texture.refCount++; if (item.onSuccess != null) { item.onSuccess(texture); continue; } } UnityWebRequest unityWebRequest = new UnityWebRequest(item.url); DownloadHandlerTexture handlerTexture = new DownloadHandlerTexture(true); unityWebRequest.downloadHandler = handlerTexture; yield return(unityWebRequest.SendWebRequest()); if (string.IsNullOrEmpty(unityWebRequest.error)) { Texture2D texture = handlerTexture.texture; NTexture nTexture = new NTexture(texture); _pool[item.url] = nTexture; item.onSuccess?.Invoke(nTexture); } else { item.onFail?.Invoke(unityWebRequest.error); } //WWW www = new WWW(item.url); //yield return www; //if (string.IsNullOrEmpty(www.error)) //{ // Texture2D image = new Texture2D(4, 4, TextureFormat.ARGB32, false); // www.LoadImageIntoTexture(image); // NTexture texture = new NTexture(image); // _pool[item.url] = texture; // if (item.onSuccess != null) // item.onSuccess(texture); // // Debug.Log(texture.width+""); //} //else //{ // if (item.onFail != null) // item.onFail(www.error); //} } _started = false; }
private void Awake() { loadItem = GetComponent <LoadItem>(); }
private decimal PutTwoLessonOnTwoWeek(List <Position> freePositions, decimal Load, LoadItem item) { for (int counter = 0; counter < freePositions.Count - 1 && Load > 0; counter++) { Position curr = freePositions[counter]; Position next = freePositions[counter + 1]; if (curr.Time.WeekNumber > 2 || next.Time.WeekNumber > 2) { continue; } ScheduleTime CurrAfterTwoWeek = GetTimeAfterTwoWeek(curr.Time); ScheduleTime NextAfterTwoWeek = GetTimeAfterTwoWeek(next.Time); ScheduleDay currDay = Shedule.GetDay(curr.Time); ScheduleDay nextDay = Shedule.GetDay(CurrAfterTwoWeek); if (!IsHoursNear(curr.Time, next.Time) || !currDay.LimitLessonsNotExceeded(item.Groups, currDay.Week, currDay.Day, 2) || !nextDay.LimitLessonsNotExceeded(item.Groups, CurrAfterTwoWeek.Week, CurrAfterTwoWeek.Day, 2)) { continue; } if (CanPutToPosition(curr.Time, curr.Room, item) && CanPutToPosition(next.Time, next.Room, item) && CanPutToPosition(CurrAfterTwoWeek, curr.Room, item) && CanPutToPosition(NextAfterTwoWeek, next.Room, item)) { Load = PutLesson(item, curr.Time, curr.Room, Load); Load = PutLesson(item, next.Time, next.Room, Load); Load = PutLesson(item, CurrAfterTwoWeek, curr.Room, Load); Load = PutLesson(item, NextAfterTwoWeek, next.Room, Load); counter++; return(Load); } } return(Load); }