首次提交

This commit is contained in:
Bob.Song
2026-03-05 18:07:55 +08:00
commit e125bb869e
4534 changed files with 563920 additions and 0 deletions

View File

@@ -0,0 +1,99 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace FairyGUI.Utils
{
/// <summary>
///
/// </summary>
public class HtmlButton : IHtmlObject
{
public GComponent button { get; private set; }
public const string CLICK_EVENT = "OnHtmlButtonClick";
public static string resource;
RichTextField _owner;
HtmlElement _element;
EventCallback1 _clickHandler;
public HtmlButton()
{
button = UIPackage.CreateObjectFromURL(resource).asCom;
_clickHandler = (EventContext context) =>
{
_owner.DispatchEvent(CLICK_EVENT, context.data, this);
};
}
public DisplayObject displayObject
{
get { return button != null ? button.displayObject : null; }
}
public HtmlElement element
{
get { return _element; }
}
public float width
{
get { return button != null ? button.width : 0; }
}
public float height
{
get { return button != null ? button.height : 0; }
}
public void Create(RichTextField owner, HtmlElement element)
{
_owner = owner;
_element = element;
if (button == null)
return;
button.onClick.Add(_clickHandler);
int width = element.GetInt("width", button.sourceWidth);
int height = element.GetInt("height", button.sourceHeight);
button.SetSize(width, height);
button.text = element.GetString("value");
}
public void SetPosition(float x, float y)
{
if (button != null)
button.SetXY(x, y);
}
public void Add()
{
if (button != null)
_owner.AddChild(button.displayObject);
}
public void Remove()
{
if (button != null && button.displayObject.parent != null)
_owner.RemoveChild(button.displayObject);
}
public void Release()
{
if (button != null)
button.RemoveEventListeners();
_owner = null;
_element = null;
}
public void Dispose()
{
if (button != null)
button.Dispose();
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 268c2d7ad77b66449b4e0e39a6d0ca15
timeCreated: 1461773298
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,215 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace FairyGUI.Utils
{
/// <summary>
///
/// </summary>
public enum HtmlElementType
{
Text,
Link,
Image,
Input,
Select,
Object,
//internal
LinkEnd,
}
/// <summary>
///
/// </summary>
public class HtmlElement
{
public HtmlElementType type;
public string name;
public string text;
public TextFormat format;
public int charIndex;
public IHtmlObject htmlObject;
public int status; //1 hidden 2 clipped 4 added
public int space;
public Vector2 position;
Hashtable attributes;
public HtmlElement()
{
format = new TextFormat();
}
public object Get(string attrName)
{
if (attributes == null)
return null;
return attributes[attrName];
}
public void Set(string attrName, object attrValue)
{
if (attributes == null)
attributes = new Hashtable();
attributes[attrName] = attrValue;
}
public string GetString(string attrName)
{
return GetString(attrName, null);
}
public string GetString(string attrName, string defValue)
{
if (attributes == null)
return defValue;
object ret = attributes[attrName];
if (ret != null)
return ret.ToString();
else
return defValue;
}
public int GetInt(string attrName)
{
return GetInt(attrName, 0);
}
public int GetInt(string attrName, int defValue)
{
string value = GetString(attrName);
if (value == null || value.Length == 0)
return defValue;
if (value[value.Length - 1] == '%')
{
int ret;
if (int.TryParse(value.Substring(0, value.Length - 1), out ret))
return Mathf.CeilToInt(ret / 100.0f * defValue);
else
return defValue;
}
else
{
int ret;
if (int.TryParse(value, out ret))
return ret;
else
return defValue;
}
}
public float GetFloat(string attrName)
{
return GetFloat(attrName, 0);
}
public float GetFloat(string attrName, float defValue)
{
string value = GetString(attrName);
if (value == null || value.Length == 0)
return defValue;
float ret;
if (float.TryParse(value, out ret))
return ret;
else
return defValue;
}
public bool GetBool(string attrName)
{
return GetBool(attrName, false);
}
public bool GetBool(string attrName, bool defValue)
{
string value = GetString(attrName);
if (value == null || value.Length == 0)
return defValue;
bool ret;
if (bool.TryParse(value, out ret))
return ret;
else
return defValue;
}
public Color GetColor(string attrName, Color defValue)
{
string value = GetString(attrName);
if (value == null || value.Length == 0)
return defValue;
return ToolSet.ConvertFromHtmlColor(value);
}
public void FetchAttributes()
{
attributes = XMLIterator.GetAttributes(attributes);
}
public bool isEntity
{
get { return type == HtmlElementType.Image || type == HtmlElementType.Select || type == HtmlElementType.Input || type == HtmlElementType.Object; }
}
#region Pool Support
static Stack<HtmlElement> elementPool = new Stack<HtmlElement>();
#if UNITY_2019_3_OR_NEWER
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
static void InitializeOnLoad()
{
elementPool.Clear();
}
#endif
public static HtmlElement GetElement(HtmlElementType type)
{
HtmlElement ret;
if (elementPool.Count > 0)
ret = elementPool.Pop();
else
ret = new HtmlElement();
ret.type = type;
if (type != HtmlElementType.Text && ret.attributes == null)
ret.attributes = new Hashtable();
return ret;
}
public static void ReturnElement(HtmlElement element)
{
element.name = null;
element.text = null;
element.htmlObject = null;
element.status = 0;
if (element.attributes != null)
element.attributes.Clear();
elementPool.Push(element);
}
public static void ReturnElements(List<HtmlElement> elements)
{
int count = elements.Count;
for (int i = 0; i < count; i++)
{
HtmlElement element = elements[i];
ReturnElement(element);
}
elements.Clear();
}
#endregion
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 7d92c6025bf750145af0e456a7fd3f33
timeCreated: 1461773298
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,126 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace FairyGUI.Utils
{
/// <summary>
///
/// </summary>
public class HtmlImage : IHtmlObject
{
public GLoader loader { get; private set; }
RichTextField _owner;
HtmlElement _element;
bool _externalTexture;
public HtmlImage()
{
loader = (GLoader)UIObjectFactory.NewObject(ObjectType.Loader);
loader.gameObjectName = "HtmlImage";
loader.fill = FillType.ScaleFree;
loader.touchable = false;
}
public DisplayObject displayObject
{
get { return loader.displayObject; }
}
public HtmlElement element
{
get { return _element; }
}
public float width
{
get { return loader.width; }
}
public float height
{
get { return loader.height; }
}
public void Create(RichTextField owner, HtmlElement element)
{
_owner = owner;
_element = element;
int sourceWidth = 0;
int sourceHeight = 0;
NTexture texture = owner.htmlPageContext.GetImageTexture(this);
if (texture != null)
{
sourceWidth = texture.width;
sourceHeight = texture.height;
loader.texture = texture;
_externalTexture = true;
}
else
{
string src = element.GetString("src");
if (src != null)
{
PackageItem pi = UIPackage.GetItemByURL(src);
if (pi != null)
{
sourceWidth = pi.width;
sourceHeight = pi.height;
}
}
loader.url = src;
_externalTexture = false;
}
int width = element.GetInt("width", sourceWidth);
int height = element.GetInt("height", sourceHeight);
if (width == 0)
width = 5;
if (height == 0)
height = 10;
loader.SetSize(width, height);
}
public void SetPosition(float x, float y)
{
loader.SetXY(x, y);
}
public void Add()
{
_owner.AddChild(loader.displayObject);
}
public void Remove()
{
if (loader.displayObject.parent != null)
_owner.RemoveChild(loader.displayObject);
}
public void Release()
{
loader.RemoveEventListeners();
if (_externalTexture)
{
_owner.htmlPageContext.FreeImageTexture(this, loader.texture);
_externalTexture = false;
}
loader.url = null;
_owner = null;
_element = null;
}
public void Dispose()
{
if (_externalTexture)
_owner.htmlPageContext.FreeImageTexture(this, loader.texture);
loader.Dispose();
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 81871e13cb458ab4da28358d5634e082
timeCreated: 1535374214
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,117 @@
using UnityEngine;
namespace FairyGUI.Utils
{
/// <summary>
///
/// </summary>
public class HtmlInput : IHtmlObject
{
public GTextInput textInput { get; private set; }
RichTextField _owner;
HtmlElement _element;
bool _hidden;
public static int defaultBorderSize = 2;
public static Color defaultBorderColor = ToolSet.ColorFromRGB(0xA9A9A9);
public static Color defaultBackgroundColor = Color.clear;
public HtmlInput()
{
textInput = (GTextInput)UIObjectFactory.NewObject(ObjectType.InputText);
textInput.gameObjectName = "HtmlInput";
textInput.verticalAlign = VertAlignType.Middle;
}
public DisplayObject displayObject
{
get { return textInput.displayObject; }
}
public HtmlElement element
{
get { return _element; }
}
public float width
{
get { return _hidden ? 0 : textInput.width; }
}
public float height
{
get { return _hidden ? 0 : textInput.height; }
}
public void Create(RichTextField owner, HtmlElement element)
{
_owner = owner;
_element = element;
string type = element.GetString("type");
if (type != null)
type = type.ToLower();
_hidden = type == "hidden";
if (!_hidden)
{
int width = element.GetInt("width", 0);
int height = element.GetInt("height", 0);
int borderSize = element.GetInt("border", defaultBorderSize);
Color borderColor = element.GetColor("border-color", defaultBorderColor);
Color backgroundColor = element.GetColor("background-color", defaultBackgroundColor);
if (width == 0)
{
width = element.space;
if (width > _owner.width / 2 || width < 100)
width = (int)_owner.width / 2;
}
if (height == 0)
height = element.format.size + 10;
textInput.textFormat = element.format;
textInput.displayAsPassword = type == "password";
textInput.maxLength = element.GetInt("maxlength", int.MaxValue);
textInput.border = borderSize;
textInput.borderColor = borderColor;
textInput.backgroundColor = backgroundColor;
textInput.SetSize(width, height);
}
textInput.text = element.GetString("value");
}
public void SetPosition(float x, float y)
{
if (!_hidden)
textInput.SetXY(x, y);
}
public void Add()
{
if (!_hidden)
_owner.AddChild(textInput.displayObject);
}
public void Remove()
{
if (!_hidden && textInput.displayObject.parent != null)
_owner.RemoveChild(textInput.displayObject);
}
public void Release()
{
textInput.RemoveEventListeners();
textInput.text = null;
_owner = null;
_element = null;
}
public void Dispose()
{
textInput.Dispose();
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: e1c8ffa51408aef45839b1d00198b819
timeCreated: 1535374215
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,113 @@
namespace FairyGUI.Utils
{
/// <summary>
///
/// </summary>
public class HtmlLink : IHtmlObject
{
RichTextField _owner;
HtmlElement _element;
SelectionShape _shape;
EventCallback1 _clickHandler;
EventCallback1 _rolloverHandler;
EventCallback0 _rolloutHandler;
public HtmlLink()
{
_shape = new SelectionShape();
_shape.gameObject.name = "HtmlLink";
_shape.cursor = "text-link";
_clickHandler = (EventContext context) =>
{
_owner.BubbleEvent("onClickLink", _element.GetString("href"));
};
_rolloverHandler = (EventContext context) =>
{
if (_owner.htmlParseOptions.linkHoverBgColor.a > 0)
_shape.color = _owner.htmlParseOptions.linkHoverBgColor;
};
_rolloutHandler = () =>
{
if (_owner.htmlParseOptions.linkHoverBgColor.a > 0)
_shape.color = _owner.htmlParseOptions.linkBgColor;
};
}
public DisplayObject displayObject
{
get { return _shape; }
}
public HtmlElement element
{
get { return _element; }
}
public float width
{
get { return 0; }
}
public float height
{
get { return 0; }
}
public void Create(RichTextField owner, HtmlElement element)
{
_owner = owner;
_element = element;
_shape.onClick.Add(_clickHandler);
_shape.onRollOver.Add(_rolloverHandler);
_shape.onRollOut.Add(_rolloutHandler);
_shape.color = _owner.htmlParseOptions.linkBgColor;
}
public void SetArea(int startLine, float startCharX, int endLine, float endCharX)
{
if (startLine == endLine && startCharX > endCharX)
{
float tmp = startCharX;
startCharX = endCharX;
endCharX = tmp;
}
_shape.rects.Clear();
_owner.textField.GetLinesShape(startLine, startCharX, endLine, endCharX, true, _shape.rects);
_shape.Refresh();
}
public void SetPosition(float x, float y)
{
_shape.SetXY(x, y);
}
public void Add()
{
//add below _shape
_owner.AddChildAt(_shape, 0);
}
public void Remove()
{
if (_shape.parent != null)
_owner.RemoveChild(_shape);
}
public void Release()
{
_shape.RemoveEventListeners();
_owner = null;
_element = null;
}
public void Dispose()
{
_shape.Dispose();
_shape = null;
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: b2132a66ecae9cc4c99c6fbe37051723
timeCreated: 1470116309
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,179 @@
using System.Collections.Generic;
using UnityEngine;
namespace FairyGUI.Utils
{
/// <summary>
///
/// </summary>
public class HtmlPageContext : IHtmlPageContext
{
Stack<IHtmlObject> _imagePool;
Stack<IHtmlObject> _inputPool;
Stack<IHtmlObject> _buttonPool;
Stack<IHtmlObject> _selectPool;
Stack<IHtmlObject> _linkPool;
static HtmlPageContext _inst;
public static HtmlPageContext inst
{
get
{
if (_inst == null)
_inst = new HtmlPageContext();
return _inst;
}
}
static Transform _poolManager;
#if UNITY_2019_3_OR_NEWER
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
static void InitializeOnLoad()
{
_inst = null;
_poolManager = null;
}
#endif
public HtmlPageContext()
{
_imagePool = new Stack<IHtmlObject>();
_inputPool = new Stack<IHtmlObject>();
_buttonPool = new Stack<IHtmlObject>();
_selectPool = new Stack<IHtmlObject>();
_linkPool = new Stack<IHtmlObject>();
if (Application.isPlaying && _poolManager == null)
_poolManager = Stage.inst.CreatePoolManager("HtmlObjectPool");
}
virtual public IHtmlObject CreateObject(RichTextField owner, HtmlElement element)
{
IHtmlObject ret = null;
bool fromPool = false;
if (element.type == HtmlElementType.Image)
{
if (_imagePool.Count > 0 && _poolManager != null)
{
ret = _imagePool.Pop();
fromPool = true;
}
else
ret = new HtmlImage();
}
else if (element.type == HtmlElementType.Link)
{
if (_linkPool.Count > 0 && _poolManager != null)
{
ret = _linkPool.Pop();
fromPool = true;
}
else
ret = new HtmlLink();
}
else if (element.type == HtmlElementType.Input)
{
string type = element.GetString("type");
if (type != null)
type = type.ToLower();
if (type == "button" || type == "submit")
{
if (_buttonPool.Count > 0 && _poolManager != null)
{
ret = _buttonPool.Pop();
fromPool = true;
}
else
{
if (HtmlButton.resource != null)
ret = new HtmlButton();
else
Debug.LogWarning("FairyGUI: Set HtmlButton.resource first");
}
}
else
{
if (_inputPool.Count > 0 && _poolManager != null)
{
ret = _inputPool.Pop();
fromPool = true;
}
else
ret = new HtmlInput();
}
}
else if (element.type == HtmlElementType.Select)
{
if (_selectPool.Count > 0 && _poolManager != null)
{
ret = _selectPool.Pop();
fromPool = true;
}
else
{
if (HtmlSelect.resource != null)
ret = new HtmlSelect();
else
Debug.LogWarning("FairyGUI: Set HtmlSelect.resource first");
}
}
//Debug.Log("from=" + fromPool);
if (ret != null)
{
//可能已经被GameObject tree deleted了不再使用
if (fromPool && ret.displayObject != null && ret.displayObject.isDisposed)
{
ret.Dispose();
return CreateObject(owner, element);
}
ret.Create(owner, element);
if (ret.displayObject != null)
ret.displayObject.home = owner.cachedTransform;
}
return ret;
}
virtual public void FreeObject(IHtmlObject obj)
{
if (_poolManager == null)
{
obj.Dispose();
return;
}
//可能已经被GameObject tree deleted了不再回收
if (obj.displayObject != null && obj.displayObject.isDisposed)
{
obj.Dispose();
return;
}
obj.Release();
if (obj is HtmlImage)
_imagePool.Push(obj);
else if (obj is HtmlInput)
_inputPool.Push(obj);
else if (obj is HtmlButton)
_buttonPool.Push(obj);
else if (obj is HtmlLink)
_linkPool.Push(obj);
if (obj.displayObject != null)
obj.displayObject.cachedTransform.SetParent(_poolManager, false);
}
virtual public NTexture GetImageTexture(HtmlImage image)
{
return null;
}
virtual public void FreeImageTexture(HtmlImage image, NTexture texture)
{
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 5454bca8f43f9094ea66614837a2c0be
timeCreated: 1461773298
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace FairyGUI.Utils
{
/// <summary>
///
/// </summary>
public class HtmlParseOptions
{
/// <summary>
///
/// </summary>
public bool linkUnderline;
/// <summary>
///
/// </summary>
public Color linkColor;
/// <summary>
///
/// </summary>
public Color linkBgColor;
/// <summary>
///
/// </summary>
public Color linkHoverBgColor;
/// <summary>
///
/// </summary>
public bool ignoreWhiteSpace;
/// <summary>
///
/// </summary>
public static bool DefaultLinkUnderline = true;
/// <summary>
///
/// </summary>
public static Color DefaultLinkColor = new Color32(0x3A, 0x67, 0xCC, 0xFF);
/// <summary>
///
/// </summary>
public static Color DefaultLinkBgColor = Color.clear;
/// <summary>
///
/// </summary>
public static Color DefaultLinkHoverBgColor = Color.clear;
public HtmlParseOptions()
{
linkUnderline = DefaultLinkUnderline;
linkColor = DefaultLinkColor;
linkBgColor = DefaultLinkBgColor;
linkHoverBgColor = DefaultLinkHoverBgColor;
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 8e3e6e98345b46a43a4181a0790d4f30
timeCreated: 1470231110
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,395 @@
using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
namespace FairyGUI.Utils
{
/// <summary>
///
/// </summary>
public class HtmlParser
{
public static HtmlParser inst = new HtmlParser();
protected class TextFormat2 : TextFormat
{
public bool colorChanged;
}
protected List<TextFormat2> _textFormatStack;
protected int _textFormatStackTop;
protected TextFormat2 _format;
protected List<HtmlElement> _elements;
protected HtmlParseOptions _defaultOptions;
static List<string> sHelperList1 = new List<string>();
static List<string> sHelperList2 = new List<string>();
#if UNITY_2019_3_OR_NEWER
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
static void InitializeOnLoad()
{
inst = new HtmlParser();
}
#endif
public HtmlParser()
{
_textFormatStack = new List<TextFormat2>();
_format = new TextFormat2();
_defaultOptions = new HtmlParseOptions();
}
virtual public void Parse(string aSource, TextFormat defaultFormat, List<HtmlElement> elements, HtmlParseOptions parseOptions)
{
if (parseOptions == null)
parseOptions = _defaultOptions;
_elements = elements;
_textFormatStackTop = 0;
_format.CopyFrom(defaultFormat);
_format.colorChanged = false;
int skipText = 0;
bool ignoreWhiteSpace = parseOptions.ignoreWhiteSpace;
bool skipNextCR = false;
string text;
XMLIterator.Begin(aSource, true);
while (XMLIterator.NextTag())
{
if (skipText == 0)
{
text = XMLIterator.GetText(ignoreWhiteSpace);
if (text.Length > 0)
{
if (skipNextCR && text[0] == '\n')
text = text.Substring(1);
AppendText(text);
}
}
skipNextCR = false;
switch (XMLIterator.tagName)
{
case "b":
if (XMLIterator.tagType == XMLTagType.Start)
{
PushTextFormat();
_format.bold = true;
}
else
PopTextFormat();
break;
case "i":
if (XMLIterator.tagType == XMLTagType.Start)
{
PushTextFormat();
_format.italic = true;
}
else
PopTextFormat();
break;
case "u":
if (XMLIterator.tagType == XMLTagType.Start)
{
PushTextFormat();
_format.underline = true;
}
else
PopTextFormat();
break;
case "strike":
if (XMLIterator.tagType == XMLTagType.Start)
{
PushTextFormat();
_format.strikethrough = true;
}
else
PopTextFormat();
break;
case "sub":
{
if (XMLIterator.tagType == XMLTagType.Start)
{
PushTextFormat();
_format.specialStyle = TextFormat.SpecialStyle.Subscript;
}
else
PopTextFormat();
}
break;
case "sup":
{
if (XMLIterator.tagType == XMLTagType.Start)
{
PushTextFormat();
_format.specialStyle = TextFormat.SpecialStyle.Superscript;
}
else
PopTextFormat();
}
break;
case "font":
if (XMLIterator.tagType == XMLTagType.Start)
{
PushTextFormat();
_format.size = XMLIterator.GetAttributeInt("size", _format.size);
string color = XMLIterator.GetAttribute("color");
if (color != null)
{
string[] parts = color.Split(',');
if (parts.Length == 1)
{
_format.color = ToolSet.ConvertFromHtmlColor(color);
_format.gradientColor = null;
_format.colorChanged = true;
}
else
{
if (_format.gradientColor == null)
_format.gradientColor = new Color32[4];
_format.gradientColor[0] = ToolSet.ConvertFromHtmlColor(parts[0]);
_format.gradientColor[1] = ToolSet.ConvertFromHtmlColor(parts[1]);
if (parts.Length > 2)
{
_format.gradientColor[2] = ToolSet.ConvertFromHtmlColor(parts[2]);
if (parts.Length > 3)
_format.gradientColor[3] = ToolSet.ConvertFromHtmlColor(parts[3]);
else
_format.gradientColor[3] = _format.gradientColor[2];
}
else
{
_format.gradientColor[2] = _format.gradientColor[0];
_format.gradientColor[3] = _format.gradientColor[1];
}
}
}
}
else if (XMLIterator.tagType == XMLTagType.End)
PopTextFormat();
break;
case "br":
AppendText("\n");
break;
case "img":
if (XMLIterator.tagType == XMLTagType.Start || XMLIterator.tagType == XMLTagType.Void)
{
HtmlElement element = HtmlElement.GetElement(HtmlElementType.Image);
element.FetchAttributes();
element.name = element.GetString("name");
element.format.align = _format.align;
_elements.Add(element);
}
break;
case "a":
if (XMLIterator.tagType == XMLTagType.Start)
{
PushTextFormat();
_format.underline = _format.underline || parseOptions.linkUnderline;
if (!_format.colorChanged && parseOptions.linkColor.a != 0)
_format.color = parseOptions.linkColor;
HtmlElement element = HtmlElement.GetElement(HtmlElementType.Link);
element.FetchAttributes();
element.name = element.GetString("name");
element.format.align = _format.align;
_elements.Add(element);
}
else if (XMLIterator.tagType == XMLTagType.End)
{
PopTextFormat();
HtmlElement element = HtmlElement.GetElement(HtmlElementType.LinkEnd);
_elements.Add(element);
}
break;
case "input":
{
HtmlElement element = HtmlElement.GetElement(HtmlElementType.Input);
element.FetchAttributes();
element.name = element.GetString("name");
element.format.CopyFrom(_format);
_elements.Add(element);
}
break;
case "select":
{
if (XMLIterator.tagType == XMLTagType.Start || XMLIterator.tagType == XMLTagType.Void)
{
HtmlElement element = HtmlElement.GetElement(HtmlElementType.Select);
element.FetchAttributes();
if (XMLIterator.tagType == XMLTagType.Start)
{
sHelperList1.Clear();
sHelperList2.Clear();
while (XMLIterator.NextTag())
{
if (XMLIterator.tagName == "select")
break;
if (XMLIterator.tagName == "option")
{
if (XMLIterator.tagType == XMLTagType.Start || XMLIterator.tagType == XMLTagType.Void)
sHelperList2.Add(XMLIterator.GetAttribute("value", string.Empty));
else
sHelperList1.Add(XMLIterator.GetText());
}
}
element.Set("items", sHelperList1.ToArray());
element.Set("values", sHelperList2.ToArray());
}
element.name = element.GetString("name");
element.format.CopyFrom(_format);
_elements.Add(element);
}
}
break;
case "p":
if (XMLIterator.tagType == XMLTagType.Start)
{
PushTextFormat();
string align = XMLIterator.GetAttribute("align");
switch (align)
{
case "center":
_format.align = AlignType.Center;
break;
case "right":
_format.align = AlignType.Right;
break;
}
if (!IsNewLine())
AppendText("\n");
}
else if (XMLIterator.tagType == XMLTagType.End)
{
AppendText("\n");
skipNextCR = true;
PopTextFormat();
}
break;
case "ui":
case "div":
case "li":
if (XMLIterator.tagType == XMLTagType.Start)
{
if (!IsNewLine())
AppendText("\n");
}
else
{
AppendText("\n");
skipNextCR = true;
}
break;
case "html":
case "body":
//full html
ignoreWhiteSpace = true;
break;
case "head":
case "style":
case "script":
case "form":
if (XMLIterator.tagType == XMLTagType.Start)
skipText++;
else if (XMLIterator.tagType == XMLTagType.End)
skipText--;
break;
}
}
if (skipText == 0)
{
text = XMLIterator.GetText(ignoreWhiteSpace);
if (text.Length > 0)
{
if (skipNextCR && text[0] == '\n')
text = text.Substring(1);
AppendText(text);
}
}
_elements = null;
}
protected void PushTextFormat()
{
TextFormat2 tf;
if (_textFormatStack.Count <= _textFormatStackTop)
{
tf = new TextFormat2();
_textFormatStack.Add(tf);
}
else
tf = _textFormatStack[_textFormatStackTop];
tf.CopyFrom(_format);
tf.colorChanged = _format.colorChanged;
_textFormatStackTop++;
}
protected void PopTextFormat()
{
if (_textFormatStackTop > 0)
{
TextFormat2 tf = _textFormatStack[_textFormatStackTop - 1];
_format.CopyFrom(tf);
_format.colorChanged = tf.colorChanged;
_textFormatStackTop--;
}
}
protected bool IsNewLine()
{
if (_elements.Count > 0)
{
HtmlElement element = _elements[_elements.Count - 1];
if (element != null && element.type == HtmlElementType.Text)
return element.text.EndsWith("\n");
else
return false;
}
return true;
}
protected void AppendText(string text)
{
HtmlElement element;
if (_elements.Count > 0)
{
element = _elements[_elements.Count - 1];
if (element.type == HtmlElementType.Text && element.format.EqualStyle(_format))
{
element.text += text;
return;
}
}
element = HtmlElement.GetElement(HtmlElementType.Text);
element.text = text;
element.format.CopyFrom(_format);
_elements.Add(element);
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 7ddf5eb218ff0cf438894e2ceb54f494
timeCreated: 1535374214
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,102 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace FairyGUI.Utils
{
/// <summary>
///
/// </summary>
public class HtmlSelect : IHtmlObject
{
public GComboBox comboBox { get; private set; }
public const string CHANGED_EVENT = "OnHtmlSelectChanged";
public static string resource;
RichTextField _owner;
HtmlElement _element;
EventCallback0 _changeHandler;
public HtmlSelect()
{
comboBox = UIPackage.CreateObjectFromURL(resource).asComboBox;
_changeHandler = () =>
{
_owner.DispatchEvent(CHANGED_EVENT, null, this);
};
}
public DisplayObject displayObject
{
get { return comboBox.displayObject; }
}
public HtmlElement element
{
get { return _element; }
}
public float width
{
get { return comboBox != null ? comboBox.width : 0; }
}
public float height
{
get { return comboBox != null ? comboBox.height : 0; }
}
public void Create(RichTextField owner, HtmlElement element)
{
_owner = owner;
_element = element;
if (comboBox == null)
return;
comboBox.onChanged.Add(_changeHandler);
int width = element.GetInt("width", comboBox.sourceWidth);
int height = element.GetInt("height", comboBox.sourceHeight);
comboBox.SetSize(width, height);
comboBox.items = (string[])element.Get("items");
comboBox.values = (string[])element.Get("values");
comboBox.value = element.GetString("value");
}
public void SetPosition(float x, float y)
{
if (comboBox != null)
comboBox.SetXY(x, y);
}
public void Add()
{
if (comboBox != null)
_owner.AddChild(comboBox.displayObject);
}
public void Remove()
{
if (comboBox != null && comboBox.displayObject.parent != null)
_owner.RemoveChild(comboBox.displayObject);
}
public void Release()
{
if (comboBox != null)
comboBox.RemoveEventListeners();
_owner = null;
_element = null;
}
public void Dispose()
{
if (comboBox != null)
comboBox.Dispose();
}
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: a9047de8f5e36634b9cb9d7270dfb1e8
timeCreated: 1461773298
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace FairyGUI.Utils
{
/// <summary>
/// Create->SetPosition->(Add<->Remove)->Release->Dispose
/// </summary>
public interface IHtmlObject
{
float width { get; }
float height { get; }
DisplayObject displayObject { get; }
HtmlElement element { get; }
void Create(RichTextField owner, HtmlElement element);
void SetPosition(float x, float y);
void Add();
void Remove();
void Release();
void Dispose();
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: d5a416822d3ee0a4d80e32f6a03ba56f
timeCreated: 1461773298
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,15 @@
namespace FairyGUI.Utils
{
/// <summary>
///
/// </summary>
public interface IHtmlPageContext
{
IHtmlObject CreateObject(RichTextField owner, HtmlElement element);
void FreeObject(IHtmlObject obj);
NTexture GetImageTexture(HtmlImage image);
void FreeImageTexture(HtmlImage image, NTexture texture);
}
}

View File

@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 0f24771f8977b674aa4fbf86f45e2105
timeCreated: 1461773298
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: