浏览代码

Merge pull request #114 from Unity-Technologies/zxw/fix_editor_panel_crash

fix an editor panel crash
/siyaoH-1.17-PlatformMessage
GitHub 4 年前
当前提交
7caa4556
共有 1 个文件被更改,包括 24 次插入41 次删除
  1. 65
      com.unity.uiwidgets/Runtime/rendering/debug_overflow_indicator.cs

65
com.unity.uiwidgets/Runtime/rendering/debug_overflow_indicator.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using Unity.UIWidgets.widgets;
using UnityEngine;
using Color = Unity.UIWidgets.ui.Color;
using Gradient = Unity.UIWidgets.ui.Gradient;

const float _indicatorFraction = 0.1f;
const float _indicatorFontSizePixels = 7.5f;
const float _indicatorLabelPaddingPixels = 1.0f;
static readonly TextStyle _indicatorTextStyle = new TextStyle(
color: new Color(0xFF900000),
fontSize: _indicatorFontSizePixels,
fontWeight: FontWeight.w800
);
static readonly Paint _indicatorPaint = new Paint();
static readonly Paint _labelBackgroundPaint = new Paint();
static readonly List<TextPainter> _indicatorLabel = new List<TextPainter>(4);
static DebugOverflowIndicatorMixin() {
_indicatorPaint.shader = Gradient.linear(
new Offset(0.0f, 0.0f),
new Offset(10.0f, 10.0f),
new List<Color> {_black, _yellow, _yellow, _black},
new List<float> {0.25f, 0.25f, 0.75f, 0.75f},
TileMode.repeated
);
_labelBackgroundPaint.color = new Color(0xFFFFFFFF);
_OverflowSide e = new _OverflowSide();
var len = Enum.GetNames(e.GetType()).Length;
for (int i = 0; i < len; i++) {
_indicatorLabel.Add(new TextPainter(textDirection: TextDirection.ltr));
}
}
static readonly Dictionary<RenderObject, bool> _overflowReportNeeded = new Dictionary<RenderObject, Boolean>();

return;
}
TextStyle _indicatorTextStyle = new TextStyle(
color: new Color(0xFF900000),
fontSize: _indicatorFontSizePixels,
fontWeight: FontWeight.w800
);
Paint _indicatorPaint = new Paint{ shader = Gradient.linear(
new Offset(0.0f, 0.0f),
new Offset(10.0f, 10.0f),
new List<Color> {_black, _yellow, _yellow, _black},
new List<float> {0.25f, 0.25f, 0.75f, 0.75f},
TileMode.repeated
)};
Paint _labelBackgroundPaint = new Paint{color = new Color(0xFFFFFFFF)};
TextSpan textSpan = _indicatorLabel[(int) region.side].text as TextSpan;
if (textSpan?.text != region.label) {
_indicatorLabel[(int) region.side].text = new TextSpan(
var textPainter = new TextPainter(textDirection: TextDirection.ltr) {
text = new TextSpan(
style: _indicatorTextStyle
);
_indicatorLabel[(int) region.side].layout();
}
style: _indicatorTextStyle)
};
textPainter.layout();
Offset centerOffset = new Offset(-_indicatorLabel[(int) region.side].width / 2.0f, 0.0f);
Rect textBackgroundRect = centerOffset & _indicatorLabel[(int) region.side].size;
Offset centerOffset = new Offset(-textPainter.width / 2.0f, 0.0f);
Rect textBackgroundRect = centerOffset & textPainter.size;
_indicatorLabel[(int) region.side].paint(context.canvas, centerOffset);
textPainter.paint(context.canvas, centerOffset);
context.canvas.restore();
}

正在加载...
取消
保存