Skip to content

Commit 2791924

Browse files
committed
允许通过脚本重写 GLoader3D
1 parent e1ab24a commit 2791924

2 files changed

Lines changed: 35 additions & 2 deletions

File tree

Assets/Scripts/UI/GLoader3D.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using UnityEngine;
22
using FairyGUI.Utils;
3+
using System;
34

45
namespace FairyGUI
56
{
@@ -25,6 +26,11 @@ public partial class GLoader3D : GObject, IAnimationGear, IColorGear
2526
protected PackageItem _contentItem;
2627
protected GoWrapper _content;
2728

29+
#if FAIRYGUI_PUERTS
30+
public Action __loadExternal;
31+
public Action __freeExternal;
32+
#endif
33+
2834
public GLoader3D()
2935
{
3036
_url = string.Empty;
@@ -387,11 +393,24 @@ virtual protected void OnChange(string propertyName)
387393

388394
virtual protected void LoadExternal()
389395
{
396+
#if FAIRYGUI_PUERTS
397+
if (__loadExternal != null)
398+
{
399+
__loadExternal();
400+
return;
401+
}
402+
#endif
390403
}
391404

392405
virtual protected void FreeExternal()
393406
{
394-
GameObject.DestroyImmediate(_content.wrapTarget);
407+
#if FAIRYGUI_PUERTS
408+
if (__freeExternal != null)
409+
{
410+
__freeExternal();
411+
}
412+
if (_content.wrapTarget != null) GameObject.DestroyImmediate(_content.wrapTarget);
413+
#endif
395414
}
396415

397416
protected void UpdateLayout()

Assets/Scripts/UI/UIObjectFactory.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ public class UIObjectFactory
1414
{
1515
public delegate GComponent GComponentCreator();
1616
public delegate GLoader GLoaderCreator();
17+
public delegate GLoader3D GLoader3DCreator();
1718

1819
static Dictionary<string, GComponentCreator> packageItemExtensions = new Dictionary<string, GComponentCreator>();
1920
static GLoaderCreator loaderCreator;
21+
static GLoader3DCreator loader3DCreator;
2022

2123
/// <summary>
2224
///
@@ -81,6 +83,15 @@ public static void SetLoaderExtension(GLoaderCreator creator)
8183
loaderCreator = creator;
8284
}
8385

86+
/// <summary>
87+
///
88+
/// </summary>
89+
/// <param name="creator"></param>
90+
public static void SetLoader3DExtension(GLoader3DCreator creator)
91+
{
92+
loader3DCreator = creator;
93+
}
94+
8495
internal static void ResolvePackageItemExtension(PackageItem pi)
8596
{
8697
if (!packageItemExtensions.TryGetValue(UIPackage.URL_PREFIX + pi.owner.id + pi.id, out pi.extensionCreator)
@@ -193,7 +204,10 @@ public static GObject NewObject(ObjectType type)
193204
return new GTree();
194205

195206
case ObjectType.Loader3D:
196-
return new GLoader3D();
207+
if (loader3DCreator != null)
208+
return loader3DCreator();
209+
else
210+
return new GLoader3D();
197211

198212
default:
199213
return null;

0 commit comments

Comments
 (0)