浏览代码

use queue

/siyaoH-1.17-PlatformMessage
siyao 4 年前
当前提交
eddcaa9a
共有 4 个文件被更改,包括 97 次插入92 次删除
  1. 2
      com.unity.uiwidgets/Editor/UIWidgetsPanelEditor.cs
  2. 8
      com.unity.uiwidgets/Runtime/engine2/UIWidgetsPanel.cs
  3. 2
      com.unity.uiwidgets/Runtime/gestures/converter.cs
  4. 177
      com.unity.uiwidgets/Runtime/services/keyboard.cs

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


EditorGUILayout.PropertyField(serializedObject.FindProperty("fonts"), true);
// EditorGUILayout.PropertyField(pixelRatioProperty);
EditorGUILayout.PropertyField(pixelRatioProperty);
EditorGUILayout.PropertyField(antiAliasingProperty);
UIWidgetsPanel panel = (UIWidgetsPanel)target;

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


return result;
}
public float devicePixelRatioOverride {
get => Screen.dpi / 96.0f;
}
public float devicePixelRatioOverride;
public float hardwareAntiAliasing;
// RectTransform rectTransform {

void Input_OnGUI() {
Event e = Event.current;
if (e.isKey) {
PointerEventConverter.KeyEvent = e;
PointerEventConverter.KeyEvent.Enqueue(new Event(e));
UIWidgetsPanel_onKey(_ptr, e.keyCode, e.type == EventType.KeyDown);
if (e.character != 0) {
UIWidgetsPanel_onChar(_ptr, e.character);

2
com.unity.uiwidgets/Runtime/gestures/converter.cs


}
}
public static Event KeyEvent = null;
public static Queue<Event> KeyEvent = new Queue<Event>();
static float _toLogicalPixels(float physicalPixels, float devicePixelRatio) {
return physicalPixels / devicePixelRatio;
}

177
com.unity.uiwidgets/Runtime/services/keyboard.cs


using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;

using Unity.UIWidgets.gestures;
using Unity.UIWidgets.ui;
using UnityEngine;
public delegate RawInputKeyResponse GlobalKeyEventHandlerDelegate(RawKeyEvent rawEvt, bool enableCustomAction = false);
public delegate RawInputKeyResponse GlobalKeyEventHandlerDelegate(RawKeyEvent rawEvt,
bool enableCustomAction = false);
public class RawInputKeyResponse {
public readonly bool swallow;
public readonly char input;

this.input = input;
this.inputAction = inputAction;
}
false,
false,
evt.data.unityEvent.character,
null);
}

interface KeyboardDelegate: IDisposable {
interface KeyboardDelegate : IDisposable {
void setStyle(Dictionary<string, object> args);
void setIMEPos(Offset imeGlobalPos);

bool imeRequired();
TextEditingValue _value;
public void show() {

}
public void setEditableSizeAndTransform(Dictionary<string, object> args) {
//todo
//todo
//todo
//todo
}
Offset _editorWindowPosToScreenPos(Offset position) {

public void setIMEPos(Offset imeGlobalPos) {
var uiWidgetWindowAdapter = Window.instance;
Offset screenPos = uiWidgetWindowAdapter != null
? uiWidgetWindowAdapter.windowPosToScreenPos(imeGlobalPos)
Offset screenPos = uiWidgetWindowAdapter != null
? uiWidgetWindowAdapter.windowPosToScreenPos(imeGlobalPos)
Input.compositionCursorPos = new Vector2(screenPos.dx, screenPos.dy);
}

if (_client == 0) {
return;
}
var currentEvent = PointerEventConverter.KeyEvent;
Debug.Log($"event: {currentEvent}");
var oldValue = _value;
while (!PointerEventConverter.KeyEvent.isEmpty()) {
var currentEvent = PointerEventConverter.KeyEvent.Dequeue();
Debug.Log($"event: {currentEvent} c: {currentEvent.character}");
var oldValue = _value;
if (currentEvent.modifiers == EventModifiers.FunctionKey) {
continue;
}
if (currentEvent != null && currentEvent.type == EventType.KeyDown) {
var response = TextInput._handleGlobalInputKey(_client,
new RawKeyDownEvent(new RawKeyEventData(currentEvent)));
if (currentEvent != null && currentEvent.type == EventType.KeyDown) {
var response = TextInput._handleGlobalInputKey(_client,
new RawKeyDownEvent(new RawKeyEventData(currentEvent)));
if (response.swallow) {
if (response.inputAction != null) {
Window.instance.run(
() => { TextInput._performAction(_client, response.inputAction.Value); });
}
if (response.swallow) {
if (response.inputAction != null) {
Window.instance.run(() => { TextInput._performAction(_client, response.inputAction.Value); });
if (_validateCharacter(response.input)) {
_value = _value.insert(new string(response.input, 1));
}
if (_validateCharacter(response.input)) {
_value = _value.insert(new string(response.input, 1));
else if (currentEvent.keyCode == KeyCode.Backspace) {
if (_value.selection.isValid) {
_value = _value.deleteSelection(true);
}
} else if (currentEvent.keyCode == KeyCode.Backspace) {
if (_value.selection.isValid) {
_value = _value.deleteSelection(true);
else if (currentEvent.character != '\0') {
_value = _value.clearCompose();
char ch = currentEvent.character;
if (ch == '\r' || ch == 3) {
ch = '\n';
}
if (ch == '\n') {
Window.instance.run(() => { TextInput._performAction(_client, TextInputAction.newline); });
}
if (_validateCharacter(ch)) {
_value = _value.insert(new string(ch, 1));
}
} else if (currentEvent.character != '\0') {
_value = _value.clearCompose();
char ch = currentEvent.character;
if (ch == '\r' || ch == 3) {
ch = '\n';
else if (!string.IsNullOrEmpty(currentEvent.keyCode.ToString())) {
isIMEInput = true;
Debug.Log($"event:? {currentEvent}");
_value = _value.compose(currentEvent.keyCode.ToString());
if (ch == '\n') {
Window.instance.run(() => { TextInput._performAction(_client, TextInputAction.newline); });
}
if (_validateCharacter(ch)) {
_value = _value.insert(new string(ch, 1));
}
}
else if (!string.IsNullOrEmpty(currentEvent.keyCode.ToString())) {
isIMEInput = true;
Debug.Log($"event:? {currentEvent}");
_value = _value.compose(currentEvent.keyCode.ToString());
currentEvent.Use();
currentEvent.Use();
}
if (_value != oldValue) {
if (this.isIMEInput) {
var isIMEInput = this.isIMEInput;
Timer.create(TimeSpan.Zero, () => {
TextInput._updateEditingState(_client, _value, isIMEInput);
});
this.isIMEInput = false;
}
else {
Timer.create(TimeSpan.Zero, () => {
TextInput._updateEditingState(_client, _value);
});
if (_value != oldValue) {
if (this.isIMEInput) {
var isIMEInput = this.isIMEInput;
Timer.create(TimeSpan.Zero,
() => { TextInput._updateEditingState(_client, _value, isIMEInput); });
this.isIMEInput = false;
}
else {
Timer.create(TimeSpan.Zero, () => { TextInput._updateEditingState(_client, _value); });
}
}
}
}

return ch >= ' ' || ch == '\t' || ch == '\r' || ch == 10 || ch == '\n';
}
}
class UnityTouchScreenKeyboardDelegate : KeyboardDelegate, TextInputUpdateListener {
int _client;
string _lastCompositionString;

: TextSelection.collapsed(0)
);
var changed = _value != newValue;
_value = newValue;
if (changed) {
Window.instance.run(() => {

}
abstract class AbstractUIWidgetsKeyboardDelegate : KeyboardDelegate {
UIWidgetsMessageManager.instance.
AddChannelMessageDelegate("TextInput", _handleMethodCall);
UIWidgetsMessageManager.instance.AddChannelMessageDelegate("TextInput", _handleMethodCall);
UIWidgetsMessageManager.instance.
RemoveChannelMessageDelegate("TextInput", _handleMethodCall);
UIWidgetsMessageManager.instance.RemoveChannelMessageDelegate("TextInput", _handleMethodCall);
}
public abstract void show();

public abstract void setEditingState(TextEditingValue value);
public void setEditableSizeAndTransform(Dictionary<string, object> args) {
throw new NotImplementedException();
}

public abstract void setClient(int client, TextInputConfiguration configuration);
public abstract void clearClient();
public virtual bool imeRequired() {
return false;
}

/*if (TextInput._currentConnection == null) {
return;
}

throw new UIWidgetsError($"unknown method ${method}");
}
}*/
}
}
#if UNITY_WEBGL
class UIWidgetsWebGLKeyboardDelegate : AbstractUIWidgetsKeyboardDelegate {

}
#endif
#if UNITY_IOS || UNITY_ANDROID
class UIWidgetsTouchScreenKeyboardDelegate : AbstractUIWidgetsKeyboardDelegate {

#elif UNITY_ANDROID
internal static void UIWidgetsTextInputShow() {
using (
AndroidJavaClass pluginClass = new AndroidJavaClass("com.unity.uiwidgets.plugin.editing.TextInputPlugin")
AndroidJavaClass pluginClass =
new AndroidJavaClass("com.unity.uiwidgets.plugin.editing.TextInputPlugin")
) {
pluginClass.CallStatic("show");
}

using (
AndroidJavaClass pluginClass = new AndroidJavaClass("com.unity.uiwidgets.plugin.editing.TextInputPlugin")
AndroidJavaClass pluginClass =
new AndroidJavaClass("com.unity.uiwidgets.plugin.editing.TextInputPlugin")
) {
pluginClass.CallStatic("hide");
}

using (
AndroidJavaClass pluginClass = new AndroidJavaClass("com.unity.uiwidgets.plugin.editing.TextInputPlugin")
AndroidJavaClass pluginClass =
new AndroidJavaClass("com.unity.uiwidgets.plugin.editing.TextInputPlugin")
) {
pluginClass.CallStatic("setClient", client, configuration);

internal static void UIWidgetsTextInputSetTextInputEditingState(string jsonText) {
using (
AndroidJavaClass pluginClass = new AndroidJavaClass("com.unity.uiwidgets.plugin.editing.TextInputPlugin")
AndroidJavaClass pluginClass =
new AndroidJavaClass("com.unity.uiwidgets.plugin.editing.TextInputPlugin")
) {
pluginClass.CallStatic("setEditingState", jsonText);
}

using (
AndroidJavaClass pluginClass = new AndroidJavaClass("com.unity.uiwidgets.plugin.editing.TextInputPlugin")
AndroidJavaClass pluginClass =
new AndroidJavaClass("com.unity.uiwidgets.plugin.editing.TextInputPlugin")
) {
pluginClass.CallStatic("clearClient");
}

#endif
#endif
}
正在加载...
取消
保存