public GameObject getCustomAsset() { ++_refCount; if (!_queue.isEmpty()) { ResourceNode node = _queue.poll(); _parent.pickOne(id); return(node.obj); } else { Func <GameObject> func = _custemCreateFuncDic.get(id); if (func == null) { Ctrl.throwError("未注册自定义创建方法", id); return(null); } return(func()); } }
/** 遍历值(null的不传) */ public void forEachValue(Action <V> consumer) { if (_size == 0) { return; } int version = _version; V[] vals = _values; V v; for (int i = vals.Length - 1; i >= 0; --i) { if ((v = vals[i]) != null) { consumer(v); } } if (version != _version) { Ctrl.throwError("ForeachModificationException"); } }
/** 获取app包扩展名 */ public static string getAppExName() { switch (SystemControl.platform) { case RuntimePlatform.WindowsEditor: case RuntimePlatform.WindowsPlayer: { return("exe"); } case RuntimePlatform.OSXEditor: case RuntimePlatform.OSXPlayer: { return("dmg"); } break; case RuntimePlatform.Android: { return("apk"); } case RuntimePlatform.IPhonePlayer: { return("ipa"); } default: { Ctrl.throwError("暂未支持的平台类型", SystemControl.platform); return(""); } break; } }
/** 遍历 */ public void forEach(Action <int, bool> consumer) { if (_size == 0) { return; } int version = _version; int free = _freeValue; int[] keys = _set; bool[] vals = _values; for (int i = (keys.Length) - 1; i >= 0; --i) { int key; if ((key = keys[i]) != free) { consumer(key, vals[i]); } } if (version != _version) { Ctrl.throwError("ForeachModificationException"); } }
public void forEach(Action <K, V> consumer) { if (_size == 0) { return; } int version = _version; K[] keys = _set; V[] vals = _values; K key; for (int i = (keys.Length) - 1; i >= 0; --i) { if (!Equals(_defaultKey, key = keys[i])) { consumer(key, vals[i]); } } if (version != _version) { Ctrl.throwError("ForeachModificationException"); } }
/** 遍历 */ public void forEach(Action <long> consumer) { if (_size == 0) { return; } int version = _version; long free = _freeValue; long[] keys = _set; for (int i = keys.Length - 1; i >= 0; --i) { long key; if ((key = keys[i]) != free) { consumer(key); } } if (version != _version) { Ctrl.throwError("ForeachModificationException"); } }
/** 截取list */ public SList <V> subList(int from, int end) { if (from < 0) { from = 0; } if (end >= size()) { end = size(); } int len = end - from; if (len == 0) { return(new SList <V>()); } if (len < 0) { Ctrl.throwError("subList,数据非法", from, end); return(new SList <V>()); } SList <V> re = new SList <V>(len); Array.Copy(_values, from, re._values, 0, len); re.justSetSize(len); return(re); }
/** 获取平台名 */ public static string getPlatformName() { switch (SystemControl.platform) { case RuntimePlatform.WindowsEditor: case RuntimePlatform.WindowsPlayer: { return("windows"); } case RuntimePlatform.OSXEditor: case RuntimePlatform.OSXPlayer: { return("mac"); } break; case RuntimePlatform.Android: { return("android"); } case RuntimePlatform.IPhonePlayer: { return("ios"); } default: { Ctrl.throwError("暂未支持的平台类型", SystemControl.platform); return(""); } break; } }
/** 获取对应元素 */ public char get(int index) { if (index >= _size) { Ctrl.throwError("indexOutOfBound"); } return(_values[index]); }
/** 设置对应元素 */ public void set(int index, V obj) { if (index >= _size) { Ctrl.throwError("indexOutOfBound"); } _values[index] = obj; }
public void set(int index, char value) { if (index >= _size) { Ctrl.throwError("indexOutOfBound"); } _values[index] = value; }
/** 检查当前在主线程 */ public static void checkCurrentIsMainThread() { if (ShineSetting.openCheck) { if (Thread.CurrentThread != _mainThread) { Ctrl.throwError("不是主线程"); } } }
/** 构造 */ public void make() { _list.sort(compare); if (_list.isEmpty()) { Ctrl.errorLog("SectionTool不能没有数据"); return; } int len = _list.size(); _keys = new int[len + 1]; _values = new T[len + 1]; if (_list.get(0).min == -1) { _list.get(0).min = 0; _leftFree = true; } if (_list.getLast().max == -1) { _list.getLast().max = int.MaxValue; _values[len] = _list.getLast().obj; } else { _values[len] = default(T); } _keys[len] = _list.getLast().max; SectionObj obj; for (int i = 0; i < len; i++) { obj = _list.get(i); _keys[i] = obj.min; _values[i] = obj.obj; if (i < len - 1) { if (obj.max < _list.get(i + 1).min) { Ctrl.throwError("配置表错误,max比min小2"); } } } }
/** 加载一个 */ public void loadOne(int id) { //-1不加载 if (id == -1) { clear(); _isLoading = false; //不返回 return; } //相同资源,加载中跳过 if (_isLoading && _resourceID == id) { return; } toClear(false); _loadVersion = LoadControl.getVersion(); int index = ++_index; _isLoading = true; AssetPoolControl.loadOne(_type, _resourceID = id, () => { if (_index == index && LoadControl.getVersion() == _loadVersion) { _isLoading = false; releaseCache(); _cacheResourceID = id; _cacheObject = AssetPoolControl.getAsset(_type, id); if (_cacheObject == null) { Ctrl.throwError("获取Asset为空,可能是业务层调用了Destroy", _type, id); } else { if (_completeCall != null) { _completeCall(_cacheObject); } } } }); }
public bool contains(K key) { if (Equals(_defaultKey, key)) { Ctrl.throwError("key不能为空"); return(false); } if (_size == 0) { return(false); } return(index(key) >= 0); }
/** 是否存在 */ public bool contains(string key) { if (key == null) { Ctrl.throwError("key不能为空"); return(false); } if (_size == 0) { return(false); } return(index(key) >= 0); }
/// <summary> /// 延迟delay毫秒,执行方法 /// </summary> public int setTimeOut(Action func, int delay) { if (delay <= 0) { Ctrl.throwError("传入的时间间隔<=0", delay); return(-1); } TimeExecuteData tData = new TimeExecuteData(); tData.func = func; tData.timeMax = delay; tData.isGoOn = false; return(addTimeEx(tData)); }
/** 通过id取得Request类型 */ public static BaseData getRequestByID(int dataID) { if (dataID == -1) { return(null); } BaseData re = _requestMaker.getDataByID(dataID); if (re == null) { Ctrl.throwError("找不到Request类型" + dataID); return(null); } return(re); }
/// <summary> /// 间隔delay毫秒,执行方法(如掉帧,只回调一次) /// </summary> public int setInterval(Action <int> func, int delay) { if (delay <= 0) { Ctrl.throwError("传入的时间间隔<=0", delay); return(-1); } TimeExecuteData tData = new TimeExecuteData(); tData.intFunc = func; tData.timeMax = delay; tData.isGoOn = true; tData.isCut = true; return(addTimeEx(tData)); }
/// <summary> /// 放回一个 /// </summary> public virtual void back(T obj) { if (obj == null) { Ctrl.throwError("对象池添加空对象"); return; } if (!_enable || _queue.size() >= _maxSize) { if (_releaseFunc != null) { _releaseFunc(obj); } return; } if (_needClear) { if (obj is IPoolObject) { ((IPoolObject)obj).clear(); } } if (ShineSetting.openCheck) { if (_checkSet.contains(obj)) { Ctrl.print("上次调用", _callStackDic.get(obj)); Ctrl.throwError("对象池重复添加!", obj); return; } _checkSet.add(obj); string stackTrace = Ctrl.getStackTrace(); stackTrace = stackTrace.Replace("\n", " "); _callStackDic.put(obj, stackTrace); } _queue.add(obj); }
/** 替换方法字符串 */ private static string replaceMethod(string content, string methodKey, string methodContent) { int index = content.IndexOf(methodKey); if (index == -1) { Ctrl.throwError("未找到该方法", methodKey); return(""); } int leftIndex = content.IndexOf("{", index + methodKey.Length); int rightIndex = StringUtils.getAnotherIndex(content, "{", "}", leftIndex); string re = content.Substring(0, leftIndex + 1) + methodContent + content.Substring(rightIndex); return(re); }
/** 初始化(系统用) */ public void init(int index, Func <T, T, float, T> getValueFunc, T start, T end, int delay, Action <T> func, Action overFunc, int easeType) { if (delay <= 0) { Ctrl.throwError("tween delay不能小于0"); } this.index = index; _start = start; _end = end; _delay = delay; _getValueFunc = getValueFunc; _func = func; _overFunc = overFunc; _easeFunc = Ease.getEaseFunc(easeType); _time = 0; }
/** 移除timeEx */ private void removeTimeEx(int index) { if (index <= 0) { Ctrl.throwError("timeIndex不能<=0"); return; } TimeExecuteData tData = _timeExDic.get(index); if (tData == null) { return; } _timeExDic.remove(index); }
public bool MoveNext() { if (_tSet == null) { return(false); } long key; if (_index <= _tSafeIndex) { while (--_index >= 0) { if ((key = _tSet[_index]) != _tFv) { _entry.key = key; _entry.value = _tValues[_index]; return(true); } } _index = _tSet.Length; return(MoveNext()); } else { while (--_index > _tSafeIndex) { if ((key = _tSet[_index]) != _tFv) { _entry.key = key; _entry.value = _tValues[_index]; return(true); } } if (_tVersion != _map._version) { Ctrl.throwError("ForeachModificationException"); } return(false); } }
public int putIfAbsent(string key, int value) { if (key == null) { Ctrl.throwError("key不能为空"); return(0); } int index = insert(key, value); if (index < 0) { return(0); } else { return(_values[index]); } }
/** 没有就赋值(成功添加返回null,否则返回原值) */ public V putIfAbsent(K key, V value) { if (Equals(_defaultKey, key)) { Ctrl.throwError("key不能为空"); return(default(V)); } int index = insert(key, value); if (index < 0) { return(default(V)); } else { return(_values[index]); } }
public static void init() { _poolRoot = GameObject.Find(ShineSetting.poolRootName); if (_poolRoot == null) { Ctrl.throwError("未找到池对象根"); return; } _poolRootTrans = _poolRoot.transform; _poolRoot.SetActive(false); //最多50种 _poolArr = new AssetPool[50]; TimeDriver.instance.setInterval(onSecond, 1000); registPool(AssetPoolType.Default, 200, 120 * 1000); }
/** 移除后部 index到末尾 */ public void removeBack(int len) { if (isEmpty()) { return; } if (len > _size) { Ctrl.throwError("indexOutOfBound"); return; } int last = _size - len; while (_size > last) { pop(); } }
public void put(string key, int value) { if (key == null) { Ctrl.throwError("key不能为空"); return; } int index = insert(key, value); if (index < 0) { return; } else { _values[index] = value; return; } }
public void put(K key, V value) { if (Equals(key, _defaultKey)) { Ctrl.throwError("key不能为空"); return; } int index = insert(key, value); if (index < 0) { return; } else { _values[index] = value; return; } }