Skip to content

Commit 757b7b4

Browse files
authored
Merge pull request #142 from Geequlim/puerts
添加 puerts 支持
2 parents 5a87fc3 + 37e3b64 commit 757b7b4

File tree

4 files changed

+76
-0
lines changed

4 files changed

+76
-0
lines changed

Assets/Scripts/UI/GComponent.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ public class GComponent : GObject
4444
Controller _applyingController;
4545

4646
EventListener _onDrop;
47+
48+
#if FAIRYGUI_PUERTS
49+
public Utils.VirualClassObject scriptInstance;
50+
#endif
4751

4852
public GComponent()
4953
{
@@ -1563,6 +1567,11 @@ internal void ConstructFromResource(List<GObject> objectPool, int poolIndex)
15631567

15641568
#if FAIRYGUI_TOLUA
15651569
CallLua("ctor");
1570+
#endif
1571+
#if FAIRYGUI_PUERTS
1572+
if (scriptInstance != null) {
1573+
scriptInstance.Call("OnConstruct");
1574+
}
15661575
#endif
15671576
}
15681577

Assets/Scripts/UI/Window.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,11 @@ virtual protected void OnInit()
388388
{
389389
#if FAIRYGUI_TOLUA
390390
CallLua("OnInit");
391+
#endif
392+
#if FAIRYGUI_PUERTS
393+
if (scriptInstance != null) {
394+
scriptInstance.Call("OnInit");
395+
}
391396
#endif
392397
}
393398

@@ -398,6 +403,11 @@ virtual protected void OnShown()
398403
{
399404
#if FAIRYGUI_TOLUA
400405
CallLua("OnShown");
406+
#endif
407+
#if FAIRYGUI_PUERTS
408+
if (scriptInstance != null) {
409+
scriptInstance.Call("OnShown");
410+
}
401411
#endif
402412
}
403413

@@ -408,6 +418,11 @@ virtual protected void OnHide()
408418
{
409419
#if FAIRYGUI_TOLUA
410420
CallLua("OnHide");
421+
#endif
422+
#if FAIRYGUI_PUERTS
423+
if (scriptInstance != null) {
424+
scriptInstance.Call("OnHide");
425+
}
411426
#endif
412427
}
413428

@@ -419,6 +434,10 @@ virtual protected void DoShowAnimation()
419434
#if FAIRYGUI_TOLUA
420435
if (!CallLua("DoShowAnimation"))
421436
OnShown();
437+
#elif FAIRYGUI_PUERTS
438+
if (scriptInstance == null || !scriptInstance.Call("DoShowAnimation")) {
439+
OnShown();
440+
}
422441
#else
423442
OnShown();
424443
#endif
@@ -432,6 +451,10 @@ virtual protected void DoHideAnimation()
432451
#if FAIRYGUI_TOLUA
433452
if (!CallLua("DoHideAnimation"))
434453
HideImmediately();
454+
#elif FAIRYGUI_PUERTS
455+
if (scriptInstance == null || !scriptInstance.Call("DoHideAnimation")) {
456+
HideImmediately();
457+
}
435458
#else
436459
HideImmediately();
437460
#endif
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace FairyGUI.Utils {
5+
6+
public class VirualClassObject {
7+
private Dictionary<string, Action> methods = new Dictionary<string, Action>();
8+
9+
public static VirualClassObject Instance(Action<VirualClassObject> initializer) {
10+
var obj = new VirualClassObject();
11+
if (initializer != null) {
12+
initializer(obj);
13+
}
14+
return obj;
15+
}
16+
17+
public void AddMethod(string method, Action callback) {
18+
methods[method] = callback;
19+
}
20+
21+
public bool Call(string method) {
22+
Action callback;
23+
if (methods.TryGetValue(method, out callback)) {
24+
if (callback != null) {
25+
callback();
26+
return true;
27+
}
28+
}
29+
return false;
30+
}
31+
}
32+
33+
}

Assets/Scripts/Utils/VirualClassObject.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)