/// <summary> /// 获取infomation中记录的版本号的数值大小 /// unitLength : 版本号以.分割的单个单位长度, 如0.0.100单位长度为3 /// </summary> public static int GetVersionValue(string versionStr, int unitLength) { int tempVersionValue = 0; if (string.IsNullOrEmpty(versionStr) == false) { try { string[] versionValues = versionStr.Split('.'); int tempValue; for (int i = 0, length = versionValues.Length; i < length; i++) { tempValue = int.Parse(versionValues[i]); if (0 != tempValue) { tempValue = tempValue * (int)Mathf.Pow(10, (length - 1 - i) * unitLength); } tempVersionValue += tempValue; } }catch (System.Exception e) { DYLogger.LogErrorFormat("Parse cache version failed!! Version text: {0}\nerr={1}", versionStr, e); } } return(tempVersionValue); }
public void DestroyUI <T>(T ui) where T : BaseUI { if (ui == null) { DYLogger.LogError("Destroy Fail!"); return; } ui.DestroyUI(); }
public void ShowUI(BaseUI ui, bool show, params object[] args) { if (ui == null) { DYLogger.LogError("ShowUI Fail!"); return; } ui.Show(show, args); }
//从bundle创建一个面板 public T CreateUIPrefab <T>(string bundleName, Transform parent) where T : MonoBehaviour { try { Object uipref = null; return(CreateUIPrefab <T>(uipref as GameObject, parent)); } catch (System.Exception ex) { DYLogger.Log("UIManager.CreateUIPrefab fail \n" + ex.Message); } return(null); }
private static void InitRandomNameConfig() { try{ //UnityEngine.Object configObj = ResourceManager.Instance.GetLoadedAsset(AssetBundleConst.kConfigRandomname, "randomName.bytes"); //TextAsset textObj = configObj as TextAsset; //_randomNameConfig = JsonMapper.ToObject(textObj.text); }catch (System.Exception e) { DYLogger.LogError(e); } }
public void SyncSortingLayer() { if (false == EnableSyncLayer) { return; } if (InheritedLayer) { Canvas parentCanvas = this.GetComponentInParent <Canvas>(); OverrideSortingLayerId = null != parentCanvas ? parentCanvas.sortingLayerID : SortingLayer.NameToID("Default"); OverrideSortingLayerName = SortingLayer.IDToName(OverrideSortingLayerId); } int sortingOrderValue = SortingOrder; if (SetSortingOrder && RelativeSortingOrder) { int baseSortingOrderValue = 0; Canvas[] parentCanvas = this.GetComponentsInParent <Canvas>(); Canvas tempCanvas; for (int i = 0, count = parentCanvas.Length; i < count; i++) { tempCanvas = parentCanvas[i]; if (tempCanvas.gameObject == this.gameObject) { continue; } if (false == tempCanvas.isRootCanvas && false == tempCanvas.overrideSorting) { continue; } if (false == tempCanvas.isRootCanvas && tempCanvas.sortingLayerID != OverrideSortingLayerId) { continue; } baseSortingOrderValue = tempCanvas.sortingOrder; break; } sortingOrderValue = baseSortingOrderValue + SortingOrder; } if (false == SortingLayer.IsValid(OverrideSortingLayerId)) { DYLogger.LogError("SyncSortingLayer fail, get unvalid sortinglayer " + OverrideSortingLayerName); return; } Util.SetGameObjectSortingLayer(this.gameObject, OverrideSortingLayerId, IgnoreHigherLayer, SetSortingOrder, sortingOrderValue, RaycastTarget); }
// protected Sequence _tweenSequence; protected override void Awake() { if (null == MainTweenWidget) { DYLogger.LogError("Try init DOTweenSequence Fail, need one specific main tween"); return; } CachedAsyncTweenWidget(); SetupSequence(AsyncTweenWidgets, SyncTweenWidgets, true); base.Awake(); }
public static string GetSystemCopyBuffer() { string result = ""; try { #if UNITY_ANDROID AndroidJavaClass tempAndroidClass = new AndroidJavaClass("com.util.copybuffer.ClipboardTools"); result = tempAndroidClass.CallStatic <string>("getTextFromClipboard"); #elif UNITY_IOS #else result = GUIUtility.systemCopyBuffer; #endif }catch (System.Exception e) { DYLogger.LogException(e); } return(result); }
public static void SetSystemCopyBuffer(string content) { if (string.IsNullOrEmpty(content)) { return; } try { #if UNITY_ANDROID AndroidJavaClass tempAndroidClass = new AndroidJavaClass("com.util.copybuffer.ClipboardTools"); tempAndroidClass.CallStatic("copyTextToClipboard", content); #elif UNITY_IOS && !UNITY_EDITOR _copyTextToClipboard(content); #else GUIUtility.systemCopyBuffer = content; #endif }catch (System.Exception e) { DYLogger.LogException(e); } }
public static string GetRandomName() { string result = ""; try{ JsonData surnameArray = _randomNameConfig["surname"]; JsonData firstNameArray = _randomNameConfig["firstName"]; JsonData firstNameRatio = _randomNameConfig["firstNameRatio"]; int firstNameRandomCount = 0; float firstNameRandomValue = Random.Range(0, 1.0f); double nextRatio = 0; for (int i = 0, count = firstNameRatio.Count; i < count; i++) { nextRatio += (double)(firstNameRatio[i]["ratio"]); if (firstNameRandomValue <= nextRatio) { firstNameRandomCount = (int)(firstNameRatio[i]["randomCount"]); break; } } if (0 != firstNameRandomValue) { string surname = surnameArray[Random.Range(0, surnameArray.Count)].ToString(); string firstName = ""; for (int i = 0; i < firstNameRandomCount; i++) { firstName += firstNameArray[Random.Range(0, firstNameArray.Count)].ToString(); } result = surname + firstName; } else { DYLogger.LogError("get firstName random count err! check the ratio please"); } }catch (System.Exception e) { DYLogger.LogError(e); } return(result); }
public static T Instantiate <T>(GameObject originObj, Transform parent) where T : Component { T result = null; if (null != originObj) { GameObject tempGO = Instantiate(originObj, parent); result = tempGO.GetComponent <T>(); } else { DYLogger.LogError("Util.Instantiate fail, prefab cannot be null"); } if (null == result) { DYLogger.LogError("Util.Instantiate fail, get component null, prefabName=" + originObj.name); } return(result); }
public static int GetDropdownOptionIndex(string itemStr, Dropdown dropDownWidget) { int result = 0; foreach (Dropdown.OptionData tempOptionData in dropDownWidget.options) { if (itemStr == tempOptionData.text) { break; } result++; } if (result == dropDownWidget.options.Count) { DYLogger.LogError("找不到对应的option: " + itemStr); result = dropDownWidget.value; } return(result); }
public static Texture2D CaptureScreenshot(List <Camera> cams) { if (null == cams || cams.Count == 0) { DYLogger.LogError("CaptureScreenshot fail!, render camera cannot be null!"); return(null); } RenderTexture rt = new RenderTexture(Screen.width, Screen.height, 16); RenderTexture oriRt = RenderTexture.active; Camera tempCam; cams.Sort(delegate(Camera x, Camera y) { if (x == null || y == null) { return(0); } return(x.depth.CompareTo(y.depth)); }); RenderTexture[] cachedOriginRTs = new RenderTexture[cams.Count]; for (int i = 0, count = cams.Count; i < count; i++) { tempCam = cams[i]; if (null == tempCam) { continue; } cachedOriginRTs[i] = tempCam.targetTexture; tempCam.targetTexture = rt; tempCam.Render(); } RenderTexture.active = rt; Texture2D t = new Texture2D(Screen.width, Screen.height); t.filterMode = FilterMode.Bilinear; t.anisoLevel = 1; t.wrapMode = TextureWrapMode.Clamp; t.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0); t.Apply(); for (int i = 0, count = cams.Count; i < count; i++) { tempCam = cams[i]; if (null == tempCam) { continue; } tempCam.targetTexture = cachedOriginRTs[i]; } RenderTexture.active = oriRt; return(t); }
protected virtual void SetupSequence(IDOTweenUtil[] asyncTweens, IDOTweenUtil[] syncTweens, bool isInit) { /* * if(null != _tweenSequence) _tweenSequence.Kill(); * * _tweenSequence = DOTween.Sequence(); * * IDOTweenUtil tween; * for(int i = 0, count = asyncTweens.Length; i<count; i++) * { * tween = asyncTweens[i]; * if(null == tween) continue; * tween.SetTarget(Target); * tween.SetResetOnDisable(false); * tween.SetAutoPlayOnEnable(false); * tween.ResetTween(); * _tweenSequence.Append(tween.GetTween()); * } * * _tweenSequence.OnComplete(OnSequenceCallback); * * if(null != syncTweens && syncTweens.Length > 0) * { * for(int i = 0, count = syncTweens.Length; i<count; i++) * { * tween = syncTweens[i]; * if(null == tween) continue; * tween.SetTarget(Target); * tween.SetResetOnDisable(false); * tween.SetAutoPlayOnEnable(false); * tween.ResetTween(); * } * } */ _tweenSequence.Clear(); _isPlaying = false; _playingTweenInSequeue = null; IDOTweenUtil tween; for (int i = 0, count = asyncTweens.Length; i < count; i++) { tween = asyncTweens[i]; if (null == tween) { continue; } if (tween == this) { DYLogger.LogError("Can not add self to sequence"); continue; } tween.SetTarget(Target); tween.SetResetOnDisable(false); tween.SetAutoPlayOnEnable(false); tween.ResetTween(); AppendTween(tween); } if (null != syncTweens && syncTweens.Length > 0) { for (int i = 0, count = syncTweens.Length; i < count; i++) { tween = syncTweens[i]; if (null == tween) { continue; } tween.SetTarget(Target); tween.SetResetOnDisable(false); tween.SetAutoPlayOnEnable(false); tween.ResetTween(); } } Pause(); }