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

[Unity3D-sdk] Fix conflicts between different UnityNodes #115

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions Unity3D/PocoManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
public class PocoManager : MonoBehaviour
{
public const int versionCode = 6;
[SerializeField] private UnityNodeProvider nodeProvider;
public int port = 5001;
private bool mRunning;
public AsyncTcpServer server = null;
private RPCParser rpc = null;
private SimpleProtocolFilter prot = null;
private UnityDumper dumper = new UnityDumper();
private UnityDumper dumper = null;
private ConcurrentDictionary<string, TcpClientState> inbox = new ConcurrentDictionary<string, TcpClientState>();
private VRSupport vr_support = new VRSupport();
private Dictionary<string, long> debugProfilingData = new Dictionary<string, long>() {
Expand All @@ -35,10 +36,36 @@ class RPC : Attribute
{
}

#if UNITY_EDITOR
private void OnValidate()
{
if (!nodeProvider)
{
UnityNodeProvider otherNodeProvider = null;
foreach (var nodeFactoryAssetGuid in UnityEditor.AssetDatabase.FindAssets("t:UnityNodeProvider"))
{
var nodeFactoryAssetPath = UnityEditor.AssetDatabase.GUIDToAssetPath(nodeFactoryAssetGuid);
otherNodeProvider = UnityEditor.AssetDatabase.LoadAssetAtPath<UnityNodeProvider>(nodeFactoryAssetPath);
if (otherNodeProvider) break;
}

if (otherNodeProvider)
{
nodeProvider = otherNodeProvider;
}
else
{
Debug.LogError("Failed to find UnityNodeProvider for Poco.");
}
}
}
#endif

void Awake()
{
Application.runInBackground = true;
DontDestroyOnLoad(this);
dumper = new UnityDumper(nodeProvider);
prot = new SimpleProtocolFilter();
rpc = new RPCParser();
rpc.addRpcMethod("isVRSupported", vr_support.isVRSupported);
Expand Down Expand Up @@ -170,7 +197,7 @@ private object SetText(List<object> param)
{
if (go.GetInstanceID() == instanceId)
{
return UnityNode.SetText(go, textVal);
return nodeProvider.SetText(go, textVal);
}
}
return false;
Expand Down
21 changes: 13 additions & 8 deletions Unity3D/UnityDumper.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using UnityEngine;

namespace Poco
{
public class UnityDumper : AbstractDumper
{
private readonly UnityNodeProvider nodeProvider;

public UnityDumper(UnityNodeProvider nodeProvider)
{
this.nodeProvider = nodeProvider;
}

public override AbstractNode getRoot()
{
return new RootNode();
return nodeProvider ? new RootNode(nodeProvider) : null;
}
}

public class RootNode : AbstractNode
{
private List<AbstractNode> children = null;
private readonly List<AbstractNode> children = new List<AbstractNode>();

public RootNode()
public RootNode(UnityNodeProvider nodeProvider)
{
children = new List<AbstractNode>();
foreach (GameObject obj in Transform.FindObjectsOfType(typeof(GameObject)))
foreach (GameObject obj in Object.FindObjectsOfType(typeof(GameObject)))
{
if (obj.transform.parent == null)
{
children.Add(new UnityNode(obj));
children.Add(nodeProvider.CreateNode(obj));
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions Unity3D/UnityNodeProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using UnityEngine;

namespace Poco
{
public abstract class UnityNodeProvider: ScriptableObject
{
public abstract AbstractNode CreateNode(GameObject gameObject);
public abstract bool SetText(GameObject go, string textVal);
}
}
Binary file added Unity3D/fairygui/FairyGuiUnityNodeProvider.asset
Binary file not shown.
17 changes: 17 additions & 0 deletions Unity3D/fairygui/FairyGuiUnityNodeProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using UnityEngine;

namespace Poco.FairyGUI
{
public class FairyGuiUnityNodeProvider : UnityNodeProvider
{
public override AbstractNode CreateNode(GameObject gameObject)
{
return new UnityNode(gameObject);
}

public override bool SetText(GameObject go, string textVal)
{
return UnityNode.SetText(go, textVal);
}
}
}
2 changes: 1 addition & 1 deletion Unity3D/fairygui/UnityNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using UnityEngine;
using FairyGUI;

namespace Poco
namespace Poco.FairyGUI
{
public class UnityNode : AbstractNode
{
Expand Down
Binary file added Unity3D/ngui/NGuiUnityNodeProvider.asset
Binary file not shown.
17 changes: 17 additions & 0 deletions Unity3D/ngui/NGuiUnityNodeProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using UnityEngine;

namespace Poco.NGUI
{
public class NGuiUnityNodeProvider : UnityNodeProvider
{
public override AbstractNode CreateNode(GameObject gameObject)
{
return new UnityNode(gameObject);
}

public override bool SetText(GameObject go, string textVal)
{
return UnityNode.SetText(go, textVal);
}
}
}
2 changes: 1 addition & 1 deletion Unity3D/ngui/UnityNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using UnityEngine;


namespace Poco
namespace Poco.NGUI
{
public class UnityNode : AbstractNode
{
Expand Down
Binary file added Unity3D/ugui/UGuiUnityNodeProvider.asset
Binary file not shown.
17 changes: 17 additions & 0 deletions Unity3D/ugui/UGuiUnityNodeProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using UnityEngine;

namespace Poco.UGUI
{
public class UGuiUnityNodeProvider : UnityNodeProvider
{
public override AbstractNode CreateNode(GameObject gameObject)
{
return new UnityNode(gameObject);
}

public override bool SetText(GameObject go, string textVal)
{
return UnityNode.SetText(go, textVal);
}
}
}
2 changes: 1 addition & 1 deletion Unity3D/ugui/UnityNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using TMPro;


namespace Poco
namespace Poco.UGUI
{
public class UnityNode : AbstractNode
{
Expand Down
Binary file not shown.
17 changes: 17 additions & 0 deletions Unity3D/uguiWithTMPro/UGuiWithTMProUnityNodeProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using UnityEngine;

namespace Poco.UGUIWithTMPro
{
public class UGuiWithTMProUnityNodeProvider : UnityNodeProvider
{
public override AbstractNode CreateNode(GameObject gameObject)
{
return new UnityNode(gameObject);
}

public override bool SetText(GameObject go, string textVal)
{
return UnityNode.SetText(go, textVal);
}
}
}
9 changes: 5 additions & 4 deletions Unity3D/uguiWithTMPro/UnityNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
using TMPro;


namespace Poco
namespace Poco.UGUIWithTMPro
{
public class UnityNode : AbstractNode
{
Expand Down Expand Up @@ -215,16 +214,18 @@ private bool GameObjectClickable(List<string> components)

private string GameObjectText()
{
TMP_Text tmpText = gameObject.GetComponent<TMP_Text>();
#if UNITY_2018_1_OR_NEWER
var tmpText = gameObject.GetComponent<TMPro.TMP_Text>();
if (tmpText)
{
return tmpText.GetParsedText();
}
TextMeshProUGUI tmpUIText = gameObject.GetComponent<TextMeshProUGUI>();
var tmpUIText = gameObject.GetComponent<TMPro.TextMeshProUGUI>();
if (tmpUIText)
{
return tmpUIText.GetParsedText();
}
#endif
Text text = gameObject.GetComponent<Text>();
return text ? text.text : null;
}
Expand Down