diff --git a/Assets/Scripts/Core/DisplayObject.cs b/Assets/Scripts/Core/DisplayObject.cs
index 5e15c61d..4d14fdfa 100644
--- a/Assets/Scripts/Core/DisplayObject.cs
+++ b/Assets/Scripts/Core/DisplayObject.cs
@@ -226,6 +226,59 @@ public EventListener onFocusOut
}
+ ///
+ ///
+ ///
+ public EventListener onEnable
+ {
+ get
+ {
+ CreateEventComponent();
+ return _onEnable ?? (_onEnable = new EventListener(this, "onEnable"));
+ }
+ }
+
+ ///
+ ///
+ ///
+ public EventListener onDisable
+ {
+ get
+ {
+ CreateEventComponent();
+ return _onDisable ?? (_onDisable = new EventListener(this, "onDisable"));
+ }
+ }
+ EventListener _onEnable;
+ EventListener _onDisable;
+
+
+ class DisplayObjectEvents : MonoBehaviour
+ {
+ public Action onEnable;
+ public Action onDisable;
+
+ void OnDisable()
+ {
+ onDisable?.Invoke();
+ }
+
+ void OnEnable()
+ {
+ onEnable?.Invoke();
+ }
+ }
+ DisplayObjectEvents _events;
+ protected void CreateEventComponent()
+ {
+ if (_events == null)
+ {
+ _events = gameObject.AddComponent();
+ _events.onEnable = () => _onEnable?.Call();
+ _events.onDisable = () => _onDisable?.Call();
+ }
+ }
+
protected void CreateGameObject(string gameObjectName)
{
gameObject = new GameObject(gameObjectName);
diff --git a/Assets/Scripts/Extensions/TextMeshPro/TMPFont.cs b/Assets/Scripts/Extensions/TextMeshPro/TMPFont.cs
index 01482ba6..8a312d3f 100644
--- a/Assets/Scripts/Extensions/TextMeshPro/TMPFont.cs
+++ b/Assets/Scripts/Extensions/TextMeshPro/TMPFont.cs
@@ -99,8 +99,8 @@ void Init()
void OnCreateNewMaterial(Material mat)
{
- mat.SetFloat(ShaderUtilities.ID_TextureWidth, mainTexture.width);
- mat.SetFloat(ShaderUtilities.ID_TextureHeight, mainTexture.height);
+ mat.SetFloat(ShaderUtilities.ID_TextureWidth, fontAsset.atlasWidth);
+ mat.SetFloat(ShaderUtilities.ID_TextureHeight, fontAsset.atlasHeight);
mat.SetFloat(ShaderUtilities.ID_GradientScale, _gradientScale);
mat.SetFloat(ShaderUtilities.ID_WeightNormal, fontAsset.normalStyle);
mat.SetFloat(ShaderUtilities.ID_WeightBold, fontAsset.boldStyle);
diff --git a/Assets/Scripts/UI/GComponent.cs b/Assets/Scripts/UI/GComponent.cs
index 8c19a0a9..3002ea4a 100644
--- a/Assets/Scripts/UI/GComponent.cs
+++ b/Assets/Scripts/UI/GComponent.cs
@@ -66,6 +66,22 @@ override protected void CreateDisplayObject()
override public void Dispose()
{
+
+#if FAIRYGUI_TOLUA
+ if (_peerTable != null)
+ {
+ _peerTable.Dispose();
+ _peerTable = null;
+ }
+#endif
+
+#if FAIRYGUI_PUERTS
+ if (__onDispose != null)
+ __onDispose();
+ __onConstruct = null;
+ __onDispose = null;
+#endif
+
int cnt = _transitions.Count;
for (int i = 0; i < cnt; ++i)
{
@@ -83,8 +99,6 @@ override public void Dispose()
if (scrollPane != null)
scrollPane.Dispose();
- base.Dispose(); //Dispose native tree first, avoid DisplayObject.RemoveFromParent call
-
cnt = _children.Count;
for (int i = cnt - 1; i >= 0; --i)
{
@@ -93,20 +107,7 @@ override public void Dispose()
obj.Dispose();
}
-#if FAIRYGUI_TOLUA
- if (_peerTable != null)
- {
- _peerTable.Dispose();
- _peerTable = null;
- }
-#endif
-
-#if FAIRYGUI_PUERTS
- if (__onDispose != null)
- __onDispose();
- __onConstruct = null;
- __onDispose = null;
-#endif
+ base.Dispose(); //Dispose native tree first, avoid DisplayObject.RemoveFromParent call
}
///
diff --git a/Assets/Scripts/UI/GGraph.cs b/Assets/Scripts/UI/GGraph.cs
index 2dfed8e8..7b90989d 100644
--- a/Assets/Scripts/UI/GGraph.cs
+++ b/Assets/Scripts/UI/GGraph.cs
@@ -100,6 +100,7 @@ public void SetNativeObject(DisplayObject obj)
_shape = null;
}
+ if (displayObject != null) displayObject.Dispose();
displayObject = obj;
if (displayObject != null)
diff --git a/Assets/Scripts/UI/GLoader.cs b/Assets/Scripts/UI/GLoader.cs
index 3749ee22..02d90aa2 100644
--- a/Assets/Scripts/UI/GLoader.cs
+++ b/Assets/Scripts/UI/GLoader.cs
@@ -33,6 +33,7 @@ public class GLoader : GObject, IAnimationGear, IColorGear
#if FAIRYGUI_PUERTS
public Action __loadExternal;
public Action __freeExternal;
+ public Action __setUrl;
#endif
public GLoader()
@@ -94,6 +95,12 @@ public string url
ClearContent();
_url = value;
+#if FAIRYGUI_PUERTS
+ if (__setUrl != null)
+ {
+ __setUrl(_url);
+ }
+#endif
LoadContent();
UpdateGear(7);
}
@@ -405,6 +412,21 @@ protected void LoadContent()
LoadExternal();
}
+ public void SetComponentContent(GComponent obj)
+ {
+ if (obj == _content2) return;
+ ClearContent();
+ _content2 = obj;
+
+ if (_content2 != null)
+ {
+ ((Container)displayObject).AddChild(obj.displayObject);
+ sourceWidth = (int)_content2.width;
+ sourceHeight = (int)_content2.height;
+ UpdateLayout();
+ }
+ }
+
protected void LoadFromPackage(string itemURL)
{
_contentItem = UIPackage.GetItemByURL(itemURL);
@@ -635,11 +657,14 @@ protected void UpdateLayout()
{
if (_useResize)
{
- _content2.SetScale(1, 1);
+ sx = sy = 1;
+ contentWidth = width;
+ contentHeight = height;
+ _content2.SetXY(0, 0);
+ _content2.SetScale(sx, sy);
_content2.SetSize(contentWidth, contentHeight, true);
}
- else
- _content2.SetScale(sx, sy);
+ _content2.SetScale(sx, sy);
}
else
_content.size = new Vector2(contentWidth, contentHeight);
@@ -724,6 +749,8 @@ override public void Setup_BeforeAdd(ByteBuffer buffer, int beginPos)
}
if (buffer.version >= 7)
_useResize = buffer.ReadBool();
+ else
+ _useResize = _fill == FillType.ScaleFree;
if (!string.IsNullOrEmpty(_url))
LoadContent();
diff --git a/Assets/Scripts/UI/GLoader3D.cs b/Assets/Scripts/UI/GLoader3D.cs
index a9a092de..b2de8120 100644
--- a/Assets/Scripts/UI/GLoader3D.cs
+++ b/Assets/Scripts/UI/GLoader3D.cs
@@ -1,5 +1,6 @@
using UnityEngine;
using FairyGUI.Utils;
+using System;
namespace FairyGUI
{
@@ -25,6 +26,11 @@ public partial class GLoader3D : GObject, IAnimationGear, IColorGear
protected PackageItem _contentItem;
protected GoWrapper _content;
+#if FAIRYGUI_PUERTS
+ public Action __loadExternal;
+ public Action __freeExternal;
+#endif
+
public GLoader3D()
{
_url = string.Empty;
@@ -387,11 +393,24 @@ virtual protected void OnChange(string propertyName)
virtual protected void LoadExternal()
{
+#if FAIRYGUI_PUERTS
+ if (__loadExternal != null)
+ {
+ __loadExternal();
+ return;
+ }
+#endif
}
virtual protected void FreeExternal()
{
- GameObject.DestroyImmediate(_content.wrapTarget);
+#if FAIRYGUI_PUERTS
+ if (__freeExternal != null)
+ {
+ __freeExternal();
+ }
+ if (_content.wrapTarget != null) GameObject.DestroyImmediate(_content.wrapTarget);
+#endif
}
protected void UpdateLayout()
diff --git a/Assets/Scripts/UI/GRoot.cs b/Assets/Scripts/UI/GRoot.cs
index 21e8546c..7a064cdc 100644
--- a/Assets/Scripts/UI/GRoot.cs
+++ b/Assets/Scripts/UI/GRoot.cs
@@ -33,6 +33,13 @@ public static int contentScaleLevel
GObject _tooltipWin;
GObject _defaultTooltipWin;
+ GComponent _popupLayer;
+ public GComponent popupLayer
+ {
+ get { return _popupLayer != null ? _popupLayer : this; }
+ set { _popupLayer = value; }
+ }
+
internal static GRoot _inst;
public static GRoot inst
{
@@ -130,7 +137,7 @@ public void ApplyContentScaleFactor()
///
public void ShowWindow(Window win)
{
- AddChild(win);
+ popupLayer.AddChild(win);
AdjustModalLayer();
}
@@ -162,8 +169,8 @@ public void HideWindowImmediately(Window win)
/// True to dispose the window.
public void HideWindowImmediately(Window win, bool dispose)
{
- if (win.parent == this)
- RemoveChild(win, dispose);
+ if (win.parent == popupLayer)
+ popupLayer.RemoveChild(win, dispose);
else if (dispose)
win.Dispose();
@@ -176,16 +183,16 @@ public void HideWindowImmediately(Window win, bool dispose)
///
public void BringToFront(Window win)
{
- int cnt = this.numChildren;
+ int cnt = popupLayer.numChildren;
int i;
if (_modalLayer != null && _modalLayer.parent != null && !win.modal)
- i = GetChildIndex(_modalLayer) - 1;
+ i = popupLayer.GetChildIndex(_modalLayer) - 1;
else
i = cnt - 1;
for (; i >= 0; i--)
{
- GObject g = GetChildAt(i);
+ GObject g = popupLayer.GetChildAt(i);
if (g == win)
return;
if (g is Window)
@@ -193,7 +200,7 @@ public void BringToFront(Window win)
}
if (i >= 0)
- SetChildIndex(win, i);
+ popupLayer.SetChildIndex(win, i);
}
///
@@ -208,12 +215,12 @@ public void ShowModalWait()
if (_modalWaitPane == null || _modalWaitPane.isDisposed)
{
_modalWaitPane = UIPackage.CreateObjectFromURL(UIConfig.globalModalWaiting);
- _modalWaitPane.SetHome(this);
+ _modalWaitPane.SetHome(popupLayer);
}
- _modalWaitPane.SetSize(this.width, this.height);
- _modalWaitPane.AddRelation(this, RelationType.Size);
+ _modalWaitPane.SetSize(popupLayer.width, popupLayer.height);
+ _modalWaitPane.AddRelation(popupLayer, RelationType.Size);
- AddChild(_modalWaitPane);
+ popupLayer.AddChild(_modalWaitPane);
}
}
@@ -223,7 +230,7 @@ public void ShowModalWait()
public void CloseModalWait()
{
if (_modalWaitPane != null && _modalWaitPane.parent != null)
- RemoveChild(_modalWaitPane);
+ popupLayer.RemoveChild(_modalWaitPane);
}
///
@@ -258,10 +265,10 @@ public void CloseAllWindows()
///
public Window GetTopWindow()
{
- int cnt = this.numChildren;
+ int cnt = popupLayer.numChildren;
for (int i = cnt - 1; i >= 0; i--)
{
- GObject g = this.GetChildAt(i);
+ GObject g = popupLayer.GetChildAt(i);
if (g is Window)
{
return (Window)(g);
@@ -288,10 +295,10 @@ public GGraph modalLayer
void CreateModalLayer()
{
_modalLayer = new GGraph();
- _modalLayer.DrawRect(this.width, this.height, 0, Color.white, UIConfig.modalLayerColor);
- _modalLayer.AddRelation(this, RelationType.Size);
+ _modalLayer.DrawRect(popupLayer.width, popupLayer.height, 0, Color.white, UIConfig.modalLayerColor);
+ _modalLayer.AddRelation(popupLayer, RelationType.Size);
_modalLayer.name = _modalLayer.gameObjectName = "ModalLayer";
- _modalLayer.SetHome(this);
+ _modalLayer.SetHome(popupLayer);
}
///
@@ -346,26 +353,26 @@ private void AdjustModalLayer()
if (_modalLayer == null || _modalLayer.isDisposed)
CreateModalLayer();
- int cnt = this.numChildren;
+ int cnt = popupLayer.numChildren;
if (_modalWaitPane != null && _modalWaitPane.parent != null)
- SetChildIndex(_modalWaitPane, cnt - 1);
+ popupLayer.SetChildIndex(_modalWaitPane, cnt - 1);
for (int i = cnt - 1; i >= 0; i--)
{
- GObject g = this.GetChildAt(i);
+ GObject g = popupLayer.GetChildAt(i);
if ((g is Window) && (g as Window).modal)
{
if (_modalLayer.parent == null)
- AddChildAt(_modalLayer, i);
+ popupLayer.AddChildAt(_modalLayer, i);
else
- SetChildIndexBefore(_modalLayer, i);
+ popupLayer.SetChildIndexBefore(_modalLayer, i);
return;
}
}
if (_modalLayer.parent != null)
- RemoveChild(_modalLayer);
+ _modalLayer.RemoveFromParent();
}
///
@@ -448,7 +455,7 @@ public void ShowPopup(GObject popup, GObject target, PopupDirection dir, bool cl
GObject p = target;
while (p != null)
{
- if (p.parent == this)
+ if (p.parent == popupLayer)
{
if (popup.sortingOrder < p.sortingOrder)
{
@@ -460,7 +467,7 @@ public void ShowPopup(GObject popup, GObject target, PopupDirection dir, bool cl
}
}
- AddChild(popup);
+ popupLayer.AddChild(popup);
AdjustModalLayer();
if ((popup is Window) && target == null && dir == PopupDirection.Auto)
@@ -495,14 +502,14 @@ public Vector2 GetPoupPosition(GObject popup, GObject target, PopupDirection dir
}
else
{
- pos = this.GlobalToLocal(Stage.inst.touchPosition);
+ pos = popupLayer.GlobalToLocal(Stage.inst.touchPosition);
}
float xx, yy;
xx = pos.x;
- if (xx + popup.width > this.width)
+ if (xx + popup.width > popupLayer.width)
xx = xx + size.x - popup.width;
yy = pos.y + size.y;
- if ((dir == PopupDirection.Auto && yy + popup.height > this.height)
+ if ((dir == PopupDirection.Auto && yy + popup.height > popupLayer.height)
|| dir == PopupDirection.Up)
{
yy = pos.y - popup.height - 1;
@@ -622,7 +629,7 @@ void ClosePopup(GObject target)
if (target is Window)
((Window)target).Hide();
else
- RemoveChild(target);
+ target.RemoveFromParent();
}
}
@@ -652,7 +659,7 @@ public void ShowTooltips(string msg, float delay)
}
_defaultTooltipWin = UIPackage.CreateObjectFromURL(resourceURL);
- _defaultTooltipWin.SetHome(this);
+ _defaultTooltipWin.SetHome(popupLayer);
_defaultTooltipWin.touchable = false;
}
@@ -690,13 +697,13 @@ void __showTooltipsWin(object param)
float xx = Stage.inst.touchPosition.x + 10;
float yy = Stage.inst.touchPosition.y + 20;
- Vector2 pt = this.GlobalToLocal(new Vector2(xx, yy));
+ Vector2 pt = popupLayer.GlobalToLocal(new Vector2(xx, yy));
xx = pt.x;
yy = pt.y;
- if (xx + _tooltipWin.width > this.width)
+ if (xx + _tooltipWin.width > popupLayer.width)
xx = xx - _tooltipWin.width;
- if (yy + _tooltipWin.height > this.height)
+ if (yy + _tooltipWin.height > popupLayer.height)
{
yy = yy - _tooltipWin.height - 1;
if (yy < 0)
@@ -705,7 +712,7 @@ void __showTooltipsWin(object param)
_tooltipWin.x = Mathf.RoundToInt(xx);
_tooltipWin.y = Mathf.RoundToInt(yy);
- AddChild(_tooltipWin);
+ popupLayer.AddChild(_tooltipWin);
}
///
@@ -716,7 +723,7 @@ public void HideTooltips()
if (_tooltipWin != null)
{
if (_tooltipWin.parent != null)
- RemoveChild(_tooltipWin);
+ _tooltipWin.RemoveFromParent();
_tooltipWin = null;
}
}
diff --git a/Assets/Scripts/UI/UIObjectFactory.cs b/Assets/Scripts/UI/UIObjectFactory.cs
index 12e90ff4..403453c9 100644
--- a/Assets/Scripts/UI/UIObjectFactory.cs
+++ b/Assets/Scripts/UI/UIObjectFactory.cs
@@ -14,9 +14,11 @@ public class UIObjectFactory
{
public delegate GComponent GComponentCreator();
public delegate GLoader GLoaderCreator();
+ public delegate GLoader3D GLoader3DCreator();
static Dictionary packageItemExtensions = new Dictionary();
static GLoaderCreator loaderCreator;
+ static GLoader3DCreator loader3DCreator;
///
///
@@ -81,6 +83,15 @@ public static void SetLoaderExtension(GLoaderCreator creator)
loaderCreator = creator;
}
+ ///
+ ///
+ ///
+ ///
+ public static void SetLoader3DExtension(GLoader3DCreator creator)
+ {
+ loader3DCreator = creator;
+ }
+
internal static void ResolvePackageItemExtension(PackageItem pi)
{
if (!packageItemExtensions.TryGetValue(UIPackage.URL_PREFIX + pi.owner.id + pi.id, out pi.extensionCreator)
@@ -193,7 +204,10 @@ public static GObject NewObject(ObjectType type)
return new GTree();
case ObjectType.Loader3D:
- return new GLoader3D();
+ if (loader3DCreator != null)
+ return loader3DCreator();
+ else
+ return new GLoader3D();
default:
return null;