浏览代码

ios keyboard

/main
fzhangtj 6 年前
当前提交
4bf67a5a
共有 20 个文件被更改,包括 1591 次插入151 次删除
  1. 14
      Runtime/editor/editor_window.cs
  2. 235
      Runtime/service/keyboard.cs
  3. 215
      Runtime/service/text_input.cs
  4. 2
      Runtime/service/text_input_utils.cs
  5. 4
      Runtime/ui/painting/canvas_impl.cs
  6. 1
      Runtime/ui/painting/txt/mesh_generator.cs
  7. 2
      Runtime/ui/window.cs
  8. 35
      Runtime/widgets/editable_text.cs
  9. 43
      Samples/UIWidgetSample/TextInput.unity
  10. 61
      Samples/UIWidgetSample/TextInputSample.cs
  11. 1
      UIWidgetCleanupPlugin.DotSettings
  12. 85
      Runtime/engine/UIWidgetsMessageManager.cs
  13. 11
      Runtime/engine/UIWidgetsMessageManager.cs.meta
  14. 8
      Runtime/external.meta
  15. 5
      Runtime/external/.editorconfig
  16. 8
      Runtime/external/simplejson.meta
  17. 1001
      Runtime/external/simplejson/SimpleJSON.cs
  18. 11
      Runtime/external/simplejson/SimpleJSON.cs.meta

14
Runtime/editor/editor_window.cs


readonly TimeSpan _epoch = new TimeSpan(Stopwatch.GetTimestamp());
readonly MicrotaskQueue _microtaskQueue = new MicrotaskQueue();
readonly TimerProvider _timerProvider = new TimerProvider();
readonly TextInput _textInput = new TextInput();
readonly Rasterizer _rasterizer = new Rasterizer();
readonly ScrollInput _scrollInput = new ScrollInput();

}
}
if (this._textInput != null) {
this._textInput.keyboardManager.OnGUI();
}
TextInput.OnGUI();
}
void _updateScrollInput() {

using (this.getScope()) {
this._updateScrollInput();
if (this._textInput != null) {
this._textInput.keyboardManager.Update();
}
TextInput.Update();
this._timerProvider.update(this.flushMicrotasks);
this.flushMicrotasks();
}

}
}
public override TextInput textInput {
get { return this._textInput; }
}
internal void _forceRepaint() {
using (this.getScope()) {
RenderObjectVisitor visitor = null;

235
Runtime/service/keyboard.cs


using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Unity.UIWidgets.engine;
using Unity.UIWidgets.external.simplejson;
using Unity.UIWidgets.foundation;
public class KeyboadManager {
interface KeyboardDelegate: IDisposable {
void show();
void hide();
void setEditingState(TextEditingValue value);
void setClient(int client, TextInputConfiguration configuration);
void clearClient();
bool hashPreview();
}
public interface TextInputUpdateListener {
void Update();
}
public interface TextInputOnGUIListener {
void OnGUI();
}
class DefaultKeyboardDelegate : KeyboardDelegate, TextInputOnGUIListener {
TextInputConfiguration _configuration;
TouchScreenKeyboard _keyboard;
RangeInt? _pendingSelection;
bool _screenKeyboardDone;
readonly TextInput _textInput;
public KeyboadManager(TextInput textInput) {
this._textInput = textInput;
public void show() {
public void Update() {
if (!TouchScreenKeyboard.isSupported) {
return;
}
public void hide() {
}
if (this._client == 0 || this._keyboard == null) {
return;
}
public void setEditingState(TextEditingValue value) {
this._value = value;
}
public void setClient(int client, TextInputConfiguration configuration) {
this._client = client;
}
if (this._keyboard.canSetSelection && this._pendingSelection != null) {
this._keyboard.selection = this._pendingSelection.Value;
this._pendingSelection = null;
}
public void clearClient() {
this._client = 0;
}
if (this._keyboard.status == TouchScreenKeyboard.Status.Done) {
if (!this._screenKeyboardDone) {
this._screenKeyboardDone = true;
Window.instance.run(() => {
this._textInput._performAction(this._client,
TextInputAction.done);
});
}
}
else if (this._keyboard.status == TouchScreenKeyboard.Status.Visible) {
var keyboardSelection = this._keyboard.selection;
var newValue = new TextEditingValue(
this._keyboard.text,
this._keyboard.canGetSelection
? new TextSelection(keyboardSelection.start, keyboardSelection.end)
: this._value.selection
);
var changed = this._value != newValue;
this._value = newValue;
if (changed) {
Window.instance.run(() => {
this._textInput._updateEditingState(this._client,
this._value);
});
}
}
public bool hashPreview() {
return false;
}
public void OnGUI() {

if (currentEvent != null && currentEvent.type == EventType.KeyDown) {
var action = TextInputUtils.getInputAction(currentEvent);
if (action != null) {
Window.instance.run(() => { this._textInput._performAction(this._client, action.Value); });
Window.instance.run(() => { TextInput._performAction(this._client, action.Value); });
Window.instance.run(() => { this._textInput._updateEditingState(this._client, this._value); });
Window.instance.run(() => { TextInput._updateEditingState(this._client, this._value); });
}
}

if (!string.IsNullOrEmpty(Input.compositionString) &&
this._lastCompositionString != Input.compositionString) {
this._value = this._value.compose(Input.compositionString);
Window.instance.run(() => { this._textInput._updateEditingState(this._client, this._value); });
Window.instance.run(() => { TextInput._updateEditingState(this._client, this._value); });
public void show() {
if (!TouchScreenKeyboard.isSupported) {
public void Dispose() {
}
}
class UnityTouchScreenKeyboardDelegate : KeyboardDelegate, TextInputUpdateListener {
int _client;
string _lastCompositionString;
TextInputConfiguration _configuration;
TextEditingValue _value;
TouchScreenKeyboard _keyboard;
RangeInt? _pendingSelection;
bool _screenKeyboardDone;
readonly TextInput _textInput;
public void Update() {
if (this._client == 0 || this._keyboard == null) {
if (this._keyboard.canSetSelection && this._pendingSelection != null) {
this._keyboard.selection = this._pendingSelection.Value;
this._pendingSelection = null;
}
if (this._keyboard.status == TouchScreenKeyboard.Status.Done) {
if (!this._screenKeyboardDone) {
this._screenKeyboardDone = true;
Window.instance.run(() => {
TextInput._performAction(this._client,
TextInputAction.done);
});
}
}
else if (this._keyboard.status == TouchScreenKeyboard.Status.Visible) {
var keyboardSelection = this._keyboard.selection;
var newValue = new TextEditingValue(
this._keyboard.text,
this._keyboard.canGetSelection
? new TextSelection(keyboardSelection.start, keyboardSelection.end)
: this._value.selection
);
var changed = this._value != newValue;
this._value = newValue;
if (changed) {
Window.instance.run(() => {
TextInput._updateEditingState(this._client,
this._value);
});
}
}
}
public void show() {
var secure = this._configuration.obscureText;
var multiline = this._configuration.inputType == TextInputType.multiline;
var autocorrection = this._configuration.autocorrect;

this._client = 0;
}
public bool hashPreview() {
return this._keyboard != null;
}
public void setClient(int client, TextInputConfiguration configuration) {
this._client = client;
this._configuration = configuration;

}
}
}
public bool textInputOnKeyboard() {
return TouchScreenKeyboard.isSupported;
}
static TouchScreenKeyboardType getKeyboardTypeForConfiguration(TextInputConfiguration config) {
var inputType = config.inputType;

return TouchScreenKeyboardType.Default;
}
public void Dispose() {
}
#if UNITY_IOS || UNITY_ANDROID
class UIWidgetsTouchScreenKeyboardDelegate : KeyboardDelegate {
public UIWidgetsTouchScreenKeyboardDelegate() {
UIWidgetsMessageManager.instance.AddChannelMessageDelegate("TextInput", this.handleMethodCall);
}
public void Dispose() {
UIWidgetsMessageManager.instance.RemoveChannelMessageDelegate("TextInput", this.handleMethodCall);
}
public void show() {
UIWidgetsTextInputShow();
}
public void hide() {
UIWidgetsTextInputHide();
}
public void setEditingState(TextEditingValue value) {
UIWidgetsTextInputSetTextInputEditingState(value.toJson().ToString());
}
public void setClient(int client, TextInputConfiguration configuration) {
UIWidgetsTextInputSetClient(client, configuration.toJson().ToString());
}
public void clearClient() {
UIWidgetsTextInputClearTextInputClient();
}
public bool hashPreview() {
return false;
}
void handleMethodCall(string method, List<JSONNode> args) {
if (TextInput._currentConnection == null) {
return;
}
int client = args[0].AsInt;
if (client != TextInput._currentConnection._id) {
return;
}
using (TextInput._currentConnection._window.getScope()) {
switch (method) {
case "TextInputClient.updateEditingState":
TextInput._updateEditingState(client, TextEditingValue.fromJson(args[1].AsObject));
break;
case "TextInputClient.performAction":
TextInput._performAction(client, TextInputUtils._toTextInputAction(args[1].Value));
break;
default:
throw new UIWidgetsError($"unknown method ${method}");
}
}
}
[DllImport ("__Internal")]
internal static extern float UIWidgetsTextInputShow();
[DllImport ("__Internal")]
internal static extern float UIWidgetsTextInputHide();
[DllImport ("__Internal")]
internal static extern float UIWidgetsTextInputSetClient(int client, string configuration);
[DllImport ("__Internal")]
internal static extern float UIWidgetsTextInputSetTextInputEditingState(string jsonText); // also send to client ?
[DllImport ("__Internal")]
internal static extern float UIWidgetsTextInputClearTextInputClient();
#endif
}
}

215
Runtime/service/text_input.cs


using System;
using System.Collections.Generic;
using Unity.UIWidgets.external.simplejson;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.ui;
using UnityEngine;

"text", "multiline", "number", "phone", "datetime", "emailAddress", "url"
};
public Dictionary<string, object> toJson() {
return new Dictionary<string, object>() {
{"name", this._name},
{"signed", this.signed},
{"decimal", this.decimalNum}
};
public JSONNode toJson() {
JSONObject jsonObject = new JSONObject();
jsonObject["name"] = this._name;
jsonObject["signed"] = this.signed;
jsonObject["decimal"] = this.decimalNum;
return jsonObject;
}
string _name {

}
}
static partial class TextInputUtils {
internal static TextAffinity? _toTextAffinity(string affinity) {
switch (affinity) {
case "TextAffinity.downstream":
return TextAffinity.downstream;
case "TextAffinity.upstream":
return TextAffinity.upstream;
}
return null;
}
internal static TextInputAction _toTextInputAction(string action) {
switch (action) {
case "TextInputAction.none":
return TextInputAction.none;
case "TextInputAction.unspecified":
return TextInputAction.unspecified;
case "TextInputAction.go":
return TextInputAction.go;
case "TextInputAction.search":
return TextInputAction.search;
case "TextInputAction.send":
return TextInputAction.send;
case "TextInputAction.next":
return TextInputAction.next;
case "TextInputAction.previuos":
return TextInputAction.previous;
case "TextInputAction.continue_action":
return TextInputAction.continueAction;
case "TextInputAction.join":
return TextInputAction.join;
case "TextInputAction.route":
return TextInputAction.route;
case "TextInputAction.emergencyCall":
return TextInputAction.emergencyCall;
case "TextInputAction.done":
return TextInputAction.done;
case "TextInputAction.newline":
return TextInputAction.newline;
}
throw new UIWidgetsError("Unknown text input action: $action");
}
}
static JSONNode defaultIndexNode = new JSONNumber(-1);
public TextEditingValue(string text = "", TextSelection selection = null, TextRange composing = null) {
this.text = text;
this.selection = selection ?? TextSelection.collapsed(-1);

public static TextEditingValue fromJson(JSONObject json) {
TextAffinity? affinity =
TextInputUtils._toTextAffinity(json["selectionAffinity"].Value);
return new TextEditingValue(
text: json["text"].Value,
selection: new TextSelection(
baseOffset: json.GetValueOrDefault("selectionBase", defaultIndexNode).AsInt,
extentOffset: json.GetValueOrDefault("selectionExtent", defaultIndexNode).AsInt,
affinity: affinity != null ? affinity.Value : TextAffinity.downstream,
isDirectional: json["selectionIsDirectional"].AsBool
),
composing: new TextRange(
start: json.GetValueOrDefault("composingBase", defaultIndexNode).AsInt,
end: json.GetValueOrDefault("composingExtent", defaultIndexNode).AsInt
)
);
}
public TextEditingValue copyWith(string text = null, TextSelection selection = null,
TextRange composing = null) {
return new TextEditingValue(

public override string ToString() {
return $"Text: {this.text}, Selection: {this.selection}, Composing: {this.composing}";
}
public JSONNode toJson() {
var json = new JSONObject();
json["text"] = this.text;
json["selectionBase"] = this.selection.baseOffset;
json["selectionExtent"] = this.selection.extentOffset;
json["selectionAffinity"] = this.selection.affinity.ToString();
json["selectionIsDirectional"] = this.selection.isDirectional;
json["composingBase"] = this.composing.start;
json["composingExtent"] = this.composing.end;
return json;
}
}
public interface TextSelectionDelegate {

scrollPageDown,
}
public class TextInputConfiguration {
class TextInputConfiguration {
bool obscureText = false, bool autocorrect = true, TextInputAction inputAction = TextInputAction.done) {
bool obscureText = false, bool autocorrect = true, TextInputAction inputAction = TextInputAction.done,
bool unityTouchKeyboard = false) {
this.unityTouchKeyboard = unityTouchKeyboard;
}
public readonly TextInputType inputType;

public readonly bool unityTouchKeyboard;
public Dictionary<string, object> toJson() {
return new Dictionary<string, object>() {
{"inputType", this.inputType.toJson()},
{"obscureText", this.obscureText},
{"autocorrect", this.autocorrect},
{"inputAction", this.inputAction.ToString()}
};
public JSONNode toJson() {
var json = new JSONObject();
json["inputType"] = this.inputType.toJson();
json["obscureText"] = this.obscureText;
json["autocorrect"] = this.autocorrect;
json["inputAction"] = $"TextInputAction.{this.inputAction.ToString()}";
json["unityTouchKeyboard"] = this.unityTouchKeyboard;
return json;
internal TextInputConnection(TextInputClient client, TextInput textInput) {
internal TextInputConnection(TextInputClient client) {
D.assert(textInput != null);
this._window = Window.instance;
this._textInput = textInput;
get { return this._textInput._currentConnection == this; }
get { return TextInput._currentConnection == this; }
this._textInput.keyboardManager.setEditingState(value);
TextInput.keyboardDelegate.setEditingState(value);
this._textInput.setCompositionCursorPos(x, y);
TextInput.setCompositionCursorPos(x, y);
this._textInput.keyboardManager.clearClient();
this._textInput._currentConnection = null;
TextInput.keyboardDelegate.clearClient();
TextInput._currentConnection = null;
this._textInput._scheduleHide();
TextInput._scheduleHide();
}
D.assert(!this.attached);

D.assert(this.attached);
Input.imeCompositionMode = IMECompositionMode.On;
this._textInput.keyboardManager.show();
TextInput.keyboardDelegate.show();
internal readonly TextInput _textInput;
internal readonly Window _window;
public class TextInput {
internal TextInputConnection _currentConnection;
class TextInput {
static internal TextInputConnection _currentConnection;
public readonly KeyboadManager keyboardManager;
static internal KeyboardDelegate keyboardDelegate;
this.keyboardManager = new KeyboadManager(this);
public TextInputConnection attach(TextInputClient client, TextInputConfiguration configuration) {
public static TextInputConnection attach(TextInputClient client, TextInputConfiguration configuration) {
var connection = new TextInputConnection(client, this);
this.keyboardManager.setClient(connection._id, configuration);
this._currentConnection = connection;
var connection = new TextInputConnection(client);
_currentConnection = connection;
string x = configuration.toJson();
if (keyboardDelegate != null) {
keyboardDelegate.Dispose();
}
if (TouchScreenKeyboard.isSupported) {
#if UNITY_IOS || UNITY_ANDROID
if (configuration.unityTouchKeyboard) {
keyboardDelegate = new UnityTouchScreenKeyboardDelegate();
}
else {
keyboardDelegate = new UIWidgetsTouchScreenKeyboardDelegate();
}
#else
keyboardDelegate = new UnityTouchScreenKeyboardDelegate();
#endif
}
else {
keyboardDelegate = new DefaultKeyboardDelegate();
}
keyboardDelegate.setClient(connection._id, configuration);
public void setCompositionCursorPos(float x, float y) {
internal static void Update() {
if (_currentConnection != null && _currentConnection._window == Window.instance) {
(keyboardDelegate as TextInputUpdateListener)?.Update();
}
}
internal static void OnGUI() {
if (_currentConnection != null && _currentConnection._window == Window.instance) {
(keyboardDelegate as TextInputOnGUIListener)?.OnGUI();
}
}
public static void setCompositionCursorPos(float x, float y) {
internal void _updateEditingState(int client, TextEditingValue value) {
if (this._currentConnection == null) {
internal static void _updateEditingState(int client, TextEditingValue value) {
if (_currentConnection == null) {
if (client != this._currentConnection._id) {
if (client != _currentConnection._id) {
this._currentConnection._client.updateEditingValue(value);
_currentConnection._client.updateEditingValue(value);
internal void _performAction(int client, TextInputAction action) {
if (this._currentConnection == null) {
internal static void _performAction(int client, TextInputAction action) {
if (_currentConnection == null) {
if (client != this._currentConnection._id) {
if (client != _currentConnection._id) {
this._currentConnection._client.performAction(action);
_currentConnection._client.performAction(action);
bool _hidePending = false;
static bool _hidePending = false;
internal void _scheduleHide() {
if (this._hidePending) {
static internal void _scheduleHide() {
if (_hidePending) {
this._hidePending = true;
_hidePending = true;
this._hidePending = false;
if (this._currentConnection == null) {
this.keyboardManager.hide();
_hidePending = false;
if (_currentConnection == null) {
keyboardDelegate.hide();
}
}
}
}

2
Runtime/service/text_input_utils.cs


using UnityEngine;
namespace Unity.UIWidgets.service {
public class TextInputUtils {
static partial class TextInputUtils {
static Dictionary<Event, TextInputAction> _keyToOperations;
public static TextInputAction? getInputAction(Event evt) {

4
Runtime/ui/painting/canvas_impl.cs


if (cmd.textMesh != null) {
mesh = cmd.textMesh.resovleMesh();
}
if (mesh == null) {
continue;
}
cmd.meshObj.SetVertices(mesh.vertices);
cmd.meshObj.SetTriangles(mesh.triangles, 0, false);

1
Runtime/ui/painting/txt/mesh_generator.cs


}
if (vertices.Count == 0) {
this._mesh = null;
return null;
}

2
Runtime/ui/window.cs


public abstract Timer runInMain(Action callback);
public abstract TextInput textInput { get; }
public abstract IDisposable getScope();
}
}

35
Runtime/widgets/editable_text.cs


using Unity.UIWidgets.scheduler;
using Unity.UIWidgets.service;
using Unity.UIWidgets.ui;
using UnityEngine;
using Color = Unity.UIWidgets.ui.Color;
using Rect = Unity.UIWidgets.ui.Rect;
using TextStyle = Unity.UIWidgets.painting.TextStyle;
namespace Unity.UIWidgets.widgets {

public readonly List<TextInputFormatter> inputFormatters;
public readonly bool rendererIgnoresPointer;
public readonly bool unityTouchKeyboard;
public EditableText(TextEditingController controller, FocusNode focusNode, TextStyle style,
Color cursorColor, bool obscureText = false, bool autocorrect = false,

ValueChanged<string> onChanged = null, VoidCallback onEditingComplete = null,
ValueChanged<string> onSubmitted = null, SelectionChangedCallback onSelectionChanged = null,
List<TextInputFormatter> inputFormatters = null, bool rendererIgnoresPointer = false,
EdgeInsets scrollPadding = null,
EdgeInsets scrollPadding = null, bool unityTouchKeyboard = false,
Key key = null) : base(key) {
D.assert(controller != null);
D.assert(focusNode != null);

this.onEditingComplete = onEditingComplete;
this.rendererIgnoresPointer = rendererIgnoresPointer;
this.selectionControls = selectionControls;
this.unityTouchKeyboard = unityTouchKeyboard;
if (maxLines == 1) {
this.inputFormatters = new List<TextInputFormatter>();
this.inputFormatters.Add(BlacklistingTextInputFormatter.singleLineFormatter);

this._hideSelectionOverlayIfNeeded();
this._showCaretOnScreen();
if (this.widget.obscureText && value.text.Length == this._value.text.Length + 1) {
this._obscureShowCharTicksPending = _kObscureShowLatestCharCursorTicks;
this._obscureShowCharTicksPending = !this._unityKeyboard() ? _kObscureShowLatestCharCursorTicks : 0;
this._obscureLatestCharIndex = this._value.selection.baseOffset;
}
}

get { return this._textInputConnection != null && this._textInputConnection.attached; }
}
this._textInputConnection = Window.instance.textInput.attach(this, new TextInputConfiguration(
this._textInputConnection = TextInput.attach(this, new TextInputConfiguration(
: TextInputAction.done)
: TextInputAction.done),
unityTouchKeyboard: this.widget.unityTouchKeyboard
));
this._textInputConnection.setEditingState(localValue);
}

this._hideSelectionOverlayIfNeeded();
if (this.widget.selectionControls != null) {
if (this.widget.selectionControls != null && !this._unityKeyboard()) {
this._selectionOverlay = new TextSelectionOverlay(
context: this.context,
value: this._value,

}
void _cursorTick() {
this._showCursor.value = !this._showCursor.value;
this._showCursor.value = !this._unityKeyboard() && !this._showCursor.value;
if (this._obscureShowCharTicksPending > 0) {
this.setState(() => { this._obscureShowCharTicksPending--; });
}

this._showCursor.value = true;
this._showCursor.value = !this._unityKeyboard();
this._cursorTimer = Window.instance.run(_kCursorBlinkHalfPeriod, this._cursorTick,
periodic: true);
}

}
void _startOrStopCursorTimerIfNeeded() {
if (this._cursorTimer == null && this._hasFocus && this._value.selection.isCollapsed &&
!Window.instance.textInput.keyboardManager.textInputOnKeyboard()) {
if (this._cursorTimer == null && this._hasFocus && this._value.selection.isCollapsed) {
this._startCursorTimer();
}
else if (this._cursorTimer != null && (!this._hasFocus || !this._value.selection.isCollapsed)) {

if (this.widget.obscureText) {
text = new string(RenderEditable.obscuringCharacter, text.Length);
int o = this._obscureShowCharTicksPending > 0 ? this._obscureLatestCharIndex : -1;
if (!Window.instance.textInput.keyboardManager.textInputOnKeyboard() && o >= 0 && o < text.Length) {
if (o >= 0 && o < text.Length) {
text = text.Substring(0, o) + this._value.text.Substring(o, 1) + text.Substring(o + 1);
}
}

}
// unity keyboard has a preview view with editing function, text selection & cursor function of this widget is disable
// in the case
bool _unityKeyboard() {
return TouchScreenKeyboard.isSupported && this.widget.unityTouchKeyboard;
}
}
class _Editable : LeafRenderObjectWidget {
public readonly TextSpan textSpan;

43
Samples/UIWidgetSample/TextInput.unity


m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1777916081}
m_CullTransparentMesh: 0
--- !u!1 &1829967422
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1829967424}
- component: {fileID: 1829967423}
m_Layer: 0
m_Name: messageManager
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1829967423
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1829967422}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: efd031068fc9d41d6b4c165afaaa25ba, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!4 &1829967424
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1829967422}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

61
Samples/UIWidgetSample/TextInputSample.cs


}
}
public class EditableInputTypeWidget : StatelessWidget {
public class EditableInputTypeWidget : StatefulWidget {
public EditableInputTypeWidget(Key key = null) : base(key) {
}
public override State createState() {
return new _EditableInputTypeWidgetState();
}
}
class _EditableInputTypeWidgetState : State<EditableInputTypeWidget> {
bool unityKeyboard = false;
Widget rowWidgets(string title, Widget widget) {
return new Container(
height: 80,

}
));
}
public override Widget build(BuildContext context) {
List<Widget> widgets = new List<Widget>();
List<Widget> buildInputs(bool unityKeyboard) {
List<Widget> widgets = new List<Widget>();
new EditableText(controller, node, style, cursorColor, selectionColor: selectionColor, onSubmitted: this.textSubmitted)))));
new EditableText(controller, node, style, cursorColor, selectionColor: selectionColor, onSubmitted: this.textSubmitted
, unityTouchKeyboard: unityKeyboard, selectionControls: MaterialUtils.materialTextSelectionControls)))));
onSubmitted: this.textSubmitted)))));
onSubmitted: this.textSubmitted, unityTouchKeyboard: unityKeyboard,
selectionControls: MaterialUtils.materialTextSelectionControls)))));
onSubmitted: this.textSubmitted)))));
onSubmitted: this.textSubmitted, unityTouchKeyboard: unityKeyboard,
selectionControls: MaterialUtils.materialTextSelectionControls)))));
onSubmitted: this.textSubmitted)))));
onSubmitted: this.textSubmitted, unityTouchKeyboard: unityKeyboard,
selectionControls: MaterialUtils.materialTextSelectionControls)))));
onSubmitted: this.textSubmitted)))));
onSubmitted: this.textSubmitted, unityTouchKeyboard: unityKeyboard,
selectionControls: MaterialUtils.materialTextSelectionControls)))));
onSubmitted: this.textSubmitted)))));
onSubmitted: this.textSubmitted, unityTouchKeyboard: unityKeyboard,
selectionControls: MaterialUtils.materialTextSelectionControls)))));
onSubmitted: this.textSubmitted)))));
return new Column(
onSubmitted: this.textSubmitted, unityTouchKeyboard: unityKeyboard,
selectionControls: MaterialUtils.materialTextSelectionControls)))));
return widgets;
}
public override Widget build(BuildContext context) {
List<Widget> widgets = new List<Widget>();
widgets.Add(new Text("UIWidgets Touch Keyboard", style: new TextStyle(fontSize:20, height:2.0f), textAlign: TextAlign.center));
widgets.AddRange(this.buildInputs(false));
widgets.Add(new Text("Unity Touch Keyboard", style: new TextStyle(fontSize:20, height:2.0f), textAlign: TextAlign.center));
widgets.AddRange(this.buildInputs(true));
return new Container(
padding: EdgeInsets.all(12),
child: new SingleChildScrollView(child: new Column(
children: widgets);
children: widgets)));
public class EditStateProvider : StatefulWidget {
public delegate EditableText EditableBuilder(BuildContext context,
TextEditingController controller, FocusNode focusNode);

1
UIWidgetCleanupPlugin.DotSettings


<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/Highlighting/ReadSettingsFromFileLevel/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CodeCleanup/Profiles/=UIWidgets/@EntryIndexedValue">&lt;?xml version="1.0" encoding="utf-16"?&gt;&lt;Profile name="UIWidgets"&gt;&lt;JsReformatCode&gt;True&lt;/JsReformatCode&gt;&lt;CSCodeStyleAttributes ArrangeTypeAccessModifier="True" ArrangeTypeMemberAccessModifier="True" SortModifiers="False" RemoveRedundantParentheses="False" AddMissingParentheses="True" ArrangeBraces="True" ArrangeAttributes="False" ArrangeArgumentsStyle="False" ArrangeCodeBodyStyle="True" ArrangeVarStyle="False" /&gt;&lt;CSOptimizeUsings&gt;&lt;OptimizeUsings&gt;True&lt;/OptimizeUsings&gt;&lt;EmbraceInRegion&gt;False&lt;/EmbraceInRegion&gt;&lt;RegionName&gt;&lt;/RegionName&gt;&lt;/CSOptimizeUsings&gt;&lt;CSReformatCode&gt;True&lt;/CSReformatCode&gt;&lt;CSFixBuiltinTypeReferences&gt;True&lt;/CSFixBuiltinTypeReferences&gt;&lt;CSArrangeQualifiers&gt;True&lt;/CSArrangeQualifiers&gt;&lt;CSShortenReferences&gt;True&lt;/CSShortenReferences&gt;&lt;IDEA_SETTINGS&gt;&amp;lt;profile version="1.0"&amp;gt;
&amp;lt;option name="myName" value="UIWidgets" /&amp;gt;
&amp;lt;inspection_tool class="ES6ShorthandObjectProperty" enabled="false" level="INFORMATION" enabled_by_default="false" /&amp;gt;

85
Runtime/engine/UIWidgetsMessageManager.cs


using System.Collections.Generic;
using System.Runtime.InteropServices;
using Unity.UIWidgets.external.simplejson;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.service;
using UnityEngine;
namespace Unity.UIWidgets.engine {
public class UIWidgetsMessageManager: MonoBehaviour {
public delegate void MethodChannelMessageDelegate(string method, List<JSONNode> args);
static UIWidgetsMessageManager _instance;
readonly Dictionary<string, MethodChannelMessageDelegate> _methodChannelMessageDelegates =
new Dictionary<string, MethodChannelMessageDelegate>();
public static UIWidgetsMessageManager instance {
get { return _instance; }
}
string _lastObjectName;
void OnEnable() {
D.assert(_instance == null, "Only one instance of UIWidgetsMessageManager should exists");
_instance = this;
this.UpdateNameIfNeed();
}
void OnDisable() {
D.assert(_instance != null, "_instance should not be null");
_instance = null;
}
void Update() {
this.UpdateNameIfNeed();
}
void UpdateNameIfNeed() {
var name = this.gameObject.name;
if (name != this._lastObjectName) {
this._lastObjectName = name;
#if UNITY_IOS
if (!Application.isEditor) {
UIWidgetsMessageSetObjectName(this._lastObjectName);
}
#endif
}
}
public void AddChannelMessageDelegate(string channel, MethodChannelMessageDelegate del) {
MethodChannelMessageDelegate exists;
this._methodChannelMessageDelegates.TryGetValue(channel, out exists);
this._methodChannelMessageDelegates[channel] = exists + del;
}
public void RemoveChannelMessageDelegate(string channel, MethodChannelMessageDelegate del) {
MethodChannelMessageDelegate exists;
this._methodChannelMessageDelegates.TryGetValue(channel, out exists);
if (exists != null) {
this._methodChannelMessageDelegates[channel] = exists - del;
}
}
void OnUIWidgetsMethodMessage(string message) {
JSONObject jsonObject = (JSONObject)JSON.Parse(message);
string channel = jsonObject["channel"].Value;
string method = jsonObject["method"].Value;
var args = new List<JSONNode>(jsonObject["args"].AsArray.Children);
if (string.IsNullOrEmpty(channel) || string.IsNullOrEmpty(method)) {
Debug.LogError("invalid uiwidgets method message");
}
else {
MethodChannelMessageDelegate exists;
this._methodChannelMessageDelegates.TryGetValue(channel, out exists);
exists?.Invoke(method, args);
}
}
#if UNITY_IOS
[DllImport("__Internal")]
static extern void UIWidgetsMessageSetObjectName(string objectName);
#endif
}
}

11
Runtime/engine/UIWidgetsMessageManager.cs.meta


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

8
Runtime/external.meta


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

5
Runtime/external/.editorconfig


root = true
# For CSharp Only
[*.cs]
csharp_instance_members_qualify_members=none

8
Runtime/external/simplejson.meta


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

1001
Runtime/external/simplejson/SimpleJSON.cs
文件差异内容过多而无法显示
查看文件

11
Runtime/external/simplejson/SimpleJSON.cs.meta


fileFormatVersion: 2
guid: c1511f3e459f641589f4f62495cd64e6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存