Unity3D调用快三平台出租原生Android和IOS复制粘贴功能

今天要实现快三平台出租 haozbbs.com Q1446595067 用Unity调用设备的复制到粘贴板功能,Unity没有实现这个功能,所以需要调用设备原生的功能了,在网上找了一下,不算太多而且大多都不能使用,或者一使用程序就卡死的情况。没办法只能靠自己了,但对于Android和IOS开发的小白的我来说,自己实现是不可能的了,这辈子都不可能的。

不过还好,今天我在网上找到一篇靠谱的文章:http://www.andrewnoske.com/wiki/Unity_-_Clipboard

下面的代码就是Unity怎么使用这个插件,包括复制到粘贴板和粘贴功能都已经详细说明怎么使用了。

using UnityEngine;
using System.Runtime.InteropServices;

public class UniClipboard
{
static IBoard _board;
static IBoard board{
get{
if (_board == null) {
#if UNITY_EDITOR
_board = new EditorBoard();
#elif UNITY_ANDROID
_board = new AndroidBoard();
#elif UNITY_IOS
_board = new IOSBoard ();
#endif
}
return _board;
}
}

public static void SetText(string str){
Debug.Log ("SetText");
board.SetText (str);
}

public static string GetText(){
return board.GetText ();
}
}

interface IBoard{
void SetText(string str);
string GetText();
}

class EditorBoard : IBoard {
public void SetText(string str){
GUIUtility.systemCopyBuffer = str;
}

public string GetText(){
return GUIUtility.systemCopyBuffer;
}
}

#if UNITY_IOS
class IOSBoard : IBoard {
[DllImport("_Internal")]
static extern void SetText
(string str);
[DllImport("_Internal")]
static extern string GetText
();

public void SetText(string str){
if (Application.platform != RuntimePlatform.OSXEditor) {
SetText_ (str);
}
}

public string GetText(){
return GetText_();
}
}
#endif

#if UNITY_ANDROID
class AndroidBoard : IBoard {

AndroidJavaClass cb = new AndroidJavaClass("jp.ne.donuts.uniclipboard.Clipboard");

public void SetText(string str){
Debug.Log ("Set Text At AndroidBoard: " + str);
cb.CallStatic ("setText", str);
}

public string GetText(){
return cb.CallStatic<string> ("getText");
}
}
#endif

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80

本人测试完美成功

重点就是原生功能的实现了。没关系我已经在下面送出了整个工程源码,里面包含了Android的Jar文件,和IOS的.m文件。

猜你喜欢

转载自blog.51cto.com/13861280/2139591