Skip to content

Commit

Permalink
Merge pull request #142 from Geequlim/puerts
Browse files Browse the repository at this point in the history
添加 puerts 支持
  • Loading branch information
xiaoguzhu authored Sep 3, 2020
2 parents 5a87fc3 + 37e3b64 commit 757b7b4
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Assets/Scripts/UI/GComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public class GComponent : GObject
Controller _applyingController;

EventListener _onDrop;

#if FAIRYGUI_PUERTS
public Utils.VirualClassObject scriptInstance;
#endif

public GComponent()
{
Expand Down Expand Up @@ -1563,6 +1567,11 @@ internal void ConstructFromResource(List<GObject> objectPool, int poolIndex)

#if FAIRYGUI_TOLUA
CallLua("ctor");
#endif
#if FAIRYGUI_PUERTS
if (scriptInstance != null) {
scriptInstance.Call("OnConstruct");
}
#endif
}

Expand Down
23 changes: 23 additions & 0 deletions Assets/Scripts/UI/Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,11 @@ virtual protected void OnInit()
{
#if FAIRYGUI_TOLUA
CallLua("OnInit");
#endif
#if FAIRYGUI_PUERTS
if (scriptInstance != null) {
scriptInstance.Call("OnInit");
}
#endif
}

Expand All @@ -398,6 +403,11 @@ virtual protected void OnShown()
{
#if FAIRYGUI_TOLUA
CallLua("OnShown");
#endif
#if FAIRYGUI_PUERTS
if (scriptInstance != null) {
scriptInstance.Call("OnShown");
}
#endif
}

Expand All @@ -408,6 +418,11 @@ virtual protected void OnHide()
{
#if FAIRYGUI_TOLUA
CallLua("OnHide");
#endif
#if FAIRYGUI_PUERTS
if (scriptInstance != null) {
scriptInstance.Call("OnHide");
}
#endif
}

Expand All @@ -419,6 +434,10 @@ virtual protected void DoShowAnimation()
#if FAIRYGUI_TOLUA
if (!CallLua("DoShowAnimation"))
OnShown();
#elif FAIRYGUI_PUERTS
if (scriptInstance == null || !scriptInstance.Call("DoShowAnimation")) {
OnShown();
}
#else
OnShown();
#endif
Expand All @@ -432,6 +451,10 @@ virtual protected void DoHideAnimation()
#if FAIRYGUI_TOLUA
if (!CallLua("DoHideAnimation"))
HideImmediately();
#elif FAIRYGUI_PUERTS
if (scriptInstance == null || !scriptInstance.Call("DoHideAnimation")) {
HideImmediately();
}
#else
HideImmediately();
#endif
Expand Down
33 changes: 33 additions & 0 deletions Assets/Scripts/Utils/VirualClassObject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;

namespace FairyGUI.Utils {

public class VirualClassObject {
private Dictionary<string, Action> methods = new Dictionary<string, Action>();

public static VirualClassObject Instance(Action<VirualClassObject> initializer) {
var obj = new VirualClassObject();
if (initializer != null) {
initializer(obj);
}
return obj;
}

public void AddMethod(string method, Action callback) {
methods[method] = callback;
}

public bool Call(string method) {
Action callback;
if (methods.TryGetValue(method, out callback)) {
if (callback != null) {
callback();
return true;
}
}
return false;
}
}

}
11 changes: 11 additions & 0 deletions Assets/Scripts/Utils/VirualClassObject.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 757b7b4

Please sign in to comment.