Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (1)
Tags (27)
master
v2020.12.31
v2020.11.03
v2020.07.30
v2020.07.10
v2020.06.16
v2020.05.18
v2020.04.21
v2019.11.26
v2019.11.09
v2019.10.13
v2019.07.20
v2019.2.1
v2019.2.0
v2019.1.0
v3.1.8
v3.1.7
v3.1.6
v3.1.5
v3.1.4
v3.1.3
master
Branches (1)
Tags (27)
master
v2020.12.31
v2020.11.03
v2020.07.30
v2020.07.10
v2020.06.16
v2020.05.18
v2020.04.21
v2019.11.26
v2019.11.09
v2019.10.13
v2019.07.20
v2019.2.1
v2019.2.0
v2019.1.0
v3.1.8
v3.1.7
v3.1.6
v3.1.5
v3.1.4
v3.1.3
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (1)
Tags (27)
master
v2020.12.31
v2020.11.03
v2020.07.30
v2020.07.10
v2020.06.16
v2020.05.18
v2020.04.21
v2019.11.26
v2019.11.09
v2019.10.13
v2019.07.20
v2019.2.1
v2019.2.0
v2019.1.0
v3.1.8
v3.1.7
v3.1.6
v3.1.5
v3.1.4
v3.1.3
UnityGameFramework
/
Scripts
/
Runtime
/
FileSystem
/
AndroidFileSystemStream.cs
UnityGameFramework
/
Scripts
/
Runtime
/
FileSystem
/
AndroidFileSystemStream.cs
AndroidFileSystemStream.cs 9.84 KB
Copy Edit Raw Blame History
Jiang Yin authored 2021年03月08日 11:43 +08:00 . 兼容Unity2020.2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
//------------------------------------------------------------
// Game Framework
// Copyright © 2013-2021 Jiang Yin. All rights reserved.
// Homepage: https://gameframework.cn/
// Feedback: mailto:ellan@gameframework.cn
//------------------------------------------------------------
using GameFramework;
using GameFramework.FileSystem;
using System;
using System.IO;
using UnityEngine;
namespace UnityGameFramework.Runtime
{
/// <summary>
/// 安卓文件系统流。
/// </summary>
public sealed class AndroidFileSystemStream : FileSystemStream
{
private static readonly string SplitFlag = "!/assets/";
private static readonly int SplitFlagLength = SplitFlag.Length;
private static readonly AndroidJavaObject s_AssetManager = null;
private static readonly IntPtr s_InternalReadMethodId = IntPtr.Zero;
private static readonly jvalue[] s_InternalReadArgs = null;
private readonly AndroidJavaObject m_FileStream;
private readonly IntPtr m_FileStreamRawObject;
static AndroidFileSystemStream()
{
AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
if (unityPlayer == null)
{
throw new GameFrameworkException("Unity player is invalid.");
}
AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
if (currentActivity == null)
{
throw new GameFrameworkException("Current activity is invalid.");
}
AndroidJavaObject assetManager = currentActivity.Call<AndroidJavaObject>("getAssets");
if (assetManager == null)
{
throw new GameFrameworkException("Asset manager is invalid.");
}
s_AssetManager = assetManager;
IntPtr inputStreamClassPtr = AndroidJNI.FindClass("java/io/InputStream");
s_InternalReadMethodId = AndroidJNIHelper.GetMethodID(inputStreamClassPtr, "read", "([BII)I");
s_InternalReadArgs = new jvalue[3];
AndroidJNI.DeleteLocalRef(inputStreamClassPtr);
currentActivity.Dispose();
unityPlayer.Dispose();
}
/// <summary>
/// 初始化安卓文件系统流的新实例。
/// </summary>
/// <param name="fullPath">要加载的文件系统的完整路径。</param>
/// <param name="access">要加载的文件系统的访问方式。</param>
/// <param name="createNew">是否创建新的文件系统流。</param>
public AndroidFileSystemStream(string fullPath, FileSystemAccess access, bool createNew)
{
if (string.IsNullOrEmpty(fullPath))
{
throw new GameFrameworkException("Full path is invalid.");
}
if (access != FileSystemAccess.Read)
{
throw new GameFrameworkException(Utility.Text.Format("'{0}' is not supported in AndroidFileSystemStream.", access.ToString()));
}
if (createNew)
{
throw new GameFrameworkException("Create new is not supported in AndroidFileSystemStream.");
}
int position = fullPath.LastIndexOf(SplitFlag, StringComparison.Ordinal);
if (position < 0)
{
throw new GameFrameworkException("Can not find split flag in full path.");
}
string fileName = fullPath.Substring(position + SplitFlagLength);
m_FileStream = InternalOpen(fileName);
if (m_FileStream == null)
{
throw new GameFrameworkException(Utility.Text.Format("Open file '{0}' from Android asset manager failure.", fullPath));
}
m_FileStreamRawObject = m_FileStream.GetRawObject();
}
/// <summary>
/// 获取或设置文件系统流位置。
/// </summary>
protected override long Position
{
get
{
throw new GameFrameworkException("Get position is not supported in AndroidFileSystemStream.");
}
set
{
Seek(value, SeekOrigin.Begin);
}
}
/// <summary>
/// 获取文件系统流长度。
/// </summary>
protected override long Length
{
get
{
return InternalAvailable();
}
}
/// <summary>
/// 设置文件系统流长度。
/// </summary>
/// <param name="length">要设置的文件系统流的长度。</param>
protected override void SetLength(long length)
{
throw new GameFrameworkException("SetLength is not supported in AndroidFileSystemStream.");
}
/// <summary>
/// 定位文件系统流位置。
/// </summary>
/// <param name="offset">要定位的文件系统流位置的偏移。</param>
/// <param name="origin">要定位的文件系统流位置的方式。</param>
protected override void Seek(long offset, SeekOrigin origin)
{
if (origin == SeekOrigin.End)
{
Seek(Length + offset, SeekOrigin.Begin);
return;
}
if (origin == SeekOrigin.Begin)
{
InternalReset();
}
while (offset > 0)
{
long skip = InternalSkip(offset);
if (skip < 0)
{
return;
}
offset -= skip;
}
}
/// <summary>
/// 从文件系统流中读取一个字节。
/// </summary>
/// <returns>读取的字节,若已经到达文件结尾,则返回 -1。</returns>
protected override int ReadByte()
{
return InternalRead();
}
/// <summary>
/// 从文件系统流中读取二进制流。
/// </summary>
/// <param name="buffer">存储读取文件内容的二进制流。</param>
/// <param name="startIndex">存储读取文件内容的二进制流的起始位置。</param>
/// <param name="length">存储读取文件内容的二进制流的长度。</param>
/// <returns>实际读取了多少字节。</returns>
protected override int Read(byte[] buffer, int startIndex, int length)
{
byte[] result = null;
int bytesRead = InternalRead(length, out result);
Array.Copy(result, 0, buffer, startIndex, bytesRead);
return bytesRead;
}
/// <summary>
/// 向文件系统流中写入一个字节。
/// </summary>
/// <param name="value">要写入的字节。</param>
protected override void WriteByte(byte value)
{
throw new GameFrameworkException("WriteByte is not supported in AndroidFileSystemStream.");
}
/// <summary>
/// 向文件系统流中写入二进制流。
/// </summary>
/// <param name="buffer">存储写入文件内容的二进制流。</param>
/// <param name="startIndex">存储写入文件内容的二进制流的起始位置。</param>
/// <param name="length">存储写入文件内容的二进制流的长度。</param>
protected override void Write(byte[] buffer, int startIndex, int length)
{
throw new GameFrameworkException("Write is not supported in AndroidFileSystemStream.");
}
/// <summary>
/// 将文件系统流立刻更新到存储介质中。
/// </summary>
protected override void Flush()
{
throw new GameFrameworkException("Flush is not supported in AndroidFileSystemStream.");
}
/// <summary>
/// 关闭文件系统流。
/// </summary>
protected override void Close()
{
InternalClose();
m_FileStream.Dispose();
}
private AndroidJavaObject InternalOpen(string fileName)
{
return s_AssetManager.Call<AndroidJavaObject>("open", fileName);
}
private int InternalAvailable()
{
return m_FileStream.Call<int>("available");
}
private void InternalClose()
{
m_FileStream.Call("close");
}
private int InternalRead()
{
return m_FileStream.Call<int>("read");
}
private int InternalRead(int length, out byte[] result)
{
#if UNITY_2019_2_OR_NEWER
#pragma warning disable CS0618
#endif
IntPtr resultPtr = AndroidJNI.NewByteArray(length);
#if UNITY_2019_2_OR_NEWER
#pragma warning restore CS0618
#endif
int offset = 0;
int bytesLeft = length;
while (bytesLeft > 0)
{
s_InternalReadArgs[0] = new jvalue() { l = resultPtr };
s_InternalReadArgs[1] = new jvalue() { i = offset };
s_InternalReadArgs[2] = new jvalue() { i = bytesLeft };
int bytesRead = AndroidJNI.CallIntMethod(m_FileStreamRawObject, s_InternalReadMethodId, s_InternalReadArgs);
if (bytesRead <= 0)
{
break;
}
offset += bytesRead;
bytesLeft -= bytesRead;
}
#if UNITY_2019_2_OR_NEWER
#pragma warning disable CS0618
#endif
result = AndroidJNI.FromByteArray(resultPtr);
#if UNITY_2019_2_OR_NEWER
#pragma warning restore CS0618
#endif
AndroidJNI.DeleteLocalRef(resultPtr);
return offset;
}
private void InternalReset()
{
m_FileStream.Call("reset");
}
private long InternalSkip(long offset)
{
return m_FileStream.Call<long>("skip", offset);
}
}
}
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

Releases

No release

Contributors

All

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/linghanjunzi/UnityGameFramework.git
git@gitee.com:linghanjunzi/UnityGameFramework.git
linghanjunzi
UnityGameFramework
UnityGameFramework
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /