コード例 #1
0
    static void CopyTableAndGenerateVersion()
    {
        //先把表格复制到持久化目录,然后生成版本控制文件,然后把bundle都压缩,最后把压缩文件,表格和version复制到流目录中
        string sourceTablePath = Application.streamingAssetsPath + "/res/DataTable";
        string destTablePath   = Application.persistentDataPath + "/res/DataTable";

        // 老的删掉
        DeleteAllFile(destTablePath);
        //老的version删掉
        if (File.Exists(ConstantVal.GetVersionStreamPath()))
        {
            File.Delete(ConstantVal.GetVersionStreamPath());
        }
        //复制表格
        CopyDirectory(new DirectoryInfo(sourceTablePath), new DirectoryInfo(destTablePath));
        List <FileInfo> fileList = GetFile(Application.persistentDataPath, new List <FileInfo>());

        Debug.Log(fileList);
        //打好的bundle包转移到持久化目录,生成版本控制文件
        GenerateTheVersion(Application.persistentDataPath + "/res");

        //把版本控制文件也放到streamingasset
        FileInfo fileInfo = new FileInfo(ConstantVal.GetVersionPersistentPath());

        fileInfo.CopyTo(ConstantVal.GetVersionStreamPath());
        //将打好的bundle包压缩后,和版本控制文件一起放到stramingasset
        Debug.Log("版本文件生成成功");
    }
コード例 #2
0
    /// <summary>
    /// 打开一个面板
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="parent">父对象</param>
    /// <param name="args">参数</param>
    public T OpenPanel <T>(Transform parent, params object[] args) where T : PanelBase
    {
        if (parent == null)
        {
            return(null);
        }

        string typeName = typeof(T).ToString();

        string path = ConstantVal.GetPanelPath(typeName);//mao 获取panel路径
        // GameObject plobj = GameObject.Instantiate<GameObject>(Resources.Load<GameObject>(path), parent);
        //ObjectPoolSingle res=ObjectPoolSingle.None;
        bool available = Enum.TryParse <ObjectPoolSingle>(typeName, out ObjectPoolSingle singleType);

        //res
        //ObjectPoolSingle singleType = (ObjectPoolSingle)Enum.Parse(typeof(ObjectPoolSingle), typeName);
        if (!available)
        {
            Debug.LogError("没有定义该类型的对象池枚举" + typeName);
        }
        GameObject plobj = ObjectPoolManager.Instance.GetObjcectFromPool(singleType, path, true);

        plobj.transform.SetParent(parent, false);
        plobj.name = typeName;
        T t = plobj.GetComponent <T>();

        if (null == t)
        {
            t = plobj.AddComponent <T>();
        }
        t.objType  = singleType;
        t.isTmpObj = true;
        t.obj      = plobj;
        t.Clear();
        t.Init(args);
        t.OnOpenIng();

        if (!panelDic.ContainsKey(singleType))
        {
            panelDic.Add(singleType, t);
        }

        if (!panelList.Contains(t))
        {
            panelList.Add(t);
        }
        return(t);
    }
コード例 #3
0
    /// <summary>
    /// 打开一个小面板
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="parent">父对象</param>
    /// <param name="args">参数</param>
    public T OpenSingle <T>(Transform parent, params object[] args) where T : SingleViewBase
    {
        if (parent == null)
        {
            Debug.Log("在无父物体的位置创建single!!!" + typeof(T).ToString());
        }
        //return null;



        string typeName = typeof(T).ToString();

        string path = ConstantVal.GetPanelPath(typeName);//mao 获取panel路径
        // GameObject plobj = GameObject.Instantiate<GameObject>(Resources.Load<GameObject>(path), parent);
        bool available = Enum.TryParse <ObjectPoolSingle>(typeName, out ObjectPoolSingle singleType);

        if (!available)
        {
            Debug.LogError("没有定义该类型的对象池枚举" + typeName);
        }
        GameObject plobj = ObjectPoolManager.Instance.GetObjcectFromPool(singleType, path, true);

        plobj.transform.SetParent(parent, false);
        plobj.name = typeName;
        T t = plobj.GetComponent <T>();

        if (null == t)
        {
            t = plobj.AddComponent <T>();
        }
        t.objType  = singleType;
        t.isTmpObj = true;
        t.obj      = plobj;
        t.Clear();
        t.Init(args);
        t.OnOpenIng();
        return(t);
    }
コード例 #4
0
ファイル: Game.cs プロジェクト: eterner2/-HighSchool
    /// <summary>
    /// 判断持久化目录有没有version,如果没有说明还没复制过, 把streamingasset的文件放到持久化目录
    /// </summary>
    IEnumerator CopyFromStreamToPersist(Action okCallBack)
    {
        //对比 流目录version/服务器version 若一样 则拷贝version和所有table到持久化目录,然后不需要任何下载 进游戏完事了


        //若流目录version和服务器version不一样 则直接对比持久化目录和服务器version(这里先做判断,如果持久化目录没有version,则将流目录的version和table全部放到持久化目录,再对比持久化目录version和服务器version下载))



        //FileInfo fileInfo = new FileInfo(PathConstant.GetVersionPersistentPath());
        //持久化目录里面没有,需要复制
        //if (!fileInfo.Exists)
        //{
        //先复制version 再复制version里面提到的
        FileInfo StreamfileInfo = new FileInfo(ConstantVal.GetVersionStreamPath());

        List <string> streamResPathList = new List <string>();//流目录下所有资源的位置
        //Debug.Log("尝试从流目录加载资源" + PathConstant.GetVersionStreamPath());
        WWW www = new WWW(ConstantVal.GetVersionStreamPath());

        yield return(www);

        if (www.isDone)
        {
            //Debug.Log("流目录加载version成功!");

            using (var reader = new StringReader(www.text))
            {
                //s = reader.ReadToEnd();

                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    var fields = line.Split(':');
                    if (fields.Length > 1)
                    {
                        streamResPathList.Add(fields[0]);
                    }
                }
            }
            //拷贝数据到指定路径
            File.WriteAllBytes(ConstantVal.GetVersionPersistentPath(), www.bytes);
            //Debug.Log("拷贝version到指定路径成功");
        }

        for (int i = 0; i < streamResPathList.Count; i++)
        {
            //这些path从version里面取
            string path = ConstantVal.GetFileInStreamPath(streamResPathList[i]);
            //"file://"+ Application.streamingAssetsPath + "/" + streamResPathList[i];
            string targetPath = Application.persistentDataPath + "/" + streamResPathList[i];

            DirectoryInfo info = new DirectoryInfo(Application.persistentDataPath + "/res/DataTable");
            if (!info.Exists)
            {
                Directory.CreateDirectory(Application.persistentDataPath + "/res/DataTable");

                // Debug.Log("创建datatable到持久化目录成功"+ Application.persistentDataPath + "/res/DataTable");
            }

            // Debug.Log("尝试从流目录加载" + path);

            WWW www2 = new WWW(path);
            //Debug.Log("流目录加载文件成功" + path);
            yield return(www2);

            if (www2.isDone)
            {
                // Debug.Log("拷贝数据到指定路径" + targetPath);

                //拷贝数据到指定路径
                //string path = Application.persistentDataPath + "/" + "map_data.db";
                File.WriteAllBytes(targetPath, www2.bytes);
            }
        }
        Debug.Log("所有文件加载成功!");
        //}
        //持久化目录有,不复制,直接用持久化目录的version
        //else
        //{
        //    FileInfo fileInfo3 = new FileInfo(PathConstant.GetVersionPersistentPath());
        //    if (fileInfo3.Exists)
        //    {
        //        StreamReader r = new StreamReader(PathConstant.GetVersionPersistentPath());
        //        s = r.ReadToEnd();
        //    }
        //}

        //暂时不用加载服务器versino
        // StartCoroutine(LoadVersions(s));

        if (okCallBack != null)
        {
            okCallBack();
        }
    }