예제 #1
0
        /// <summary>
        /// 同步加载
        /// </summary>
        /// <param name="path">AssetPathManager.Instance.GetStreamAssetDataPath("csv/csvList.csv")</param>
        /// <param name="callBack"></param>
        /// <param name="errorCallBack"></param>
        public static void LoadAsset(string path, Action <UnityWebRequest> callBack, Action <UnityWebRequest> errorCallBack = null)
        {
            Uri uri = new Uri(path);

            LDebug.LogWarning(" >路径: \n AbsoluteUri : " + uri.AbsoluteUri + " \n AbsolutePath: " + uri.AbsolutePath + " \n LocalPath: " + uri.LocalPath);
            using (UnityWebRequest uwr = UnityWebRequest.Get(uri))
            {
                uwr.timeout = 3;
                uwr.disposeUploadHandlerOnDispose      = true;
                uwr.disposeDownloadHandlerOnDispose    = true;
                uwr.disposeCertificateHandlerOnDispose = true;

                uwr.SendWebRequest();

                while (true)
                {
                    if (uwr.isHttpError || uwr.isNetworkError)
                    {
                        LDebug.LogError("  >Error: " + uwr.error + " " + uwr.url);
                        errorCallBack?.Invoke(uwr);
                        return;
                    }
                    else if (uwr.downloadProgress == 1)
                    {
                        LDebug.Log(" >Received: \n" + uwr.downloadHandler.text);
                        callBack?.Invoke(uwr);
                        return;
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// 协程加载
        /// </summary>
        /// <param name="path">例如:AssetPathManager.Instance.GetStreamAssetDataPath("csv/csvList.csv")</param>
        /// <param name="callBack"></param>
        /// <param name="errorCallBack"></param>
        /// <returns></returns>
        public static IEnumerator ILoadAsset(string path, Action <string> callBack, Action <UnityWebRequest> errorCallBack = null)
        {
            Uri uri = new Uri(path);

            LDebug.LogWarning(" >路径: \n AbsoluteUri : " + uri.AbsoluteUri + " \n AbsolutePath: " + uri.AbsolutePath + " \n LocalPath: " + uri.LocalPath);
            using (UnityWebRequest uwr = UnityWebRequest.Get(uri))
            {
                uwr.timeout = 3;
                uwr.disposeUploadHandlerOnDispose      = true;
                uwr.disposeDownloadHandlerOnDispose    = true;
                uwr.disposeCertificateHandlerOnDispose = true;

                yield return(uwr.SendWebRequest());

                if (uwr.isNetworkError || uwr.isHttpError)
                {
                    LDebug.LogError("  >Error: " + uwr.error);
                    errorCallBack?.Invoke(uwr);
                }
                else
                {
                    callBack?.Invoke(uwr.downloadHandler.text);
                    //LDebug.Log( " >Received: \n" + uwr.downloadHandler.text );
                }
            }
        }
예제 #3
0
 /// <summary>
 /// 查找指定文件夹下指定后缀名的文件
 /// </summary>
 /// <param name="directory">文件夹</param>
 /// <param name="pattern">后缀名</param>
 /// <returns>文件路径</returns>
 private static void GetFiles(DirectoryInfo directory, string pattern, List <ABVersion> listwriter)
 {
     if (directory.Exists || pattern.Trim() != string.Empty)
     {
         try
         {
             foreach (FileInfo info in directory.GetFiles("*." + pattern))
             {
                 string realName = info.FullName.Replace("\\", "/");
                 realName = realName.Substring(realName.LastIndexOf("StreamingAssets") + "StreamingAssets".Length + 1);
                 if (listwriter.Any(e => e.AbName == realName))
                 {
                     LDebug.LogWarning($">>配置档 {realName} 重复录入。已忽略 ");
                     continue;
                 }
                 listwriter.Add(new ABVersion {
                     AbName = realName, MD5 = LitFramework.Crypto.Crypto.md5.GetFileHash(info.FullName), Version = 0
                 });
             }
         }
         catch (Exception ex)
         {
             Console.WriteLine(ex.ToString());
         }
         foreach (DirectoryInfo info in directory.GetDirectories()) //获取文件夹下的子文件夹
         {
             GetFiles(info, pattern, listwriter);                   //递归调用该函数,获取子文件夹下的文件
         }
     }
 }
예제 #4
0
        /// <summary>
        /// 保存截图 ,默认存储于TempPath
        /// </summary>
        /// <param name="targetCamera">目标摄像机</param>
        /// <param name="captureSize">截图尺寸</param>
        /// <param name="outPutName">文件名称</param>
        /// <param name="outPut">存储路径 - 外部输入格式: AssetPathManager.Instance.GetTemporaryCachePath( outPutName , false )</param>
        /// <param name="fixedSizeX">指定截图尺寸下的纵横像素值X</param>
        /// <param name="fixedSizeY">指定截图尺寸下的纵横像素值Y</param>
        public static Texture2D SaveCapture(Camera targetCamera, CaptureSize captureSize = CaptureSize.ScreenResolution, string outPutName = "cameraCapture.png", string outPut = "default", float fixedSizeX = 0f, float fixedSizeY = 0f)
        {
            Vector2 size = new Vector2(fixedSizeX, fixedSizeY);

            if (captureSize == CaptureSize.CameraSize)
            {
                size = new Vector2(targetCamera.pixelWidth, targetCamera.pixelHeight);
            }
            else if (captureSize == CaptureSize.ScreenResolution)
            {
                size = new Vector2(Screen.currentResolution.width, Screen.currentResolution.height);
            }
            else if (captureSize == CaptureSize.FixedSize)
            {
                if (size == Vector2.zero)
                {
                    size = new Vector2(Screen.currentResolution.width, Screen.currentResolution.height);
                    LDebug.LogWarning("[SaveCapture]当前截屏方式为CaptureSize.FixedSize,且未指定区域像素范围。采用当前屏幕分辨率横纵像素值!");
                }
            }
            string    path          = outPut.Equals("default")  ?AssetPathManager.Instance.GetTemporaryCachePath(outPutName, false) : outPut;
            Texture2D captureResult = Capture(targetCamera, ( int )size.x, ( int )size.y);

            SaveTexture(path, captureResult);

            return(captureResult);
        }
예제 #5
0
 /// <summary>
 /// 广播事件。推荐用于临时事件注册
 /// </summary>
 /// <param name="id">Event ID</param>
 /// <param name="msg">事件参数</param>
 public void Broadcast(string id, MsgArgs msg = null)
 {
     if (!_internalMsgTempleDict.ContainsKey(id))
     {
         LDebug.LogWarning("事件未注册:" + id.ToString()); return;
     }
     _internalMsgTempleDict[id].Invoke(msg);
     msg?.Dispose();
     msg = null;
 }
예제 #6
0
    /// <summary>
    /// 广播事件。统用枚举类
    /// </summary>
    /// <typeparam name="T">统用枚举类。可接受多种枚举。这里会转换为ushort类型。<em>通用枚举的转换,采用的是IConvertible.ToUInt16。中间借用了format涉及到了拆装箱,ID转换将会固定产生40B</em></typeparam>
    /// <param name="id">Event ID</param>
    /// <param name="msg">事件参数</param>
    public void Broadcast <T>(T id, MsgArgs msg = null) where T : IComparable, IConvertible, IFormattable
    {
        ushort idCode = id.ToUInt16(null);

        if (!_internalMsgDict.ContainsKey(idCode))
        {
            LDebug.LogWarning("事件未注册:" + id.ToString()); return;
        }
        _internalMsgDict[idCode].Invoke(msg);
        msg?.Dispose();
        msg = null;
    }
예제 #7
0
        public void Install()
        {
            _allRegisterUIDict  = new Dictionary <string, string>();
            _stackCurrentUI     = new Stack <BaseUI>();
            _dictLoadedAllUIs   = new Dictionary <string, BaseUI>();
            _dictCurrentShowUIs = new Dictionary <string, BaseUI>();

            TransRoot   = GameObject.FindGameObjectWithTag(UISysDefine.SYS_TAG_ROOTCANVAS).transform;
            TransNormal = UnityHelper.FindTheChildNode(TransRoot, UISysDefine.SYS_TAG_NORMALCANVAS);
            TransFixed  = UnityHelper.FindTheChildNode(TransRoot, UISysDefine.SYS_TAG_FIXEDCANVAS);
            TransPopUp  = UnityHelper.FindTheChildNode(TransRoot, UISysDefine.SYS_TAG_POPUPCANVAS);
            TransGlobal = UnityHelper.FindTheChildNode(TransRoot, UISysDefine.SYS_TAG_GLOBALCANVAS);

            RectransRoot   = TransRoot.GetComponent <RectTransform>();
            RectransNormal = TransNormal.GetComponent <RectTransform>();
            RectransFixed  = TransFixed.GetComponent <RectTransform>();
            RectransPopUp  = TransPopUp.GetComponent <RectTransform>();
            RectransGlobal = TransGlobal.GetComponent <RectTransform>();

            _fadeImage = UnityHelper.FindTheChildNode(TransGlobal, "Image_fadeBG").GetComponent <Image>();

            try
            {
                if (_fadeImage == null)
                {
                    LDebug.LogWarning("Image_fadeBG 未定义");
                }
                else if (!_fadeImage.gameObject.activeInHierarchy)
                {
                    LDebug.LogWarning("Image_fadeBG 未启用");
                }

                _fadeImage.raycastTarget = false;
                _fadeImage.gameObject.SetActive(true);
            }
            catch (Exception e)
            {
                LDebug.LogError("Image_fadeBG 错误");
            }

            //Mask蒙版初始化
            var ss = UIMaskManager.Instance;

            UICam        = UnityHelper.FindTheChildNode(TransRoot, "UICamera").GetComponent <Camera>();
            CanvasScaler = TransRoot.GetComponent <CanvasScaler>();
            GameObject.DontDestroyOnLoad(TransRoot.gameObject);

            AssemblyReflection();
        }
예제 #8
0
    /// <summary>
    /// 创建置灰材质球
    /// </summary>
    /// <returns></returns>
    private static Material GetGrayMat()
    {
        if (grayMat == null)
        {
            Shader shader = Resources.Load <Shader>("Shaders/UI/UIGrey");
            if (shader == null)
            {
                LDebug.LogWarning("未发现Shader Custom/UI-Gray");
                return(null);
            }
            Material mat = new Material(shader);
            grayMat = mat;
        }

        return(grayMat);
    }