浏览代码

android unpack streaming asset

/siyaoH-1.17-PlatformMessage
siyao 4 年前
当前提交
e6ff42eb
共有 8 个文件被更改,包括 104 次插入7 次删除
  1. 4
      Samples/UIWidgetsSamples_2019_4/Assets/CountDemo.cs
  2. 13
      com.unity.uiwidgets/Runtime/engine2/UIWidgetsPanelWrapper.cs
  3. 2
      engine/Build.bee.cs
  4. 14
      engine/src/assets/directory_asset_bundle.cc
  5. 42
      com.unity.uiwidgets/Runtime/engine2/AndroidUnpackStreamingAsset.cs
  6. 3
      com.unity.uiwidgets/Runtime/engine2/AndroidUnpackStreamingAsset.cs.meta
  7. 17
      engine/src/shell/platform/unity/android_unpack_streaming_asset.cc
  8. 16
      engine/src/shell/platform/unity/android_unpack_streaming_asset.h

4
Samples/UIWidgetsSamples_2019_4/Assets/CountDemo.cs


using System.Collections.Generic;
using uiwidgets;
using Unity.UIWidgets.cupertino;
using Unity.UIWidgets.engine2;
using Unity.UIWidgets.ui;

child: new Column(children: new List<Widget>()
{
new Text($"count: {count}", style: new TextStyle(color: Color.fromARGB(255, 0 ,0 ,255))),
new Icon(CupertinoIcons.battery_charging, color: Colors.yellow),
new Text($"count: {count}", style: new TextStyle(fontFamily: "CupertixnoIcons", color: Color.fromARGB(255, 0 ,0 ,255))),
new Text($"count: {count}", style: new TextStyle(fontFamily: "CupertinoIcons", color: Color.fromARGB(255, 0 ,0 ,255))),
new CupertinoButton(
onPressed: () =>
{

13
com.unity.uiwidgets/Runtime/engine2/UIWidgetsPanelWrapper.cs


using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using AOT;
using Unity.UIWidgets.engine2;

using Unity.UIWidgets.ui;
using UnityEngine;
using Path = Unity.UIWidgets.ui.Path;
namespace Unity.UIWidgets.editor2 {

#region Platform: MacOs Specific Functionalities
#if (UNITY_EDITOR && UNITY_EDITOR_OSX) || UNITY_STANDALONE_OSX
#if (UNITY_EDITOR && UNITY_EDITOR_OSX) || UNITY_STANDALONE_OSX
public Texture renderTexture {
get { return _renderTexture; }
}

void _enableUIWidgetsPanel(string font_settings) {
UIWidgetsPanel_onEnable(_ptr, _renderTexture.GetNativeTexturePtr(),
_width, _height, _devicePixelRatio, Application.streamingAssetsPath, font_settings);
_width, _height, _devicePixelRatio, Application.temporaryCachePath, font_settings);
}
void _resizeUIWidgetsPanel() {

Dictionary<string, object> settings) {
D.assert(_renderTexture == null);
NativeConsole.OnEnable();
#if !UNITY_EDITOR && UNITY_ANDROID
AndroidUnpackStreamingAssets.OnEnable();
#endif
_enableUIWidgetsPanel(JSONMessageCodec.instance.toJson(settings));
}

2
engine/Build.bee.cs


"src/shell/platform/unity/gfx_worker_task_runner.h",
"src/shell/platform/unity/uiwidgets_system.h",
"src/shell/platform/unity/android_unpack_streaming_asset.cc",
"src/shell/platform/unity/android_unpack_streaming_asset.h",
"src/shell/platform/unity/unity_console.cc",
"src/shell/platform/unity/unity_console.h",

14
engine/src/assets/directory_asset_bundle.cc


#include "flutter/fml/file.h"
#include "flutter/fml/mapping.h"
#include "shell/platform/unity/android_unpack_streaming_asset.h"
namespace uiwidgets {
DirectoryAssetBundle::DirectoryAssetBundle(fml::UniqueFD descriptor)

// |AssetResolver|
std::unique_ptr<fml::Mapping> DirectoryAssetBundle::GetAsMapping(
const std::string& asset_name) const {
if (!is_valid_) {
const std::string &asset_name) const
{
if (!is_valid_)
{
#if __ANDROID__
bool success = AndroidUnpackStreamingAsset::Unpack(asset_name.c_str());
#endif
auto mapping = std::make_unique<fml::FileMapping>(fml::OpenFile(
descriptor_, asset_name.c_str(), false, fml::FilePermission::kRead));

return mapping;
}
} // namespace uiwidgets
} // namespace uiwidgets

42
com.unity.uiwidgets/Runtime/engine2/AndroidUnpackStreamingAsset.cs


using UnityEngine;
using AOT;
using System;
using System.IO;
using System.Runtime.InteropServices;
using NativeBindings = Unity.UIWidgets.ui.NativeBindings;
public static class AndroidUnpackStreamingAssets {
[DllImport(NativeBindings.dllName)]
internal static extern void InitUnpackFile(UnpackFileCallback unpack);
internal delegate bool UnpackFileCallback(string file);
[MonoPInvokeCallback(typeof(UnpackFileCallback))]
internal static bool unpackFile(string file) {
if (Application.platform == RuntimePlatform.Android) {
var dir = Application.temporaryCachePath + "/";
if (!File.Exists(dir + file)) {
WWW unpackerWWW = new WWW("jar:file://" + Application.dataPath + "!/assets/" + file);
while (!unpackerWWW.isDone) {
} // This will block in the webplayer.
if (!string.IsNullOrEmpty(unpackerWWW.error)) {
Debug.Log("Error unpacking 'jar:file://" + Application.dataPath + "!/assets/" + file +
"'");
dir = "";
return false;
}
File.WriteAllBytes(dir + file, unpackerWWW.bytes); // 64MB limit on File.WriteAllBytes.
}
return true;
}
return false;
}
public static void OnEnable()
{
InitUnpackFile(unpackFile);
}
}

3
com.unity.uiwidgets/Runtime/engine2/AndroidUnpackStreamingAsset.cs.meta


fileFormatVersion: 2
guid: 76a442e0d2934484b6b95ed3b22889f2
timeCreated: 1616467811

17
engine/src/shell/platform/unity/android_unpack_streaming_asset.cc


#include "android_unpack_streaming_asset.h"
#include <stdarg.h>
namespace uiwidgets {
bool AndroidUnpackStreamingAsset::Unpack(const char* file) {
return _unpack(file);
}
UnpackFileCallback AndroidUnpackStreamingAsset::_unpack;
UIWIDGETS_API(void)
InitUnpackFile(UnpackFileCallback _unpack) {
AndroidUnpackStreamingAsset::_unpack = _unpack;
}
}

16
engine/src/shell/platform/unity/android_unpack_streaming_asset.h


#pragma once
#include "runtime/mono_api.h"
namespace uiwidgets {
typedef bool (*UnpackFileCallback)(const char* file);
class AndroidUnpackStreamingAsset{
public:
static UnpackFileCallback _unpack;
static bool Unpack(const char* file);
};
} // namespace uiwidgets
正在加载...
取消
保存