浏览代码

screenshot & config font

/siyaoH-1.17-PlatformMessage
siyao 4 年前
当前提交
e916b0f8
共有 29 个文件被更改,包括 1370 次插入319 次删除
  1. 30
      Samples/UIWidgetsSamples_2019_4/Assets/TextTest.unity
  2. 220
      Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsExample.cs
  3. 6
      com.unity.uiwidgets/Editor/UIWidgetsPanelEditor.cs
  4. 2
      com.unity.uiwidgets/Runtime/async/coroutine.cs.meta
  5. 14
      com.unity.uiwidgets/Runtime/async/microtask_queue.cs.meta
  6. 2
      com.unity.uiwidgets/Runtime/async/timer.cs.meta
  7. 55
      com.unity.uiwidgets/Runtime/engine2/UIWidgetsPanel.cs
  8. 7
      com.unity.uiwidgets/Runtime/services/message_codecs.cs
  9. 1
      engine/src/common/settings.h
  10. 14
      engine/src/lib/ui/text/font_collection.cc
  11. 3
      engine/src/lib/ui/text/font_collection.h
  12. 22
      engine/src/shell/common/engine.cc
  13. 1
      engine/src/shell/platform/embedder/embedder.cc
  14. 1
      engine/src/shell/platform/embedder/embedder.h
  15. 37
      engine/src/shell/platform/unity/uiwidgets_panel.cc
  16. 3
      engine/src/shell/platform/unity/uiwidgets_panel.h
  17. 8
      Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets.meta
  18. 1001
      Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/CupertinoIcons.ttf
  19. 7
      Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/CupertinoIcons.ttf.meta
  20. 7
      Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/Ranchers-Regular.ttf.meta
  21. 7
      Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/Roboto-BlackItalic.ttf.meta
  22. 7
      Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/Roboto-Italic.ttf.meta
  23. 7
      Samples/UIWidgetsSamples_2019_4/Assets/TextTest.unity.meta
  24. 11
      Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsExample.cs.meta
  25. 11
      com.unity.uiwidgets/Runtime/material/colors.cs.meta
  26. 3
      com.unity.uiwidgets/Runtime/painting/inline_span.cs.meta
  27. 8
      com.unity.uiwidgets/Scripts/node_modules.meta
  28. 8
      com.unity.uiwidgets/StreamingAssets.meta
  29. 186
      Samples/UIWidgetsSamples_2019_4/Assets/TextTest.cs

30
Samples/UIWidgetsSamples_2019_4/Assets/TextTest.unity


m_Father: {fileID: 2122288190}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: -1.3, y: 0.8}
m_SizeDelta: {x: 483, y: 399}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &847097471
CanvasRenderer:

m_GameObject: {fileID: 847097468}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 84eecb3d75338e24185f4fcd9d813a55, type: 3}
m_Script: {fileID: 11500000, guid: 169ec79ce040653478e1a7725f34bbe1, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}

y: 0
width: 1
height: 1
fonts: []
fonts:
- family: racher
fonts:
- asset: Ranchers-Regular.ttf
weight: 0
- family: roboto
fonts:
- asset: Roboto-Italic.ttf
weight: 0
- asset: Roboto-BlackItalic.ttf
weight: 900
- family: CupertinoIcons
fonts:
- asset: CupertinoIcons.ttf
weight: 0
- family: robotox
fonts:
- asset: Roboto-Italic.ttf
weight: 0
devicePixelRatioOverride: 0
hardwareAntiAliasing: 0
--- !u!1 &1548023132

220
Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsExample.cs


 using System.Collections.Generic;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.engine;
using Unity.UIWidgets.engine2;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.material;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using UnityEngine;
using Color = Unity.UIWidgets.ui.Color;
using FontStyle = Unity.UIWidgets.ui.FontStyle;
using ui_ = Unity.UIWidgets.widgets.ui_;
using System.Collections.Generic;
using Unity.UIWidgets.engine2;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.material;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using TextStyle = Unity.UIWidgets.painting.TextStyle;
using ui_ = Unity.UIWidgets.widgets.ui_;
namespace UIWidgetsSample {
public class UIWidgetsExample : UIWidgetsPanel {
protected void OnEnable() {
// if you want to use your own font or font icons.
// FontManager.instance.addFont(Resources.Load<Font>(path: "path to your font"), "font family name");
namespace UIWidgetsSample
{
public class UIWidgetsExample : UIWidgetsPanel
{
protected void OnEnable()
{
base.OnEnable();
}
// load custom font with weight & style. The font weight & style corresponds to fontWeight, fontStyle of
// a TextStyle object
// FontManager.instance.addFont(Resources.Load<Font>(path: "path to your font"), "Roboto", FontWeight.w500,
// FontStyle.italic);
protected override void main()
{
ui_.runApp(new MyApp());
}
// add material icons, familyName must be "Material Icons"
// FontManager.instance.addFont(Resources.Load<Font>(path: "path to material icons"), "Material Icons");
base.OnEnable();
}
protected override void main()
{
ui_.runApp(new MyApp());
}
class MyApp : StatelessWidget
{
public override Widget build(BuildContext context)
{
return new WidgetsApp(
home: new ExampleApp(),
pageRouteBuilder: (settings, builder) =>
new PageRouteBuilder(
settings: settings,
pageBuilder: (Buildcontext, animation, secondaryAnimation) => builder(context)
)
);
}
}
class MyApp : StatelessWidget
{
public override Widget build(BuildContext context)
{
return new WidgetsApp(
home: new ExampleApp(),
pageRouteBuilder: (RouteSettings settings, WidgetBuilder builder) =>
new PageRouteBuilder(
settings: settings,
pageBuilder: (BuildContext Buildcontext, Animation<float> animation,
Animation<float> secondaryAnimation) => builder(context)
)
);
}
}
// protected override Widget createWidget() {
// return new WidgetsApp(
// home: new ExampleApp(),
// pageRouteBuilder: (RouteSettings settings, WidgetBuilder builder) =>
// new PageRouteBuilder(
// settings: settings,
// pageBuilder: (BuildContext context, Animation<float> animation,
// Animation<float> secondaryAnimation) => builder(context)
// )
// );
// }
class ExampleApp : StatefulWidget
{
public ExampleApp(Key key = null) : base(key)
{
}
class ExampleApp : StatefulWidget {
public ExampleApp(Key key = null) : base(key) {
}
public override State createState()
{
return new ExampleState();
}
}
public override State createState() {
return new ExampleState();
}
}
class ExampleState : State<ExampleApp>
{
int counter;
class ExampleState : State<ExampleApp> {
int counter = 0;
public override Widget build(BuildContext context)
{
return new Container(
color: Colors.green,
child: new Column(
children: new List<Widget>
{
new Text("Counter: " + counter,
style: new TextStyle(fontSize: 18, fontWeight: FontWeight.w100)),
new Text("Counter: " + counter,
style: new TextStyle(fontFamily: "racher", fontSize: 18, fontWeight: FontWeight.w100)),
new Text("Counter: " + counter,
style: new TextStyle(fontFamily: "roboto", fontSize: 18, fontWeight: FontWeight.w200)),
new Text("Counter: " + counter,
style: new TextStyle(fontFamily: "roboto", fontSize: 18, fontWeight: FontWeight.w300)),
new Text("Counter: " + counter,
style: new TextStyle(fontFamily: "roboto", fontSize: 18, fontWeight: FontWeight.w400)),
new Text("Counter: " + counter,
style: new TextStyle(fontFamily: "roboto", fontSize: 18, fontWeight: FontWeight.w500)),
new Text("Counter: " + counter,
style: new TextStyle(fontFamily: "roboto", fontSize: 18, fontWeight: FontWeight.w600)),
new Text("Counter: " + counter,
style: new TextStyle(fontFamily: "roboto", fontSize: 18, fontWeight: FontWeight.w700)),
new Text("Counter: " + counter,
style: new TextStyle(fontFamily: "roboto", fontSize: 18, fontWeight: FontWeight.w800)),
new Text("Counter: " + counter,
style: new TextStyle(fontFamily: "roboto", fontSize: 18, fontWeight: FontWeight.w900)),
new Text("Counter: " + counter,
style: new TextStyle(fontFamily: "roboto", fontSize: 18, fontWeight: FontWeight.w900,
fontStyle: FontStyle.italic)),
new Text("Counter: " + counter,
style: new TextStyle(fontFamily: "roboto", fontSize: 18, fontWeight: FontWeight.w100)),
new Text("Counter: " + counter,
style: new TextStyle(fontFamily: "roboto", fontSize: 18, fontWeight: FontWeight.w900)),
new Text("-----"),
new Text("Counter: " + counter,
style: new TextStyle(fontFamily: "robotox", fontSize: 18, fontWeight: FontWeight.w200)),
new Text("Counter: " + counter,
style: new TextStyle(fontFamily: "robotox", fontSize: 18, fontWeight: FontWeight.w300)),
new Text("Counter: " + counter,
style: new TextStyle(fontFamily: "robotox", fontSize: 18, fontWeight: FontWeight.w400)),
new Text("Counter: " + counter,
style: new TextStyle(fontFamily: "robotox", fontSize: 18, fontWeight: FontWeight.w500)),
new Text("Counter: " + counter,
style: new TextStyle(fontFamily: "robotox", fontSize: 18, fontWeight: FontWeight.w600)),
new Text("Counter: " + counter,
style: new TextStyle(fontFamily: "robotox", fontSize: 18, fontWeight: FontWeight.w700)),
new Text("Counter: " + counter,
style: new TextStyle(fontFamily: "robotox", fontSize: 18, fontWeight: FontWeight.w800)),
new Text("Counter: " + counter,
style: new TextStyle(fontFamily: "robotox", fontSize: 18, fontWeight: FontWeight.w900)),
new Text("Counter: " + counter,
style: new TextStyle(fontFamily: "robotox", fontSize: 18, fontWeight: FontWeight.w900,
fontStyle: FontStyle.italic)),
new Text("Counter: " + counter + (char) 0xf472 + (char) 0xf442 + (char) 0xf43b,
style: new TextStyle(fontFamily: "CupertinoIcons", fontSize: 18)),
public override Widget build(BuildContext context) {
return new Container(
color: Colors.green,
child: new Column(
children: new List<Widget> {
new Text("Counter: " + this.counter),
new GestureDetector(
onTap: () => {
this.setState(()
=> {
this.counter++;
});
},
child: new Container(
padding: EdgeInsets.symmetric(20, 20),
color: this.counter % 2 == 0 ? Colors.blue : Colors.red,
child: new Text("Click Me")
)
)
}
new GestureDetector(
onTap: () =>
{
setState(()
=>
{
counter++;
});
},
child: new Container(
padding: EdgeInsets.symmetric(20, 20),
color: counter % 2 == 0 ? Colors.blue : Colors.red,
child: new Text("Click Me",
style: new TextStyle(fontFamily: "racher", fontWeight: FontWeight.w100))
)
)
}
);
}
}
}
}
);
}
}
}
}

6
com.unity.uiwidgets/Editor/UIWidgetsPanelEditor.cs


using Unity.UIWidgets.engine2;
using UnityEditor;
using UnityEditor.UI;
using UnityEngine;
namespace Unity.UIWidgets.Editor {
[CustomEditor(typeof(UIWidgetsPanel), true)]

EditorGUILayout.PropertyField(pixelRatioProperty);
EditorGUILayout.PropertyField(antiAliasingProperty);
UIWidgetsPanel panel = (UIWidgetsPanel)target;
if (GUILayout.Button("Take Screenshot")) {
panel.TakeScreenshot();
}
serializedObject.ApplyModifiedProperties();
}
}

2
com.unity.uiwidgets/Runtime/async/coroutine.cs.meta


fileFormatVersion: 2
guid: edd74736642e341e29510a7e3dafb5f6
guid: e9bd0a7bbd499ef4a93eb37a4af67391
MonoImporter:
externalObjects: {}
serializedVersion: 2

14
com.unity.uiwidgets/Runtime/async/microtask_queue.cs.meta


fileFormatVersion: 2
guid: 6d95e65550134a478f8f77093fc6d6f1
timeCreated: 1535723558
fileFormatVersion: 2
guid: 009230d259197ba4ebf6f9590c8b6009
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

2
com.unity.uiwidgets/Runtime/async/timer.cs.meta


fileFormatVersion: 2
guid: 22e7b4cca5d354a4e9aa008cafcfdfe8
guid: 79d38f7d7b0725b4887dbc2f3ec30cee
MonoImporter:
externalObjects: {}
serializedVersion: 2

55
com.unity.uiwidgets/Runtime/engine2/UIWidgetsPanel.cs


using System.Runtime.InteropServices;
using AOT;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.services;
using Canvas = UnityEngine.Canvas;
public partial class UIWidgetsPanel : RawImage{
public partial class UIWidgetsPanel : RawImage {
public string path;
public string name;
public string family;
[SerializeField] public Font[] fonts;
[Serializable]
public struct Font {
public string asset;
public int weight;
}
static object fontsToObject(TextFont[] textFont) {
var result = new object[textFont.Length];
for (int i = 0; i < textFont.Length; i++) {
var font = new Dictionary<string, object>();
font.Add("family", textFont[i].family);
var dic = new Dictionary<string, object>[textFont[i].fonts.Length];
for (int j = 0; j < textFont[i].fonts.Length; j++) {
dic[j] = new Dictionary<string, object>();
if (textFont[i].fonts[j].asset.Length > 0) {
dic[j].Add("asset", textFont[i].fonts[j].asset);
}
if (textFont[i].fonts[j].weight > 0) {
dic[j].Add("weight", textFont[i].fonts[j].weight);
}
}
font.Add("fonts", dic);
result[i] = font;
}
return result;
}
public float devicePixelRatioOverride;
public float hardwareAntiAliasing;

// Texture texture {
// set { texture = value; }
// }
public static UIWidgetsPanel current {
get { return Window.instance._panel; }
}

_handle = GCHandle.Alloc(this);
_ptr = UIWidgetsPanel_constructor((IntPtr) _handle, UIWidgetsPanel_entrypoint);
var settings = new Dictionary<string, object>();
settings.Add("fonts", fontsToObject(fonts));
_width, _height, _devicePixelRatio, Application.streamingAssetsPath);
_width, _height, _devicePixelRatio, Application.streamingAssetsPath,
JSONMessageCodec.instance.toJson(settings));
Input_OnEnable();
}

}
protected override void OnRectTransformDimensionsChange() {
if (_ptr != IntPtr.Zero && _renderTexture) {
if (_ptr != IntPtr.Zero && _renderTexture) {
if (_recreateRenderTexture(_currentWidth, _currentHeight, _currentDevicePixelRatio)) {
UIWidgetsPanel_onRenderTexture(_ptr,
_renderTexture.GetNativeTexturePtr(),

[DllImport(NativeBindings.dllName)]
static extern void UIWidgetsPanel_onEnable(IntPtr ptr,
IntPtr nativeTexturePtr, int width, int height, float dpi, string streamingAssetsPath);
IntPtr nativeTexturePtr, int width, int height, float dpi, string streamingAssetsPath, string settings);
[DllImport(NativeBindings.dllName)]
static extern void UIWidgetsPanel_onDisable(IntPtr ptr);

UIWidgetsPanel_onMouseLeave(_ptr);
}
public void TakeScreenshot() {
UIWidgetsPanel_takeScreenShot(_ptr);
}
public void OnDrag(PointerEventData eventData) {
var pos = _getPointerPosition(Input.mousePosition);
if (pos == null) {

[DllImport(NativeBindings.dllName)]
static extern void UIWidgetsPanel_onMouseLeave(IntPtr ptr);
[DllImport(NativeBindings.dllName)]
static extern void UIWidgetsPanel_takeScreenShot(IntPtr ptr);
}
}

7
com.unity.uiwidgets/Runtime/services/message_codecs.cs


public static readonly JSONMessageCodec instance = new JSONMessageCodec();
public byte[] encodeMessage(object message) {
var json = toJson(message);
return StringCodec.instance.encodeMessage(json);
}
public string toJson(object message) {
return StringCodec.instance.encodeMessage(sb.ToString());
return sb.ToString();
}
public object decodeMessage(byte[] message) {

1
engine/src/common/settings.h


fml::UniqueFD::element_type assets_dir =
fml::UniqueFD::traits_type::InvalidValue();
std::string assets_path;
std::string font_data;
// Callback to handle the timings of a rasterized frame. This is called as
// soon as a frame is rasterized.

14
engine/src/lib/ui/text/font_collection.cc


#include "asset_manager_font_provider.h"
#include "lib/ui/ui_mono_state.h"
#include "lib/ui/window/window.h"
#include "rapidjson/document.h"
#include "rapidjson/rapidjson.h"
#include "txt/asset_font_manager.h"
#include "txt/test_font_manager.h"

return;
}
if (!document.IsArray()) {
return;
if (document.IsArray()) {
RegisterFonts(asset_manager, document.GetArray());
}
void FontCollection::RegisterFonts(
std::shared_ptr<AssetManager> asset_manager, rapidjson::Value::Array fonts) {
for (const auto& family : document.GetArray()) {
for (const auto& family : fonts) {
auto family_name = family.FindMember("family");
if (family_name == family.MemberEnd() || !family_name->value.IsString()) {
continue;

font_asset->value.GetString());
}
}
collection_->SetAssetFontManager(
sk_make_sp<txt::AssetFontManager>(std::move(font_provider)));
}

3
engine/src/lib/ui/text/font_collection.h


#include "flutter/fml/macros.h"
#include "flutter/fml/memory/ref_ptr.h"
#include "txt/font_collection.h"
#include "rapidjson/document.h"
#include "rapidjson/rapidjson.h"
namespace uiwidgets {

void SetupDefaultFontManager();
void RegisterFonts(std::shared_ptr<AssetManager> asset_manager);
void RegisterFonts(std::shared_ptr<AssetManager> asset_manager, rapidjson::Value::Array fonts);
void LoadFontFromList(const uint8_t* font_data, int length,
std::string family_name);

22
engine/src/shell/common/engine.cc


#include "flutter/fml/paths.h"
#include "flutter/fml/trace_event.h"
#include "flutter/fml/unique_fd.h"
#include "lib/ui/text/font_collection.h"
#include "lib/ui/text/font_collection.h"
#include "rapidjson/document.h"
#include "shell/common/animator.h"
#include "shell/common/platform_view.h"

if (!asset_manager_) {
return false;
}
//// Using libTXT as the text engine.
rapidjson::Document document;
document.Parse(settings_.font_data);
if (!document.HasParseError()) {
auto settings = document.GetObject();
auto fontSettings = settings.FindMember("fonts");
if (fontSettings != settings.MemberEnd() && fontSettings->value.IsArray()) {
rapidjson::Value::Array fontArray = fontSettings->value.GetArray();
font_collection_.RegisterFonts(asset_manager_, fontArray);
return true;
}
}
return true;
}

}
void Engine::SetupDefaultFontManager() {
TRACE_EVENT0("uiwidgets", "Engine::SetupDefaultFontManager");
font_collection_.SetupDefaultFontManager();
TRACE_EVENT0("uiwidgets", "Engine::SetupDefaultFontManager");
font_collection_.SetupDefaultFontManager();
}
Engine::RunStatus Engine::Run(RunConfiguration configuration) {

1
engine/src/shell/platform/embedder/embedder.cc


settings.icu_data_path = icu_data_path;
settings.icu_mapper = args->icu_mapper;
settings.assets_path = args->assets_path;
settings.font_data = args->font_asset;
settings.task_observer_add = [task_observer_add = args->task_observer_add,
user_data](intptr_t key,

1
engine/src/shell/platform/embedder/embedder.h


typedef struct {
size_t struct_size;
const char* assets_path;
const char* font_asset;
const char* icu_data_path;
uiwidgets::MappingCallback icu_mapper;
int command_line_argc;

37
engine/src/shell/platform/unity/uiwidgets_panel.cc


#include <Windows.h>
#include <flutter/fml/synchronization/waitable_event.h>
#include <include\utils\SkBase64.h>
#include <fstream>
#include "shell/platform/embedder/embedder_engine.h"
#include "shell/platform/embedder/embedder_engine.h"
#include "uiwidgets_system.h"
#include "unity_external_texture_gl.h"

void UIWidgetsPanel::OnEnable(void* native_texture_ptr, size_t width,
size_t height, float device_pixel_ratio,
const char* streaming_assets_path) {
const char* streaming_assets_path,
const char* settings) {
surface_manager_ = std::make_unique<UnitySurfaceManager>(
UIWidgetsSystem::GetInstancePtr()->GetUnityInterfaces());

args.struct_size = sizeof(UIWidgetsProjectArgs);
args.assets_path = streaming_assets_path;
args.font_asset = settings;
// std::string icu_path = std::string(streaming_assets_path) + "/icudtl.dat";
// args.icu_data_path = icu_path.c_str();

}
}
void UIWidgetsPanel::TakeScreenShot() {
if (process_events_) {
auto* engine = reinterpret_cast<EmbedderEngine*>(engine_);
Rasterizer::Screenshot screenshot = engine->GetShell().Screenshot(
Rasterizer::ScreenshotType::SkiaPicture, true);
const char* screenshot_char =
static_cast<const char*>(screenshot.data->data());
int size = screenshot.data->size();
SkBase64 temp;
temp.decode(screenshot_char, screenshot.data->size());
char* decoded = temp.getData();
std::ofstream myfile;
myfile.open("example.txt");
myfile.write(decoded, temp.getDataSize());
myfile.close();
}
}
UIWIDGETS_API(UIWidgetsPanel*)
UIWidgetsPanel_constructor(
Mono_Handle handle,

UIWIDGETS_API(void)
UIWidgetsPanel_onEnable(UIWidgetsPanel* panel, void* native_texture_ptr,
size_t width, size_t height, float device_pixel_ratio,
const char* streaming_assets_path) {
const char* streaming_assets_path,
const char* settings) {
streaming_assets_path);
streaming_assets_path, settings);
}
UIWIDGETS_API(void) UIWidgetsPanel_onDisable(UIWidgetsPanel* panel) {

UIWIDGETS_API(void)
UIWidgetsPanel_onMouseLeave(UIWidgetsPanel* panel) { panel->OnMouseLeave(); }
UIWIDGETS_API(void)
UIWidgetsPanel_takeScreenShot(UIWidgetsPanel* panel) {
panel->TakeScreenShot();
}
} // namespace uiwidgets

3
engine/src/shell/platform/unity/uiwidgets_panel.h


~UIWidgetsPanel();
void OnEnable(void* native_texture_ptr, size_t width, size_t height,
float device_pixel_ratio, const char* streaming_assets_path);
float device_pixel_ratio, const char* streaming_assets_path, const char* settings);
void MonoEntrypoint();

void OnMouseLeave();
void TakeScreenShot();
private:
UIWidgetsPanel(Mono_Handle handle, EntrypointCallback entrypoint_callback);

8
Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets.meta


fileFormatVersion: 2
guid: 0e116be5168fd954b911f42dfdd513e0
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

1001
Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/CupertinoIcons.ttf
文件差异内容过多而无法显示
查看文件

7
Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/CupertinoIcons.ttf.meta


fileFormatVersion: 2
guid: 1d9b44ef4202d544689bb9a8322eb32e
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

7
Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/Ranchers-Regular.ttf.meta


fileFormatVersion: 2
guid: e9d8d9b0e7292d944b164abae466da23
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

7
Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/Roboto-BlackItalic.ttf.meta


fileFormatVersion: 2
guid: e58e756ae69d77245ada723bd63636e8
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

7
Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/Roboto-Italic.ttf.meta


fileFormatVersion: 2
guid: bb7f0fe585121134387b937c917fcba9
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

7
Samples/UIWidgetsSamples_2019_4/Assets/TextTest.unity.meta


fileFormatVersion: 2
guid: c589e2cf933dc4042b07f7290e302402
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

11
Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsExample.cs.meta


fileFormatVersion: 2
guid: 169ec79ce040653478e1a7725f34bbe1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

11
com.unity.uiwidgets/Runtime/material/colors.cs.meta


fileFormatVersion: 2
guid: dfc0e036c07e1441d8dbd3158bb6f923
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

3
com.unity.uiwidgets/Runtime/painting/inline_span.cs.meta


fileFormatVersion: 2
guid: 575cf08436e24fa88feb437a5034d766
timeCreated: 1602582475

8
com.unity.uiwidgets/Scripts/node_modules.meta


fileFormatVersion: 2
guid: 7d3f82c412afe4d419f727fcdca86158
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

8
com.unity.uiwidgets/StreamingAssets.meta


fileFormatVersion: 2
guid: ab11c80750d2b144daf3455bc8ff7b19
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

186
Samples/UIWidgetsSamples_2019_4/Assets/TextTest.cs


using System;
using System.Collections.Generic;
using System.IO;
using Unity.UIWidgets.async2;
using Unity.UIWidgets.engine2;
using Unity.UIWidgets.ui;
using UnityEngine;
using Canvas = Unity.UIWidgets.ui.Canvas;
using Color = Unity.UIWidgets.ui.Color;
using Path = System.IO.Path;
using Rect = Unity.UIWidgets.ui.Rect;
class TextTest : UIWidgetsPanel
{
private bool check = true;
void beginFrame(TimeSpan timeStamp)
{
// The timeStamp argument to beginFrame indicates the timing information we
// should use to clock our animations. It's important to use timeStamp rather
// than reading the system time because we want all the parts of the system to
// coordinate the timings of their animations. If each component read the
// system clock independently, the animations that we processed later would be
// slightly ahead of the animations we processed earlier.
// PAINT
Rect paintBounds = Offset.zero & (Window.instance.physicalSize / Window.instance.devicePixelRatio);
PictureRecorder recorder = new PictureRecorder();
Canvas canvas = new Canvas(recorder, paintBounds);
canvas.translate(paintBounds.width / 2.0f, paintBounds.height / 2.0f);
// Here we determine the rotation according to the timeStamp given to us by
// the engine.
float t = (float) timeStamp.TotalMilliseconds / 1800.0f;
canvas.rotate(Mathf.PI * (t % 2.0f));
var paint = new Paint();
paint.color = Color.fromARGB(100, 100, 100, 0);
canvas.drawRect(Rect.fromLTRB(0, 0, 100.0f, 100.0f), paint);
Draw(canvas);
Picture picture = recorder.endRecording();
// COMPOSITE
float devicePixelRatio = Window.instance.devicePixelRatio;
var deviceTransform = new float[16];
deviceTransform[0] = devicePixelRatio;
deviceTransform[5] = devicePixelRatio;
deviceTransform[10] = 1.0f;
deviceTransform[15] = 1.0f;
SceneBuilder sceneBuilder = new SceneBuilder();
sceneBuilder.pushTransform(deviceTransform);
sceneBuilder.addPicture(Offset.zero, picture);
sceneBuilder.pop();
Window.instance.render(sceneBuilder.build());
// After rendering the current frame of the animation, we ask the engine to
// schedule another frame. The engine will call beginFrame again when its time
// to produce the next frame.
Window.instance.scheduleFrame();
}
void Draw(Canvas canvas)
{
if (check)
{
foreach (var font in fonts)
{
var path = Path.Combine(Application.streamingAssetsPath, font.path);
var fontFile = File.ReadAllBytes(path);
ui_.loadFontFromList(fontFile, font.name).then(value =>
{
Debug.Log("finish loading");
return FutureOr.nil;
});
}
check = false;
}
var style = new ParagraphStyle(
fontFamily: "Arial",
height: 4,
strutStyle: new StrutStyle(fontFamily: "ranchers",
fontFamilyFallback: new List<string>() {"Roboto-RegularB"},
fontSize: 30),
ellipsis: "and so on..."
);
var pb = new ParagraphBuilder(style);
pb.addText("just for testxxx\n");
var ts_roboto_regular = new TextStyle(
color: new Color(0xF000000F),
decoration: TextDecoration.lineThrough,
decorationStyle: TextDecorationStyle.doubleLine,
fontFamily: "Roboto-Regular",
fontFamilyFallback: new List<string>() {"ranchers"},
fontSize: 30,
height: 1.5f
);
pb.pushStyle(ts_roboto_regular);
pb.addText("just for test\n");
var ts_roboto_regular_bold = new TextStyle(
color: new Color(0xF000000F),
decoration: TextDecoration.lineThrough,
decorationStyle: TextDecorationStyle.doubleLine,
fontFamily: "Roboto-RegularB",
fontSize: 30,
height: 1.5f
);
pb.pushStyle(ts_roboto_regular_bold);
pb.addText("just for test\n");
var ts_rachers = new TextStyle(
color: new Color(0xF000000F),
decoration: TextDecoration.lineThrough,
decorationStyle: TextDecorationStyle.doubleLine,
fontFamily: "ranchers",
fontSize: 30,
height: 1.5f
);
pb.pushStyle(ts_rachers);
pb.addText("just for test\n");
var ts = new TextStyle(
color: new Color(0xFFFF00F0),
decoration: TextDecoration.lineThrough,
decorationStyle: TextDecorationStyle.doubleLine,
fontFamily: "Arial",
fontSize: 30,
height: 1.5f
);
pb.pushStyle(ts);
pb.addText("just for test\n 中文测试 分段测试 分段测试 分段测试 分段测试 分段测试 分段测试 分段测试\n1234");
var ts2 = new TextStyle(
decoration: TextDecoration.underline,
decorationStyle: TextDecorationStyle.dashed,
fontFamily: "Arial",
fontSize: 40,
height: 1.5f,
background: new Paint()
{
color = new Color(0xAAFF7F00),
},
foreground: new Paint()
{
color = new Color(0xAAFFFF00)
}
);
pb.pushStyle(ts2);
pb.addText("test push one more style");
pb.pop();
pb.addText("test pop style");
pb.addPlaceholder(10, 10, PlaceholderAlignment.baseline, TextBaseline.alphabetic);
var p = pb.build();
p.layout(new ParagraphConstraints(300));
var wordBoundary = p.getWordBoundary(new TextPosition(10));
Debug.Log(wordBoundary);
var positionForOffset = p.getPositionForOffset(new Offset(10, 1));
Debug.Log(positionForOffset);
var lineBoundary = p.getLineBoundary(new TextPosition(10));
Debug.Log(lineBoundary);
foreach (var textBox in p.getBoxesForPlaceholders())
{
Debug.Log($"{textBox.bottom} {textBox.direction} {textBox.left} {textBox.right}");
}
foreach (var textBox in p.getBoxesForRange(1, 20))
{
Debug.Log($"{textBox.bottom} {textBox.direction} {textBox.left} {textBox.right}");
}
foreach (var lineMetrics in p.computeLineMetrics())
{
Debug.Log($"{lineMetrics.height} {lineMetrics.lineNumber}");
}
canvas.drawParagraph(p, new Offset(-100, -100));
}
protected override void main()
{
Window.instance.onBeginFrame = beginFrame;
Window.instance.scheduleFrame();
}
}
正在加载...
取消
保存