简体   繁体   English

使用现有的 ios 框架进行统一。 如何找到viewController的替换

[英]using existing ios framework for unity. how to find replacement of viewController

i am writing ios plugins for existing ios framework.我正在为现有的 ios 框架编写 ios 插件。

in framework, there is already a method like:在框架中,已经有一个方法,如:

public func present(from parentController: UIViewController, key: String, completionHandler handler: @escaping (Bool, String) -> Void) {
}

i understand a bit how to communicate with unity <-> swift framework.我有点了解如何与统一 <-> swift 框架进行通信。 but i am facing a challenge like,但我面临着这样的挑战,

i have a basic UI, canvas and buttons.我有一个基本的用户界面,canvas 和按钮。 i want that when user tap on button, it should call above framework method.我希望当用户点击按钮时,它应该调用上面的框架方法。 i know how to call a unity method when button tap.我知道点击按钮时如何调用统一方法。

But how can i call above method from unity, with button tap, as unity is not aware of UIViewController.但是我如何从统一调用上述方法,通过按钮点击,因为统一不知道 UIViewController。

please note: ios side is a framework, not an app, so framework is not aware of any UIKit stuffs.请注意:ios 端是框架,而不是应用程序,因此框架不知道任何 UIKit 的东西。

I think the problem you are having is that you are trying to code 1:1 Swift operations in Unity when you might want to think about encapsulation.我认为您遇到的问题是,当您可能想考虑封装时,您正在尝试在 Unity 中编写 1:1 Swift 操作。

It might be easier to have a single proxy/middleman component in your Swift code that performs operations on behalf of your Unity code.在您的 Swift 代码中拥有一个代表您的 Unity 代码执行操作的代理/中间人组件可能更容易。 In this way much of the complexity and iOS-specific aspects are hidden (encapsulated) away from your Unity code.通过这种方式,大部分复杂性和特定于 iOS 的方面都隐藏(封装)在 Unity 代码之外。 After all, all your Unity code might be concerned about is that a certain window be shown , it does not care how it is done.毕竟,您的所有 Unity 代码可能关心的是显示某个 window ,它并不关心它是如何完成的。

So you might expose a very simple contract to Unity like (pseudo code):因此,您可能会向 Unity 公开一个非常简单的合约,例如(伪代码):

ShowWindow (string name, callback allDone);

...then in your Unity code: ...然后在您的 Unity 代码中:

PluginManager pluginManager; // a set of predefined [DllImport]s

void OnZapRobotClicked()
{
   pluginManager.ShowWindow ("ZapRobot", () => { Debug.Log("Done"); } );
}

When ShowWindow is called in your Swift code, you use the appropriate Swift APIs to display the appropriate view with the appropriate controller.在 Swift 代码中调用ShowWindow时,您可以使用相应的 Swift API 来显示带有相应 controller 的相应视图。 How that is done exactly is no different to showing windows in Swift at the best of times.如何做到这一点与在最好的情况下在 Swift 中显示 windows 没有什么不同。

Now instead of having to code up a zillion [DllImport] s Unity-side just to show a single window, you simply have one method per feature that you want to expose, ShowWindow being the very first.现在不必编写无数[DllImport]的 Unity 端来显示单个 window,您只需为每个要公开的功能提供一个方法ShowWindow是第一个。 You might have other methods like SendMessage , LoadSettings , SaveSettings , DisablePlugin .您可能有其他方法,例如SendMessageLoadSettingsSaveSettingsDisablePlugin

Depending on how you are designing your plugin system, you might want to consider making this main proxy plugin the router that directs commands from your C# code to the appropriate plugin Swift-side.根据您设计插件系统的方式,您可能需要考虑将此主代理插件作为路由器,将命令从您的 C# 代码定向到适当的插件 Swift 端。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM