public static UnityWebRequest postString(string url, string strData, CLAssetType type, object successCallback, object failedCallback, object orgs, bool isCheckTimeout) { try { if (string.IsNullOrEmpty(url)) { return(null); } self.enabled = true; UnityWebRequest www = UnityWebRequest.Post(url, strData); Coroutine cor = self.StartCoroutine(self.exeWWW(www, url, type, successCallback, failedCallback, orgs, isCheckTimeout, (url2) => { post(url2, strData, type, successCallback, failedCallback, orgs, isCheckTimeout); })); wwwMap4Get[url] = cor; return(www); } catch (System.Exception e) { Debug.LogError(e); Utl.doCallback(failedCallback, null, orgs); return(null); } }
public void doSetPrefab(string path, string name, object finishCallback, object args, object progressCB) { if (name == null) { return; } if (MapEx.getBool(isSettingPrefabMap, name)) { return; } if (_havePrefab(name)) { if (finishCallback != null) { Utl.doCallback(finishCallback, prefabMap [name], args); } } else { isSettingPrefabMap [name] = true; Callback cb = onGetAssetsBundle; CLVerManager.self.getNewestRes(path, CLAssetType.assetBundle, cb, isAutoReleaseAssetBundle, finishCallback, name, args, progressCB); } }
private static UnityWebRequest _uploadFile(string url, string sectionName, string fileName, byte[] fileContent, CLAssetType type, object successCallback, object failedCallback, object orgs, bool isCheckTimeout, int maxFailTimes, int failedTimes) { try { if (string.IsNullOrEmpty(url)) { return(null); } self.enabled = true; MultipartFormFileSection fileSection = new MultipartFormFileSection(sectionName, fileContent, fileName, "Content-Type: multipart/form-data;"); List <IMultipartFormSection> multForom = new List <IMultipartFormSection>(); multForom.Add(fileSection); UnityWebRequest www = UnityWebRequest.Post(url, multForom); Coroutine cor = self.StartCoroutine( self.exeWWW(www, url, type, successCallback, failedCallback, orgs, isCheckTimeout, maxFailTimes, failedTimes, (url2) => { _uploadFile(url2, sectionName, fileName, fileContent, type, successCallback, failedCallback, orgs, isCheckTimeout, maxFailTimes, failedTimes + 1); })); wwwMap4Get[url] = cor; return(www); } catch (System.Exception e) { Debug.LogError(e); Utl.doCallback(failedCallback, null, orgs); return(null); } }
void procScalerSoft(Vector2 delta) { if (!canScale) { return; } float offset = 0; if (Input.touchCount == 2) { float dis = Vector2.Distance(Input.touches [0].position, Input.touches [1].position); if (oldTowFingersDis == -1) { oldTowFingersDis = dis; return; } offset = (dis - oldTowFingersDis); oldTowFingersDis = dis; } else { offset = Mathf.Abs(delta.y) > Mathf.Abs(delta.x) ? delta.y : delta.x; } if (onDragScaleDelegate != null) { Utl.doCallback(onDragScaleDelegate, delta, offset); } else { procScaler(offset); } }
private static UnityWebRequest _put(string url, byte[] data, CLAssetType type, object successCallback, object failedCallback, object orgs, bool isCheckTimeout, int maxFailTimes, int failedTimes) { try { if (string.IsNullOrEmpty(url)) { return(null); } self.enabled = true; UnityWebRequest www = UnityWebRequest.Put(url, data); Coroutine cor = self.StartCoroutine( self.exeWWW(www, url, type, successCallback, failedCallback, orgs, isCheckTimeout, maxFailTimes, failedTimes, (url2) => { _put(url2, data, type, successCallback, failedCallback, orgs, isCheckTimeout, maxFailTimes, failedTimes + 1); })); wwwMap4Get[url] = cor; return(www); } catch (System.Exception e) { Debug.LogError(e); Utl.doCallback(failedCallback, null, orgs); return(null); } }
/// <summary> /// Move the dragged object by the specified amount. /// </summary> void Move(Vector3 worldDelta, bool isDoLimitView = false) { Vector3 before = target.position; Vector3 orgDelta = worldDelta; target.position = before + worldDelta; scaleTarget.LateUpdate(); //执行一次跟随 bool inGround = true; if (isDoLimitView) { inGround = limitDisplayView(ref worldDelta); } else { inGround = isInviewBounds(ref worldDelta); } if (!inGround) { if (!isDoLimitView) { //target.position = before + worldDelta; target.position = before + orgDelta; CancelMovement(); } } else { Utl.doCallback(onDragMoveDelegate, worldDelta); } }
/// <summary> /// 初始化 GameCenter 登陆 /// </summary> public static void authenticate(object callback, object orgs) { #if UNITY_IPHONE || UNITY_IOS Social.localUser.Authenticate(success => { if (success) { authenticated = Social.localUser.authenticated; Debug.Log("Authentication successful"); Hashtable m = new Hashtable(); m ["Username"] = Social.localUser.userName; m ["UserID"] = Social.localUser.id; m ["IsUnderage"] = Social.localUser.underage; m ["state"] = Social.localUser.state.ToString(); userInfo = JSON.JsonEncode(m); Debug.Log(userInfo); Utl.doCallback(callback, success, userInfo, orgs); } else { Debug.Log("Authentication failed"); userInfo = ""; Utl.doCallback(callback, success, userInfo, orgs); } }); #endif }
void doInvokeByUpdate() { int count = invokeByUpdateList.Count; NewList list = null; object callbakFunc; object orgs; float sec; int index = 0; LuaFunction func = null; while (index < invokeByUpdateList.Count) { list = (NewList)(invokeByUpdateList [index]); callbakFunc = list [0]; orgs = list [1]; sec = (float)(list [2]); if (sec <= Time.unscaledTime) { Utl.doCallback(callbakFunc, orgs); invokeByUpdateList.RemoveAt(index); ObjPool.listPool.returnObject(list); } else { index++; } } list = null; }
void doFixedInvoke(long key) { if (fixedInvokeMap == null && fixedInvokeMap.Count <= 0) { return; } if (fixedInvokeMap [key] == null) { return; } object[] content = null; List <object[]> funcList = (List <object[]>)(fixedInvokeMap [key]); object callback = null; if (funcList != null) { for (int i = 0; i < funcList.Count; i++) { content = funcList [i]; callback = content [0]; Utl.doCallback(callback, content [1]); } funcList.Clear(); funcList = null; fixedInvokeMap.Remove(key); } }
void _appendList(ArrayList list) { if (list.Count == 0) { return; } int dataIndex = 0; int tmpIndex = itemList.Count; UIWidget uiw = null; Transform t = null; for (int i = 0; i < cachedTransform.childCount; i++) { if (dataIndex >= list.Count) { break; } t = cachedTransform.GetChild(i); if (t.gameObject.activeSelf) { continue; } uiw = t.GetComponent <UIWidget> (); if (uiw == null) { continue; } uiw.name = NumEx.nStrForLen(tmpIndex + dataIndex, 6); NGUITools.SetActive(t.gameObject, true); Utl.doCallback(this.initCellCallback, t.GetComponent <CLCellBase> (), list [dataIndex]); NGUITools.updateAll(t); // itemList.Add (uiw); dataIndex++; } }
private static UnityWebRequest _postBytes(string url, byte[] bytes, CLAssetType type, object successCallback, object failedCallback, object orgs, bool isCheckTimeout, int maxFailTimes, int failedTimes) { try { self.enabled = true; UnityWebRequest www = new UnityWebRequest(url, UnityWebRequest.kHttpVerbPOST); UploadHandlerRaw MyUploadHandler = new UploadHandlerRaw(bytes); DownloadHandlerBuffer downloadHandler = new DownloadHandlerBuffer(); //MyUploadHandler.contentType = "application/x-www-form-urlencoded"; // might work with 'multipart/form-data' www.uploadHandler = MyUploadHandler; www.downloadHandler = downloadHandler; Coroutine cor = self.StartCoroutine( self.exeWWW(www, url, type, successCallback, failedCallback, orgs, isCheckTimeout, maxFailTimes, failedTimes, (url2) => { _postBytes(url2, bytes, type, successCallback, failedCallback, orgs, isCheckTimeout, maxFailTimes, failedTimes + 1); })); wwwMap4Get[url] = cor; return(www); } catch (System.Exception e) { Debug.LogError(e); Utl.doCallback(failedCallback, null, orgs); return(null); } }
public virtual void onFinishSetPrefab(object[] paras) { if (paras != null && paras.Length > 1) { T unit = paras [0] as T; string name = paras [1].ToString(); ArrayList list = OnSetPrefabCallbacks.getDelegates(name); int count = list.Count; ArrayList cell = null; object cb = null; object orgs = null; for (int i = 0; i < count; i++) { cell = list [i] as ArrayList; if (cell != null && cell.Count > 1) { cb = cell [0]; orgs = cell [1]; if (cb != null) { Utl.doCallback(cb, unit, orgs); } } } list.Clear(); OnSetPrefabCallbacks.removeDelegates(name); } }
/// <summary> /// Sepcs the proc4 assets. /// </summary> /// <param name="unit">Unit.</param> /// <param name="cb">Cb.</param> /// <param name="args">Arguments.</param> public virtual void sepcProc4Assets(T unit, object cb, object args, object progressCB) { GameObject go = null; if (typeof(T) == typeof(GameObject)) { go = unit as GameObject; } else if (unit is MonoBehaviour) { go = (unit as MonoBehaviour).gameObject; } if (go != null) { CLSharedAssets sharedAsset = go.GetComponent <CLSharedAssets> (); if (sharedAsset != null) { NewList param = ObjPool.listPool.borrowObject(); param.Add(cb); param.Add(unit); param.Add(args); sharedAsset.init((Callback)onGetSharedAssets, param, progressCB); } else { finishSetPrefab(unit); Utl.doCallback(cb, unit, args); } } else { finishSetPrefab(unit); Utl.doCallback(cb, unit, args); } }
public virtual void onGetSharedAssets(params object[] param) { if (param == null) { Debug.LogWarning("param == null"); return; } NewList list = (NewList)(param [0]); if (list.Count >= 3) { object cb = list [0]; T obj = list [1] as T; object orgs = list [2]; finishSetPrefab(obj); if (cb != null) { Utl.doCallback(cb, obj, orgs); } } else { Debug.LogWarning("list.Count ====0"); } ObjPool.listPool.returnObject(list); }
static void onGetSharedAssets(params object[] param) { if (param == null) { Debug.LogWarning("param == null"); return; } NewList list = (NewList)(param[0]); if (list.Count >= 3) { object cb = list[0]; CLPanelBase p = list[1] as CLPanelBase; object orgs = list[2]; if (cb != null) { Utl.doCallback(cb, p, orgs); } } else { Debug.LogWarning("list.Count ====0"); } ObjPool.listPool.returnObject(list); }
public static UnityWebRequest post(string url, Hashtable map, CLAssetType type, object successCallback, object failedCallback, object orgs, bool isCheckTimeout) { try { self.enabled = true; WWWForm data = new WWWForm(); if (map != null) { foreach (DictionaryEntry cell in map) { if (cell.Value is int) { data.AddField(cell.Key.ToString(), int.Parse(cell.Value.ToString())); } else if (cell.Value is byte[]) { data.AddBinaryData(cell.Key.ToString(), (byte[])(cell.Value)); } else { data.AddField(cell.Key.ToString(), cell.Value.ToString()); } } } return(post(url, data, type, successCallback, failedCallback, orgs, isCheckTimeout)); } catch (System.Exception e) { Debug.LogError(e); Utl.doCallback(failedCallback, null, orgs); return(null); } }
void LateUpdate() { if (netGateDataQueue.Count > 0) { netData = netGateDataQueue.Dequeue(); if (netData != null) { if (dispatchGate != null) { //dispatchGate.Call (netData); Utl.doCallback(dispatchGate, netData); } } } if (netGameDataQueue.Count > 0) { netData = netGameDataQueue.Dequeue(); if (netData != null) { if (dispatchGame != null) { //dispatchGame.Call (netData); Utl.doCallback(dispatchGame, netData); } } } }
void onGridStateChg() { for (int i = 0; i < OnGridStateChgCallbacks.Count; i++) { Utl.doCallback(OnGridStateChgCallbacks[i]); } }
IEnumerator _doBorrowObj(string name, object onGetCallbak, object orgs) { yield return(null); T unit = _borrowObj(name); Utl.doCallback(onGetCallbak, name, unit, orgs); }
protected override void OnUpdate(float factor, bool isFinished) { value = Mathf.Lerp(from, to, factor); if (isFinished) { Utl.doCallback(finishCallback); } }
void initCell(GameObject go, int wrapIndex, int realIndex) { Debug.Log(wrapIndex + "========" + realIndex); if (initCellFunc != null && realIndex >= 0 && list != null && realIndex < list.Count) { Utl.doCallback(initCellFunc, go.GetComponent <CLCellBase> (), list [realIndex]); } }
static void initFailed(params object[] param) { if (progressCallback != null) { Utl.doCallback(progressCallback, needUpgradeVerver.Count, progress, null); } loadPriorityVer(); loadOtherResVer(false); }
public IEnumerator exeCallback(object cbFunc) { yield return(null); if (cbFunc != null) { Utl.doCallback(cbFunc, this); } }
/// <summary> /// Reads the new all text. 异步读取。优先从persistentDataPath目录取得,再从streamingAssetsPath读书 /// </summary> /// <returns>The new all text.</returns> /// <param name="fName">F name.</param> public static IEnumerator readNewAllTextAsyn(string fName, object OnGet) { string buff = ""; #if UNITY_WEBGL if (!CLCfgBase.self.isEditMode) { byte[] bytes = CLPreLoadRes4Webgl.getContent(fName); if (bytes != null) { buff = Encoding.UTF8.GetString(bytes); } } else { buff = readNewAllText(fName); } yield return(null); #else string fPath = CLPathCfg.persistentDataPath + "/" + fName; if (File.Exists(fPath)) { yield return(null); buff = File.ReadAllText(fPath); } else { fPath = Application.streamingAssetsPath + "/" + fName; if (Application.platform == RuntimePlatform.Android) { WWW www = new WWW(Utl.urlAddTimes(fPath)); yield return(www); buff = www.text; www.Dispose(); www = null; } else { yield return(null); if (File.Exists(fPath)) { buff = File.ReadAllText(fPath); } } } #if UNITY_EDITOR if (buff == null) { Debug.LogError("Get null content == " + fPath); } #endif #endif Utl.doCallback(OnGet, buff); }
/// <summary> /// Moving the specified deltaTime.处理移动 /// </summary> /// <param name="deltaTime">Delta time.会根据不同的情况传入</param> protected void moving(float deltaTime) { if (pathList == null || nextPahtIndex >= pathList.Count) { Debug.LogError("moving error"); if (pathList == null) { Debug.LogError("pathList == null!"); } stopMove(); Utl.doCallback(onArrivedCallback); return; } movePersent += (deltaTime * speed * 0.3f * offsetSpeed); if (movePersent >= 1) { movePersent = 1; finishOneSubPath = true; } if (turningSpeed > 0) { rotateTowards(diff4Moving, false); } mTransform.position = fromPos4Moving + diff4Moving * movePersent; Utl.doCallback(onMovingCallback); if (nextPahtIndex == pathList.Count - 1) { //最后一段路径,即将要到达目的地 if (finishOneSubPath || Vector3.Distance(mTransform.position, pathList[pathList.Count - 1]) <= endReachedDistance) { stopMove(); Utl.doCallback(onArrivedCallback); } } else { if (finishOneSubPath) { //移动完成一段路径,进入下一段路径的准备(一些变量的初始化) nextPahtIndex++; movePersent = 0; finishOneSubPath = false; fromPos4Moving = pathList[nextPahtIndex - 1]; diff4Moving = pathList[nextPahtIndex] - pathList[nextPahtIndex - 1]; offsetSpeed = 1.0f / Vector3.Distance(pathList[nextPahtIndex - 1], pathList[nextPahtIndex]); if (turningSpeed <= 0) { rotateTowards(diff4Moving, true); } } } }
public void onFinishFire(bool needRelease) { if (needRelease) { isFireNow = false; stop(); } Utl.doCallback(onFinishCallback, this); }
/// <summary> /// Starts the GP. /// </summary> /// <returns>The GP.</returns> /// <param name="callback">Callback.</param> /// callback(errMsg, LocationInfo localInfor); /// LocationInfo /// 属性如下: /// (1) altitude -- 海拔高度 /// (2) horizontalAccuracy -- 水平精度 /// (3) latitude -- 纬度 /// (4) longitude -- 经度 /// (5) timestamp -- 最近一次定位的时间戳,从1970开始 /// (6) verticalAccuracy -- 垂直精度 public static IEnumerator StartGPS(float desired, object callback) { // Input.location 用于访问设备的位置属性(手持设备), 静态的LocationService位置 // LocationService.isEnabledByUser 用户设置里的定位服务是否启用 string errMsg = ""; if (!Input.location.isEnabledByUser) { errMsg = "isEnabledByUser value is:" + Input.location.isEnabledByUser.ToString() + " Please turn on the GPS"; } else { // LocationService.Start() 启动位置服务的更新,最后一个位置坐标会被使用 /*void Start(float desiredAccuracyInMeters = 10f, float updateDistanceInMeters = 10f); * 参数详解: * desiredAccuracyInMeters 服务所需的精度,以米为单位。如果使用较高的值,比如500,那么通常不需要打开GPS芯片(比如可以利用信号基站进行三角定位),从而节省电池电量。像5-10这样的值,可以被用来获得最佳的精度。默认值是10米。 * updateDistanceInMeters 最小距离(以米为单位)的设备必须横向移动前Input.location属性被更新。较高的值,如500意味着更少的开销。默认值是10米。 */ if (Input.location.status == LocationServiceStatus.Failed || Input.location.status == LocationServiceStatus.Stopped) { Input.location.Start(desired); int maxWait = 20; while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0) { // 暂停协同程序的执行(1秒) yield return(new WaitForSeconds(1)); maxWait--; } if (maxWait < 1) { errMsg = "Init GPS service time out"; } else if (Input.location.status == LocationServiceStatus.Failed) { errMsg = "Unable to determine device location"; } else { errMsg = ""; Debug.Log("--------N:" + Input.location.lastData.latitude + " E:" + Input.location.lastData.longitude); // yield return new WaitForSeconds(1); } } Debug.Log("======N:" + Input.location.lastData.latitude + " E:" + Input.location.lastData.longitude); // yield return new WaitForSeconds(1); } Utl.doCallback(callback, errMsg, Input.location.lastData); // StopGPS (); }
public override void OnClick() { try { if (onClickCallback != null) { Utl.doCallback(onClickCallback, this); } base.OnClick(); } catch (System.Exception e) { Debug.LogError(e); } }
static void checkVervers() { progress = 0; needUpgradeVerver.Clear(); isNeedUpgradePriority = false; string ver = null; ArrayList keysList = MapEx.keys2List(serververVer); int count = keysList.Count; string basePath = CLPathCfg.self.basePath; string key = ""; for (int i = 0; i < count; i++) { key = keysList[i] as string; ver = MapEx.getString(localverVer, key); //实际上这个时间localverVer是空的 if (ver == null || ver != MapEx.getString(serververVer, key)) { if (!key.Contains(PStr.b().a(basePath).a("/ui/panel").e()) && !key.Contains(PStr.b().a(basePath).a("/ui/cell").e()) && !key.Contains(PStr.b().a(basePath).a("/ui/other").e())) { MapEx.set(needUpgradeVerver, key, false); } } } keysList.Clear(); keysList = null; if (needUpgradeVerver.Count > 0) { if (progressCallback != null) { Utl.doCallback(progressCallback, needUpgradeVerver.Count, 0); } keysList = MapEx.keys2List(needUpgradeVerver); count = keysList.Count; key = ""; for (int i = 0; i < count; i++) { key = keysList[i] as string; getVerinfor(key, MapEx.getString(serververVer, key)); } keysList.Clear(); keysList = null; } else { loadPriorityVer(); loadOtherResVer(true); } }
static void onGetVerinfor(params object[] param) { byte[] content = param[0] as byte[]; object orgs = param[1]; if (content != null) { string fPath = orgs as string; progress = progress + 1; MapEx.set(localverVer, fPath, MapEx.getString(serververVer, fPath)); string fName = PStr.b().a(CLPathCfg.persistentDataPath).a("/").a(newestVerPath).a("/").a(fPath).e(); if (Path.GetFileName(fName) == "priority.ver") { //-- 优先更新需要把所有资源更新完后才记录 isNeedUpgradePriority = true; serverPriorityVer = CLVerManager.self.toMap(content); CLVerManager.self.localPriorityVer = serverPriorityVer; } else { otherResVerNew = CLVerManager.self.toMap(content); CLVerManager.self.otherResVerNew = otherResVerNew; } MapEx.set(needUpgradeVerver, fPath, true); if (progressCallback != null) { Utl.doCallback(progressCallback, needUpgradeVerver.Count, progress); } //-- if (isFinishAllGet()) then if (needUpgradeVerver.Count == progress) { if (!isNeedUpgradePriority) { //-- 说明没有优先资源需要更新,可以不做其它处理了 //--同步到本地 loadPriorityVer(); loadOtherResVer(true); } else { checkPriority(); //--处理优先资源更新 } } } else { initFailed(); } }