├── README.md
├── demo
├── Assembly-CSharp-vs.csproj
├── Assembly-CSharp.csproj
├── Assets
│ ├── AssetStoreTools.meta
│ ├── AssetStoreTools
│ │ ├── Editor.meta
│ │ ├── Editor
│ │ │ ├── AssetStoreTools.dll
│ │ │ ├── AssetStoreTools.dll.meta
│ │ │ ├── AssetStoreToolsExtra.dll
│ │ │ ├── AssetStoreToolsExtra.dll.meta
│ │ │ ├── DroidSansMono.ttf
│ │ │ ├── DroidSansMono.ttf.meta
│ │ │ ├── icon.png
│ │ │ └── icon.png.meta
│ │ └── Labels.asset
│ ├── NativeEditPlugin.meta
│ ├── NativeEditPlugin
│ │ ├── Plugins.meta
│ │ ├── Plugins
│ │ │ ├── Android
│ │ │ │ ├── AndroidManifest.xml
│ │ │ │ └── nativeeditplugin.jar
│ │ │ ├── iOS.meta
│ │ │ └── iOS
│ │ │ │ ├── EditBox_iOS.h
│ │ │ │ ├── EditBox_iOS.h.meta
│ │ │ │ ├── EditBox_iOS.m
│ │ │ │ ├── EditBox_iOS.m.meta
│ │ │ │ ├── JsonObject.h
│ │ │ │ ├── JsonObject.h.meta
│ │ │ │ ├── JsonObject.m
│ │ │ │ ├── JsonObject.m.meta
│ │ │ │ ├── PlaceholderTextView.h
│ │ │ │ ├── PlaceholderTextView.h.meta
│ │ │ │ ├── PlaceholderTextView.m
│ │ │ │ ├── PlaceholderTextView.m.meta
│ │ │ │ ├── PluginMsgInterface.mm
│ │ │ │ └── PluginMsgInterface.mm.meta
│ │ ├── README.md
│ │ ├── demo.meta
│ │ ├── demo
│ │ │ ├── demo.cs
│ │ │ ├── demo.cs.meta
│ │ │ ├── demo.unity
│ │ │ └── demo.unity.meta
│ │ ├── scripts.meta
│ │ └── scripts
│ │ │ ├── JsonObject.cs
│ │ │ ├── JsonObject.cs.meta
│ │ │ ├── MiniJSON.cs
│ │ │ ├── MiniJSON.cs.meta
│ │ │ ├── NativeEditBox.cs
│ │ │ ├── NativeEditBox.cs.meta
│ │ │ ├── PluginMsgHandler.cs
│ │ │ └── PluginMsgHandler.cs.meta
│ ├── Plugins.meta
│ └── Plugins
│ │ ├── Android.meta
│ │ └── Android
│ │ ├── AndroidManifest.xml
│ │ └── AndroidManifest.xml.meta
├── ProjectSettings
│ ├── AudioManager.asset
│ ├── DynamicsManager.asset
│ ├── EditorBuildSettings.asset
│ ├── EditorSettings.asset
│ ├── GraphicsSettings.asset
│ ├── InputManager.asset
│ ├── NavMeshAreas.asset
│ ├── NetworkManager.asset
│ ├── Physics2DSettings.asset
│ ├── ProjectSettings.asset
│ ├── ProjectVersion.txt
│ ├── QualitySettings.asset
│ ├── TagManager.asset
│ └── TimeManager.asset
├── demo-csharp.sln
├── demo.sln
├── demo.userprefs
├── nativeedit-csharp.sln
├── nativeedit.sln
└── nativeedit.userprefs
├── release
└── NativeEditPlugin
│ ├── Plugins
│ ├── Android
│ │ ├── AndroidManifest.xml
│ │ └── nativeeditplugin.jar
│ └── iOS
│ │ ├── EditBox_iOS.h
│ │ ├── EditBox_iOS.m
│ │ ├── JsonObject.h
│ │ ├── JsonObject.m
│ │ ├── PlaceholderTextView.h
│ │ ├── PlaceholderTextView.m
│ │ └── PluginMsgInterface.mm
│ ├── README.md
│ ├── demo
│ ├── demo.cs
│ └── demo.unity
│ └── scripts
│ ├── JsonObject.cs
│ ├── MiniJSON.cs
│ ├── NativeEditBox.cs
│ └── PluginMsgHandler.cs
└── src
└── androidProj
├── .gradle
└── 2.2.1
│ └── taskArtifacts
│ ├── cache.properties
│ ├── cache.properties.lock
│ ├── fileHashes.bin
│ ├── fileSnapshots.bin
│ ├── outputFileStates.bin
│ └── taskArtifacts.bin
├── .idea
├── .name
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── gradle.xml
├── libraries
│ ├── appcompat_v7_22_0_0.xml
│ ├── classes.xml
│ ├── support_annotations_22_0_0.xml
│ └── support_v4_22_0_0.xml
├── misc.xml
├── modules.xml
├── scopes
│ └── scope_settings.xml
├── vcs.xml
└── workspace.xml
├── androidProj.iml
├── app
└── app.iml
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── local.properties
├── nativeeditplugin
├── .gitignore
├── build.gradle
├── libs
│ └── classes.jar
├── nativeeditplugin.iml
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── bkmin
│ │ └── android
│ │ └── ApplicationTest.java
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── bkmin
│ │ └── android
│ │ ├── EditBox.java
│ │ └── NativeEditPlugin.java
│ └── res
│ └── values
│ └── strings.xml
└── settings.gradle
/README.md:
--------------------------------------------------------------------------------
1 | ## UnityNativeEdit v1.0
2 | Unity Native Input Plugin for both iOS and Android (Unity UI InputField compatible).
3 | This means you don't need a separate 'Unity' Input box and you can use all native text functions such as `Select`, `Copy` and `Paste`
4 |
5 | ## Usage
6 | 1. Simply copy the files in `release/NativeEditPlugin` into your existing unity project asset folder.
7 | 2. Make empty Gameobject and attach ```PluginMsgHandler``` to your new GameObject
8 | 3. Attach ```NativeEditBox``` script to your UnityUI ```InputField```object.
9 | 4. Build and run on your android or ios device!
10 | 5. For `Android` make sure your `AndroidManifest.xml` has the following setting
11 |
12 | ```xml
13 |
15 | ...
16 |
17 | ...
18 |
19 | ```
20 | You can refer to sample `AndroidManifest.xml` in `/Plugings/Android` folder
21 |
22 |
23 | ## Etc
24 | 1. NativeEditBox will work with delegate defined in your Unity UI InputField, `On Value Change` and `End Edit`
25 | 2. It's open source and free to use/redistribute!
26 | 3. Please refer to `demo` Unity project.
27 |
--------------------------------------------------------------------------------
/demo/Assembly-CSharp-vs.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 10.0.20506
7 | 2.0
8 | {C132594A-928C-86DF-54BB-28617E4DB357}
9 | Library
10 | Properties
11 |
12 | Assembly-CSharp
13 | v3.5
14 | 512
15 | Assets
16 |
17 |
18 | true
19 | full
20 | false
21 | Temp\bin\Debug\
22 | DEBUG;TRACE;UNITY_5_0_1;UNITY_5_0;UNITY_5;ENABLE_LICENSE_RENAME;ENABLE_NEW_BUGREPORTER;ENABLE_2D_PHYSICS;ENABLE_4_6_FEATURES;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_FRAME_DEBUGGER;ENABLE_GENERICS;ENABLE_HOME_SCREEN;ENABLE_IMAGEEFFECTS;ENABLE_LIGHT_PROBES_LEGACY;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_NEW_HIERARCHY;ENABLE_PHYSICS;ENABLE_PHYSICS_PHYSX3;ENABLE_PLUGIN_INSPECTOR;ENABLE_SHADOWS;ENABLE_SINGLE_INSTANCE_BUILD_SETTING;ENABLE_SPRITES;ENABLE_TERRAIN;ENABLE_UNITYEVENTS;ENABLE_WEBCAM;ENABLE_WWW;ENABLE_AUDIOMIXER_SUSPEND;ENABLE_NONPRO;INCLUDE_DYNAMIC_GI;INCLUDE_GI;INCLUDE_IL2CPP;PLATFORM_SUPPORTS_MONO;UNITY_IPHONE;ENABLE_RUNTIME_GI;ENABLE_SUBSTANCE;ENABLE_GAMECENTER;ENABLE_NETWORK;UNITY_IPHONE_API;UNITY_IOS;ENABLE_TEXTUREID_MAP;PLAYERCONNECTION_LISTENS_FIXED_PORT;DEBUGGER_LISTENS_FIXED_PORT;ENABLE_MONO;DEVELOPMENT_BUILD;ENABLE_PROFILER;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_OSX
23 | prompt
24 | 4
25 | 0169
26 |
27 |
28 | pdbonly
29 | true
30 | Temp\bin\Release\
31 | TRACE
32 | prompt
33 | 4
34 | 0169
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 | /Applications/Unity/Unity.app/Contents/Frameworks/Managed/UnityEngine.dll
43 |
44 |
45 | /Applications/Unity/Unity.app/Contents/Frameworks/Managed/UnityEditor.dll
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 | /Applications/Unity/Unity.app/Contents/UnityExtensions/Unity/GUISystem/UnityEngine.UI.dll
58 |
59 |
60 | /Applications/Unity/Unity.app/Contents/PlaybackEngines/iossupport/UnityEditor.iOS.Extensions.Xcode.dll
61 |
62 |
63 |
64 |
71 |
72 |
73 |
--------------------------------------------------------------------------------
/demo/Assembly-CSharp.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | AnyCPU
6 | 10.0.20506
7 | 2.0
8 | {C132594A-928C-86DF-54BB-28617E4DB357}
9 | Library
10 | Properties
11 |
12 | Assembly-CSharp
13 | v3.5
14 | 512
15 | Assets
16 |
17 |
18 | true
19 | full
20 | false
21 | Temp\bin\Debug\
22 | DEBUG;TRACE;UNITY_5_0_1;UNITY_5_0;UNITY_5;ENABLE_LICENSE_RENAME;ENABLE_NEW_BUGREPORTER;ENABLE_2D_PHYSICS;ENABLE_4_6_FEATURES;ENABLE_AUDIO;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_FRAME_DEBUGGER;ENABLE_GENERICS;ENABLE_HOME_SCREEN;ENABLE_IMAGEEFFECTS;ENABLE_LIGHT_PROBES_LEGACY;ENABLE_MICROPHONE;ENABLE_MULTIPLE_DISPLAYS;ENABLE_NEW_HIERARCHY;ENABLE_PHYSICS;ENABLE_PHYSICS_PHYSX3;ENABLE_PLUGIN_INSPECTOR;ENABLE_SHADOWS;ENABLE_SINGLE_INSTANCE_BUILD_SETTING;ENABLE_SPRITES;ENABLE_TERRAIN;ENABLE_UNITYEVENTS;ENABLE_WEBCAM;ENABLE_WWW;ENABLE_AUDIOMIXER_SUSPEND;ENABLE_NONPRO;INCLUDE_DYNAMIC_GI;INCLUDE_GI;INCLUDE_IL2CPP;PLATFORM_SUPPORTS_MONO;UNITY_IPHONE;ENABLE_RUNTIME_GI;ENABLE_SUBSTANCE;ENABLE_GAMECENTER;ENABLE_NETWORK;UNITY_IPHONE_API;UNITY_IOS;ENABLE_TEXTUREID_MAP;PLAYERCONNECTION_LISTENS_FIXED_PORT;DEBUGGER_LISTENS_FIXED_PORT;ENABLE_MONO;DEVELOPMENT_BUILD;ENABLE_PROFILER;UNITY_EDITOR;UNITY_EDITOR_64;UNITY_EDITOR_OSX
23 | prompt
24 | 4
25 | 0169
26 |
27 |
28 | pdbonly
29 | true
30 | Temp\bin\Release\
31 | TRACE
32 | prompt
33 | 4
34 | 0169
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 | /Applications/Unity/Unity.app/Contents/Frameworks/Managed/UnityEngine.dll
43 |
44 |
45 | /Applications/Unity/Unity.app/Contents/Frameworks/Managed/UnityEditor.dll
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 | /Applications/Unity/Unity.app/Contents/UnityExtensions/Unity/GUISystem/UnityEngine.UI.dll
58 |
59 |
60 | /Applications/Unity/Unity.app/Contents/PlaybackEngines/iossupport/UnityEditor.iOS.Extensions.Xcode.dll
61 |
62 |
63 |
64 |
71 |
72 |
73 |
--------------------------------------------------------------------------------
/demo/Assets/AssetStoreTools.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: b0264992f90e27e48beeee54b801c8f2
3 | folderAsset: yes
4 | timeCreated: 1430955535
5 | licenseType: Pro
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/demo/Assets/AssetStoreTools/Editor.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 47c3c77b488bde14eac761a5144660ed
3 | folderAsset: yes
4 | timeCreated: 1430955535
5 | licenseType: Pro
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/demo/Assets/AssetStoreTools/Editor/AssetStoreTools.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kmbang/UnityNativeEdit/ed0d364b8d101bc85397d141666376575ed75d79/demo/Assets/AssetStoreTools/Editor/AssetStoreTools.dll
--------------------------------------------------------------------------------
/demo/Assets/AssetStoreTools/Editor/AssetStoreTools.dll.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 11188de2b6632fa4486c470af4b55fa0
3 | PluginImporter:
4 | serializedVersion: 1
5 | iconMap: {}
6 | executionOrder: {}
7 | isPreloaded: 0
8 | platformData:
9 | Any:
10 | enabled: 1
11 | settings: {}
12 | userData:
13 | assetBundleName:
14 | assetBundleVariant:
15 |
--------------------------------------------------------------------------------
/demo/Assets/AssetStoreTools/Editor/AssetStoreToolsExtra.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kmbang/UnityNativeEdit/ed0d364b8d101bc85397d141666376575ed75d79/demo/Assets/AssetStoreTools/Editor/AssetStoreToolsExtra.dll
--------------------------------------------------------------------------------
/demo/Assets/AssetStoreTools/Editor/AssetStoreToolsExtra.dll.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: e35231d99115e9e4c8cb29414445831f
3 | PluginImporter:
4 | serializedVersion: 1
5 | iconMap: {}
6 | executionOrder: {}
7 | isPreloaded: 0
8 | platformData:
9 | Any:
10 | enabled: 1
11 | settings: {}
12 | userData:
13 | assetBundleName:
14 | assetBundleVariant:
15 |
--------------------------------------------------------------------------------
/demo/Assets/AssetStoreTools/Editor/DroidSansMono.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kmbang/UnityNativeEdit/ed0d364b8d101bc85397d141666376575ed75d79/demo/Assets/AssetStoreTools/Editor/DroidSansMono.ttf
--------------------------------------------------------------------------------
/demo/Assets/AssetStoreTools/Editor/DroidSansMono.ttf.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 35021dda9bd03434195c7dcd6ad7618f
3 | TrueTypeFontImporter:
4 | serializedVersion: 2
5 | fontSize: 16
6 | forceTextureCase: -2
7 | characterSpacing: 1
8 | characterPadding: 0
9 | includeFontData: 1
10 | use2xBehaviour: 0
11 | fontNames: []
12 | customCharacters:
13 | fontRenderingMode: 0
14 | userData:
15 | assetBundleName:
16 | assetBundleVariant:
17 |
--------------------------------------------------------------------------------
/demo/Assets/AssetStoreTools/Editor/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kmbang/UnityNativeEdit/ed0d364b8d101bc85397d141666376575ed75d79/demo/Assets/AssetStoreTools/Editor/icon.png
--------------------------------------------------------------------------------
/demo/Assets/AssetStoreTools/Editor/icon.png.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 41844c716792706449720732c95b2747
3 | TextureImporter:
4 | fileIDToRecycleName: {}
5 | serializedVersion: 2
6 | mipmaps:
7 | mipMapMode: 0
8 | enableMipMap: 1
9 | linearTexture: 0
10 | correctGamma: 0
11 | fadeOut: 0
12 | borderMipMap: 0
13 | mipMapFadeDistanceStart: 1
14 | mipMapFadeDistanceEnd: 3
15 | bumpmap:
16 | convertToNormalMap: 0
17 | externalNormalMap: 0
18 | heightScale: .25
19 | normalMapFilter: 0
20 | isReadable: 0
21 | grayScaleToAlpha: 0
22 | generateCubemap: 0
23 | cubemapConvolution: 0
24 | cubemapConvolutionSteps: 8
25 | cubemapConvolutionExponent: 1.5
26 | seamlessCubemap: 0
27 | textureFormat: -1
28 | maxTextureSize: 1024
29 | textureSettings:
30 | filterMode: -1
31 | aniso: -1
32 | mipBias: -1
33 | wrapMode: -1
34 | nPOTScale: 1
35 | lightmap: 0
36 | rGBM: 0
37 | compressionQuality: 50
38 | spriteMode: 0
39 | spriteExtrude: 1
40 | spriteMeshType: 1
41 | alignment: 0
42 | spritePivot: {x: .5, y: .5}
43 | spriteBorder: {x: 0, y: 0, z: 0, w: 0}
44 | spritePixelsToUnits: 100
45 | alphaIsTransparency: 0
46 | textureType: -1
47 | buildTargetSettings: []
48 | spriteSheet:
49 | sprites: []
50 | spritePackingTag:
51 | userData:
52 | assetBundleName:
53 | assetBundleVariant:
54 |
--------------------------------------------------------------------------------
/demo/Assets/AssetStoreTools/Labels.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kmbang/UnityNativeEdit/ed0d364b8d101bc85397d141666376575ed75d79/demo/Assets/AssetStoreTools/Labels.asset
--------------------------------------------------------------------------------
/demo/Assets/NativeEditPlugin.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d541cfba5912d43fc837495d4a0d6011
3 | folderAsset: yes
4 | timeCreated: 1430959055
5 | licenseType: Pro
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/demo/Assets/NativeEditPlugin/Plugins.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 6aacecba01ec1410bbf45026b033c1ab
3 | folderAsset: yes
4 | timeCreated: 1430955862
5 | licenseType: Pro
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/demo/Assets/NativeEditPlugin/Plugins/Android/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
14 |
15 |
20 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/demo/Assets/NativeEditPlugin/Plugins/Android/nativeeditplugin.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kmbang/UnityNativeEdit/ed0d364b8d101bc85397d141666376575ed75d79/demo/Assets/NativeEditPlugin/Plugins/Android/nativeeditplugin.jar
--------------------------------------------------------------------------------
/demo/Assets/NativeEditPlugin/Plugins/iOS.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 86b9e2365e8a748a7b13e8ba9458dd8d
3 | folderAsset: yes
4 | DefaultImporter:
5 | userData:
6 |
--------------------------------------------------------------------------------
/demo/Assets/NativeEditPlugin/Plugins/iOS/EditBox_iOS.h:
--------------------------------------------------------------------------------
1 | #import
2 | #import
3 | #import "JsonObject.h"
4 |
5 | /// UnityEditBox Plugin
6 | /// Written by bkmin 2014/11 Nureka Inc.
7 |
8 | #define MSG_CREATE @"CreateEdit"
9 | #define MSG_REMOVE @"RemoveEdit"
10 | #define MSG_SET_TEXT @"SetText"
11 | #define MSG_GET_TEXT @"GetText"
12 | #define MSG_SET_RECT @"SetRect"
13 | #define MSG_SET_FOCUS @"SetFocus"
14 | #define MSG_SET_VISIBLE @"SetVisible"
15 | #define MSG_TEXT_CHANGE @"TextChange"
16 | #define MSG_TEXT_END_EDIT @"TextEndEdit"
17 |
18 | @interface EditBoxHoldView : UIView
19 | {
20 |
21 | }
22 |
23 | -(id) initHoldView:(CGRect) frame;
24 |
25 | @end
26 |
27 | @interface EditBox : NSObject
28 | {
29 | UIView* editView;
30 | UIViewController* viewController;
31 | CGRect rectKeyboardFrame;
32 | UIToolbar* keyboardDoneButtonView;
33 | UIBarButtonItem* doneButton;
34 | int tag;
35 | }
36 |
37 | +(void) initializeEditBox:(UIViewController*) _unityViewController unityName:(const char*) unityName;
38 | +(JsonObject*) processRecvJsonMsg:(int)nSenderId msg:(JsonObject*) jsonMsg;
39 | +(void) finalizeEditBox;
40 |
41 | -(void) showKeyboard:(bool)isShow;
42 | -(BOOL) IsFocused;
43 | @end
44 |
--------------------------------------------------------------------------------
/demo/Assets/NativeEditPlugin/Plugins/iOS/EditBox_iOS.h.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 4be821ace4f6e414596aefd815c62414
3 | DefaultImporter:
4 | userData:
5 |
--------------------------------------------------------------------------------
/demo/Assets/NativeEditPlugin/Plugins/iOS/EditBox_iOS.m:
--------------------------------------------------------------------------------
1 | #import "EditBox_iOS.h"
2 | #import "PlaceholderTextView.h"
3 | #import
4 |
5 | /// UnityEditBox Plugin
6 | /// Written by bkmin 2014/11 Nureka Inc.
7 |
8 | UIViewController* unityViewController = nil;
9 | NSMutableDictionary* dictEditBox = nil;
10 | EditBoxHoldView* viewPlugin = nil;
11 |
12 | #define DEF_PixelPerPoint 2.2639f // 72 points per inch. iPhone 163DPI
13 | char g_unityName[64];
14 |
15 | bool approxEqualFloat(float x, float y)
16 | {
17 | return fabs(x-y) < 0.001f;
18 | }
19 |
20 | @implementation EditBoxHoldView
21 |
22 | -(id) initHoldView:(CGRect) frame
23 | {
24 | if (self = [super initWithFrame:frame])
25 | {
26 | UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
27 | [self addGestureRecognizer:tap];
28 | self.userInteractionEnabled = YES;
29 | }
30 | return self;
31 | }
32 |
33 | -(void) tapAction:(id) sender
34 | {
35 | for (EditBox *eb in [dictEditBox allValues])
36 | {
37 | if ([eb IsFocused])
38 | {
39 | [eb showKeyboard:NO];
40 | }
41 | }
42 | }
43 |
44 | @end
45 |
46 |
47 | @implementation EditBox
48 |
49 | +(void) initializeEditBox:(UIViewController*) _unityViewController unityName:(const char*) unityName
50 | {
51 | unityViewController = _unityViewController;
52 | dictEditBox = [[NSMutableDictionary alloc] init];
53 |
54 | CGRect frameView = unityViewController.view.frame;
55 | frameView.origin = CGPointMake(0.0f, 0.0f);
56 | viewPlugin = [[EditBoxHoldView alloc] initHoldView:frameView];
57 | [unityViewController.view addSubview:viewPlugin];
58 |
59 | strcpy(g_unityName, unityName);
60 | }
61 |
62 | +(JsonObject*) makeJsonRet:(BOOL) isError error:(NSString*) strError
63 | {
64 | JsonObject* jsonRet = [[JsonObject alloc] init];
65 |
66 | [jsonRet setBool:@"bError" value:isError];
67 | [jsonRet setString:@"strError" value:strError];
68 | return jsonRet;
69 | }
70 |
71 | +(JsonObject*) processRecvJsonMsg:(int)nSenderId msg:(JsonObject*) jsonMsg
72 | {
73 | JsonObject* jsonRet;
74 |
75 | NSString* msg = [jsonMsg getString:@"msg"];
76 | if ([msg isEqualToString:MSG_CREATE])
77 | {
78 | EditBox* nb = [[EditBox alloc] initWithViewController:unityViewController _tag:nSenderId];
79 | [nb create:jsonMsg];
80 | [dictEditBox setObject:nb forKey:[NSNumber numberWithInt:nSenderId]];
81 | jsonRet = [EditBox makeJsonRet:NO error:@""];
82 | }
83 | else
84 | {
85 | EditBox* b = [dictEditBox objectForKey:[NSNumber numberWithInt:nSenderId]];
86 | if (b)
87 | {
88 | jsonRet = [b processJsonMsg:msg json:jsonMsg];
89 | }
90 | else
91 | {
92 | jsonRet = [EditBox makeJsonRet:YES error:@"EditBox not found"];
93 | }
94 | }
95 | return jsonRet;
96 | }
97 |
98 | +(void) finalizeEditBox
99 | {
100 | NSArray* objs = [dictEditBox allValues];
101 | for (EditBox* b in objs)
102 | {
103 | [b remove];
104 | }
105 | dictEditBox = nil;
106 | }
107 |
108 | -(BOOL) IsFocused
109 | {
110 | return editView.isFirstResponder;
111 | }
112 |
113 | -(void) sendJsonToUnity:(JsonObject*) json
114 | {
115 | [json setInt:@"senderId" value:tag];
116 |
117 |
118 | NSData *jsonData = [json serialize];
119 | NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
120 | UnitySendMessage(g_unityName, "OnMsgFromPlugin", [jsonString UTF8String]);
121 | }
122 |
123 | -(JsonObject*) processJsonMsg:(NSString*) msg json:(JsonObject*) jsonMsg
124 | {
125 | JsonObject* jsonRet = [EditBox makeJsonRet:NO error:@""];
126 | if ([msg isEqualToString:MSG_REMOVE])
127 | {
128 | [self remove];
129 | }
130 | else if ([msg isEqualToString:MSG_SET_TEXT])
131 | {
132 | [self setText:jsonMsg];
133 | }
134 | else if ([msg isEqualToString:MSG_GET_TEXT])
135 | {
136 | NSString* text = [self getText];
137 | [jsonRet setString:@"text" value:text];
138 | }
139 | else if ([msg isEqualToString:MSG_SET_RECT])
140 | {
141 | [self setRect:jsonMsg];
142 | }
143 | else if ([msg isEqualToString:MSG_SET_FOCUS])
144 | {
145 | BOOL isFocus = [jsonMsg getBool:@"isFocus"];
146 | [self setFocus:isFocus];
147 | }
148 | else if ([msg isEqualToString:MSG_SET_VISIBLE])
149 | {
150 | BOOL isVisible = [jsonMsg getBool:@"isVisible"];
151 | [self setVisible:isVisible];
152 | }
153 |
154 | return jsonRet;
155 | }
156 |
157 | -(id)initWithViewController:(UIViewController*)theViewController _tag:(int)_tag
158 | {
159 | if(self = [super init]) {
160 | viewController = theViewController;
161 | tag = _tag;
162 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
163 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
164 | }
165 | return self;
166 | }
167 |
168 | -(void) setRect:(JsonObject*)json
169 | {
170 | float x = [json getFloat:@"x"] * viewController.view.bounds.size.width;
171 | float y = [json getFloat:@"y"] * viewController.view.bounds.size.height;
172 | float width = [json getFloat:@"width"] * viewController.view.bounds.size.width;
173 | float height = [json getFloat:@"height"] * viewController.view.bounds.size.height;
174 |
175 | x -= editView.superview.frame.origin.x;
176 | y -= editView.superview.frame.origin.y;
177 | editView.frame = CGRectMake(x, y, width, height);
178 | }
179 |
180 | -(void) create:(JsonObject*)json
181 | {
182 | NSString* placeholder = [json getString:@"placeHolder"];
183 |
184 | NSString* font = [json getString:@"font"];
185 | float fontSize = [json getFloat:@"fontSize"];
186 |
187 | float x = [json getFloat:@"x"] * viewController.view.bounds.size.width;
188 | float y = [json getFloat:@"y"] * viewController.view.bounds.size.height;
189 | float width = [json getFloat:@"width"] * viewController.view.bounds.size.width;
190 | float height = [json getFloat:@"height"] * viewController.view.bounds.size.height;
191 |
192 | float textColor_r = [json getFloat:@"textColor_r"];
193 | float textColor_g = [json getFloat:@"textColor_g"];
194 | float textColor_b = [json getFloat:@"textColor_b"];
195 | float textColor_a = [json getFloat:@"textColor_a"];
196 | float backColor_r = [json getFloat:@"backColor_r"];
197 | float backColor_g = [json getFloat:@"backColor_g"];
198 | float backColor_b = [json getFloat:@"backColor_b"];
199 | float backColor_a = [json getFloat:@"backColor_a"];
200 |
201 | NSString* contentType = [json getString:@"contentType"];
202 | NSString* alignment = [json getString:@"align"];
203 | BOOL withDoneButton = [json getBool:@"withDoneButton"];
204 | BOOL multiline = [json getBool:@"multiline"];
205 |
206 | BOOL autoCorr = NO;
207 | BOOL password = NO;
208 | UIKeyboardType keyType = UIKeyboardTypeDefault;
209 |
210 | if ([contentType isEqualToString:@"Autocorrected"])
211 | {
212 | autoCorr = YES;
213 | }
214 | else if ([contentType isEqualToString:@"IntegerNumber"])
215 | {
216 | keyType = UIKeyboardTypeNumberPad;
217 | }
218 | else if ([contentType isEqualToString:@"DecimalNumber"])
219 | {
220 | keyType = UIKeyboardTypeDecimalPad;
221 | }
222 | else if ([contentType isEqualToString:@"Alphanumeric"])
223 | {
224 | keyType = UIKeyboardTypeAlphabet;
225 | }
226 | else if ([contentType isEqualToString:@"Name"])
227 | {
228 | keyType = UIKeyboardTypeNamePhonePad;
229 | }
230 | else if ([contentType isEqualToString:@"EmailAddress"])
231 | {
232 | keyType = UIKeyboardTypeEmailAddress;
233 | }
234 | else if ([contentType isEqualToString:@"Password"])
235 | {
236 | password = YES;
237 | }
238 | else if ([contentType isEqualToString:@"Pin"])
239 | {
240 | keyType = UIKeyboardTypePhonePad;
241 | }
242 |
243 | UIControlContentHorizontalAlignment halign = UIControlContentHorizontalAlignmentLeft;
244 | UIControlContentVerticalAlignment valign = UIControlContentVerticalAlignmentCenter;
245 |
246 | if ([alignment isEqualToString:@"UpperLeft"])
247 | {
248 | valign = UIControlContentVerticalAlignmentTop;
249 | halign = UIControlContentHorizontalAlignmentLeft;
250 | }
251 | else if ([alignment isEqualToString:@"UpperCenter"])
252 | {
253 | valign = UIControlContentVerticalAlignmentTop;
254 | halign = UIControlContentHorizontalAlignmentCenter;
255 | }
256 | else if ([alignment isEqualToString:@"UpperRight"])
257 | {
258 | valign = UIControlContentVerticalAlignmentTop;
259 | halign = UIControlContentHorizontalAlignmentRight;
260 | }
261 | else if ([alignment isEqualToString:@"MiddleLeft"])
262 | {
263 | valign = UIControlContentVerticalAlignmentCenter;
264 | halign = UIControlContentHorizontalAlignmentLeft;
265 | }
266 | else if ([alignment isEqualToString:@"MiddleCenter"])
267 | {
268 | valign = UIControlContentVerticalAlignmentCenter;
269 | halign = UIControlContentHorizontalAlignmentCenter;
270 | }
271 | else if ([alignment isEqualToString:@"MiddleRight"])
272 | {
273 | valign = UIControlContentVerticalAlignmentCenter;
274 | halign = UIControlContentHorizontalAlignmentRight;
275 | }
276 | else if ([alignment isEqualToString:@"LowerLeft"])
277 | {
278 | valign = UIControlContentVerticalAlignmentBottom;
279 | halign = UIControlContentHorizontalAlignmentLeft;
280 | }
281 | else if ([alignment isEqualToString:@"LowerCenter"])
282 | {
283 | valign = UIControlContentVerticalAlignmentBottom;
284 | halign = UIControlContentHorizontalAlignmentCenter;
285 | }
286 | else if ([alignment isEqualToString:@"LowerRight"])
287 | {
288 | valign = UIControlContentVerticalAlignmentBottom;
289 | halign = UIControlContentHorizontalAlignmentRight;
290 | }
291 |
292 | fontSize = fontSize / DEF_PixelPerPoint;
293 |
294 | if (withDoneButton)
295 | {
296 | keyboardDoneButtonView = [[UIToolbar alloc] init];
297 | [keyboardDoneButtonView sizeToFit];
298 | doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self
299 | action:@selector(doneClicked:)];
300 |
301 | UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
302 | [keyboardDoneButtonView setItems:[NSArray arrayWithObjects:flexibleSpace, flexibleSpace,doneButton, nil]];
303 | }
304 | else
305 | {
306 | keyboardDoneButtonView = nil;
307 | }
308 |
309 | if (multiline)
310 | {
311 | PlaceholderTextView* textView = [[PlaceholderTextView alloc] initWithFrame:CGRectMake(x, y, width, height)];
312 | textView.keyboardType = keyType;
313 | [textView setFont:[UIFont fontWithName:font size:fontSize]];
314 | textView.scrollEnabled = TRUE;
315 |
316 | textView.delegate = self;
317 | textView.tag = 0;
318 | textView.text = @"";
319 |
320 | textView.textColor = [UIColor colorWithRed:textColor_r green:textColor_g blue:textColor_b alpha:textColor_a];
321 | textView.backgroundColor =[UIColor colorWithRed:backColor_r green:backColor_g blue:backColor_b alpha:backColor_a];
322 | textView.returnKeyType = UIReturnKeyDefault;
323 | textView.autocorrectionType = autoCorr ? UITextAutocorrectionTypeYes : UITextAutocorrectionTypeNo ;
324 | textView.contentInset = UIEdgeInsetsMake(0.0f, 0.0f, 0.0f, 0.0f);
325 | textView.placeholder = placeholder;
326 | textView.delegate = self;
327 |
328 | [textView setSecureTextEntry:password];
329 | if (keyboardDoneButtonView != nil) textView.inputAccessoryView = keyboardDoneButtonView;
330 |
331 |
332 | /// Todo
333 | /// UITextView Alignment is not implemented
334 |
335 | editView = textView;
336 | }
337 | else
338 | {
339 | UITextField* textField = [[UITextField alloc] initWithFrame:CGRectMake(x, y, width, height)];
340 | textField.keyboardType = keyType;
341 | [textField setFont:[UIFont fontWithName:font size:fontSize]];
342 | textField.delegate = self;
343 | textField.tag = 0;
344 | textField.text = @"";
345 | textField.textColor = [UIColor colorWithRed:textColor_r green:textColor_g blue:textColor_b alpha:textColor_a];
346 | textField.backgroundColor =[UIColor colorWithRed:backColor_r green:backColor_g blue:backColor_b alpha:backColor_a];
347 | textField.returnKeyType = UIReturnKeyDefault;
348 | textField.autocorrectionType = autoCorr ? UITextAutocorrectionTypeYes : UITextAutocorrectionTypeNo;
349 | textField.contentVerticalAlignment = valign;
350 | textField.contentHorizontalAlignment = halign;
351 | textField.placeholder = placeholder;
352 | textField.delegate = self;
353 |
354 | [textField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
355 | [textField setSecureTextEntry:password];
356 | if (keyboardDoneButtonView != nil) textField.inputAccessoryView = keyboardDoneButtonView;
357 |
358 | editView = textField;
359 | }
360 | [viewPlugin addSubview:editView];
361 | }
362 |
363 | -(void) setText:(JsonObject*)json
364 | {
365 | NSString* newText = [json getString:@"text"];
366 | if([editView isKindOfClass:[UITextField class]]) {
367 | [((UITextField*)editView) setText:newText];
368 | } else if([editView isKindOfClass:[UITextView class]]){
369 | [((UITextView*)editView) setText:newText];
370 | }
371 | }
372 |
373 | -(IBAction) doneClicked:(id)sender
374 | {
375 | [self showKeyboard:false];
376 | }
377 |
378 | -(int) getLineCount
379 | {
380 | if([editView isKindOfClass:[UITextField class]]) {
381 | return 1;
382 | } else if([editView isKindOfClass:[UITextView class]]){
383 | UITextView* tv = ((UITextView*)editView);
384 | int lineCount = (int) tv.contentSize.height / tv.font.lineHeight;
385 | return (lineCount);
386 | }
387 | return 0;
388 | }
389 |
390 |
391 | -(void) remove
392 | {
393 | [[NSNotificationCenter defaultCenter] removeObserver:self];
394 | [editView resignFirstResponder];
395 | [editView removeFromSuperview];
396 | if (keyboardDoneButtonView != nil)
397 | {
398 | doneButton = nil;
399 | keyboardDoneButtonView = nil;
400 | }
401 | }
402 |
403 | -(void) setFocus:(BOOL) isFocus
404 | {
405 | if (isFocus)
406 | {
407 | [editView becomeFirstResponder];
408 | }
409 | else
410 | {
411 | [editView resignFirstResponder];
412 | }
413 | }
414 |
415 | -(NSString*) getText
416 | {
417 | if([editView isKindOfClass:[UITextField class]]) {
418 | return ((UITextField*)editView).text;
419 | } else if([editView isKindOfClass:[UITextView class]]){
420 | return ((UITextView*)editView).text;
421 | }
422 | return @"";
423 | }
424 |
425 | -(bool) isFocused
426 | {
427 | return editView.isFirstResponder;
428 | }
429 |
430 | -(void) showKeyboard:(bool)isShow
431 | {
432 | [viewController.view endEditing:(isShow ? YES : NO)];
433 | }
434 | -(void) setVisible:(bool)isVisible
435 | {
436 | editView.hidden = (isVisible ? NO : YES);
437 | }
438 |
439 | -(void) onTextChange:(NSString*) text
440 | {
441 | JsonObject* jsonToUnity = [[JsonObject alloc] init];
442 |
443 | [jsonToUnity setString:@"msg" value:MSG_TEXT_CHANGE];
444 | [jsonToUnity setString:@"text" value:text];
445 | [self sendJsonToUnity:jsonToUnity];
446 | }
447 |
448 | -(void) onTextEditEnd:(NSString*) text
449 | {
450 | JsonObject* jsonToUnity = [[JsonObject alloc] init];
451 |
452 | [jsonToUnity setString:@"msg" value:MSG_TEXT_END_EDIT];
453 | [jsonToUnity setString:@"text" value:text];
454 | [self sendJsonToUnity:jsonToUnity];
455 | }
456 |
457 | -(void) textViewDidChange:(UITextView *)textView
458 | {
459 | [self onTextChange:textView.text];
460 | }
461 |
462 | -(void) textViewDidEndEditing:(UITextView *)textView
463 | {
464 | [self onTextEditEnd:textView.text];
465 | }
466 |
467 | -(void) textFieldDidChange :(UITextField *)theTextField{
468 | [self onTextChange:theTextField.text];
469 | }
470 |
471 | -(void) textFieldDidEndEditing:(UITextField *)textField
472 | {
473 | [self onTextEditEnd:textField.text];
474 | }
475 |
476 | -(void) keyboardWillShow:(NSNotification *)notification
477 | {
478 | if (![editView isFirstResponder]) return;
479 |
480 | NSDictionary* keyboardInfo = [notification userInfo];
481 | NSValue* keyboardFrameBegin = [keyboardInfo valueForKey:UIKeyboardFrameBeginUserInfoKey];
482 | rectKeyboardFrame = [keyboardFrameBegin CGRectValue];
483 |
484 | }
485 |
486 | -(void) keyboardWillHide:(NSNotification*)notification
487 | {
488 | if (![editView isFirstResponder]) return;
489 |
490 | }
491 |
492 | -(float) getKeyboardheight
493 | {
494 | float height = rectKeyboardFrame.size.height / viewController.view.bounds.size.height;
495 | return height;
496 | }
497 |
498 |
499 | @end
500 |
--------------------------------------------------------------------------------
/demo/Assets/NativeEditPlugin/Plugins/iOS/EditBox_iOS.m.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 5815c9642cf774804aadf042a07142e6
3 | DefaultImporter:
4 | userData:
5 |
--------------------------------------------------------------------------------
/demo/Assets/NativeEditPlugin/Plugins/iOS/JsonObject.h:
--------------------------------------------------------------------------------
1 | //
2 | // JsonObject.h
3 | // stockissue
4 | //
5 | // Created by KYUNGMIN BANG on 12/8/14.
6 | // Copyright (c) 2014 Nureka Inc. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface JsonObject : NSObject
12 |
13 | @property (nonatomic, strong) NSMutableDictionary* dict;
14 |
15 | -(id)initWithJsonData:(NSData*) json;
16 | -(id)initWithCmd:(NSString*) cmd;
17 | -(id)initWithDictionary:(NSMutableDictionary*) _dict;
18 | -(NSData*)serialize;
19 |
20 | -(void) setInt:(NSString*) key value:(int)value;
21 | -(void) setFloat:(NSString*) key value:(float)value;
22 | -(void) setBool:(NSString*) key value:(BOOL)value;
23 | -(void) setString:(NSString*) key value:(NSString*)value;
24 | -(void) setArray:(NSString*) key value:(NSArray*) value;
25 | -(void) setJsonObject:(NSString*) key value:(JsonObject*) value;
26 |
27 | -(int) getInt:(NSString*) key;
28 | -(float) getFloat:(NSString*) key;
29 | -(BOOL) getBool:(NSString*) key;
30 | -(NSString*) getString:(NSString*) key;
31 | -(NSArray*) getJsonArray:(NSString*) key;
32 | -(NSArray*) getDictArray:(NSString*) key;
33 | -(JsonObject*) getJsonObject:(NSString*) key;
34 |
35 | @end
36 |
37 |
--------------------------------------------------------------------------------
/demo/Assets/NativeEditPlugin/Plugins/iOS/JsonObject.h.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 44a934fb557174e1e9af925e42770b24
3 | timeCreated: 1430351529
4 | licenseType: Pro
5 | PluginImporter:
6 | serializedVersion: 1
7 | iconMap: {}
8 | executionOrder: {}
9 | isPreloaded: 0
10 | platformData:
11 | Any:
12 | enabled: 1
13 | settings: {}
14 | userData:
15 | assetBundleName:
16 | assetBundleVariant:
17 |
--------------------------------------------------------------------------------
/demo/Assets/NativeEditPlugin/Plugins/iOS/JsonObject.m:
--------------------------------------------------------------------------------
1 | //
2 | // JsonObject.m
3 | // stockissue
4 | //
5 | // Created by KYUNGMIN BANG on 12/8/14.
6 | // Copyright (c) 2014 Nureka Inc. All rights reserved.
7 | //
8 |
9 | #import "JsonObject.h"
10 |
11 |
12 | @implementation JsonObject
13 | @synthesize dict;
14 |
15 | -(void) dealloc
16 | {
17 | dict = nil;
18 | }
19 |
20 | -(id)init
21 | {
22 | self = [super init];
23 | if (self)
24 | {
25 | dict = [[NSMutableDictionary alloc] init];
26 |
27 | }
28 | return self;
29 | }
30 |
31 | -(id)initWithDictionary:(NSMutableDictionary*) _dict
32 | {
33 | self = [super init];
34 | if (self)
35 | {
36 | dict = _dict;
37 |
38 | }
39 | return self;
40 | }
41 |
42 | -(id)initWithJsonData:(NSData*) json
43 | {
44 | self = [super init];
45 | if (self)
46 | {
47 | NSError *error;
48 |
49 | dict = [NSJSONSerialization
50 | JSONObjectWithData:json
51 | options:NSJSONReadingMutableContainers
52 | error:&error];
53 | if (dict == nil)
54 | {
55 | NSLog(@"Json parse error %@",[error description]);
56 | }
57 | }
58 | return self;
59 | }
60 | -(id)initWithCmd:(NSString*) cmd
61 | {
62 | self = [self init];
63 | if (dict)
64 | {
65 | dict[@"cmd"] = cmd;
66 | }
67 | return self;
68 | }
69 |
70 | -(NSData*)serialize
71 | {
72 | NSError *error;
73 | NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict
74 | options:0
75 | error:&error];
76 | return jsonData;
77 | }
78 |
79 | -(void) setInt:(NSString*) key value:(int)value
80 | {
81 | dict[key] = [NSNumber numberWithInt:value];
82 | }
83 | -(void) setFloat:(NSString*) key value:(float)value
84 | {
85 | dict[key] = [NSNumber numberWithFloat:value];
86 | }
87 | -(void) setBool:(NSString*) key value:(BOOL)value
88 | {
89 | dict[key] = [NSNumber numberWithBool:value];
90 | }
91 | -(void) setString:(NSString*) key value:(NSString*)value
92 | {
93 | dict[key] = value;
94 | }
95 | -(void) setArray:(NSString*) key value:(NSArray*) value
96 | {
97 | dict[key] = value;
98 | }
99 | -(void) setJsonObject:(NSString*) key value:(JsonObject*) value
100 | {
101 | dict[key] = value.dict;
102 | }
103 |
104 | -(int) getInt:(NSString*) key
105 | {
106 | id obj = [dict objectForKey:key];
107 | if (obj == nil || obj == (id)[NSNull null]) return 0;
108 | return [obj intValue];
109 | }
110 | -(float) getFloat:(NSString*) key
111 | {
112 | id obj = [dict objectForKey:key];
113 | if (obj == nil || obj == (id)[NSNull null]) return 0.0f;
114 | return [obj floatValue];
115 | }
116 | -(BOOL) getBool:(NSString*) key
117 | {
118 | id obj = [dict objectForKey:key];
119 | if (obj == nil || obj == (id)[NSNull null]) return NO;
120 | return [obj boolValue];
121 | }
122 | -(NSString*) getString:(NSString*) key
123 | {
124 | id obj = [dict objectForKey:key];
125 | if (!obj || obj == (id)[NSNull null]) return @"";
126 | return (NSString*) obj;
127 | }
128 | -(NSArray*) getDictArray:(NSString*) key
129 | {
130 | id obj = [dict objectForKey:key];
131 | if (obj == nil || obj == (id)[NSNull null]) return [[NSArray alloc] init];
132 | return (NSArray*) obj;
133 | }
134 | -(NSArray*) getJsonArray:(NSString*) key
135 | {
136 | id obj = [dict objectForKey:key];
137 | NSMutableArray* arr = [[NSMutableArray alloc] init];
138 | if (obj == nil || obj == (id)[NSNull null]) return arr;
139 | for (id arrObj in (NSMutableArray*) obj) {
140 | JsonObject* newObj = [[JsonObject alloc] initWithDictionary:(NSMutableDictionary*) arrObj];
141 | [arr addObject:newObj];
142 | }
143 | return (NSArray*) arr;
144 | }
145 | -(JsonObject*) getJsonObject:(NSString*) key
146 | {
147 | id obj = [dict objectForKey:key];
148 | JsonObject* newObj = [[JsonObject alloc] init];
149 | if (obj == nil || obj == (id)[NSNull null]) return newObj;
150 | newObj.dict = (NSMutableDictionary*) obj;
151 | return newObj;
152 | }
153 |
154 | @end
155 |
--------------------------------------------------------------------------------
/demo/Assets/NativeEditPlugin/Plugins/iOS/JsonObject.m.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: b4de1bb970b5a49a982cc91817847573
3 | timeCreated: 1430351529
4 | licenseType: Pro
5 | PluginImporter:
6 | serializedVersion: 1
7 | iconMap: {}
8 | executionOrder: {}
9 | isPreloaded: 0
10 | platformData:
11 | Any:
12 | enabled: 1
13 | settings: {}
14 | userData:
15 | assetBundleName:
16 | assetBundleVariant:
17 |
--------------------------------------------------------------------------------
/demo/Assets/NativeEditPlugin/Plugins/iOS/PlaceholderTextView.h:
--------------------------------------------------------------------------------
1 | #import
2 |
3 |
4 | @interface PlaceholderTextView : UITextView
5 | {
6 | NSObject* _editBox;
7 | }
8 |
9 | @property(nonatomic, strong) NSString *placeholder;
10 |
11 | @property (nonatomic, strong) UIColor *realTextColor UI_APPEARANCE_SELECTOR;
12 | @property (nonatomic, strong) UIColor *placeholderColor UI_APPEARANCE_SELECTOR;
13 |
14 | -(void) SetEditbox:(NSObject*) box;
15 |
16 | @end
--------------------------------------------------------------------------------
/demo/Assets/NativeEditPlugin/Plugins/iOS/PlaceholderTextView.h.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 80d5992a0f19242b280f279570b95e50
3 | DefaultImporter:
4 | userData:
5 |
--------------------------------------------------------------------------------
/demo/Assets/NativeEditPlugin/Plugins/iOS/PlaceholderTextView.m:
--------------------------------------------------------------------------------
1 | #import "PlaceholderTextView.h"
2 | #import "EditBox_iOS.h"
3 |
4 | @interface PlaceholderTextView ()
5 |
6 | @property (unsafe_unretained, nonatomic, readonly) NSString* realText;
7 |
8 | - (void) beginEditing:(NSNotification*) notification;
9 | - (void) endEditing:(NSNotification*) notification;
10 |
11 | @end
12 |
13 | @implementation PlaceholderTextView
14 |
15 | @synthesize realTextColor;
16 | @synthesize placeholder;
17 | @synthesize placeholderColor;
18 |
19 | #pragma mark -
20 | #pragma mark Initialisation
21 |
22 | - (id) initWithFrame:(CGRect)frame {
23 | if ((self = [super initWithFrame:frame])) {
24 | [self awakeFromNib];
25 | }
26 | return self;
27 | }
28 |
29 | - (void)awakeFromNib {
30 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(beginEditing:) name:UITextViewTextDidBeginEditingNotification object:self];
31 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(endEditing:) name:UITextViewTextDidEndEditingNotification object:self];
32 |
33 | self.realTextColor = self.textColor;
34 | self.placeholderColor = [UIColor lightGrayColor];
35 | }
36 |
37 | #pragma mark -
38 | #pragma mark Setter/Getters
39 |
40 | - (void) setPlaceholder:(NSString *)aPlaceholder {
41 | if ([self.realText isEqualToString:placeholder] && ![self isFirstResponder]) {
42 | self.text = aPlaceholder;
43 | }
44 | if (aPlaceholder != placeholder) {
45 | placeholder = aPlaceholder;
46 | }
47 |
48 |
49 | [self endEditing:nil];
50 | }
51 |
52 | - (void)setPlaceholderColor:(UIColor *)aPlaceholderColor {
53 | placeholderColor = aPlaceholderColor;
54 |
55 | if ([super.text isEqualToString:self.placeholder]) {
56 | self.textColor = self.placeholderColor;
57 | }
58 | }
59 |
60 | - (NSString *) text {
61 | NSString* text = [super text];
62 | if ([text isEqualToString:self.placeholder]) return @"";
63 | return text;
64 | }
65 |
66 | - (void) setText:(NSString *)text {
67 | if (([text isEqualToString:@""] || text == nil) && ![self isFirstResponder]) {
68 | super.text = self.placeholder;
69 | }
70 | else {
71 | super.text = text;
72 | }
73 |
74 | if ([text isEqualToString:self.placeholder] || text == nil) {
75 | self.textColor = self.placeholderColor;
76 | }
77 | else {
78 | self.textColor = self.realTextColor;
79 | }
80 | }
81 |
82 | - (NSString *) realText {
83 | return [super text];
84 | }
85 |
86 | - (void) beginEditing:(NSNotification*) notification {
87 | if ([self.realText isEqualToString:self.placeholder]) {
88 | super.text = nil;
89 | self.textColor = self.realTextColor;
90 | }
91 | }
92 |
93 | - (void) endEditing:(NSNotification*) notification {
94 | if ([self.realText isEqualToString:@""] || self.realText == nil) {
95 | super.text = self.placeholder;
96 | self.textColor = self.placeholderColor;
97 | }
98 | }
99 |
100 | - (void) setTextColor:(UIColor *)textColor {
101 | if ([self.realText isEqualToString:self.placeholder]) {
102 | if ([textColor isEqual:self.placeholderColor]){
103 | [super setTextColor:textColor];
104 | } else {
105 | self.realTextColor = textColor;
106 | }
107 | }
108 | else {
109 | self.realTextColor = textColor;
110 | [super setTextColor:textColor];
111 | }
112 | }
113 |
114 | -(void) SetEditbox:(NSObject*)box
115 | {
116 | _editBox = box;
117 |
118 | }
119 |
120 | #pragma mark -
121 | #pragma mark Dealloc
122 |
123 | - (void)dealloc {
124 | [[NSNotificationCenter defaultCenter] removeObserver:self];
125 |
126 | }
127 |
128 | @end
--------------------------------------------------------------------------------
/demo/Assets/NativeEditPlugin/Plugins/iOS/PlaceholderTextView.m.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ead440a6679c8498bad6d96a9f96282e
3 | DefaultImporter:
4 | userData:
5 |
--------------------------------------------------------------------------------
/demo/Assets/NativeEditPlugin/Plugins/iOS/PluginMsgInterface.mm:
--------------------------------------------------------------------------------
1 | //
2 | // PluginMsgHandler.m
3 | // Unity-iPhone
4 | //
5 | // Created by KYUNGMIN BANG on 2/24/15.
6 | //
7 | //
8 |
9 | #import "EditBox_iOS.h"
10 |
11 | UIViewController* UnityGetGLViewController();
12 |
13 | char* gCopyString(const char* string) {
14 | if(string == NULL) {
15 | return NULL;
16 | }
17 | char* ret = (char*) malloc(strlen(string) + 1); // memory will be auto-freed by unity
18 | strcpy(ret, string);
19 | return ret;
20 | }
21 |
22 | extern "C" {
23 |
24 | /* typedef void* MonoDomain;
25 | typedef void* MonoAssembly;
26 | typedef void* MonoImage;
27 | typedef void* MonoClass;
28 | typedef void* MonoObject;
29 | typedef void* MonoMethodDesc;
30 | typedef void* MonoMethod;
31 | typedef void* gpointer;
32 | typedef int gboolean;
33 |
34 | MonoDomain *mono_domain_get();
35 | MonoAssembly *mono_domain_assembly_open(MonoDomain *domain, const char *assemblyName);
36 | MonoImage *mono_assembly_get_image(MonoAssembly *assembly);
37 | MonoMethodDesc *mono_method_desc_new(const char *methodString, gboolean useNamespace);
38 | MonoMethodDesc *mono_method_desc_free(MonoMethodDesc *desc);
39 | MonoMethod *mono_method_desc_search_in_image(MonoMethodDesc *methodDesc, MonoImage *image);
40 | MonoObject *mono_runtime_invoke(MonoMethod *method, void *obj, void **params, MonoObject **exc);
41 | gpointer mono_object_unbox(MonoObject *obj);
42 |
43 | void initializUnityPluginHandler()
44 | {
45 | MonoDomain *domain = mono_domain_get();
46 | NSString *assemblyPath = [[[NSBundle mainBundle] bundlePath]
47 | stringByAppendingPathComponent:@"Data/Managed/Assembly-CSharp.dll"];
48 | MonoAssembly *assembly = mono_domain_assembly_open(domain, assemblyPath.UTF8String);
49 | MonoImage *image = mono_assembly_get_image(assembly);
50 |
51 | MonoMethodDesc *desc = mono_method_desc_new("PluginMsgHandler:InitializeHandlerByNative()", FALSE);
52 | MonoMethod *method = mono_method_desc_search_in_image(desc, image);
53 | mono_runtime_invoke(method, NULL, NULL, NULL);
54 | mono_method_desc_free(desc);
55 | } */
56 |
57 | void _iOS_InitPluginMsgHandler(const char* unityName)
58 | {
59 | [EditBox initializeEditBox:UnityGetGLViewController() unityName:unityName];
60 | NSLog(@"_iOS_InitPluginMsgHandler called");
61 | }
62 |
63 | char* _iOS_SendUnityMsgToPlugin(int nSenderId, const char* jsonMsgApp)
64 | {
65 | NSString* strJson = [NSString stringWithUTF8String:jsonMsgApp];
66 | JsonObject* jsonMsg = [[JsonObject alloc] initWithJsonData:[strJson dataUsingEncoding:NSUTF8StringEncoding]];
67 | JsonObject* jsonRet = [EditBox processRecvJsonMsg:nSenderId msg:jsonMsg];
68 |
69 | NSString* strRet = [[NSString alloc] initWithData:[jsonRet serialize] encoding:NSUTF8StringEncoding];
70 | return gCopyString([strRet UTF8String]);
71 | }
72 | void _iOS_ClosePluginMsgHandler()
73 | {
74 | [EditBox finalizeEditBox];
75 | }
76 | }
--------------------------------------------------------------------------------
/demo/Assets/NativeEditPlugin/Plugins/iOS/PluginMsgInterface.mm.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 49a9ded873bbe4dcf920129bd063913e
3 | timeCreated: 1430351529
4 | licenseType: Pro
5 | PluginImporter:
6 | serializedVersion: 1
7 | iconMap: {}
8 | executionOrder: {}
9 | isPreloaded: 0
10 | platformData:
11 | Any:
12 | enabled: 1
13 | settings: {}
14 | userData:
15 | assetBundleName:
16 | assetBundleVariant:
17 |
--------------------------------------------------------------------------------
/demo/Assets/NativeEditPlugin/README.md:
--------------------------------------------------------------------------------
1 | ## UnityNativeEdit v1.0
2 | Unity Native Input Plugin for both iOS and Android (Unity UI InputField compatible).
3 | This means you don't need a separate 'Unity' Input box and you can use all native text functions such as `Select`, `Copy` and `Paste`
4 |
5 | ## Usage
6 | 1. Simply copy the files in `release/NativeEditPlugin` into your existing unity project asset folder.
7 | 2. Make empty Gameobject and attach ```PluginMsgHandler``` to your new GameObject
8 | 3. Attach ```NativeEditBox``` script to your UnityUI ```InputField```object.
9 | 4. Build and run on your android or ios device!
10 | 5. For `Android` make sure your `AndroidManifest.xml` has the following setting
11 |
12 | ```xml
13 |
15 | ...
16 |
17 | ...
18 |
19 | ```
20 | You can refer to sample `AndroidManifest.xml` in `/Plugings/Android` folder
21 |
22 |
23 | ## Etc
24 | 1. NativeEditBox will work with delegate defined in your Unity UI InputField, `On Value Change` and `End Edit`
25 | 2. It's open source and free to use/redistribute!
26 | 3. Please refer to `demo` Unity project.
27 |
28 |
29 | --> Goto https://github.com/kmbang/UnityNativeEdit/ for latest update
--------------------------------------------------------------------------------
/demo/Assets/NativeEditPlugin/demo.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 9afd885945d234ee287edaf3288ca395
3 | folderAsset: yes
4 | timeCreated: 1430955862
5 | licenseType: Pro
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/demo/Assets/NativeEditPlugin/demo/demo.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using UnityEngine.EventSystems;
3 | using UnityEngine.UI;
4 | using System.Collections;
5 |
6 | public class demo : MonoBehaviour {
7 |
8 | public NativeEditBox testNativeEdit;
9 | public Canvas mainCanvas;
10 | private RectTransform rectTrans;
11 |
12 | // Use this for initialization
13 | void Start () {
14 | rectTrans = testNativeEdit.transform.FindChild("Text").GetComponent();
15 |
16 | GameObject tempTest = GameObject.Instantiate(testNativeEdit.gameObject);
17 | tempTest.transform.SetParent(mainCanvas.transform, false);
18 | tempTest.transform.position += new Vector3(0.0f, -250.0f, 0.0f);
19 |
20 | NativeEditBox tempNB = tempTest.GetComponent();;
21 | tempNB.SetTextNative("fdfdsfsd");
22 | }
23 |
24 | // Update is called once per frame
25 | void Update () {
26 |
27 |
28 | }
29 |
30 | private string GetCurObjName()
31 | {
32 | string strObjName = "";
33 | GameObject objSel = EventSystem.current.currentSelectedGameObject;
34 | if (objSel != null && objSel.transform.parent != null)
35 | {
36 | strObjName = objSel.transform.parent.name;
37 | }
38 |
39 | return strObjName;
40 | }
41 |
42 | public void OnEditValugChanged(string str)
43 | {
44 | Text txt = this.GetComponent();
45 | txt.text = string.Format("[{0}] val changed {1}", this.GetCurObjName(), str);
46 | }
47 |
48 | public void OnEditEnded(string str)
49 | {
50 | Text txt = this.GetComponent();
51 | txt.text = string.Format("[{0}] edit ended {1}", this.GetCurObjName(), str);
52 | }
53 |
54 | private bool bTempFocus = false;
55 | private bool bTempVisible = false;
56 | public void OnButton1()
57 | {
58 | bTempFocus = !bTempFocus;
59 | Debug.Log("OnButton1 clicked");
60 | testNativeEdit.SetFocusNative(bTempFocus);
61 | }
62 |
63 | public void OnButton2()
64 | {
65 | Debug.Log("OnButton2 clicked");
66 | bTempVisible = !bTempVisible;
67 | testNativeEdit.SetVisible(bTempVisible);
68 | }
69 |
70 | public void OnButton3()
71 | {
72 | rectTrans.sizeDelta = new Vector2(-20.0f, -5.0f);
73 | testNativeEdit.SetRectNative(rectTrans);
74 | Debug.Log("OnButton3 clicked");
75 | }
76 |
77 |
78 | public void OnButton4()
79 | {
80 | //rectTrans.sizeDelta = new Vector2(20.0f, 5.0f);
81 | //testNativeEdit.SetRectNative(rectTrans);
82 |
83 | Text txt = this.GetComponent();
84 | string sCurText = testNativeEdit.GetTextNative();
85 | txt.text = string.Format("[{0}] GetText {1}", this.GetCurObjName(), sCurText);
86 | Debug.Log("OnButton4 clicked");
87 | }
88 |
89 | public void OnButton5()
90 | {
91 | Debug.Log("OnButton5 clicked");
92 | testNativeEdit.SetTextNative("TestText Set!!@#@5");
93 | }
94 |
95 |
96 |
97 | }
98 |
--------------------------------------------------------------------------------
/demo/Assets/NativeEditPlugin/demo/demo.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 950b9a9e1d9e94b4db99ac9e6773096c
3 | timeCreated: 1430955862
4 | licenseType: Pro
5 | MonoImporter:
6 | serializedVersion: 2
7 | defaultReferences: []
8 | executionOrder: 0
9 | icon: {instanceID: 0}
10 | userData:
11 | assetBundleName:
12 | assetBundleVariant:
13 |
--------------------------------------------------------------------------------
/demo/Assets/NativeEditPlugin/demo/demo.unity:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kmbang/UnityNativeEdit/ed0d364b8d101bc85397d141666376575ed75d79/demo/Assets/NativeEditPlugin/demo/demo.unity
--------------------------------------------------------------------------------
/demo/Assets/NativeEditPlugin/demo/demo.unity.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 1139c7b6167ad4e309d3398cf5b01a7b
3 | timeCreated: 1430959201
4 | licenseType: Pro
5 | DefaultImporter:
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/demo/Assets/NativeEditPlugin/scripts.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: b93aa809b90c340e2ad3e386c67f81ef
3 | folderAsset: yes
4 | timeCreated: 1430955862
5 | licenseType: Pro
6 | DefaultImporter:
7 | userData:
8 | assetBundleName:
9 | assetBundleVariant:
10 |
--------------------------------------------------------------------------------
/demo/Assets/NativeEditPlugin/scripts/JsonObject.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using System.Text;
5 | using System;
6 |
7 | /*
8 | * Copyright (c) 2015 Kyungmin Bang
9 | *
10 | * Permission is hereby granted, free of charge, to any person obtaining
11 | * a copy of this software and associated documentation files (the
12 | * "Software"), to deal in the Software without restriction, including
13 | * without limitation the rights to use, copy, modify, merge, publish,
14 | * distribute, sublicense, and/or sell copies of the Software, and to
15 | * permit persons to whom the Software is furnished to do so, subject to
16 | * the following conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be
19 | * included in all copies or substantial portions of the Software.
20 | *
21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
25 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
26 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 | */
29 |
30 |
31 | ///
32 | /// JsonObject provide safe and type-compatible wrapper to access Json Element
33 | /// Safe means, even if a certain Json doesn't contain 'key', it doesn't crash.
34 | ///
35 | public class JsonObject : UnityEngine.Object {
36 | ///
37 | /// Supported object type : double, bool, string, List, Array!
38 | ///
39 | public Dictionary m_dict;
40 |
41 | public JsonObject()
42 | {
43 | m_dict = new Dictionary();
44 | }
45 |
46 | public JsonObject(string strJson)
47 | {
48 | m_dict = MiniJSON_Min.Json.Deserialize(strJson) as Dictionary;
49 | }
50 |
51 | public JsonObject(Dictionary dict)
52 | {
53 | m_dict = dict;
54 | }
55 |
56 | public System.Object this[string key]
57 | {
58 | get { return m_dict[key]; }
59 | set { m_dict[key] = value; }
60 | }
61 |
62 | public string getCmd() { return (string) m_dict["cmd"]; }
63 |
64 | public string Serialize()
65 | {
66 | string strData = MiniJSON_Min.Json.Serialize(m_dict);
67 | return strData;
68 | }
69 |
70 | //// Deserialize helper
71 |
72 | private object GetDictValue(string key)
73 | {
74 | System.Object obj;
75 | if (m_dict.TryGetValue(key, out obj))
76 | {
77 | return ((obj != null) ? obj : "");
78 | }
79 | return "";
80 | }
81 |
82 | public bool keyExist(string key)
83 | {
84 | System.Object obj;
85 | if (m_dict.TryGetValue(key, out obj))
86 | {
87 | return true;
88 | }
89 | return false;
90 | }
91 |
92 | public Dictionary GetJsonDict(string key)
93 | {
94 | System.Object obj;
95 | if (m_dict.TryGetValue(key, out obj)) return (Dictionary) obj;
96 | return new Dictionary();
97 | }
98 |
99 | public JsonObject GetJsonObject(string key)
100 | {
101 | Dictionary dict = this.GetJsonDict(key);
102 | return new JsonObject(dict);
103 | }
104 |
105 | public bool GetBool(string key)
106 | {
107 | bool val;
108 | if (bool.TryParse(this.GetDictValue(key).ToString(), out val)) return val;
109 | return false;
110 | }
111 |
112 | public int GetInt(string key)
113 | {
114 | int val;
115 | if (int.TryParse(this.GetDictValue(key).ToString(), out val)) return val;
116 | return 0;
117 | }
118 |
119 | public float GetFloat(string key)
120 | {
121 | float val;
122 | if (float.TryParse(this.GetDictValue(key).ToString(), out val)) return val;
123 | return 0.0f;
124 | }
125 |
126 | public string GetString(string key)
127 | {
128 | return (string) this.GetDictValue(key).ToString();
129 | }
130 |
131 | public object GetEnum(System.Type type, string key)
132 | {
133 | string obj = (string) this.GetDictValue(key);
134 | if (obj.Length > 0)
135 | {
136 | return System.Enum.Parse(type, obj);
137 | }
138 | return 0;
139 | }
140 |
141 | public List GetListJsonObject(string key)
142 | {
143 | System.Object obj;
144 | List retList = new List();
145 | if (m_dict.TryGetValue(key, out obj))
146 | {
147 | foreach(object elem in (List