浏览代码

add settings in editor

/siyaoH-1.17-PlatformMessage
Shiyun Wen 4 年前
当前提交
f52367db
共有 4 个文件被更改,包括 135 次插入10 次删除
  1. 13
      Samples/UIWidgetsSamples_2019_4/Assets/Editor/EditorWindowSample/GalleryMain.cs
  2. 9
      Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/GalleryMain.cs
  3. 71
      com.unity.uiwidgets/Editor/UIWidgetsEditorPanel.cs
  4. 52
      com.unity.uiwidgets/Runtime/engine2/UIWidgetsPanel.cs

13
Samples/UIWidgetsSamples_2019_4/Assets/Editor/EditorWindowSample/GalleryMain.cs


using System.Collections.Generic;
using UIWidgetsGallery.gallery;
using Unity.UIWidgets.Editor;
using UnityEditor;

{
[MenuItem("UIWidgets/EditorSample")]
public static void CountDemo()
{
CreateWindow<EditorWindowGallery>();
}
protected override void onFill()
CreateWindow<EditorWindowGallery>();
AddFont("Material Icons", new List<string>{"MaterialIcons-Regular.ttf"}, new List<int>{0});
AddFont("CupertinoIcons", new List<string>{"CupertinoIcons.ttf"}, new List<int>{0});
AddFont("GalleryIcons", new List<string>{"gallery/GalleryIcons.ttf"}, new List<int>{0});
base.onFill();
protected override void main()
{
ui_.runApp(new GalleryApp());

9
Samples/UIWidgetsSamples_2019_4/Assets/UIWidgetsGallery/GalleryMain.cs


using System.Collections.Generic;
using UIWidgetsGallery.gallery;
using Unity.UIWidgets.engine2;
using ui_ = Unity.UIWidgets.widgets.ui_;

ui_.runApp(new GalleryApp());
}
protected override void onFill()
{
AddFont("Material Icons", new List<string>{"MaterialIcons-Regular.ttf"}, new List<int>{0});
AddFont("CupertinoIcons", new List<string>{"CupertinoIcons.ttf"}, new List<int>{0});
AddFont("GalleryIcons", new List<string>{"gallery/GalleryIcons.ttf"}, new List<int>{0});
base.onFill();
}
protected new void OnEnable() {
base.OnEnable();
}

71
com.unity.uiwidgets/Editor/UIWidgetsEditorPanel.cs


using System.Collections;
using System.Collections.Generic;
using NUnit.Framework;
using Unity.UIWidgets.services;
using Unity.UIWidgets.ui;
using UnityEditor;
using UnityEngine;

public class UIWidgetsEditorPanel : EditorWindow, IUIWidgetsWindow {
UIWidgetsPanelWrapper _wrapper;
public UIWidgetsWindowType getWindowType() {
return UIWidgetsWindowType.EditorWindowPanel;
}

D.assert(_wrapper != null);
_wrapper?.Destroy();
_wrapper = null;
_internalTextFonts.Clear();
protected virtual void onFill() {}
List<UIWidgetsPanel.TextFont> _internalTextFonts = new List<UIWidgetsPanel.TextFont>();
protected void AddFont(string family, List<string> assets, List<int> weights) {
int repeat = 0;
for(int i = 0; i< _internalTextFonts.Count; i++ ) {
if (_internalTextFonts[i].family == family)
repeat++;
}
if (repeat == 0) {
UIWidgetsPanel.TextFont textFont = new UIWidgetsPanel.TextFont();
textFont.family = family;
UIWidgetsPanel.Font[] fonts = new UIWidgetsPanel.Font[assets.Count];
for (int i = 0; i < assets.Count; i++) {
UIWidgetsPanel.Font font = new UIWidgetsPanel.Font();
font.asset = assets[i];
font.weight = weights[i];
fonts[i] = font;
}
textFont.fonts = fonts;
_internalTextFonts.Add(textFont);
}
}
_wrapper.Initiate(this, _currentWidth, _currentHeight, _currentDevicePixelRatio, new Dictionary<string, object>());
onFill();
var settings = new Dictionary<string, object>();
UIWidgetsPanel.TextFont[] textFonts = loadTextFont();
settings.Add("fonts", fontsToObject(textFonts));
_wrapper.Initiate(this, _currentWidth, _currentHeight, _currentDevicePixelRatio, settings);
Input_OnEnable();
}

Vector2? _getPointerPosition(Vector2 position) {
return new Vector2(position.x, position.y);
}
static object fontsToObject(UIWidgetsPanel.TextFont[] textFont) {
if (textFont == null || textFont.Length == 0) {
return null;
}
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;
}
UIWidgetsPanel.TextFont[] loadTextFont() {
UIWidgetsPanel.TextFont[] textFonts = new UIWidgetsPanel.TextFont[_internalTextFonts.Count];
for (int i = 0; i < _internalTextFonts.Count; i++) {
textFonts[i] = _internalTextFonts[i];
}
return textFonts;
}
int _buttonToPointerId(int buttonId) {
if (buttonId == 0) {

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


using System.Collections.Generic;
using Unity.UIWidgets.editor2;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.services;
using Unity.UIWidgets.ui;
using UnityEngine;
using UnityEngine.EventSystems;

if (textFont == null || textFont.Length == 0) {
return null;
}
var result = new object[textFont.Length];
for (int i = 0; i < textFont.Length; i++) {
var font = new Dictionary<string, object>();

dic[j].Add("weight", textFont[i].fonts[j].weight);
}
}
return result;
}

}
static bool _ShowDebugLog = false;
protected virtual void onFill() {}
List<UIWidgetsPanel.TextFont> _internalTextFonts = new List<UIWidgetsPanel.TextFont>();
protected void AddFont(string family, List<string> assets, List<int> weights) {
int repeat = 0;
for(int i = 0; i< _internalTextFonts.Count; i++ ) {
if (_internalTextFonts[i].family == family)
repeat++;
}
if (repeat == 0) {
UIWidgetsPanel.TextFont textFont = new UIWidgetsPanel.TextFont();
textFont.family = family;
UIWidgetsPanel.Font[] fonts = new UIWidgetsPanel.Font[assets.Count];
for (int i = 0; i < assets.Count; i++) {
UIWidgetsPanel.Font font = new UIWidgetsPanel.Font();
font.asset = assets[i];
font.weight = weights[i];
fonts[i] = font;
}
textFont.fonts = fonts;
_internalTextFonts.Add(textFont);
}
}
protected void OnEnable() {
base.OnEnable();

}
else {
onFill();
UIWidgetsPanel.TextFont[] textFonts = loadTextFont();
settings.Add("fonts", fontsToObject(textFonts));
}
D.assert(_wrapper == null);
_wrapper = new UIWidgetsPanelWrapper();
_wrapper.Initiate(this, _currentWidth, _currentHeight, _currentDevicePixelRatio, settings);

panels.Add(this);
_ShowDebugLog = m_ShowDebugLog;
}
UIWidgetsPanel.TextFont[] loadTextFont() {
UIWidgetsPanel.TextFont[] textFonts = new UIWidgetsPanel.TextFont[_internalTextFonts.Count];
for (int i = 0; i < _internalTextFonts.Count; i++) {
textFonts[i] = _internalTextFonts[i];
}
return textFonts;
}
public void mainEntry() {
main();

_wrapper?.Destroy();
_wrapper = null;
texture = null;
/*_internalAssets.Clear();
_internalFamilys.Clear();
_internalWeights.Clear();*/
//UnityEngine.Debug.Log("output _internalAssets " + _internalAssets.Count);
Input_OnDisable();
base.OnDisable();

正在加载...
取消
保存