浏览代码

Merge branch 'dev_1.17.5' of github.com:Unity-Technologies/com.unity.uiwidgets into editorwindow

/siyaoH-1.17-PlatformMessage
xingweizhu 4 年前
当前提交
f8807f8c
共有 13 个文件被更改,包括 178 次插入65 次删除
  1. 56
      Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/shrine/expanding_bottom_sheet.cs
  2. 28
      Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/shrine/shopping_cart.cs
  3. 3
      Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/shrine/supplemental/product_card.cs
  4. 7
      Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/gallery/app.cs
  5. 6
      com.unity.uiwidgets/Editor/UIWidgetsPanelEditor.cs
  6. 34
      com.unity.uiwidgets/Runtime/engine2/UIWidgetsPanel.cs
  7. 13
      com.unity.uiwidgets/Runtime/foundation/debug.cs
  8. 5
      com.unity.uiwidgets/Runtime/gestures/binding.cs
  9. 19
      com.unity.uiwidgets/Runtime/widgets/nested_scroll_view.cs
  10. 9
      com.unity.uiwidgets/Runtime/widgets/scroll_position.cs
  11. 19
      com.unity.uiwidgets/Runtime/widgets/scrollable.cs
  12. 38
      engine/src/shell/platform/unity/windows/uiwidgets_panel.cc
  13. 6
      engine/src/shell/platform/unity/windows/uiwidgets_panel.h

56
Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/shrine/expanding_bottom_sheet.cs


public class ExpandingBottomSheet : StatefulWidget {
public ExpandingBottomSheet(Key key = null, AnimationController hideController = null)
public ExpandingBottomSheet(
Key key = null,
AnimationController hideController = null)
: base(key: key)
{
D.assert(hideController != null);

}
}
Widget _buildThumbnails(int numProducts) {
return new Container(
child: new Opacity(
opacity: _thumbnailOpacityAnimation.value,
child: new Column(
children: new List<Widget>{
new Row(
children: new List<Widget>{
new AnimatedPadding(
padding: _cartPaddingFor(numProducts),
child: new Icon(Icons.shopping_cart),
duration: TimeSpan.FromMilliseconds(225)
),
new Container(
// Accounts for the overflow number
width: numProducts > 3 ? _width - 94.0f: _width - 64.0f,
height: expanding_buttom_sheetUtils._kCartHeight,
padding: EdgeInsets.symmetric(vertical: 8.0f),
child: new ProductThumbnailRow()
),
new ExtraProductsNumber(),
}
),
}
)
Widget _buildThumbnails(int numProducts)
{
return new Opacity(
opacity: _thumbnailOpacityAnimation.value,
child: new Column(
children: new List<Widget>
{
new Row(
children: new List<Widget>
{
/* new AnimatedPadding(
padding: _cartPaddingFor(numProducts),
child: new Icon(Icons.shopping_cart),
duration: TimeSpan.FromMilliseconds(225)
),*/
new Container(
// Accounts for the overflow number
width: numProducts > 3 ? _width - 94.0f : _width - 64.0f,
height: expanding_buttom_sheetUtils._kCartHeight,
padding: EdgeInsets.symmetric(vertical: 8.0f),
child: new ProductThumbnailRow()
)//, new ExtraProductsNumber(),
}
),
}
)
);
}

}
public readonly GlobalKey<AnimatedListState> listKey;
//public readonly Delegate removedItemBuilder;
public RemovedItemBuilder removedItemBuilder;
public readonly List<int> _items;

28
Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/shrine/shopping_cart.cs


using Unity.UIWidgets.rendering;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using UnityEngine;
using Image = Unity.UIWidgets.widgets.Image;
using TextStyle = Unity.UIWidgets.painting.TextStyle;

List<Widget> _createShoppingCartRows(AppStateModel model)
{
List<Widget> widgets = new List<Widget>();
for (int id = 0; id < model.productsInCart.Count; id++)
foreach (var product in model.productsInCart.Keys)
widgets.Add(new ShoppingCartRow(
product: model.getProductById(id),
quantity: model.productsInCart[id],
onPressed: ()=> {
model.removeItemFromCart(id);
}
));
int id = product;
widgets.Add(new ShoppingCartRow(
product: model.getProductById(id),
quantity: model.productsInCart[id],
onPressed: ()=> {
model.removeItemFromCart(id);
}
));
}
return widgets;

public class ShoppingCartRow : StatelessWidget {
public ShoppingCartRow(
Product product = null,
int? quantity = null,
int quantity = 1,
this.quantity = quantity?? 0;
this.quantity = quantity;
this.onPressed = onPressed;
}

new Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: new List<Widget>{
Image.asset(
Image.file(
package: product.assetPackage,
//package: product.assetPackage,
fit: BoxFit.cover,
width: 75.0f,
height: 75.0f

new Expanded(
child: new Text($"Quantity: {quantity}")
),
new Text($"x $ {product.price : D} ")
new Text($"x $ {product.price :F} ")
}
),
new Text(

3
Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/demo/shrine/supplemental/product_card.cs


using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.widgets;
using UnityEngine;
namespace UIWidgetsGallery.demo.shrine.supplemental
{

),
new SizedBox(height: 4.0f),
new Text(
$" $ { product.price:D}",
$" $ { product.price:F}",
style: theme.textTheme.caption
),
}

7
Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/gallery/app.cs


namespace UIWidgetsGallery.gallery
{
public class GalleryApp : StatefulWidget
{
public GalleryApp(
{ public GalleryApp(
Key key = null,
UpdateUrlFetcher updateUrlFetcher = null,
bool enablePerformanceOverlay = true,

// Specifically use a blank Cupertino theme here and do not transfer
// over the Material primary color etc except the brightness to
// showcase standard iOS looks.
new Builder(builder: (BuildContext subsubContext) =>
new Builder(builder: (BuildContext context1) =>
brightness: Theme.of(context).brightness
brightness: Theme.of(context1).brightness
),
child: child
);

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


base.OnInspectorGUI();
var pixelRatioProperty = serializedObject.FindProperty("devicePixelRatioOverride");
var antiAliasingProperty = serializedObject.FindProperty("hardwareAntiAliasing");
var ShowDebugLog = serializedObject.FindProperty("m_ShowDebugLog");
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(ShowDebugLog);
if (EditorGUI.EndChangeCheck()) {
UIWidgetsPanel.ShowDebugLog = ShowDebugLog.boolValue;
}
UIWidgetsPanel panel = (UIWidgetsPanel)target;
serializedObject.ApplyModifiedProperties();

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


}
}
public bool m_ShowDebugLog = false;
public static List<UIWidgetsPanel> panels = new List<UIWidgetsPanel>();
public static bool ShowDebugLog {
get => _ShowDebugLog;
set {
foreach (var panel in panels) {
panel.m_ShowDebugLog = value;
}
_ShowDebugLog = value;
}
}
static bool _ShowDebugLog = false;
protected void OnEnable() {
base.OnEnable();
var settings = new Dictionary<string, object>();

texture = _wrapper.renderTexture;
Input_OnEnable();
panels.Add(this);
_ShowDebugLog = m_ShowDebugLog;
}
public void mainEntry() {

Input_OnDisable();
base.OnDisable();
panels.Remove(this);
}
protected virtual void Update() {

else {
_lastMousePosition = Input.mousePosition;
}
if (Input.mouseScrollDelta.magnitude != 0) {
_onScroll();
}
}
}
}

void _onMouseMove() {
var pos = _getPointerPosition(Input.mousePosition);
_wrapper.OnMouseMove(pos);
}
void _onScroll() {
var pos = _getPointerPosition(Input.mousePosition);
if (pos == null) {
return;
}
var delta = Input.mouseScrollDelta;
UIWidgetsPanel_onScroll(_ptr, delta.x, delta.y, pos.Value.x, pos.Value.y);
}
public void OnPointerDown(PointerEventData eventData) {

13
com.unity.uiwidgets/Runtime/foundation/debug.cs


using System;
using System.Diagnostics;
using System.Linq;
using Unity.UIWidgets.engine2;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.ui;
using Canvas = Unity.UIWidgets.ui.Canvas;

[Conditional("UNITY_ASSERTIONS")]
public static void assert(Func<bool> result, Func<string> message = null) {
//if (!result()) {
// throw new AssertionError(message != null ? message() : "");
//}
if (UIWidgetsPanel.ShowDebugLog && !result()) {
throw new AssertionError(message != null ? message() : "");
}
// if (!result) {
// throw new AssertionError(message != null ? message() : "");
// }
if (UIWidgetsPanel.ShowDebugLog && !result) {
throw new AssertionError(message != null ? message() : "");
}
}
public static bool debugPrintGestureArenaDiagnostics = false;

5
com.unity.uiwidgets/Runtime/gestures/binding.cs


readonly HashSet<HitTestEntry> _enteredTargets = new HashSet<HitTestEntry>();
void _handlePointerEvent(PointerEvent evt) {
if (evt is PointerScrollEvent) {
_handlePointerScrollEvent(evt);
return;
}
HitTestResult hitTestResult = null;
if (evt is PointerDownEvent || evt is PointerSignalEvent) {
D.assert(!_hitTests.ContainsKey(evt.pointer));

19
com.unity.uiwidgets/Runtime/widgets/nested_scroll_view.cs


return 0.0f;
}
public float applyClampedPointerSignalUpdate(float delta) {
D.assert(delta != 0.0f);
float min = delta > 0.0f
? float.NegativeInfinity
: Mathf.Min(minScrollExtent, pixels);
// The logic for max is equivalent but on the other side.
float max = delta < 0.0f
? float.PositiveInfinity
: Mathf.Max(maxScrollExtent, pixels);
float newPixels = (pixels + delta).clamp(min, max);
float clampedDelta = newPixels - pixels;
if (clampedDelta == 0.0f)
return delta;
forcePixels(newPixels);
didUpdateScrollPositionBy(clampedDelta);
return delta - clampedDelta;
}
public override ScrollDirection userScrollDirection {
get { return coordinator.userScrollDirection; }
}

9
com.unity.uiwidgets/Runtime/widgets/scroll_position.cs


this.keepScrollOffset = keepScrollOffset;
this.debugLabel = debugLabel;
_coordinator = coordinator;
if (oldPosition != null) {
absorb(oldPosition);
}

public bool hasMaxScrollExtent {
get { return _maxScrollExtent != null; }
}
public override float pixels {
get {
D.assert(_pixels != null);

D.assert(other != null);
D.assert(other.context == context);
D.assert(_pixels == null);
_minScrollExtent = other.minScrollExtent;
_maxScrollExtent = other.maxScrollExtent;
_minScrollExtent = other._minScrollExtent;
_maxScrollExtent = other._maxScrollExtent;
_viewportDimension = other.viewportDimension;
_viewportDimension = other._viewportDimension;
D.assert(activity == null);
D.assert(other.activity != null);

19
com.unity.uiwidgets/Runtime/widgets/scrollable.cs


}
float _targetScrollOffsetForPointerScroll(PointerScrollEvent e) {
float delta = widget.axis == Axis.horizontal ? e.delta.dx : e.delta.dy;
float delta = widget.axis == Axis.horizontal
? e.scrollDelta.dx
: e.scrollDelta.dy;
delta += -1;
delta *= -1;
}
float _pointerSignalEventDelta(PointerScrollEvent evt) {
float delta = widget.axis == Axis.horizontal
? evt.scrollDelta.dx
: evt.scrollDelta.dy;
if (AxisUtils.axisDirectionIsReversed(widget.axisDirection)) {
delta *= -1;
}
return delta;
}
void _receivedPointerSignal(PointerSignalEvent e) {

38
engine/src/shell/platform/unity/windows/uiwidgets_panel.cc


vsync_batons_.push_back(baton);
}
void UIWidgetsPanel::SetEventLocationFromCursorPosition(
UIWidgetsPointerEvent* event_data) {
POINT point;
GetCursorPos(&point);
// TODO: this is a native method, use unity position instead.
// ScreenToClient(GetWindowHandle(), &point);
event_data->x = point.x;
event_data->y = point.y;
}
void UIWidgetsPanel::SetEventPhaseFromCursorButtonState(
UIWidgetsPointerEvent* event_data) {
MouseState state = GetMouseState();

SendPointerEventWithData(event);
}
void UIWidgetsPanel::SendScroll(float delta_x, float delta_y, float px, float py) {
UIWidgetsPointerEvent event = {};
// TODO: this is a native method, use unity position instead.
event.x = px;
event.y = py;
//SetEventLocationFromCursorPosition(&event);
SetEventPhaseFromCursorButtonState(&event);
event.signal_kind = UIWidgetsPointerSignalKind::kUIWidgetsPointerSignalKindScroll;
// TODO: See if this can be queried from the OS; this value is chosen
// arbitrarily to get something that feels reasonable.
const int kScrollOffsetMultiplier = 20;
event.scroll_delta_x = delta_x * kScrollOffsetMultiplier;
event.scroll_delta_y = delta_y * kScrollOffsetMultiplier;
SendPointerEventWithData(event);
}
void UIWidgetsPanel::SendPointerEventWithData(
const UIWidgetsPointerEvent& event_data) {
MouseState mouse_state = GetMouseState();

void UIWidgetsPanel::OnMouseMove(float x, float y) {
if (process_events_) {
SendMouseMove(x, y);
}
}
void UIWidgetsPanel::OnScroll(float x, float y, float px, float py) {
if (process_events_) {
SendScroll(x, y, px, py);
}
}

//_Wait
panel->ProcessMessages();
UIWIDGETS_API(void)
UIWidgetsPanel_onScroll(UIWidgetsPanel* panel, float x, float y, float px, float py) {
panel->OnScroll(x, y, px, py);
}
} // namespace uiwidgets

6
engine/src/shell/platform/unity/windows/uiwidgets_panel.h


void VSyncCallback(intptr_t baton);
void SetEventLocationFromCursorPosition(UIWidgetsPointerEvent* event_data);
void OnScroll(float x, float y, float px, float py);
void OnMouseDown(float x, float y, int button);

void SendMouseUp(float x, float y);
void SendMouseLeave();
void SendScroll(float delta_x, float delta_y, float px, float py);
void SetEventPhaseFromCursorButtonState(UIWidgetsPointerEvent* event_data);

正在加载...
取消
保存