Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

一些优化和修正功能 #229

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
53 changes: 53 additions & 0 deletions Assets/Scripts/Core/DisplayObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,59 @@ public EventListener onFocusOut

}

/// <summary>
///
/// </summary>
public EventListener onEnable
{
get
{
CreateEventComponent();
return _onEnable ?? (_onEnable = new EventListener(this, "onEnable"));
}
}

/// <summary>
///
/// </summary>
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<DisplayObjectEvents>();
_events.onEnable = () => _onEnable?.Call();
_events.onDisable = () => _onDisable?.Call();
}
}

protected void CreateGameObject(string gameObjectName)
{
gameObject = new GameObject(gameObjectName);
Expand Down
4 changes: 2 additions & 2 deletions Assets/Scripts/Extensions/TextMeshPro/TMPFont.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
33 changes: 17 additions & 16 deletions Assets/Scripts/UI/GComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand All @@ -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
}

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions Assets/Scripts/UI/GGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public void SetNativeObject(DisplayObject obj)
_shape = null;
}

if (displayObject != null) displayObject.Dispose();
displayObject = obj;

if (displayObject != null)
Expand Down
33 changes: 30 additions & 3 deletions Assets/Scripts/UI/GLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class GLoader : GObject, IAnimationGear, IColorGear
#if FAIRYGUI_PUERTS
public Action __loadExternal;
public Action<NTexture> __freeExternal;
public Action<string> __setUrl;
#endif

public GLoader()
Expand Down Expand Up @@ -94,6 +95,12 @@ public string url

ClearContent();
_url = value;
#if FAIRYGUI_PUERTS
if (__setUrl != null)
{
__setUrl(_url);
}
#endif
LoadContent();
UpdateGear(7);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
21 changes: 20 additions & 1 deletion Assets/Scripts/UI/GLoader3D.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using UnityEngine;
using FairyGUI.Utils;
using System;

namespace FairyGUI
{
Expand All @@ -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;
Expand Down Expand Up @@ -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()
Expand Down
Loading