├── .hgignore ├── Graphics ├── AsyncScreenshot │ ├── Assets │ │ ├── Plugins.meta │ │ ├── Plugins │ │ │ ├── iOS.meta │ │ │ └── iOS │ │ │ │ ├── MyAppController.mm │ │ │ │ ├── MyAppController.mm.meta │ │ │ │ ├── ScreenshotCreator.h │ │ │ │ ├── ScreenshotCreator.h.meta │ │ │ │ ├── ScreenshotCreator.mm │ │ │ │ └── ScreenshotCreator.mm.meta │ │ ├── TestRotator.cs │ │ ├── TestRotator.cs.meta │ │ ├── TestScreenshot.cs │ │ ├── TestScreenshot.cs.meta │ │ ├── TestScreenshot.unity │ │ └── TestScreenshot.unity.meta │ ├── ProjectSettings │ │ ├── AudioManager.asset │ │ ├── DynamicsManager.asset │ │ ├── EditorBuildSettings.asset │ │ ├── EditorSettings.asset │ │ ├── GraphicsSettings.asset │ │ ├── InputManager.asset │ │ ├── NavMeshLayers.asset │ │ ├── NetworkManager.asset │ │ ├── ProjectSettings.asset │ │ ├── QualitySettings.asset │ │ ├── TagManager.asset │ │ └── TimeManager.asset │ └── README.md ├── ExternalTexture │ ├── Assets │ │ ├── Plugins.meta │ │ ├── Plugins │ │ │ ├── iOS.meta │ │ │ └── iOS │ │ │ │ ├── NativeTexture.mm │ │ │ │ ├── NativeTexture.mm.meta │ │ │ │ ├── Soft.png │ │ │ │ ├── Soft.png.meta │ │ │ │ ├── Test_Icon.png │ │ │ │ ├── Test_Icon.png.meta │ │ │ │ ├── Test_UnityLogoLarge.png │ │ │ │ └── Test_UnityLogoLarge.png.meta │ │ ├── TEST.mat │ │ ├── TEST.mat.meta │ │ ├── TestNativeTexture.cs │ │ ├── TestNativeTexture.cs.meta │ │ ├── TestNativeTexture.unity │ │ └── TestNativeTexture.unity.meta │ ├── ProjectSettings │ │ ├── AudioManager.asset │ │ ├── DynamicsManager.asset │ │ ├── EditorBuildSettings.asset │ │ ├── EditorSettings.asset │ │ ├── GraphicsSettings.asset │ │ ├── InputManager.asset │ │ ├── NavMeshLayers.asset │ │ ├── NetworkManager.asset │ │ ├── Physics2DSettings.asset │ │ ├── ProjectSettings.asset │ │ ├── QualitySettings.asset │ │ ├── TagManager.asset │ │ └── TimeManager.asset │ └── README.md ├── LoadRawTextureData │ ├── Assets │ │ ├── LoadPVRTexture.cs │ │ ├── LoadPVRTexture.cs.meta │ │ ├── LoadPVRTexture.unity │ │ ├── LoadPVRTexture.unity.meta │ │ ├── StreamingAssets.meta │ │ ├── StreamingAssets │ │ │ ├── Test_UnityLogoLarge.png │ │ │ ├── Test_UnityLogoLarge.png.meta │ │ │ ├── Test_UnityLogoLarge.pvr │ │ │ └── Test_UnityLogoLarge.pvr.meta │ │ ├── TestMaterial.mat │ │ └── TestMaterial.mat.meta │ ├── ProjectSettings │ │ ├── AudioManager.asset │ │ ├── DynamicsManager.asset │ │ ├── EditorBuildSettings.asset │ │ ├── EditorSettings.asset │ │ ├── GraphicsSettings.asset │ │ ├── InputManager.asset │ │ ├── NavMeshLayers.asset │ │ ├── NetworkManager.asset │ │ ├── ProjectSettings.asset │ │ ├── QualitySettings.asset │ │ ├── TagManager.asset │ │ └── TimeManager.asset │ └── README.md ├── MetalNativeRenderingPlugin │ ├── Assets │ │ ├── Plugins.meta │ │ ├── Plugins │ │ │ ├── iOS.meta │ │ │ └── iOS │ │ │ │ ├── MetalPlugin.m │ │ │ │ └── MetalPlugin.m.meta │ │ ├── SamplePlugin.cs │ │ ├── SamplePlugin.cs.meta │ │ ├── Test.unity │ │ ├── Test.unity.meta │ │ ├── TestPlugin.cs │ │ └── TestPlugin.cs.meta │ └── README.md └── MetalNativeShader │ ├── Assets │ ├── MetalSimpleTexture.shader │ ├── MetalSimpleTexture.shader.meta │ ├── TestMetalShader.cs │ ├── TestMetalShader.cs.meta │ ├── TestMetalShader.unity │ └── TestMetalShader.unity.meta │ └── README.md ├── LICENSE ├── NativeIntegration ├── BackgroundTasks │ └── BackgroundFetch │ │ ├── Assets │ │ ├── BackgroundFetch.cs │ │ ├── BackgroundFetch.cs.meta │ │ ├── BackgroundFetch.unity │ │ ├── BackgroundFetch.unity.meta │ │ ├── Plugins.meta │ │ └── Plugins │ │ │ ├── iOS.meta │ │ │ └── iOS │ │ │ ├── MyAppController.mm │ │ │ └── MyAppController.mm.meta │ │ ├── ProjectSettings │ │ ├── AudioManager.asset │ │ ├── DynamicsManager.asset │ │ ├── EditorBuildSettings.asset │ │ ├── EditorSettings.asset │ │ ├── GraphicsSettings.asset │ │ ├── InputManager.asset │ │ ├── NavMeshAreas.asset │ │ ├── NetworkManager.asset │ │ ├── Physics2DSettings.asset │ │ ├── ProjectSettings.asset │ │ ├── QualitySettings.asset │ │ ├── TagManager.asset │ │ └── TimeManager.asset │ │ └── README.md ├── Misc │ ├── TextureFromGallery │ │ ├── Assets │ │ │ ├── GalleryTextureLoader.cs │ │ │ ├── GalleryTextureLoader.cs.meta │ │ │ ├── Plugins.meta │ │ │ ├── Plugins │ │ │ │ ├── iOS.meta │ │ │ │ └── iOS │ │ │ │ │ ├── GalleryTextureLoaderImpl.mm │ │ │ │ │ └── GalleryTextureLoaderImpl.mm.meta │ │ │ ├── UnlitTextureMaterial.mat │ │ │ ├── UnlitTextureMaterial.mat.meta │ │ │ ├── default.unity │ │ │ └── default.unity.meta │ │ ├── ProjectSettings │ │ │ ├── AudioManager.asset │ │ │ ├── DynamicsManager.asset │ │ │ ├── EditorBuildSettings.asset │ │ │ ├── EditorSettings.asset │ │ │ ├── GraphicsSettings.asset │ │ │ ├── InputManager.asset │ │ │ ├── NavMeshLayers.asset │ │ │ ├── NetworkManager.asset │ │ │ ├── ProjectSettings.asset │ │ │ ├── QualitySettings.asset │ │ │ ├── TagManager.asset │ │ │ └── TimeManager.asset │ │ └── README.md │ └── UpdateXcodeProject │ │ ├── Assets │ │ ├── Editor.meta │ │ ├── Editor │ │ │ ├── Unity.iOS.Extensions.Xcode.dll │ │ │ ├── Unity.iOS.Extensions.Xcode.dll.meta │ │ │ ├── XcodeProjectUpdater.cs │ │ │ └── XcodeProjectUpdater.cs.meta │ │ ├── Plugins.meta │ │ ├── Plugins │ │ │ ├── iOS.meta │ │ │ └── iOS │ │ │ │ ├── MyAppController.mm │ │ │ │ └── MyAppController.mm.meta │ │ ├── TestMaterial.mat │ │ ├── TestMaterial.mat.meta │ │ ├── TestScene.unity │ │ └── TestScene.unity.meta │ │ ├── NativeAssets │ │ ├── README.md │ │ ├── TestLib.bundle │ │ │ ├── Info.plist │ │ │ ├── eject.png │ │ │ └── en.lproj │ │ │ │ └── InfoPlist.strings │ │ ├── TestLib.framework │ │ │ ├── Headers │ │ │ ├── TestLib │ │ │ └── Versions │ │ │ │ ├── A │ │ │ │ ├── Headers │ │ │ │ │ └── TestLib.h │ │ │ │ └── TestLib │ │ │ │ └── Current │ │ └── TestLib │ │ │ ├── TestLib.xcodeproj │ │ │ ├── project.pbxproj │ │ │ ├── project.xcworkspace │ │ │ │ ├── contents.xcworkspacedata │ │ │ │ └── xcuserdata │ │ │ │ │ └── povilas.xcuserdatad │ │ │ │ │ └── UserInterfaceState.xcuserstate │ │ │ └── xcuserdata │ │ │ │ └── povilas.xcuserdatad │ │ │ │ └── xcschemes │ │ │ │ ├── TestLib.xcscheme │ │ │ │ ├── TestLibResources.xcscheme │ │ │ │ └── xcschememanagement.plist │ │ │ ├── TestLib │ │ │ ├── TestLib-Prefix.pch │ │ │ ├── TestLib.h │ │ │ └── TestLib.m │ │ │ ├── TestLibResources │ │ │ ├── TestLibResources-Info.plist │ │ │ ├── TestLibResources-Prefix.pch │ │ │ ├── eject.png │ │ │ └── en.lproj │ │ │ │ └── InfoPlist.strings │ │ │ └── TestLibTests │ │ │ ├── TestLibTests-Info.plist │ │ │ ├── TestLibTests.m │ │ │ └── en.lproj │ │ │ └── InfoPlist.strings │ │ ├── ProjectSettings │ │ ├── AudioManager.asset │ │ ├── DynamicsManager.asset │ │ ├── EditorBuildSettings.asset │ │ ├── EditorSettings.asset │ │ ├── GraphicsSettings.asset │ │ ├── InputManager.asset │ │ ├── NavMeshLayers.asset │ │ ├── NetworkManager.asset │ │ ├── Physics2DSettings.asset │ │ ├── ProjectSettings.asset │ │ ├── QualitySettings.asset │ │ ├── TagManager.asset │ │ └── TimeManager.asset │ │ └── README.md ├── UI │ ├── NavigationController │ │ ├── Assets │ │ │ ├── Plugins.meta │ │ │ ├── Plugins │ │ │ │ ├── iOS.meta │ │ │ │ └── iOS │ │ │ │ │ ├── MyAppController.mm │ │ │ │ │ └── MyAppController.mm.meta │ │ │ ├── TestMaterial.mat │ │ │ ├── TestMaterial.mat.meta │ │ │ ├── TestScene.unity │ │ │ └── TestScene.unity.meta │ │ ├── ProjectSettings │ │ │ ├── AudioManager.asset │ │ │ ├── DynamicsManager.asset │ │ │ ├── EditorBuildSettings.asset │ │ │ ├── EditorSettings.asset │ │ │ ├── GraphicsSettings.asset │ │ │ ├── InputManager.asset │ │ │ ├── NavMeshLayers.asset │ │ │ ├── NetworkManager.asset │ │ │ ├── ProjectSettings.asset │ │ │ ├── QualitySettings.asset │ │ │ ├── TagManager.asset │ │ │ └── TimeManager.asset │ │ └── README.md │ ├── OverlayUI │ │ ├── Assets │ │ │ ├── Plugins.meta │ │ │ ├── Plugins │ │ │ │ ├── iOS.meta │ │ │ │ └── iOS │ │ │ │ │ ├── MyAppController.mm │ │ │ │ │ └── MyAppController.mm.meta │ │ │ ├── ShowDatePicker.cs │ │ │ ├── ShowDatePicker.cs.meta │ │ │ ├── TestDatePicker.unity │ │ │ ├── TestDatePicker.unity.meta │ │ │ ├── TestMaterial.mat │ │ │ └── TestMaterial.mat.meta │ │ ├── ProjectSettings │ │ │ ├── AudioManager.asset │ │ │ ├── DynamicsManager.asset │ │ │ ├── EditorBuildSettings.asset │ │ │ ├── EditorSettings.asset │ │ │ ├── GraphicsSettings.asset │ │ │ ├── InputManager.asset │ │ │ ├── NavMeshLayers.asset │ │ │ ├── NetworkManager.asset │ │ │ ├── ProjectSettings.asset │ │ │ ├── QualitySettings.asset │ │ │ ├── TagManager.asset │ │ │ └── TimeManager.asset │ │ └── README.md │ └── ResizedView │ │ ├── Assets │ │ ├── Plugins.meta │ │ ├── Plugins │ │ │ ├── iOS.meta │ │ │ └── iOS │ │ │ │ ├── MyAppController.mm │ │ │ │ ├── MyAppController.mm.meta │ │ │ │ ├── ScreenshotCreator.h │ │ │ │ ├── ScreenshotCreator.h.meta │ │ │ │ ├── ScreenshotCreator.mm │ │ │ │ └── ScreenshotCreator.mm.meta │ │ ├── Rotator.cs │ │ ├── Rotator.cs.meta │ │ ├── Screenshot.cs │ │ ├── Screenshot.cs.meta │ │ ├── Test.unity │ │ ├── Test.unity.meta │ │ ├── TestOrientation.cs │ │ └── TestOrientation.cs.meta │ │ └── ProjectSettings │ │ ├── AudioManager.asset │ │ ├── DynamicsManager.asset │ │ ├── EditorBuildSettings.asset │ │ ├── EditorSettings.asset │ │ ├── GraphicsSettings.asset │ │ ├── InputManager.asset │ │ ├── NavMeshLayers.asset │ │ ├── NetworkManager.asset │ │ ├── Physics2DSettings.asset │ │ ├── ProjectSettings.asset │ │ ├── QualitySettings.asset │ │ ├── TagManager.asset │ │ └── TimeManager.asset ├── Video │ ├── ReplayIt │ │ ├── Assembly-CSharp.csproj │ │ ├── Assets │ │ │ ├── Replay.cs │ │ │ ├── Replay.cs.meta │ │ │ ├── Spin.cs │ │ │ ├── Spin.cs.meta │ │ │ ├── SwitchScene.cs │ │ │ ├── SwitchScene.cs.meta │ │ │ ├── UnityReplayKit.cs │ │ │ ├── UnityReplayKit.cs.meta │ │ │ ├── UnityReplayKit.h │ │ │ ├── UnityReplayKit.h.meta │ │ │ ├── UnityReplayKit.mm │ │ │ ├── UnityReplayKit.mm.meta │ │ │ ├── capsule.unity │ │ │ ├── capsule.unity.meta │ │ │ ├── main.unity │ │ │ └── main.unity.meta │ │ ├── ProjectSettings │ │ │ ├── AudioManager.asset │ │ │ ├── ClusterInputManager.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 │ │ │ ├── UnityAdsSettings.asset │ │ │ ├── UnityAnalyticsManager.asset │ │ │ └── UnityConnectSettings.asset │ │ ├── README.md │ │ └── ReplayIt.sln │ ├── VideoPlayer │ │ ├── Assets │ │ │ ├── Plugins.meta │ │ │ ├── Plugins │ │ │ │ ├── iOS.meta │ │ │ │ └── iOS │ │ │ │ │ ├── VideoPlayerInterface.mm │ │ │ │ │ └── VideoPlayerInterface.mm.meta │ │ │ ├── StreamingAssets.meta │ │ │ ├── StreamingAssets │ │ │ │ ├── big_buck_bunny.mp4 │ │ │ │ └── big_buck_bunny.mp4.meta │ │ │ ├── TestVideoPlayer.cs │ │ │ ├── TestVideoPlayer.cs.meta │ │ │ ├── TestVideoPlayer.unity │ │ │ └── TestVideoPlayer.unity.meta │ │ ├── ProjectSettings │ │ │ ├── AudioManager.asset │ │ │ ├── DynamicsManager.asset │ │ │ ├── EditorBuildSettings.asset │ │ │ ├── EditorSettings.asset │ │ │ ├── GraphicsSettings.asset │ │ │ ├── InputManager.asset │ │ │ ├── NavMeshLayers.asset │ │ │ ├── NetworkManager.asset │ │ │ ├── ProjectSettings.asset │ │ │ ├── QualitySettings.asset │ │ │ ├── TagManager.asset │ │ │ └── TimeManager.asset │ │ └── README.md │ └── VideoPlayerTexture │ │ ├── Assets │ │ ├── Plugins.meta │ │ ├── Plugins │ │ │ ├── iOS.meta │ │ │ └── iOS │ │ │ │ ├── VideoPlayerInterface.mm │ │ │ │ └── VideoPlayerInterface.mm.meta │ │ ├── Rotator.cs │ │ ├── Rotator.cs.meta │ │ ├── StreamingAssets.meta │ │ ├── StreamingAssets │ │ │ ├── big_buck_bunny.mp4 │ │ │ └── big_buck_bunny.mp4.meta │ │ ├── TestVideo.cs │ │ ├── TestVideo.cs.meta │ │ ├── TestVideo.mat │ │ ├── TestVideo.mat.meta │ │ ├── TestVideo.unity │ │ ├── TestVideo.unity.meta │ │ ├── VideoPlayerInterface.cs │ │ └── VideoPlayerInterface.cs.meta │ │ ├── ProjectSettings │ │ ├── AudioManager.asset │ │ ├── DynamicsManager.asset │ │ ├── EditorBuildSettings.asset │ │ ├── EditorSettings.asset │ │ ├── GraphicsSettings.asset │ │ ├── InputManager.asset │ │ ├── NavMeshLayers.asset │ │ ├── NetworkManager.asset │ │ ├── ProjectSettings.asset │ │ ├── QualitySettings.asset │ │ ├── TagManager.asset │ │ └── TimeManager.asset │ │ └── README.md └── WWW │ └── CustomConnection │ ├── Assets │ ├── Plugins.meta │ ├── Plugins │ │ ├── iOS.meta │ │ └── iOS │ │ │ ├── CustomConnection.mm │ │ │ └── CustomConnection.mm.meta │ ├── TestMaterial.mat │ ├── TestMaterial.mat.meta │ ├── TestTextureSimple.unity │ ├── TestTextureSimple.unity.meta │ ├── TestWWWGetCustomConnection.cs │ └── TestWWWGetCustomConnection.cs.meta │ ├── ProjectSettings │ ├── AudioManager.asset │ ├── DynamicsManager.asset │ ├── EditorBuildSettings.asset │ ├── EditorSettings.asset │ ├── GraphicsSettings.asset │ ├── InputManager.asset │ ├── NavMeshLayers.asset │ ├── NetworkManager.asset │ ├── Physics2DSettings.asset │ ├── ProjectSettings.asset │ ├── QualitySettings.asset │ ├── TagManager.asset │ └── TimeManager.asset │ └── README.md └── readme.markdown /.hgignore: -------------------------------------------------------------------------------- 1 | syntax:glob 2 | 3 | Library/* 4 | Temp/* 5 | *plugin.log 6 | .DS_Store 7 | *.unc-backup* 8 | *.bak 9 | -------------------------------------------------------------------------------- /Graphics/AsyncScreenshot/Assets/Plugins.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fc34b005a3e4e431980a51e5dae72e86 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Graphics/AsyncScreenshot/Assets/Plugins/iOS.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b0a9b0ae18bb34278aa4576e1782125b 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Graphics/AsyncScreenshot/Assets/Plugins/iOS/MyAppController.mm: -------------------------------------------------------------------------------- 1 | #import 2 | #import "UnityAppController.h" 3 | #import "ScreenshotCreator.h" 4 | 5 | @interface MyAppController : UnityAppController 6 | { 7 | } 8 | - (void)shouldAttachRenderDelegate; 9 | @end 10 | 11 | @implementation MyAppController 12 | 13 | - (void)shouldAttachRenderDelegate; 14 | { 15 | self.renderDelegate = [[ScreenshotCreator alloc] init]; 16 | } 17 | @end 18 | 19 | 20 | IMPL_APP_CONTROLLER_SUBCLASS(MyAppController) 21 | -------------------------------------------------------------------------------- /Graphics/AsyncScreenshot/Assets/Plugins/iOS/MyAppController.mm.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 94434b8adad5e411b92cc8bbe70a73d7 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Graphics/AsyncScreenshot/Assets/Plugins/iOS/ScreenshotCreator.h: -------------------------------------------------------------------------------- 1 | #include "RenderPluginDelegate.h" 2 | 3 | extern "C" typedef void (*ScreenshotComplete)(); 4 | 5 | @interface ScreenshotCreator : RenderPluginDelegate 6 | { 7 | NSString* screenshotPath; 8 | ScreenshotComplete callback; 9 | 10 | BOOL requestedScreenshot; 11 | BOOL creatingScreenshot; 12 | } 13 | - (id)init; 14 | 15 | - (void)onBeforeMainDisplaySurfaceRecreate:(struct RenderingSurfaceParams*)params; 16 | - (void)onFrameResolved; 17 | 18 | - (void)queryScreenshot:(NSString*)path callback:(ScreenshotComplete)callback; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /Graphics/AsyncScreenshot/Assets/Plugins/iOS/ScreenshotCreator.h.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: faad0690146ed45ff8945039d242c2cf 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Graphics/AsyncScreenshot/Assets/Plugins/iOS/ScreenshotCreator.mm.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 87ace809ddd2e4f138e3c6bf637e24ec 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Graphics/AsyncScreenshot/Assets/TestRotator.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class TestRotator : MonoBehaviour 5 | { 6 | void Update() 7 | { 8 | transform.Rotate(Vector3.right * 10 * Time.deltaTime); 9 | transform.Rotate(Vector3.up * 10 * Time.deltaTime, Space.World); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Graphics/AsyncScreenshot/Assets/TestRotator.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e05c83c5586de482b9cf1b0737ae067b 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Graphics/AsyncScreenshot/Assets/TestScreenshot.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System.Runtime.InteropServices; 4 | using AOT; 5 | 6 | public class TestScreenshot : MonoBehaviour 7 | { 8 | private static bool savingScreenshot = false; 9 | 10 | 11 | private delegate void ScreenshotCompleteDelegate(); 12 | [MonoPInvokeCallback(typeof(ScreenshotCompleteDelegate))] 13 | public static void ScreenshotCompleteCallback() 14 | { 15 | // it might be called outside of player loop, so we shouldnt do anything funky 16 | savingScreenshot = false; 17 | } 18 | 19 | #if UNITY_IPHONE && !UNITY_EDITOR 20 | [DllImport("__Internal")] 21 | private static extern void CaptureScreenshot(ScreenshotCompleteDelegate completed, string filename); 22 | #endif 23 | 24 | void OnGUI() 25 | { 26 | if (!savingScreenshot && GUI.Button(new Rect(10, 10, 200, 200), "Screenshot")) 27 | { 28 | #if UNITY_IPHONE && !UNITY_EDITOR 29 | savingScreenshot = true; 30 | CaptureScreenshot(ScreenshotCompleteCallback, "test.png"); 31 | #else 32 | Application.CaptureScreenshot("test.png"); 33 | #endif 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Graphics/AsyncScreenshot/Assets/TestScreenshot.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 308f548826c46430fb7e98eb05786da1 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Graphics/AsyncScreenshot/Assets/TestScreenshot.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/AsyncScreenshot/Assets/TestScreenshot.unity -------------------------------------------------------------------------------- /Graphics/AsyncScreenshot/Assets/TestScreenshot.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b99978dba676f475abc78669015a35db 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Graphics/AsyncScreenshot/ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/AsyncScreenshot/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /Graphics/AsyncScreenshot/ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/AsyncScreenshot/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /Graphics/AsyncScreenshot/ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/AsyncScreenshot/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /Graphics/AsyncScreenshot/ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/AsyncScreenshot/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /Graphics/AsyncScreenshot/ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/AsyncScreenshot/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /Graphics/AsyncScreenshot/ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/AsyncScreenshot/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /Graphics/AsyncScreenshot/ProjectSettings/NavMeshLayers.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/AsyncScreenshot/ProjectSettings/NavMeshLayers.asset -------------------------------------------------------------------------------- /Graphics/AsyncScreenshot/ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/AsyncScreenshot/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /Graphics/AsyncScreenshot/ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/AsyncScreenshot/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /Graphics/AsyncScreenshot/ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/AsyncScreenshot/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /Graphics/AsyncScreenshot/ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/AsyncScreenshot/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /Graphics/AsyncScreenshot/ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/AsyncScreenshot/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /Graphics/AsyncScreenshot/README.md: -------------------------------------------------------------------------------- 1 | # Using RenderPlugin API 2 | 3 | 4 | ## Description 5 | 6 | This is a sample of usage of native **RenderPluginDelegate**. It will make screenshots asynchronously on demand. 7 | 8 | 9 | ##Prerequisites 10 | 11 | Unity: 4.3 12 | 13 | iOS: any 14 | 15 | 16 | ## How does it work 17 | 18 | In Plugins/iOS folder you can see our UnityAppController subclass (MyAppController.mm) and render plugin implementation (ScreenshotCreator.mm) 19 | 20 | MyAppController.mm contains shouldAttachRenderDelegate method override, to register our render plugin: 21 | 22 | - (void)shouldAttachRenderDelegate; 23 | { 24 | self.renderDelegate = [[ScreenshotCreator alloc] init]; 25 | } 26 | 27 | 28 | ScreenshotCreator.mm demonstrates basic steps needed to implement your own plugin. 29 | 30 | First, on registering we tweak Unity's Rendering Surface to back backbuffer with CVTextureCache 31 | 32 | - (void)onBeforeMainDisplaySurfaceRecreate:(struct RenderingSurfaceParams*)params 33 | { 34 | params->useCVTextureCache = true; 35 | } 36 | 37 | 38 | Second, we hook up on the unity rendering at the moment frame was fully rendered. That will be called right before blitting to screen (if resolution is not native) and presenting frame: 39 | 40 | - (void)onFrameResolved 41 | 42 | Please note, how we use the fact that backbuffer is backed by CVTextureCache: 43 | 44 | CVPixelBufferRef pixelBuf = (CVPixelBufferRef)mainDisplaySurface->cvPixelBuffer; 45 | 46 | ... 47 | 48 | // we need to copy data to avoid stalling gl 49 | CVPixelBufferLockBaseAddress(pixelBuf, kCVPixelBufferLock_ReadOnly); 50 | { 51 | ::memcpy(imageBuffer, CVPixelBufferGetBaseAddress(pixelBuf), bufferSize); 52 | } 53 | CVPixelBufferUnlockBaseAddress(pixelBuf, kCVPixelBufferLock_ReadOnly); 54 | 55 | And after we copied the contents of the screen we start saving it to image on the background thread: 56 | 57 | [self performSelectorInBackground:@selector(saveImage) withObject:NULL]; 58 | 59 | 60 | All other code is very basic saving image to file and some glue to command the plugin from C#. 61 | -------------------------------------------------------------------------------- /Graphics/ExternalTexture/Assets/Plugins.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bc0941a773aa44aecba2a98f376a58a6 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Graphics/ExternalTexture/Assets/Plugins/iOS.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a6b80430ff6ba450bad451a4bb8bb029 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Graphics/ExternalTexture/Assets/Plugins/iOS/NativeTexture.mm.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 25b8e0ad8f1b14944b9e35681a660745 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Graphics/ExternalTexture/Assets/Plugins/iOS/Soft.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/ExternalTexture/Assets/Plugins/iOS/Soft.png -------------------------------------------------------------------------------- /Graphics/ExternalTexture/Assets/Plugins/iOS/Soft.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4a3d25084ae114f9fb37a4439f1d1b6d 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 | seamlessCubemap: 0 24 | textureFormat: -3 25 | maxTextureSize: 1024 26 | textureSettings: 27 | filterMode: -1 28 | aniso: -1 29 | mipBias: -1 30 | wrapMode: -1 31 | nPOTScale: 1 32 | lightmap: 0 33 | compressionQuality: 50 34 | spriteMode: 0 35 | spriteExtrude: 1 36 | spriteMeshType: 1 37 | alignment: 0 38 | spritePivot: {x: .5, y: .5} 39 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 40 | spritePixelsToUnits: 100 41 | alphaIsTransparency: 0 42 | textureType: -1 43 | buildTargetSettings: [] 44 | spriteSheet: 45 | sprites: [] 46 | spritePackingTag: 47 | userData: 48 | -------------------------------------------------------------------------------- /Graphics/ExternalTexture/Assets/Plugins/iOS/Test_Icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/ExternalTexture/Assets/Plugins/iOS/Test_Icon.png -------------------------------------------------------------------------------- /Graphics/ExternalTexture/Assets/Plugins/iOS/Test_Icon.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 757535a7ece274732a351fe4c05d03b9 3 | TextureImporter: 4 | serializedVersion: 2 5 | mipmaps: 6 | mipMapMode: 0 7 | enableMipMap: 1 8 | linearTexture: 0 9 | correctGamma: 0 10 | fadeOut: 0 11 | borderMipMap: 0 12 | mipMapFadeDistanceStart: 1 13 | mipMapFadeDistanceEnd: 3 14 | bumpmap: 15 | convertToNormalMap: 0 16 | externalNormalMap: 0 17 | heightScale: .25 18 | normalMapFilter: 0 19 | isReadable: 0 20 | grayScaleToAlpha: 0 21 | generateCubemap: 0 22 | seamlessCubemap: 0 23 | textureFormat: -3 24 | maxTextureSize: 1024 25 | textureSettings: 26 | filterMode: -1 27 | aniso: -1 28 | mipBias: -1 29 | wrapMode: -1 30 | nPOTScale: 1 31 | lightmap: 0 32 | compressionQuality: 50 33 | textureType: 0 34 | buildTargetSettings: [] 35 | userData: 36 | -------------------------------------------------------------------------------- /Graphics/ExternalTexture/Assets/Plugins/iOS/Test_UnityLogoLarge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/ExternalTexture/Assets/Plugins/iOS/Test_UnityLogoLarge.png -------------------------------------------------------------------------------- /Graphics/ExternalTexture/Assets/Plugins/iOS/Test_UnityLogoLarge.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0d807f7f4f1d04cef82bcbf3c2ee8599 3 | TextureImporter: 4 | serializedVersion: 2 5 | mipmaps: 6 | mipMapMode: 0 7 | enableMipMap: 1 8 | linearTexture: 0 9 | correctGamma: 0 10 | fadeOut: 0 11 | borderMipMap: 0 12 | mipMapFadeDistanceStart: 1 13 | mipMapFadeDistanceEnd: 3 14 | bumpmap: 15 | convertToNormalMap: 0 16 | externalNormalMap: 0 17 | heightScale: .25 18 | normalMapFilter: 0 19 | isReadable: 0 20 | grayScaleToAlpha: 0 21 | generateCubemap: 0 22 | seamlessCubemap: 0 23 | textureFormat: -3 24 | maxTextureSize: 1024 25 | textureSettings: 26 | filterMode: -1 27 | aniso: -1 28 | mipBias: -1 29 | wrapMode: -1 30 | nPOTScale: 1 31 | lightmap: 0 32 | compressionQuality: 50 33 | textureType: 0 34 | buildTargetSettings: [] 35 | userData: 36 | -------------------------------------------------------------------------------- /Graphics/ExternalTexture/Assets/TEST.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/ExternalTexture/Assets/TEST.mat -------------------------------------------------------------------------------- /Graphics/ExternalTexture/Assets/TEST.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1a0d0e95e61df40458db4be7b6ee297a 3 | timeCreated: 1432554915 4 | licenseType: Pro 5 | NativeFormatImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Graphics/ExternalTexture/Assets/TestNativeTexture.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System.Runtime.InteropServices; 4 | 5 | public class TestNativeTexture : MonoBehaviour 6 | { 7 | private Texture2D testTex = null; 8 | public Renderer target = null; 9 | 10 | 11 | #if UNITY_IPHONE && !UNITY_EDITOR 12 | [DllImport("__Internal")] 13 | private static extern System.IntPtr CreateNativeTexture(string filename); 14 | [DllImport("__Internal")] 15 | private static extern void DestroyNativeTexture(System.IntPtr tex); 16 | #else 17 | private static System.IntPtr CreateNativeTexture(string filename) 18 | { 19 | Texture2D tex = (Texture2D)UnityEditor.AssetDatabase.LoadAssetAtPath("Assets/Plugins/iOS/" + filename + ".png", typeof(Texture2D)); 20 | return tex.GetNativeTexturePtr(); 21 | } 22 | 23 | private static void DestroyNativeTexture(System.IntPtr tex) 24 | { 25 | } 26 | 27 | #endif // if UNITY_IPHONE && !UNITY_EDITOR 28 | 29 | private string[] externalTexture = new string[] { "Test_UnityLogoLarge", "Test_Icon", "Soft" }; 30 | private int curTexIndex; 31 | 32 | private System.IntPtr curTex; 33 | 34 | void LoadTexture() 35 | { 36 | System.IntPtr texToDestroy = curTex; 37 | 38 | curTexIndex = (curTexIndex + 1) % externalTexture.Length; 39 | curTex = CreateNativeTexture(externalTexture[curTexIndex]); 40 | 41 | testTex.UpdateExternalTexture(curTex); 42 | if (texToDestroy != System.IntPtr.Zero) 43 | DestroyNativeTexture(texToDestroy); 44 | } 45 | 46 | void Start() 47 | { 48 | testTex = Texture2D.CreateExternalTexture(128, 128, TextureFormat.ARGB32, false, false, System.IntPtr.Zero); 49 | target.material.mainTexture = testTex; 50 | 51 | curTexIndex = -1; 52 | curTex = System.IntPtr.Zero; 53 | LoadTexture(); 54 | } 55 | 56 | void OnGUI() 57 | { 58 | if (GUI.Button(new Rect(10, 10, 200, 200), "Show Next")) 59 | LoadTexture(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Graphics/ExternalTexture/Assets/TestNativeTexture.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b307ce3a8e71246c7ac3d9f2060fb2d0 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Graphics/ExternalTexture/Assets/TestNativeTexture.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/ExternalTexture/Assets/TestNativeTexture.unity -------------------------------------------------------------------------------- /Graphics/ExternalTexture/Assets/TestNativeTexture.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7642e92a63e43431daf445d3c61a0a3d 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Graphics/ExternalTexture/ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/ExternalTexture/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /Graphics/ExternalTexture/ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/ExternalTexture/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /Graphics/ExternalTexture/ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/ExternalTexture/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /Graphics/ExternalTexture/ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/ExternalTexture/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /Graphics/ExternalTexture/ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/ExternalTexture/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /Graphics/ExternalTexture/ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/ExternalTexture/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /Graphics/ExternalTexture/ProjectSettings/NavMeshLayers.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/ExternalTexture/ProjectSettings/NavMeshLayers.asset -------------------------------------------------------------------------------- /Graphics/ExternalTexture/ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/ExternalTexture/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /Graphics/ExternalTexture/ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/ExternalTexture/ProjectSettings/Physics2DSettings.asset -------------------------------------------------------------------------------- /Graphics/ExternalTexture/ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/ExternalTexture/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /Graphics/ExternalTexture/ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/ExternalTexture/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /Graphics/ExternalTexture/ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/ExternalTexture/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /Graphics/ExternalTexture/ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/ExternalTexture/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /Graphics/ExternalTexture/README.md: -------------------------------------------------------------------------------- 1 | # Creating Unity Texture from GLES Texture 2 | 3 | 4 | ## Description 5 | 6 | This is a sample of usage of **Texture2D.CreateExternalTexture** and **Texture2D.UpdateExternalTexture**. It will load png into gles texture in native plugin and give it back to Unity to be used like normal Unity Texture. 7 | 8 | 9 | ##Prerequisites 10 | 11 | Unity: 4.2 12 | 13 | iOS: any 14 | 15 | 16 | ## How does it work 17 | 18 | There are two pieces of interest: TestGLESTexture.cs and Plugins/iOS/GlesTexture.mm. 19 | 20 | In Plugins/iOS folder you can see three files: GlesTexture.mm (native plugin) and two images that we will use: Test_UnityLogoLarge.png and Test_Icon.png. All of them will be copied to your project, so we can load png from App Bundle. 21 | 22 | GlesTexture.mm contains just one function: 23 | 24 | extern "C" void* GLESTexture_CreateTexture(const char* image_filename, int* w, int* h) 25 | 26 | It will load png image from App Bundle to UIImage and pass this data to OpenGL ES: 27 | 28 | glBindTexture(GL_TEXTURE_2D, texture); 29 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 30 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 31 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 32 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 33 | 34 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, imageW, imageH, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData); 35 | 36 | The returned texture id is later used in TestGLESTexture.cs to create Unity Texture2D from it: 37 | 38 | testTex = Texture2D.CreateExternalTexture(externalTexture[0].w, externalTexture[0].h, TextureFormat.ARGB32, false, false, externalTexture[0].tex); 39 | tex.filterMode = FilterMode.Bilinear; 40 | tex.wrapMode = TextureWrapMode.Repeat; 41 | 42 | Please note, that we made sure that texture settings (wrap mode and filtering) do match. 43 | 44 | When you press "Show Next" button it will cycle through loaded textures and reuse Texture object to point to different gles texture. 45 | Please note, that both textures have exact same setup: same extensions, format etc. 46 | If you want to change texture setup, you should create new Unity Texture (in case of creating from native texture, the texture is supposed to be non readable, so no extra memory is allocated) 47 | -------------------------------------------------------------------------------- /Graphics/LoadRawTextureData/Assets/LoadPVRTexture.cs: -------------------------------------------------------------------------------- 1 | 2 | // we added new overload for LoadRawTextureData 3 | // alas there is no good way to enable code path for 5.x and newer, so you just need to uncomment this define to try out new api 4 | // #define USE_RAW_TEXTURE_DATA_INTPTR_VARIANT 5 | 6 | using UnityEngine; 7 | using System.Collections; 8 | using System.Linq; 9 | using System.Runtime.InteropServices; 10 | 11 | public class LoadPVRTexture : MonoBehaviour 12 | { 13 | public Material targetMat = null; 14 | private Texture2D targetTex = null; 15 | 16 | 17 | #if UNITY_IPHONE && !UNITY_EDITOR 18 | private const int _HeaderSize = 52; 19 | #else 20 | private const int _HeaderSize = 0; 21 | #endif 22 | 23 | 24 | void Start() 25 | { 26 | #if UNITY_IPHONE && !UNITY_EDITOR 27 | targetTex = new Texture2D(128, 128, TextureFormat.PVRTC_RGBA4, true); 28 | #else 29 | targetTex = new Texture2D(128, 128); 30 | #endif 31 | 32 | StartCoroutine(LoadTexture()); 33 | targetMat.mainTexture = targetTex; 34 | } 35 | 36 | void LoadRawData(Texture2D tex, byte[] texMem) 37 | { 38 | #if USE_RAW_TEXTURE_DATA_INTPTR_VARIANT 39 | // this overload is mostly useful for native plugins, but i am too lazy to go write native code 40 | GCHandle pinnedTexMem = GCHandle.Alloc(texMem, GCHandleType.Pinned); 41 | targetTex.LoadRawTextureData(pinnedTexMem.AddrOfPinnedObject(), texMem.Length); 42 | pinnedTexMem.Free(); 43 | #else 44 | targetTex.LoadRawTextureData(texMem); 45 | #endif 46 | } 47 | 48 | IEnumerator LoadTexture() 49 | { 50 | #if UNITY_IPHONE && !UNITY_EDITOR 51 | string filePath = System.IO.Path.Combine(Application.streamingAssetsPath, "Test_UnityLogoLarge.pvr"); 52 | #else 53 | string filePath = System.IO.Path.Combine(Application.streamingAssetsPath, "Test_UnityLogoLarge.png"); 54 | #endif 55 | 56 | byte[] texMem = null; 57 | if (filePath.Contains("://")) 58 | { 59 | WWW www = new WWW(filePath); 60 | yield return www; 61 | texMem = www.bytes.Skip(_HeaderSize).ToArray(); 62 | } 63 | else 64 | { 65 | texMem = System.IO.File.ReadAllBytes(filePath).Skip(_HeaderSize).ToArray(); 66 | } 67 | 68 | #if UNITY_IPHONE && !UNITY_EDITOR 69 | LoadRawData(targetTex, texMem); 70 | targetTex.Apply(true, true); 71 | #else 72 | targetTex.LoadImage(texMem); 73 | #endif 74 | 75 | yield break; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /Graphics/LoadRawTextureData/Assets/LoadPVRTexture.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 558bf07cf56f24a01908ef1b01d4a826 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /Graphics/LoadRawTextureData/Assets/LoadPVRTexture.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/LoadRawTextureData/Assets/LoadPVRTexture.unity -------------------------------------------------------------------------------- /Graphics/LoadRawTextureData/Assets/LoadPVRTexture.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 511274ea8eba2464188279ef120e6ade 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Graphics/LoadRawTextureData/Assets/StreamingAssets.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 95851ac5915454268bf856580f8659b0 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /Graphics/LoadRawTextureData/Assets/StreamingAssets/Test_UnityLogoLarge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/LoadRawTextureData/Assets/StreamingAssets/Test_UnityLogoLarge.png -------------------------------------------------------------------------------- /Graphics/LoadRawTextureData/Assets/StreamingAssets/Test_UnityLogoLarge.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0d807f7f4f1d04cef82bcbf3c2ee8599 3 | TextureImporter: 4 | serializedVersion: 2 5 | mipmaps: 6 | mipMapMode: 0 7 | enableMipMap: 1 8 | linearTexture: 0 9 | correctGamma: 0 10 | fadeOut: 0 11 | borderMipMap: 0 12 | mipMapFadeDistanceStart: 1 13 | mipMapFadeDistanceEnd: 3 14 | bumpmap: 15 | convertToNormalMap: 0 16 | externalNormalMap: 0 17 | heightScale: .25 18 | normalMapFilter: 0 19 | isReadable: 0 20 | grayScaleToAlpha: 0 21 | generateCubemap: 0 22 | seamlessCubemap: 0 23 | textureFormat: -3 24 | maxTextureSize: 1024 25 | textureSettings: 26 | filterMode: -1 27 | aniso: -1 28 | mipBias: -1 29 | wrapMode: -1 30 | nPOTScale: 1 31 | lightmap: 0 32 | compressionQuality: 50 33 | alphaIsTransparency: 0 34 | textureType: 0 35 | buildTargetSettings: [] 36 | userData: 37 | -------------------------------------------------------------------------------- /Graphics/LoadRawTextureData/Assets/StreamingAssets/Test_UnityLogoLarge.pvr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/LoadRawTextureData/Assets/StreamingAssets/Test_UnityLogoLarge.pvr -------------------------------------------------------------------------------- /Graphics/LoadRawTextureData/Assets/StreamingAssets/Test_UnityLogoLarge.pvr.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b5751dda314b84708b1bf996629b1848 3 | PVRImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Graphics/LoadRawTextureData/Assets/TestMaterial.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/LoadRawTextureData/Assets/TestMaterial.mat -------------------------------------------------------------------------------- /Graphics/LoadRawTextureData/Assets/TestMaterial.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3fda6ecc2152c400c818948dbdc45e2f 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /Graphics/LoadRawTextureData/ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/LoadRawTextureData/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /Graphics/LoadRawTextureData/ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/LoadRawTextureData/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /Graphics/LoadRawTextureData/ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/LoadRawTextureData/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /Graphics/LoadRawTextureData/ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/LoadRawTextureData/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /Graphics/LoadRawTextureData/ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/LoadRawTextureData/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /Graphics/LoadRawTextureData/ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/LoadRawTextureData/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /Graphics/LoadRawTextureData/ProjectSettings/NavMeshLayers.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/LoadRawTextureData/ProjectSettings/NavMeshLayers.asset -------------------------------------------------------------------------------- /Graphics/LoadRawTextureData/ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/LoadRawTextureData/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /Graphics/LoadRawTextureData/ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/LoadRawTextureData/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /Graphics/LoadRawTextureData/ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/LoadRawTextureData/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /Graphics/LoadRawTextureData/ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/LoadRawTextureData/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /Graphics/LoadRawTextureData/ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/Graphics/LoadRawTextureData/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /Graphics/LoadRawTextureData/README.md: -------------------------------------------------------------------------------- 1 | # Loading raw texture data directly 2 | 3 | 4 | ## Description 5 | 6 | This is a sample of usage of **Texture2D.LoadRawTextureData**. It will load downloaded pvr data into texture. 7 | 8 | 9 | ##Prerequisites 10 | 11 | Unity: 4.3 12 | 13 | iOS: any 14 | 15 | 16 | ## How does it work 17 | 18 | This sample is purely C# so everything is in LoadPVRTexture.cs. To simplify sample we use PVR texture directly, which is not very efficient because we will need to skip file header at runtime, but we chose that way so you can see PVR texture contents in the editor. 19 | 20 | We start by "downloading" data (for sake of simplicity we put image in StreamingAssets) and get rid of the header 21 | 22 | string filePath = System.IO.Path.Combine(Application.streamingAssetsPath, "Test_UnityLogoLarge.pvr"); 23 | ... 24 | texMem = System.IO.File.ReadAllBytes(filePath).Skip(_HeaderSize).ToArray(); 25 | 26 | And then we load raw data into texture. Please be aware that we do almost no checks in there, so you can, for example, load DXT texture data here, though it will obviously result in OpenGL ES errors. 27 | 28 | targetTex.LoadRawTextureData(texMem); 29 | targetTex.Apply(true, true); 30 | -------------------------------------------------------------------------------- /Graphics/MetalNativeRenderingPlugin/Assets/Plugins.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b1de25705be9b4be79a9e0237a4266ed 3 | folderAsset: yes 4 | timeCreated: 1429792431 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Graphics/MetalNativeRenderingPlugin/Assets/Plugins/iOS.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: add4c6feaacf64c728bb6abce5a3f7b2 3 | folderAsset: yes 4 | timeCreated: 1429792436 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Graphics/MetalNativeRenderingPlugin/Assets/Plugins/iOS/MetalPlugin.m.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bd13763b18d2f4a8f9f090a8566c7c8a 3 | timeCreated: 1522913661 4 | licenseType: Pro 5 | PluginImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | iconMap: {} 9 | executionOrder: {} 10 | isPreloaded: 0 11 | isOverridable: 0 12 | platformData: 13 | - first: 14 | Any: 15 | second: 16 | enabled: 0 17 | settings: {} 18 | - first: 19 | Editor: Editor 20 | second: 21 | enabled: 0 22 | settings: 23 | DefaultValueInitialized: true 24 | - first: 25 | iPhone: iOS 26 | second: 27 | enabled: 1 28 | settings: {} 29 | userData: 30 | assetBundleName: 31 | assetBundleVariant: 32 | -------------------------------------------------------------------------------- /Graphics/MetalNativeRenderingPlugin/Assets/SamplePlugin.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.InteropServices; 2 | using UnityEngine; 3 | 4 | public class SamplePlugin { 5 | 6 | // we will do several pretty useless events to show the usage of all api functions 7 | private enum EventType { 8 | ExtraDrawCall = 0, // will do an extra draw call to currently setup rt with custom shader 9 | CopyRTtoRT, // copy src rt to internal texture and draws rect using it to dst rt 10 | }; 11 | 12 | public static void DoExtraDrawCall() { 13 | GL.IssuePluginEvent(GetRenderEventFunc(), (int)EventType.ExtraDrawCall); 14 | } 15 | public static void DoCopyRT(RenderTexture srcRT, RenderTexture dstRT) { 16 | RenderBuffer src = srcRT ? srcRT.colorBuffer : Display.main.colorBuffer, dst = dstRT ? dstRT.colorBuffer : Display.main.colorBuffer; 17 | SetRTCopyTargets(src.GetNativeRenderBufferPtr(), dst.GetNativeRenderBufferPtr()); 18 | GL.IssuePluginEvent(GetRenderEventFunc(), (int)EventType.CopyRTtoRT); 19 | } 20 | 21 | 22 | // native plugin interop: 23 | // GetRenderEventFunc is used to query plugin for function pointer to pass to GL.IssuePluginEvent 24 | 25 | #if UNITY_IPHONE && !UNITY_EDITOR 26 | [DllImport ("__Internal")] private static extern System.IntPtr GetRenderEventFunc(); 27 | [DllImport ("__Internal")] private static extern void SetRTCopyTargets(System.IntPtr srcRB, System.IntPtr dstRB); 28 | #else 29 | private static System.IntPtr GetRenderEventFunc() { return System.IntPtr.Zero; } 30 | private static void SetRTCopyTargets(System.IntPtr srcRB, System.IntPtr dstRB) {} 31 | #endif 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Graphics/MetalNativeRenderingPlugin/Assets/SamplePlugin.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3d3a207f4755d4a9997b6922f5a6c7a8 3 | timeCreated: 1522913656 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Graphics/MetalNativeRenderingPlugin/Assets/Test.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: faeeec62778c94cef854241acd3bf4d6 3 | timeCreated: 1522913690 4 | licenseType: Pro 5 | DefaultImporter: 6 | externalObjects: {} 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Graphics/MetalNativeRenderingPlugin/Assets/TestPlugin.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class TestPlugin : MonoBehaviour { 6 | IEnumerator OnFrameEnd() { 7 | yield return new WaitForEndOfFrame(); 8 | // note that we do that AFTER all unity rendering is done. 9 | // it is especially important if AA is involved, as we will end encoder (resulting in AA resolve) 10 | SamplePlugin.DoCopyRT(GetComponent().targetTexture, null); 11 | yield return null; 12 | } 13 | 14 | void OnPostRender() { 15 | SamplePlugin.DoExtraDrawCall(); 16 | StartCoroutine(OnFrameEnd()); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Graphics/MetalNativeRenderingPlugin/Assets/TestPlugin.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4126ff6e10fca4474ba3e03d959d3739 3 | timeCreated: 1522913656 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Graphics/MetalNativeShader/Assets/MetalSimpleTexture.shader: -------------------------------------------------------------------------------- 1 | Shader "MetalSimpleTexture" 2 | { 3 | Properties 4 | { 5 | _MainTex ("Texture", 2D) = "white" {} 6 | _Color ("Main Color", Color) = (1,1,1,1) 7 | } 8 | SubShader 9 | { 10 | Tags { "RenderType"="Opaque" } 11 | LOD 100 12 | 13 | Pass 14 | { 15 | METALINCLUDE 16 | #include 17 | #include 18 | ENDMETAL 19 | 20 | METALPROGRAM 21 | #pragma vertex vert 22 | #pragma fragment frag 23 | 24 | using namespace metal; 25 | 26 | // currently METALPROGRAM supports only one uniform buffer, shared between vertex program and fragment shader 27 | struct Globals 28 | { 29 | METAL_CONST_MATRIX(float, 4,4, unity_ObjectToWorld); 30 | METAL_CONST_MATRIX(float, 4,4, unity_MatrixVP); 31 | METAL_CONST_VECTOR(half, 4, _Color); 32 | }; 33 | 34 | struct ColorInput 35 | { 36 | float4 color; 37 | }; 38 | 39 | struct InputVP 40 | { 41 | float4 pos METAL_VERTEX_INPUT(0); 42 | float2 uv METAL_VERTEX_INPUT(4); 43 | }; 44 | struct OutputVP 45 | { 46 | float4 pos [[ position ]]; 47 | float2 uv [[ user(TEXCOORD0) ]]; 48 | }; 49 | struct OutputFS 50 | { 51 | half4 color [[ color(0) ]]; 52 | }; 53 | 54 | vertex OutputVP vert(constant Globals& glob [[ buffer(0) ]], InputVP input [[ stage_in ]]) 55 | { 56 | OutputVP output; 57 | output.pos = glob.unity_MatrixVP * (glob.unity_ObjectToWorld * input.pos); 58 | output.uv = input.uv; 59 | return output; 60 | } 61 | fragment OutputFS frag(constant Globals& glob [[ buffer(0) ]], METAL_BUFFER_INPUT(ColorInput, 1, _ColorBuffer), 62 | METAL_TEX_INPUT(texture2d, 0, _MainTex), 63 | OutputVP input [[ stage_in ]]) 64 | { 65 | METAL_BUFFER_INPUT_DATA(ColorInput, _ColorBuffer) 66 | 67 | OutputFS output; 68 | output.color.rgb = glob._Color.rgb * (half3)_ColorBuffer[0].color.xyz * _MainTex.sample(sampler__MainTex, input.uv).xyz; 69 | output.color.a = 1; 70 | return output; 71 | } 72 | ENDMETAL 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /Graphics/MetalNativeShader/Assets/MetalSimpleTexture.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 55390bb0c74a746e78bb46251418974a 3 | timeCreated: 1491553227 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Graphics/MetalNativeShader/Assets/TestMetalShader.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class TestMetalShader : MonoBehaviour 6 | { 7 | public Shader shader; 8 | 9 | private Material mat; 10 | private Texture tex; 11 | private ComputeBuffer buf; 12 | 13 | private Texture2D CreateTexture(int ext) 14 | { 15 | Texture2D tex = new Texture2D(ext,ext,TextureFormat.RGBA32, false,false); 16 | 17 | Color[] pixels = new Color[ext*ext]; 18 | for(int i = 0 ; i < ext ; ++i) 19 | { 20 | for(int j = 0 ; j < ext ; ++j) 21 | { 22 | // we do 4x4 blocks 23 | if((i/4) % 2 == (j/4) % 2) pixels[i*ext+j] = new Color(1,1,1,1); 24 | else pixels[i*ext+j] = new Color(0,0,0,1); 25 | } 26 | } 27 | tex.SetPixels(pixels); 28 | tex.wrapMode = TextureWrapMode.Clamp; 29 | tex.Apply(false, false); 30 | 31 | return tex; 32 | } 33 | 34 | void Start() 35 | { 36 | buf = new ComputeBuffer(1, 4*sizeof(float)); 37 | buf.SetData(new float[]{0.0f,1.0f,0.0f,1.0f}); 38 | 39 | tex = CreateTexture(32); 40 | 41 | mat = new Material(shader); 42 | mat.mainTexture = tex; 43 | mat.SetBuffer("_ColorBuffer", buf); 44 | mat.color = new Color(1,1,0,1); 45 | 46 | GetComponent().material = mat; 47 | } 48 | 49 | void OnDisable() 50 | { 51 | DestroyImmediate(mat); 52 | buf.Release(); 53 | DestroyImmediate(tex); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Graphics/MetalNativeShader/Assets/TestMetalShader.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 32225776dd2af42bfbe176082b3bf397 3 | timeCreated: 1491553976 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Graphics/MetalNativeShader/Assets/TestMetalShader.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1caf370f3915d4c96ac9660b741413f6 3 | timeCreated: 1491554516 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Graphics/MetalNativeShader/README.md: -------------------------------------------------------------------------------- 1 | # Writing Unity Shaders using Metal Shading Language 2 | 3 | 4 | ## Description 5 | 6 | This is a sample of using Metal Shading Language in Unity Shaders. 7 | 8 | 9 | ##Prerequisites 10 | 11 | Unity: 2019 12 | 13 | 14 | ## How does it work 15 | 16 | Pretty much like GLSL snippets, Metal snippets should be surrounded with `METALPROGRAM`/`ENDMETAL`. 17 | Please note that you specify entry points for vertex program and fragment shader like for "normal" unity shaders: 18 | 19 | #pragma vertex vert 20 | #pragma fragment frag 21 | 22 | To connect your shaders with Unity you need to mark vertex inputs, uniforms and textures. Please note that for uniforms only one (shared between vertex program and fragment shaders) uniform buffer is supported. 23 | 24 | Use `METAL_VERTEX_INPUT` to mark vertex data. Arguments are: 0 for position, 1 - normal, 2 - tangent, 3 - color, 4-7 - uvs 25 | 26 | struct InputVP 27 | { 28 | float4 pos METAL_VERTEX_INPUT(0); 29 | float2 uv METAL_VERTEX_INPUT(3); 30 | }; 31 | 32 | Use `METAL_TEX_INPUT` to mark used textures. Arguments are: first is metal type to use, second is the bind point and third is the property name. 33 | 34 | METAL_TEX_INPUT(texture2d, 0, _MainTex) 35 | 36 | Use `METAL_BUFFER_INPUT` to mark used buffers. HLSL analogue is StructuredBuffer, but unlike HLSL you need to pass element count yourself. Arguments are: first is the type of element, second is the bind point and third is the property name. 37 | 38 | METAL_BUFFER_INPUT(ColorInput, 1, _ColorBuffer) 39 | 40 | As metal do not have implicit UAV counters, unity is forced to allocate extra space in all Compute Buffers, so you also need `METAL_BUFFER_INPUT_DATA` to extract data pointer. Arguments are: first is the type of element, second is the property name. 41 | 42 | METAL_BUFFER_INPUT_DATA(ColorInput, _ColorBuffer) 43 | 44 | 45 | Use `METAL_CONST_MATRIX` and `METAL_CONST_VECTOR` to mark uniform declarations. Arguments are: `METAL_CONST_VECTOR(type, dim, name)` and `METAL_CONST_MATRIX(type, rows, cols, name)` 46 | 47 | struct Globals 48 | { 49 | METAL_CONST_MATRIX(float, 4,4, unity_ObjectToWorld); 50 | METAL_CONST_MATRIX(float, 4,4, unity_MatrixVP); 51 | METAL_CONST_VECTOR(half, 4, _Color); 52 | }; 53 | 54 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013-2014 Unity Technologies 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /NativeIntegration/BackgroundTasks/BackgroundFetch/Assets/BackgroundFetch.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Runtime.InteropServices; 3 | 4 | 5 | public class BackgroundFetch : MonoBehaviour 6 | { 7 | #if UNITY_IPHONE && !UNITY_EDITOR 8 | [DllImport("__Internal")] 9 | private static extern string QueryFetchedText(); 10 | #else 11 | private static string QueryFetchedText() { return null; } 12 | #endif 13 | 14 | private string fetchedText = null; 15 | public TextMesh text; 16 | 17 | void Update() 18 | { 19 | if (fetchedText == null) 20 | { 21 | fetchedText = QueryFetchedText(); 22 | if (fetchedText != null) 23 | Debug.Log("Just Fetched: " + fetchedText); 24 | } 25 | } 26 | 27 | void OnGUI() 28 | { 29 | if (fetchedText != null) 30 | text.text = fetchedText; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /NativeIntegration/BackgroundTasks/BackgroundFetch/Assets/BackgroundFetch.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8339b9ea7ecdc49d3be3a874dce05c13 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /NativeIntegration/BackgroundTasks/BackgroundFetch/Assets/BackgroundFetch.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0f5b62f77d553436b839a5b4fb564a19 3 | DefaultImporter: 4 | userData: 5 | assetBundleName: 6 | assetBundleVariant: 7 | -------------------------------------------------------------------------------- /NativeIntegration/BackgroundTasks/BackgroundFetch/Assets/Plugins.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d8479a5dda07546178afe7a940846fd1 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | assetBundleName: 7 | -------------------------------------------------------------------------------- /NativeIntegration/BackgroundTasks/BackgroundFetch/Assets/Plugins/iOS.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bb59555ac418e400e9f7bda2c3973b23 3 | folderAsset: yes 4 | PluginImporter: 5 | serializedVersion: 1 6 | iconMap: {} 7 | executionOrder: {} 8 | platformData: 9 | Any: 10 | enabled: 0 11 | settings: {} 12 | Editor: 13 | enabled: 0 14 | settings: 15 | CPU: AnyCPU 16 | OS: AnyOS 17 | Linux: 18 | enabled: 0 19 | settings: 20 | CPU: AnyCPU 21 | Linux64: 22 | enabled: 0 23 | settings: 24 | CPU: AnyCPU 25 | LinuxUniversal: 26 | enabled: 0 27 | settings: 28 | CPU: AnyCPU 29 | OSXIntel: 30 | enabled: 0 31 | settings: 32 | CPU: AnyCPU 33 | OSXIntel64: 34 | enabled: 0 35 | settings: 36 | CPU: AnyCPU 37 | OSXUniversal: 38 | enabled: 0 39 | settings: 40 | CPU: AnyCPU 41 | Win: 42 | enabled: 0 43 | settings: 44 | CPU: AnyCPU 45 | Win64: 46 | enabled: 0 47 | settings: 48 | CPU: AnyCPU 49 | iOS: 50 | enabled: 0 51 | settings: 52 | FrameworkDependencies: 53 | iPhone: 54 | enabled: 1 55 | settings: {} 56 | userData: 57 | assetBundleName: 58 | -------------------------------------------------------------------------------- /NativeIntegration/BackgroundTasks/BackgroundFetch/Assets/Plugins/iOS/MyAppController.mm: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | #import 4 | 5 | #import "UnityAppController.h" 6 | 7 | extern bool _unityAppReady; 8 | 9 | static NSString* _FetchedText; 10 | 11 | 12 | @interface MyAppController : UnityAppController 13 | { 14 | } 15 | - (void)application:(UIApplication*)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler; 16 | - (BOOL)application:(UIApplication*)application willFinishLaunchingWithOptions:(NSDictionary*)launchOptions; 17 | @end 18 | 19 | @implementation MyAppController 20 | - (BOOL)application:(UIApplication*)application willFinishLaunchingWithOptions:(NSDictionary*)launchOptions 21 | { 22 | [application setMinimumBackgroundFetchInterval: UIApplicationBackgroundFetchIntervalMinimum]; 23 | return [super application: application willFinishLaunchingWithOptions: launchOptions]; 24 | } 25 | 26 | - (void)application:(UIApplication*)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler 27 | { 28 | NSURL* url = [NSURL URLWithString: @"http://unity3d.com"]; 29 | NSURLRequest* request = [NSURLRequest requestWithURL: url cachePolicy: NSURLRequestReloadIgnoringLocalCacheData timeoutInterval: 10.0]; 30 | NSData* data = [NSURLConnection sendSynchronousRequest: request returningResponse: nil error: nil]; 31 | NSString* text = [NSString stringWithUTF8String: (const char*)data.bytes]; 32 | 33 | // i dont think this is appropriate place to fully write all the words i can say about web 2.0 obsession 34 | // so we just grab and be gone 35 | NSRange titleStartRange = [text rangeOfString: @"<title>"]; 36 | unsigned titleStart = titleStartRange.location + titleStartRange.length; 37 | NSRange titleEndRange = [text rangeOfString: @"<" options: 0 range: NSMakeRange(titleStart, text.length - titleStart)]; 38 | 39 | _FetchedText = [text substringWithRange: NSMakeRange(titleStart, titleEndRange.location - titleStart)]; 40 | 41 | // do not try to run player loop before unity is inited 42 | if (_unityAppReady) 43 | UnityBatchPlayerLoop(); 44 | 45 | completionHandler(UIBackgroundFetchResultNewData); 46 | } 47 | 48 | @end 49 | 50 | extern "C" const char* QueryFetchedText() 51 | { 52 | if (_FetchedText == nil) 53 | return 0; 54 | 55 | char* ret = (char*)::malloc(_FetchedText.length + 1); 56 | ::memcpy(ret, [_FetchedText UTF8String], _FetchedText.length); 57 | ret[_FetchedText.length] = 0; 58 | 59 | return ret; 60 | } 61 | 62 | 63 | IMPL_APP_CONTROLLER_SUBCLASS(MyAppController) 64 | -------------------------------------------------------------------------------- /NativeIntegration/BackgroundTasks/BackgroundFetch/Assets/Plugins/iOS/MyAppController.mm.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 356656511764c4c859451ec0f9ed873a 3 | DefaultImporter: 4 | userData: 5 | assetBundleName: 6 | -------------------------------------------------------------------------------- /NativeIntegration/BackgroundTasks/BackgroundFetch/ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!11 &1 4 | AudioManager: 5 | m_ObjectHideFlags: 0 6 | m_Volume: 1 7 | Rolloff Scale: 1 8 | Doppler Factor: 1 9 | Default Speaker Mode: 2 10 | m_SampleRate: 0 11 | m_DSPBufferSize: 0 12 | m_VirtualVoiceCount: 512 13 | m_RealVoiceCount: 32 14 | m_DisableAudio: 0 15 | -------------------------------------------------------------------------------- /NativeIntegration/BackgroundTasks/BackgroundFetch/ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!55 &1 4 | PhysicsManager: 5 | m_ObjectHideFlags: 0 6 | m_Gravity: {x: 0, y: -9.81000042, z: 0} 7 | m_DefaultMaterial: {fileID: 0} 8 | m_BounceThreshold: 2 9 | m_SleepThreshold: .00499999989 10 | m_DefaultContactOffset: .00999999978 11 | m_SolverIterationCount: 6 12 | m_RaycastsHitTriggers: 1 13 | m_EnableAdaptiveForce: 0 14 | m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 15 | -------------------------------------------------------------------------------- /NativeIntegration/BackgroundTasks/BackgroundFetch/ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!1045 &1 4 | EditorBuildSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | m_Scenes: 8 | - enabled: 1 9 | path: Assets/BackgroundFetch.unity 10 | -------------------------------------------------------------------------------- /NativeIntegration/BackgroundTasks/BackgroundFetch/ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!159 &1 4 | EditorSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 3 7 | m_ExternalVersionControlSupport: Visible Meta Files 8 | m_SerializationMode: 2 9 | m_WebSecurityEmulationEnabled: 0 10 | m_WebSecurityEmulationHostUrl: http://www.mydomain.com/mygame.unity3d 11 | m_DefaultBehaviorMode: 0 12 | m_SpritePackerMode: 0 13 | m_SpritePackerPaddingPower: 1 14 | -------------------------------------------------------------------------------- /NativeIntegration/BackgroundTasks/BackgroundFetch/ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!30 &1 4 | GraphicsSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 3 7 | m_Deferred: 8 | m_Mode: 1 9 | m_Shader: {fileID: 69, guid: 0000000000000000f000000000000000, type: 0} 10 | m_LegacyDeferred: 11 | m_Mode: 1 12 | m_Shader: {fileID: 63, guid: 0000000000000000f000000000000000, type: 0} 13 | m_AlwaysIncludedShaders: 14 | - {fileID: 7, guid: 0000000000000000f000000000000000, type: 0} 15 | - {fileID: 15104, guid: 0000000000000000f000000000000000, type: 0} 16 | - {fileID: 15105, guid: 0000000000000000f000000000000000, type: 0} 17 | - {fileID: 15106, guid: 0000000000000000f000000000000000, type: 0} 18 | - {fileID: 10770, guid: 0000000000000000f000000000000000, type: 0} 19 | - {fileID: 10782, guid: 0000000000000000f000000000000000, type: 0} 20 | m_PreloadedShaders: [] 21 | m_LightmapStripping: 0 22 | m_LightmapKeepPlain: 1 23 | m_LightmapKeepDirCombined: 1 24 | m_LightmapKeepDirSeparate: 1 25 | m_LightmapKeepDynamic: 1 26 | m_FogStripping: 0 27 | m_FogKeepLinear: 1 28 | m_FogKeepExp: 1 29 | m_FogKeepExp2: 1 30 | -------------------------------------------------------------------------------- /NativeIntegration/BackgroundTasks/BackgroundFetch/ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!126 &1 4 | NavMeshAreas: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | areas: 8 | - name: Walkable 9 | cost: 1 10 | - name: Not Walkable 11 | cost: 1 12 | - name: Jump 13 | cost: 2 14 | - name: 15 | cost: 1 16 | - name: 17 | cost: 1 18 | - name: 19 | cost: 1 20 | - name: 21 | cost: 1 22 | - name: 23 | cost: 1 24 | - name: 25 | cost: 1 26 | - name: 27 | cost: 1 28 | - name: 29 | cost: 1 30 | - name: 31 | cost: 1 32 | - name: 33 | cost: 1 34 | - name: 35 | cost: 1 36 | - name: 37 | cost: 1 38 | - name: 39 | cost: 1 40 | - name: 41 | cost: 1 42 | - name: 43 | cost: 1 44 | - name: 45 | cost: 1 46 | - name: 47 | cost: 1 48 | - name: 49 | cost: 1 50 | - name: 51 | cost: 1 52 | - name: 53 | cost: 1 54 | - name: 55 | cost: 1 56 | - name: 57 | cost: 1 58 | - name: 59 | cost: 1 60 | - name: 61 | cost: 1 62 | - name: 63 | cost: 1 64 | - name: 65 | cost: 1 66 | - name: 67 | cost: 1 68 | - name: 69 | cost: 1 70 | - name: 71 | cost: 1 72 | -------------------------------------------------------------------------------- /NativeIntegration/BackgroundTasks/BackgroundFetch/ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!149 &1 4 | NetworkManager: 5 | m_ObjectHideFlags: 0 6 | m_DebugLevel: 0 7 | m_Sendrate: 15 8 | m_AssetToPrefab: {} 9 | -------------------------------------------------------------------------------- /NativeIntegration/BackgroundTasks/BackgroundFetch/ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!19 &1 4 | Physics2DSettings: 5 | m_ObjectHideFlags: 0 6 | m_Gravity: {x: 0, y: -9.81000042} 7 | m_DefaultMaterial: {fileID: 0} 8 | m_VelocityIterations: 8 9 | m_PositionIterations: 3 10 | m_VelocityThreshold: 1 11 | m_MaxLinearCorrection: .200000003 12 | m_MaxAngularCorrection: 8 13 | m_MaxTranslationSpeed: 100 14 | m_MaxRotationSpeed: 360 15 | m_MinPenetrationForPenalty: .00999999978 16 | m_BaumgarteScale: .200000003 17 | m_BaumgarteTimeOfImpactScale: .75 18 | m_TimeToSleep: .5 19 | m_LinearSleepTolerance: .00999999978 20 | m_AngularSleepTolerance: 2 21 | m_RaycastsHitTriggers: 1 22 | m_RaycastsStartInColliders: 1 23 | m_ChangeStopsCallbacks: 0 24 | m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff 25 | -------------------------------------------------------------------------------- /NativeIntegration/BackgroundTasks/BackgroundFetch/ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!78 &1 4 | TagManager: 5 | serializedVersion: 2 6 | tags: [] 7 | layers: 8 | - Default 9 | - TransparentFX 10 | - Ignore Raycast 11 | - 12 | - Water 13 | - UI 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 | m_SortingLayers: 41 | - name: Default 42 | uniqueID: 0 43 | locked: 0 44 | -------------------------------------------------------------------------------- /NativeIntegration/BackgroundTasks/BackgroundFetch/ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!5 &1 4 | TimeManager: 5 | m_ObjectHideFlags: 0 6 | Fixed Timestep: .0199999996 7 | Maximum Allowed Timestep: .333333343 8 | m_TimeScale: 1 9 | -------------------------------------------------------------------------------- /NativeIntegration/BackgroundTasks/BackgroundFetch/README.md: -------------------------------------------------------------------------------- 1 | # Basic support for background execution 2 | 3 | 4 | ## Description 5 | 6 | This sample shows how to add support for background executions (in this case - fetching data from internet). 7 | 8 | 9 | ##Prerequisites 10 | 11 | Unity: 5.1 12 | 13 | iOS: any 14 | 15 | 16 | #Caveats 17 | 18 | After generating xcode project you should manually tweak info.plist: 19 | if you prefer tweaking it with xcode - add key "Required background modes" and one value "App downloads content from the network" 20 | if you want to manually edit info.plist, add: 21 | 22 | <key>UIBackgroundModes</key> 23 | <array> 24 | <string>fetch</string> 25 | </array> 26 | 27 | Background fetch happens at "random" intervals (it is up to iOS to call you), so for debugging you want to use Debug -> Simulate Simulate Background Fetch 28 | 29 | 30 | ## How does it work 31 | 32 | All the code goes into Plugins/iOS/MyAppController.mm 33 | 34 | All we need to do is just subclass unity AppController and implement 35 | 36 | -(void)application:(UIApplication*)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler; 37 | 38 | 39 | After fetching data, we do call UnityBatchPlayerLoop which will run one unity loop iteration, which will in turn call Update on scripts. 40 | 41 | In our case Update looks like that: 42 | 43 | void Update() 44 | { 45 | if (fetchedText == null) 46 | { 47 | fetchedText = QueryFetchedText(); 48 | if (fetchedText != null) 49 | Debug.Log("Just Fetched: " + fetchedText); 50 | } 51 | } 52 | 53 | so you will see it logged immediately (even though app is in background) 54 | -------------------------------------------------------------------------------- /NativeIntegration/Misc/TextureFromGallery/Assets/GalleryTextureLoader.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System.Runtime.InteropServices; 4 | using System; 5 | 6 | public class GalleryTextureLoader : MonoBehaviour 7 | { 8 | public GameObject cube; 9 | 10 | [DllImport("__Internal")] 11 | private extern static void RequestImages(); 12 | 13 | [DllImport("__Internal")] 14 | private extern static int GetGalleryImageCount(); 15 | 16 | [DllImport("__Internal")] 17 | private extern static bool GetGalleryLoadingFinished(); 18 | 19 | [DllImport("__Internal")] 20 | private extern static IntPtr GetGalleryImage(int idx, out int sz); 21 | 22 | [DllImport("__Internal")] 23 | private extern static IntPtr GetImageBuffer(IntPtr handle); 24 | 25 | [DllImport("__Internal")] 26 | private extern static void ReleaseImage(IntPtr handle); 27 | 28 | 29 | // Use this for initialization 30 | IEnumerator Start() 31 | { 32 | #if !UNITY_EDITOR 33 | RequestImages(); 34 | 35 | // Images are scanned asynchronously 36 | while (!GetGalleryLoadingFinished()) 37 | yield return null; 38 | 39 | if (GetGalleryImageCount() > 0) 40 | { 41 | int sz = 0; 42 | IntPtr handle = GetGalleryImage(0, out sz); 43 | IntPtr data = GetImageBuffer(handle); 44 | 45 | byte[] image = new byte[sz]; 46 | Marshal.Copy(data, image, 0, sz); 47 | 48 | var tex = new Texture2D(4, 4); 49 | tex.LoadImage(image); 50 | cube.GetComponent<Renderer>().material.mainTexture = tex; 51 | 52 | ReleaseImage(handle); 53 | } 54 | #endif // if !UNITY_EDITOR 55 | 56 | yield break; 57 | } 58 | 59 | // Update is called once per frame 60 | void Update() 61 | { 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /NativeIntegration/Misc/TextureFromGallery/Assets/GalleryTextureLoader.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0dca7f301dc17456eb0251566cd786e8 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /NativeIntegration/Misc/TextureFromGallery/Assets/Plugins.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c95ab1caf82064a9d8fa2de754ea7e87 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /NativeIntegration/Misc/TextureFromGallery/Assets/Plugins/iOS.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5a8a7e3f966bd44309ab947949204f94 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /NativeIntegration/Misc/TextureFromGallery/Assets/Plugins/iOS/GalleryTextureLoaderImpl.mm: -------------------------------------------------------------------------------- 1 | #import <AssetsLibrary/AssetsLibrary.h> 2 | 3 | static NSMutableArray *collector = nil; 4 | static bool done = false; 5 | static ALAssetsLibrary* al = nil; 6 | 7 | extern "C" void RequestImages() 8 | { 9 | if (collector != nil) 10 | return; 11 | 12 | collector = [[NSMutableArray alloc] initWithCapacity: 0]; 13 | 14 | NSLog(@"ListGalleryImages\n"); 15 | 16 | if (!al) 17 | al = [[ALAssetsLibrary alloc] init]; 18 | 19 | [al enumerateGroupsWithTypes: ALAssetsGroupSavedPhotos 20 | usingBlock:^(ALAssetsGroup *group, BOOL *stop) 21 | { 22 | [group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop) 23 | { 24 | if (asset) 25 | { 26 | [collector addObject: asset]; 27 | NSLog(@"Found asset: %@ !\n", [[asset defaultRepresentation] url]); 28 | } 29 | }]; 30 | 31 | done = true; 32 | } 33 | failureBlock:^(NSError *error) { done = true; NSLog(@"Image gallery scanning failed: %@!\n", error); } 34 | ]; 35 | } 36 | 37 | extern "C" bool GetGalleryLoadingFinished() 38 | { 39 | NSLog(@"Finished? %@\n", done ? @"YES" : @"NO"); 40 | return done; 41 | } 42 | 43 | extern "C" int GetGalleryImageCount() 44 | { 45 | return [collector count]; 46 | } 47 | 48 | extern "C" void* GetGalleryImage(int idx, int* sz) 49 | { 50 | if (collector == nil || idx >= [collector count]) 51 | return NULL; 52 | 53 | ALAsset* theAsset = [collector objectAtIndex: idx]; 54 | 55 | long long sizeOfRawDataInBytes = [[[collector objectAtIndex: idx] defaultRepresentation] size]; 56 | *sz = (int)sizeOfRawDataInBytes; 57 | 58 | NSMutableData* rawData = [[NSMutableData alloc]initWithCapacity: sizeOfRawDataInBytes]; 59 | uint8_t* bufferPointer = (uint8_t*)[rawData mutableBytes]; 60 | 61 | NSError* error = nil; 62 | [[theAsset defaultRepresentation] getBytes: bufferPointer fromOffset: 0 length: sizeOfRawDataInBytes error: &error]; 63 | if (error) 64 | { 65 | NSLog(@"Getting bytes failed with error: %@\n", error); 66 | return NULL; 67 | } 68 | 69 | return (__bridge_retained void*)rawData; 70 | } 71 | 72 | extern "C" void* GetImageBuffer(NSMutableData * rawData) 73 | { 74 | return [rawData mutableBytes]; 75 | } 76 | 77 | extern "C" void ReleaseImage(NSMutableData* rawData) 78 | { 79 | CFRelease((CFTypeRef)rawData); 80 | } 81 | -------------------------------------------------------------------------------- /NativeIntegration/Misc/TextureFromGallery/Assets/Plugins/iOS/GalleryTextureLoaderImpl.mm.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 34541fc03278f428391a3a1b3116287e 3 | PluginImporter: 4 | serializedVersion: 1 5 | iconMap: {} 6 | executionOrder: {} 7 | isPreloaded: 0 8 | platformData: 9 | Any: 10 | enabled: 0 11 | settings: {} 12 | Editor: 13 | enabled: 0 14 | settings: 15 | CPU: AnyCPU 16 | DefaultValueInitialized: true 17 | OS: AnyOS 18 | Linux: 19 | enabled: 0 20 | settings: 21 | CPU: AnyCPU 22 | Linux64: 23 | enabled: 0 24 | settings: 25 | CPU: AnyCPU 26 | LinuxUniversal: 27 | enabled: 0 28 | settings: 29 | CPU: AnyCPU 30 | OSXIntel: 31 | enabled: 0 32 | settings: 33 | CPU: AnyCPU 34 | OSXIntel64: 35 | enabled: 0 36 | settings: 37 | CPU: AnyCPU 38 | OSXUniversal: 39 | enabled: 0 40 | settings: 41 | CPU: AnyCPU 42 | Win: 43 | enabled: 0 44 | settings: 45 | CPU: AnyCPU 46 | Win64: 47 | enabled: 0 48 | settings: 49 | CPU: AnyCPU 50 | iOS: 51 | enabled: 1 52 | settings: 53 | CompileFlags: 54 | FrameworkDependencies: AssetsLibrary; 55 | userData: 56 | assetBundleName: 57 | -------------------------------------------------------------------------------- /NativeIntegration/Misc/TextureFromGallery/Assets/UnlitTextureMaterial.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Misc/TextureFromGallery/Assets/UnlitTextureMaterial.mat -------------------------------------------------------------------------------- /NativeIntegration/Misc/TextureFromGallery/Assets/UnlitTextureMaterial.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e0b437e17388d43e58d844055d2b9117 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /NativeIntegration/Misc/TextureFromGallery/Assets/default.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Misc/TextureFromGallery/Assets/default.unity -------------------------------------------------------------------------------- /NativeIntegration/Misc/TextureFromGallery/Assets/default.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 204f3ec4595064941b41273e19de220f 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /NativeIntegration/Misc/TextureFromGallery/ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Misc/TextureFromGallery/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /NativeIntegration/Misc/TextureFromGallery/ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Misc/TextureFromGallery/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /NativeIntegration/Misc/TextureFromGallery/ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Misc/TextureFromGallery/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /NativeIntegration/Misc/TextureFromGallery/ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Misc/TextureFromGallery/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /NativeIntegration/Misc/TextureFromGallery/ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Misc/TextureFromGallery/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /NativeIntegration/Misc/TextureFromGallery/ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Misc/TextureFromGallery/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /NativeIntegration/Misc/TextureFromGallery/ProjectSettings/NavMeshLayers.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Misc/TextureFromGallery/ProjectSettings/NavMeshLayers.asset -------------------------------------------------------------------------------- /NativeIntegration/Misc/TextureFromGallery/ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Misc/TextureFromGallery/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /NativeIntegration/Misc/TextureFromGallery/ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Misc/TextureFromGallery/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /NativeIntegration/Misc/TextureFromGallery/ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Misc/TextureFromGallery/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /NativeIntegration/Misc/TextureFromGallery/ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Misc/TextureFromGallery/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /NativeIntegration/Misc/TextureFromGallery/ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Misc/TextureFromGallery/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /NativeIntegration/Misc/TextureFromGallery/README.md: -------------------------------------------------------------------------------- 1 | # Loading camera gallery image as texture via native plugins 2 | 3 | 4 | ## Description 5 | 6 | This is sample of iOS native plugin for loading camera gallery image as texture 7 | 8 | 9 | ##Prerequisites 10 | 11 | Unity: 4.2 12 | 13 | iOS: any 14 | 15 | 16 | ## How does it work 17 | 18 | 19 | 20 | ## Notes 21 | 22 | -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/Assets/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e5249f8ce474c4b93843e521e510dc76 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/Assets/Editor/Unity.iOS.Extensions.Xcode.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Misc/UpdateXcodeProject/Assets/Editor/Unity.iOS.Extensions.Xcode.dll -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/Assets/Editor/Unity.iOS.Extensions.Xcode.dll.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4b9607f4d1ede4513baef82b894f6ab0 3 | MonoAssemblyImporter: 4 | serializedVersion: 1 5 | iconMap: {} 6 | executionOrder: {} 7 | userData: 8 | -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/Assets/Editor/XcodeProjectUpdater.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using UnityEditor.Callbacks; 4 | using System.Collections; 5 | using UnityEditor.iOS.Xcode; 6 | using System.IO; 7 | 8 | public class MyBuildPostprocessor 9 | { 10 | internal static void CopyAndReplaceDirectory(string srcPath, string dstPath) 11 | { 12 | if (Directory.Exists(dstPath)) 13 | Directory.Delete(dstPath); 14 | if (File.Exists(dstPath)) 15 | File.Delete(dstPath); 16 | 17 | Directory.CreateDirectory(dstPath); 18 | 19 | foreach (var file in Directory.GetFiles(srcPath)) 20 | File.Copy(file, Path.Combine(dstPath, Path.GetFileName(file))); 21 | 22 | foreach (var dir in Directory.GetDirectories(srcPath)) 23 | CopyAndReplaceDirectory(dir, Path.Combine(dstPath, Path.GetFileName(dir))); 24 | } 25 | 26 | [PostProcessBuild] 27 | public static void OnPostprocessBuild(BuildTarget buildTarget, string path) 28 | { 29 | if (buildTarget == BuildTarget.iPhone) 30 | { 31 | string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj"; 32 | 33 | PBXProject proj = new PBXProject(); 34 | proj.ReadFromString(File.ReadAllText(projPath)); 35 | 36 | string target = proj.TargetGuidByName("Unity-iPhone"); 37 | 38 | // Add user packages to project. Most other source or resource files and packages 39 | // can be added the same way. 40 | CopyAndReplaceDirectory("NativeAssets/TestLib.bundle", Path.Combine(path, "Frameworks/TestLib.bundle")); 41 | proj.AddFileToBuild(target, proj.AddFile("Frameworks/TestLib.bundle", 42 | "Frameworks/TestLib.bundle", PBXSourceTree.Source)); 43 | 44 | CopyAndReplaceDirectory("NativeAssets/TestLib.framework", Path.Combine(path, "Frameworks/TestLib.framework")); 45 | proj.AddFileToBuild(target, proj.AddFile("Frameworks/TestLib.framework", 46 | "Frameworks/TestLib.framework", PBXSourceTree.Source)); 47 | 48 | // Add custom system frameworks. Duplicate frameworks are ignored. 49 | // needed by our native plugin in Assets/Plugins/iOS 50 | proj.AddFrameworkToProject(target, "AssetsLibrary.framework", false /*not weak*/); 51 | 52 | // Add our framework directory to the framework include path 53 | proj.SetBuildProperty(target, "FRAMEWORK_SEARCH_PATHS", "$(inherited)"); 54 | proj.AddBuildProperty(target, "FRAMEWORK_SEARCH_PATHS", "$(PROJECT_DIR)/Frameworks"); 55 | 56 | // Set a custom link flag 57 | proj.AddBuildProperty(target, "OTHER_LDFLAGS", "-ObjC"); 58 | 59 | File.WriteAllText(projPath, proj.WriteToString()); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/Assets/Editor/XcodeProjectUpdater.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4a5b144e73f9a42579c31cfc86e95113 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/Assets/Plugins.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c95ab1caf82064a9d8fa2de754ea7e87 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/Assets/Plugins/iOS.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5a8a7e3f966bd44309ab947949204f94 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/Assets/Plugins/iOS/MyAppController.mm: -------------------------------------------------------------------------------- 1 | #import <UIKit/UIKit.h> 2 | #import "UnityAppController.h" 3 | #import "UI/UnityView.h" 4 | #import "UI/UnityViewControllerBase.h" 5 | #import "TestLib/TestLib.h" 6 | 7 | #if UNITY_VERSION < 450 8 | #import "iPhone_View.h" 9 | #endif 10 | 11 | @interface MyAppController : UnityAppController 12 | { 13 | UINavigationController* _navController; 14 | UIViewController* _embedController1; 15 | UIViewController* _embedController2; 16 | UIImage* _image; 17 | } 18 | - (void)createViewHierarchyImpl; 19 | @end 20 | 21 | @implementation MyAppController 22 | - (void)createViewHierarchyImpl; 23 | { 24 | _rootController = [[UnityViewControllerBase alloc] init]; 25 | _rootView = [[UIView alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; 26 | 27 | _embedController1 = [[UIViewController alloc] init]; 28 | _embedController1.view = _unityView; 29 | 30 | // button titles come from the TestLib.framework 31 | // image comes from the TestLib.bundle 32 | _embedController1.navigationItem.rightBarButtonItem = 33 | [[UIBarButtonItem alloc] initWithTitle: [TestLib getRightTitle] style: UIBarButtonItemStyleBordered target: self action: @selector(moveRight:)]; 34 | 35 | _embedController2 = [[UIViewController alloc] init]; 36 | _embedController2.navigationItem.leftBarButtonItem = 37 | [[UIBarButtonItem alloc] initWithTitle: [TestLib getLeftTitle] style: UIBarButtonItemStyleBordered target: self action: @selector(moveLeft:)]; 38 | 39 | UIImageView* imgView = [[UIImageView alloc] initWithImage: [UIImage imageNamed: @"TestLib.bundle/eject.png"]]; 40 | imgView.backgroundColor = [UIColor whiteColor]; 41 | _embedController2.view = imgView; 42 | 43 | _rootController.view = _rootView; 44 | 45 | _navController = [[UINavigationController alloc] initWithRootViewController: _embedController1]; 46 | [_rootView addSubview: _navController.view]; 47 | } 48 | - (void)moveRight:(id)sender 49 | { 50 | [_navController pushViewController: _embedController2 animated: NO]; 51 | } 52 | 53 | - (void)moveLeft:(id)sender 54 | { 55 | [_navController popViewControllerAnimated: NO]; 56 | } 57 | 58 | @end 59 | 60 | IMPL_APP_CONTROLLER_SUBCLASS(MyAppController) 61 | -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/Assets/Plugins/iOS/MyAppController.mm.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b30d4a8caa184492f89f5146e4df7687 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/Assets/TestMaterial.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Misc/UpdateXcodeProject/Assets/TestMaterial.mat -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/Assets/TestMaterial.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1b36e5967c8a94246a30f37ba46b5226 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/Assets/TestScene.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Misc/UpdateXcodeProject/Assets/TestScene.unity -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/Assets/TestScene.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a9604cb63b114475d87aa1de6a51e877 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/NativeAssets/README.md: -------------------------------------------------------------------------------- 1 | The TestLib directory contains an example xcode project that builds sample TestLib.framework 2 | and TestLib.bundle packages. You need to manually copy them from the build directory here. -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/NativeAssets/TestLib.bundle/Info.plist: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Misc/UpdateXcodeProject/NativeAssets/TestLib.bundle/Info.plist -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/NativeAssets/TestLib.bundle/eject.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Misc/UpdateXcodeProject/NativeAssets/TestLib.bundle/eject.png -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/NativeAssets/TestLib.bundle/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Misc/UpdateXcodeProject/NativeAssets/TestLib.bundle/en.lproj/InfoPlist.strings -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/NativeAssets/TestLib.framework/Headers: -------------------------------------------------------------------------------- 1 | Versions/Current/Headers -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/NativeAssets/TestLib.framework/TestLib: -------------------------------------------------------------------------------- 1 | Versions/Current/TestLib -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/NativeAssets/TestLib.framework/Versions/A/Headers/TestLib.h: -------------------------------------------------------------------------------- 1 | // 2 | // TestLib.h 3 | // TestLib 4 | // 5 | // Created by Povilas on 05/09/14. 6 | // Copyright (c) 2014 Unity. All rights reserved. 7 | // 8 | 9 | #import <Foundation/Foundation.h> 10 | 11 | @interface TestLib : NSObject 12 | 13 | + (NSString*)getRightTitle; 14 | + (NSString*)getLeftTitle; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/NativeAssets/TestLib.framework/Versions/A/TestLib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Misc/UpdateXcodeProject/NativeAssets/TestLib.framework/Versions/A/TestLib -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/NativeAssets/TestLib.framework/Versions/Current: -------------------------------------------------------------------------------- 1 | A -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/NativeAssets/TestLib/TestLib.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | <?xml version="1.0" encoding="UTF-8"?> 2 | <Workspace 3 | version = "1.0"> 4 | <FileRef 5 | location = "self:TestLib.xcodeproj"> 6 | </FileRef> 7 | </Workspace> 8 | -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/NativeAssets/TestLib/TestLib.xcodeproj/project.xcworkspace/xcuserdata/povilas.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Misc/UpdateXcodeProject/NativeAssets/TestLib/TestLib.xcodeproj/project.xcworkspace/xcuserdata/povilas.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/NativeAssets/TestLib/TestLib.xcodeproj/xcuserdata/povilas.xcuserdatad/xcschemes/TestLib.xcscheme: -------------------------------------------------------------------------------- 1 | <?xml version="1.0" encoding="UTF-8"?> 2 | <Scheme 3 | LastUpgradeVersion = "0510" 4 | version = "1.3"> 5 | <BuildAction 6 | parallelizeBuildables = "YES" 7 | buildImplicitDependencies = "YES"> 8 | <BuildActionEntries> 9 | <BuildActionEntry 10 | buildForTesting = "YES" 11 | buildForRunning = "YES" 12 | buildForProfiling = "YES" 13 | buildForArchiving = "YES" 14 | buildForAnalyzing = "YES"> 15 | <BuildableReference 16 | BuildableIdentifier = "primary" 17 | BlueprintIdentifier = "AA8480A719B9CF7300D60A34" 18 | BuildableName = "libTestLib.a" 19 | BlueprintName = "TestLib" 20 | ReferencedContainer = "container:TestLib.xcodeproj"> 21 | </BuildableReference> 22 | </BuildActionEntry> 23 | </BuildActionEntries> 24 | </BuildAction> 25 | <TestAction 26 | selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" 27 | selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" 28 | shouldUseLaunchSchemeArgsEnv = "YES" 29 | buildConfiguration = "Debug"> 30 | <Testables> 31 | <TestableReference 32 | skipped = "NO"> 33 | <BuildableReference 34 | BuildableIdentifier = "primary" 35 | BlueprintIdentifier = "AA8480B719B9CF7300D60A34" 36 | BuildableName = "TestLibTests.xctest" 37 | BlueprintName = "TestLibTests" 38 | ReferencedContainer = "container:TestLib.xcodeproj"> 39 | </BuildableReference> 40 | </TestableReference> 41 | </Testables> 42 | </TestAction> 43 | <LaunchAction 44 | selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" 45 | selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" 46 | launchStyle = "0" 47 | useCustomWorkingDirectory = "NO" 48 | buildConfiguration = "Debug" 49 | ignoresPersistentStateOnLaunch = "NO" 50 | debugDocumentVersioning = "YES" 51 | allowLocationSimulation = "YES"> 52 | <AdditionalOptions> 53 | </AdditionalOptions> 54 | </LaunchAction> 55 | <ProfileAction 56 | shouldUseLaunchSchemeArgsEnv = "YES" 57 | savedToolIdentifier = "" 58 | useCustomWorkingDirectory = "NO" 59 | buildConfiguration = "Release" 60 | debugDocumentVersioning = "YES"> 61 | </ProfileAction> 62 | <AnalyzeAction 63 | buildConfiguration = "Debug"> 64 | </AnalyzeAction> 65 | <ArchiveAction 66 | buildConfiguration = "Release" 67 | revealArchiveInOrganizer = "YES"> 68 | </ArchiveAction> 69 | </Scheme> 70 | -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/NativeAssets/TestLib/TestLib.xcodeproj/xcuserdata/povilas.xcuserdatad/xcschemes/TestLibResources.xcscheme: -------------------------------------------------------------------------------- 1 | <?xml version="1.0" encoding="UTF-8"?> 2 | <Scheme 3 | LastUpgradeVersion = "0510" 4 | version = "1.3"> 5 | <BuildAction 6 | parallelizeBuildables = "YES" 7 | buildImplicitDependencies = "YES"> 8 | <BuildActionEntries> 9 | <BuildActionEntry 10 | buildForTesting = "YES" 11 | buildForRunning = "YES" 12 | buildForProfiling = "YES" 13 | buildForArchiving = "YES" 14 | buildForAnalyzing = "YES"> 15 | <BuildableReference 16 | BuildableIdentifier = "primary" 17 | BlueprintIdentifier = "AA8480D519BDA56100D60A34" 18 | BuildableName = "TestLib.bundle" 19 | BlueprintName = "TestLibResources" 20 | ReferencedContainer = "container:TestLib.xcodeproj"> 21 | </BuildableReference> 22 | </BuildActionEntry> 23 | </BuildActionEntries> 24 | </BuildAction> 25 | <TestAction 26 | selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" 27 | selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" 28 | shouldUseLaunchSchemeArgsEnv = "YES" 29 | buildConfiguration = "Debug"> 30 | <Testables> 31 | </Testables> 32 | </TestAction> 33 | <LaunchAction 34 | selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" 35 | selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" 36 | launchStyle = "0" 37 | useCustomWorkingDirectory = "NO" 38 | buildConfiguration = "Debug" 39 | ignoresPersistentStateOnLaunch = "NO" 40 | debugDocumentVersioning = "YES" 41 | allowLocationSimulation = "YES"> 42 | <AdditionalOptions> 43 | </AdditionalOptions> 44 | </LaunchAction> 45 | <ProfileAction 46 | shouldUseLaunchSchemeArgsEnv = "YES" 47 | savedToolIdentifier = "" 48 | useCustomWorkingDirectory = "NO" 49 | buildConfiguration = "Release" 50 | debugDocumentVersioning = "YES"> 51 | </ProfileAction> 52 | <AnalyzeAction 53 | buildConfiguration = "Debug"> 54 | </AnalyzeAction> 55 | <ArchiveAction 56 | buildConfiguration = "Release" 57 | revealArchiveInOrganizer = "YES"> 58 | </ArchiveAction> 59 | </Scheme> 60 | -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/NativeAssets/TestLib/TestLib.xcodeproj/xcuserdata/povilas.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | <?xml version="1.0" encoding="UTF-8"?> 2 | <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 3 | <plist version="1.0"> 4 | <dict> 5 | <key>SchemeUserState</key> 6 | <dict> 7 | <key>TestLib.xcscheme</key> 8 | <dict> 9 | <key>orderHint</key> 10 | <integer>0</integer> 11 | </dict> 12 | <key>TestLibResources.xcscheme</key> 13 | <dict> 14 | <key>orderHint</key> 15 | <integer>1</integer> 16 | </dict> 17 | </dict> 18 | <key>SuppressBuildableAutocreation</key> 19 | <dict> 20 | <key>AA8480A719B9CF7300D60A34</key> 21 | <dict> 22 | <key>primary</key> 23 | <true/> 24 | </dict> 25 | <key>AA8480B719B9CF7300D60A34</key> 26 | <dict> 27 | <key>primary</key> 28 | <true/> 29 | </dict> 30 | <key>AA8480D519BDA56100D60A34</key> 31 | <dict> 32 | <key>primary</key> 33 | <true/> 34 | </dict> 35 | </dict> 36 | </dict> 37 | </plist> 38 | -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/NativeAssets/TestLib/TestLib/TestLib-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header 3 | // 4 | // The contents of this file are implicitly included at the beginning of every source file. 5 | // 6 | 7 | #ifdef __OBJC__ 8 | #import <Foundation/Foundation.h> 9 | #endif 10 | -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/NativeAssets/TestLib/TestLib/TestLib.h: -------------------------------------------------------------------------------- 1 | // 2 | // TestLib.h 3 | // TestLib 4 | // 5 | // Created by Povilas on 05/09/14. 6 | // Copyright (c) 2014 Unity. All rights reserved. 7 | // 8 | 9 | #import <Foundation/Foundation.h> 10 | 11 | @interface TestLib : NSObject 12 | 13 | + (NSString*)getRightTitle; 14 | + (NSString*)getLeftTitle; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/NativeAssets/TestLib/TestLib/TestLib.m: -------------------------------------------------------------------------------- 1 | // 2 | // TestLib.m 3 | // TestLib 4 | // 5 | // Created by Povilas on 05/09/14. 6 | // Copyright (c) 2014 Unity. All rights reserved. 7 | // 8 | 9 | #import "TestLib.h" 10 | 11 | @implementation TestLib 12 | 13 | + (NSString*)getRightTitle 14 | { 15 | return @"Go to right"; 16 | } 17 | 18 | + (NSString*)getLeftTitle 19 | { 20 | return @"Return left"; 21 | } 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/NativeAssets/TestLib/TestLibResources/TestLibResources-Info.plist: -------------------------------------------------------------------------------- 1 | <?xml version="1.0" encoding="UTF-8"?> 2 | <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 3 | <plist version="1.0"> 4 | <dict> 5 | <key>CFBundleDevelopmentRegion</key> 6 | <string>English</string> 7 | <key>CFBundleExecutable</key> 8 | <string>${EXECUTABLE_NAME}</string> 9 | <key>CFBundleIconFile</key> 10 | <string></string> 11 | <key>CFBundleIdentifier</key> 12 | <string>com.unity3d.${PRODUCT_NAME:rfc1034identifier}</string> 13 | <key>CFBundleInfoDictionaryVersion</key> 14 | <string>6.0</string> 15 | <key>CFBundleName</key> 16 | <string>${PRODUCT_NAME}</string> 17 | <key>CFBundlePackageType</key> 18 | <string>BNDL</string> 19 | <key>CFBundleShortVersionString</key> 20 | <string>1.0</string> 21 | <key>CFBundleSignature</key> 22 | <string>????</string> 23 | <key>CFBundleVersion</key> 24 | <string>1</string> 25 | <key>CFPlugInDynamicRegisterFunction</key> 26 | <string></string> 27 | <key>CFPlugInDynamicRegistration</key> 28 | <string>NO</string> 29 | <key>CFPlugInFactories</key> 30 | <dict> 31 | <key>00000000-0000-0000-0000-000000000000</key> 32 | <string>MyFactoryFunction</string> 33 | </dict> 34 | <key>CFPlugInTypes</key> 35 | <dict> 36 | <key>00000000-0000-0000-0000-000000000000</key> 37 | <array> 38 | <string>00000000-0000-0000-0000-000000000000</string> 39 | </array> 40 | </dict> 41 | <key>CFPlugInUnloadFunction</key> 42 | <string></string> 43 | <key>NSHumanReadableCopyright</key> 44 | <string>Copyright © 2014 Unity. All rights reserved.</string> 45 | </dict> 46 | </plist> 47 | -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/NativeAssets/TestLib/TestLibResources/TestLibResources-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header 3 | // 4 | // The contents of this file are implicitly included at the beginning of every source file. 5 | // 6 | 7 | #ifdef __OBJC__ 8 | #import <Cocoa/Cocoa.h> 9 | #endif 10 | -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/NativeAssets/TestLib/TestLibResources/eject.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Misc/UpdateXcodeProject/NativeAssets/TestLib/TestLibResources/eject.png -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/NativeAssets/TestLib/TestLibResources/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/NativeAssets/TestLib/TestLibTests/TestLibTests-Info.plist: -------------------------------------------------------------------------------- 1 | <?xml version="1.0" encoding="UTF-8"?> 2 | <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 3 | <plist version="1.0"> 4 | <dict> 5 | <key>CFBundleDevelopmentRegion</key> 6 | <string>en</string> 7 | <key>CFBundleExecutable</key> 8 | <string>${EXECUTABLE_NAME}</string> 9 | <key>CFBundleIdentifier</key> 10 | <string>com.unity3d.${PRODUCT_NAME:rfc1034identifier}</string> 11 | <key>CFBundleInfoDictionaryVersion</key> 12 | <string>6.0</string> 13 | <key>CFBundlePackageType</key> 14 | <string>BNDL</string> 15 | <key>CFBundleShortVersionString</key> 16 | <string>1.0</string> 17 | <key>CFBundleSignature</key> 18 | <string>????</string> 19 | <key>CFBundleVersion</key> 20 | <string>1</string> 21 | </dict> 22 | </plist> 23 | -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/NativeAssets/TestLib/TestLibTests/TestLibTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // TestLibTests.m 3 | // TestLibTests 4 | // 5 | // Created by Povilas on 05/09/14. 6 | // Copyright (c) 2014 Unity. All rights reserved. 7 | // 8 | 9 | #import <XCTest/XCTest.h> 10 | 11 | @interface TestLibTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation TestLibTests 16 | 17 | - (void)setUp 18 | { 19 | [super setUp]; 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | } 22 | 23 | - (void)tearDown 24 | { 25 | // Put teardown code here. This method is called after the invocation of each test method in the class. 26 | [super tearDown]; 27 | } 28 | 29 | - (void)testExample 30 | { 31 | XCTFail(@"No implementation for \"%s\"", __PRETTY_FUNCTION__); 32 | } 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/NativeAssets/TestLib/TestLibTests/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Misc/UpdateXcodeProject/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Misc/UpdateXcodeProject/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Misc/UpdateXcodeProject/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Misc/UpdateXcodeProject/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Misc/UpdateXcodeProject/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Misc/UpdateXcodeProject/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/ProjectSettings/NavMeshLayers.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Misc/UpdateXcodeProject/ProjectSettings/NavMeshLayers.asset -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Misc/UpdateXcodeProject/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Misc/UpdateXcodeProject/ProjectSettings/Physics2DSettings.asset -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Misc/UpdateXcodeProject/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Misc/UpdateXcodeProject/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Misc/UpdateXcodeProject/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Misc/UpdateXcodeProject/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /NativeIntegration/Misc/UpdateXcodeProject/README.md: -------------------------------------------------------------------------------- 1 | # Updating Xcode project to control building of native plugins 2 | 3 | 4 | ## Description 5 | 6 | This sample shows how to modify generated Xcode projects in order to support 7 | various types of native plugins. 8 | 9 | ##Prerequisites 10 | 11 | Unity: 4.5 12 | 13 | iOS: any 14 | 15 | ## How does it work 16 | 17 | 18 | 19 | ## Notes 20 | 21 | The project contains an external Xcode project manipulation DLL among its plugins. 22 | It's the build product of the source available 23 | [on Unity's Bitbucket repository](https://bitbucket.org/Unity-Technologies/xcodeapi). 24 | A preferred way to include Xcode project manipulation functionality is to copy the 25 | C# source code files to the Assets/Editor directory in your project. 26 | -------------------------------------------------------------------------------- /NativeIntegration/UI/NavigationController/Assets/Plugins.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cb0ab54515ff844779f13c47eb5605a3 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /NativeIntegration/UI/NavigationController/Assets/Plugins/iOS.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e30e3d70767d842d1b388d9658e18406 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /NativeIntegration/UI/NavigationController/Assets/Plugins/iOS/MyAppController.mm: -------------------------------------------------------------------------------- 1 | #import <UIKit/UIKit.h> 2 | #import "UnityAppController.h" 3 | #import "UI/UnityView.h" 4 | #import "UI/UnityViewControllerBase.h" 5 | 6 | #if UNITY_VERSION < 450 7 | #import "iPhone_View.h" 8 | #endif 9 | 10 | @interface MyAppController : UnityAppController 11 | { 12 | UINavigationController* _navController; 13 | UIViewController* _embedController1; 14 | UIViewController* _embedController2; 15 | } 16 | @end 17 | 18 | @implementation MyAppController 19 | - (void)willStartWithViewController:(UIViewController*)controller 20 | { 21 | _rootView = [[UIView alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; 22 | 23 | _embedController1 = [[UIViewController alloc] init]; 24 | _embedController1.view = _unityView; 25 | _embedController1.navigationItem.rightBarButtonItem = 26 | [[UIBarButtonItem alloc] initWithTitle: @"Right" style: UIBarButtonItemStyleBordered target: self action: @selector(moveRight:)]; 27 | 28 | _embedController2 = [[UIViewController alloc] init]; 29 | _embedController2.navigationItem.leftBarButtonItem = 30 | [[UIBarButtonItem alloc] initWithTitle: @"Left" style: UIBarButtonItemStyleBordered target: self action: @selector(moveLeft:)]; 31 | 32 | _embedController2.view = [[UIWebView alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; 33 | [(UIWebView*)_embedController2.view loadRequest: [NSURLRequest requestWithURL: [NSURL URLWithString: @"http://www.unity3d.com"]]]; 34 | 35 | _rootController.view = _rootView; 36 | 37 | _navController = [[UINavigationController alloc] initWithRootViewController: _embedController1]; 38 | [_rootView addSubview: _navController.view]; 39 | } 40 | 41 | - (void)moveRight:(id)sender 42 | { 43 | [_navController pushViewController: _embedController2 animated: NO]; 44 | } 45 | 46 | - (void)moveLeft:(id)sender 47 | { 48 | [_navController popViewControllerAnimated: NO]; 49 | } 50 | 51 | @end 52 | 53 | IMPL_APP_CONTROLLER_SUBCLASS(MyAppController) 54 | -------------------------------------------------------------------------------- /NativeIntegration/UI/NavigationController/Assets/Plugins/iOS/MyAppController.mm.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3cadb9c197a3b482d915d42b2d34b832 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /NativeIntegration/UI/NavigationController/Assets/TestMaterial.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/UI/NavigationController/Assets/TestMaterial.mat -------------------------------------------------------------------------------- /NativeIntegration/UI/NavigationController/Assets/TestMaterial.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1b36e5967c8a94246a30f37ba46b5226 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /NativeIntegration/UI/NavigationController/Assets/TestScene.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/UI/NavigationController/Assets/TestScene.unity -------------------------------------------------------------------------------- /NativeIntegration/UI/NavigationController/Assets/TestScene.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a9604cb63b114475d87aa1de6a51e877 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /NativeIntegration/UI/NavigationController/ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/UI/NavigationController/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /NativeIntegration/UI/NavigationController/ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/UI/NavigationController/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /NativeIntegration/UI/NavigationController/ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/UI/NavigationController/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /NativeIntegration/UI/NavigationController/ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/UI/NavigationController/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /NativeIntegration/UI/NavigationController/ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/UI/NavigationController/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /NativeIntegration/UI/NavigationController/ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/UI/NavigationController/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /NativeIntegration/UI/NavigationController/ProjectSettings/NavMeshLayers.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/UI/NavigationController/ProjectSettings/NavMeshLayers.asset -------------------------------------------------------------------------------- /NativeIntegration/UI/NavigationController/ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/UI/NavigationController/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /NativeIntegration/UI/NavigationController/ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/UI/NavigationController/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /NativeIntegration/UI/NavigationController/ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/UI/NavigationController/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /NativeIntegration/UI/NavigationController/ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/UI/NavigationController/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /NativeIntegration/UI/NavigationController/ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/UI/NavigationController/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /NativeIntegration/UI/NavigationController/README.md: -------------------------------------------------------------------------------- 1 | # Integrating Unity and iOS native UI 2 | # Part 2: 3 | # Inserting Unity inside NavigationController 4 | 5 | 6 | ## Description 7 | 8 | This sample shows how to insert Unity view inside UINavigationController. 9 | 10 | 11 | ##Prerequisites 12 | 13 | Unity: 4.2 14 | 15 | iOS: any 16 | 17 | 18 | ## How does it work 19 | 20 | All the code goes into Plugins/iOS/MyAppController.mm 21 | 22 | First we subclass Unity's AppController and create our own view hierarchy. 23 | 24 | _rootController = [[UnityDefaultViewController alloc] init]; 25 | _rootView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 26 | 27 | Please note, that as we make root view controller to be default unity one, we shouldnt care about proper unity orientation (as it will be done automatically). 28 | Check UnityAppController.mm in trampoline: 29 | 30 | - (void)createViewHierarchy 31 | { 32 | [self createViewHierarchyImpl]; 33 | [...] 34 | _rootController.wantsFullScreenLayout = TRUE; 35 | _rootController.view = _rootView; 36 | if([_rootController isKindOfClass: [UnityViewControllerBase class]]) 37 | [(UnityViewControllerBase*)_rootController assignUnityView:_unityView]; 38 | } 39 | 40 | we will assign unity view and UnityDefaultViewController will take care of correct rotation. 41 | 42 | The creation of navigation conroller is straigforward 43 | 44 | _embedController1 = [[UIViewController alloc] init]; 45 | _embedController1.view = _unityView; 46 | [...] 47 | _embedController2 = [[UIViewController alloc] init]; 48 | _embedController2.view = [[UIWebView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 49 | [...] 50 | 51 | _rootController.view = _rootView; 52 | _navController = [[UINavigationController alloc] initWithRootViewController:_embedController1]; 53 | [_rootView addSubview:_navController.view]; 54 | 55 | We create two controllers: one with unity content and other with UIWebView, and add former to navigation controller. 56 | 57 | Please note this line: 58 | 59 | IMPL_APP_CONTROLLER_SUBCLASS(MyAppController) 60 | 61 | You must add this, so Unity knows that you want your class as UIApplication delegate 62 | 63 | 64 | -------------------------------------------------------------------------------- /NativeIntegration/UI/OverlayUI/Assets/Plugins.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cb0ab54515ff844779f13c47eb5605a3 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /NativeIntegration/UI/OverlayUI/Assets/Plugins/iOS.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e30e3d70767d842d1b388d9658e18406 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /NativeIntegration/UI/OverlayUI/Assets/Plugins/iOS/MyAppController.mm: -------------------------------------------------------------------------------- 1 | #import <UIKit/UIKit.h> 2 | #import "UnityAppController.h" 3 | #import "UnityAppController+ViewHandling.h" 4 | #import "UI/UnityView.h" 5 | #import "UI/OrientationSupport.h" 6 | 7 | 8 | extern "C" typedef void (*DateSelectedCallback)(const char *); 9 | 10 | @interface MyAppController : UnityAppController 11 | { 12 | DateSelectedCallback _dateSelected; 13 | UIDatePicker* _datePicker; 14 | } 15 | @end 16 | 17 | @implementation MyAppController 18 | 19 | - (void)showDatePicker:(DateSelectedCallback)callback 20 | { 21 | _dateSelected = callback; 22 | [self showDatePickerView]; 23 | } 24 | 25 | - (void)showDatePickerView 26 | { 27 | if (_datePicker == nil) 28 | { 29 | _datePicker = [[UIDatePicker alloc] initWithFrame: CGRectZero]; 30 | _datePicker.autoresizingMask = UIViewAutoresizingFlexibleTopMargin; 31 | _datePicker.datePickerMode = UIDatePickerModeDate; 32 | _datePicker.frame = self.rootView.bounds; 33 | _datePicker.hidden = YES; 34 | 35 | [_datePicker addTarget: self action: @selector(dateChanged:) forControlEvents: UIControlEventValueChanged]; 36 | } 37 | 38 | _datePicker.hidden = NO; 39 | [self.rootView addSubview: _datePicker]; 40 | } 41 | 42 | - (void)hideDatePicker 43 | { 44 | [_datePicker removeFromSuperview]; 45 | _datePicker.hidden = YES; 46 | } 47 | 48 | - (void)interfaceDidChangeOrientationFrom:(UIInterfaceOrientation)fromInterfaceOrientation 49 | { 50 | _datePicker.frame = self.rootView.bounds; 51 | } 52 | 53 | - (void)dateChanged:(id)sender 54 | { 55 | NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init]; 56 | [dateFormatter setDateStyle: NSDateFormatterMediumStyle]; 57 | [dateFormatter setTimeStyle: NSDateFormatterNoStyle]; 58 | 59 | _dateSelected([[dateFormatter stringFromDate: _datePicker.date] UTF8String]); 60 | } 61 | 62 | @end 63 | 64 | 65 | extern "C" void ShowNativeDatePicker(DateSelectedCallback dateSelected) 66 | { 67 | [(MyAppController*)GetAppController () showDatePicker: dateSelected]; 68 | } 69 | 70 | extern "C" void HideNativeDatePicker() 71 | { 72 | [(MyAppController*)GetAppController ()hideDatePicker]; 73 | } 74 | 75 | IMPL_APP_CONTROLLER_SUBCLASS(MyAppController) 76 | -------------------------------------------------------------------------------- /NativeIntegration/UI/OverlayUI/Assets/Plugins/iOS/MyAppController.mm.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3cadb9c197a3b482d915d42b2d34b832 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /NativeIntegration/UI/OverlayUI/Assets/ShowDatePicker.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System.Runtime.InteropServices; 4 | using AOT; 5 | 6 | public class ShowDatePicker : MonoBehaviour 7 | { 8 | public GUIText curDateText; 9 | public int buttonExt = 100; 10 | 11 | private delegate void StringParamDelegate(string str); 12 | 13 | #if UNITY_IPHONE && !UNITY_EDITOR 14 | [DllImport("__Internal")] 15 | private static extern void ShowNativeDatePicker(StringParamDelegate dateSelected); 16 | [DllImport("__Internal")] 17 | private static extern void HideNativeDatePicker(); 18 | #else 19 | private static void ShowNativeDatePicker(StringParamDelegate dateSelected) {} 20 | private static void HideNativeDatePicker() {} 21 | #endif 22 | 23 | private static bool _DatePickerShown = false; 24 | private static string _CurDate = "no date"; 25 | 26 | [MonoPInvokeCallback(typeof(StringParamDelegate))] 27 | public static void DateSelectedCallback(string str) 28 | { 29 | _CurDate = str; 30 | } 31 | 32 | void OnGUI() 33 | { 34 | if (GUI.Button(new Rect(10, 10, buttonExt, buttonExt), "Pick Date")) 35 | { 36 | ShowNativeDatePicker(DateSelectedCallback); 37 | _DatePickerShown = true; 38 | } 39 | 40 | curDateText.text = _CurDate; 41 | 42 | if (_DatePickerShown) 43 | { 44 | if (GUI.Button(new Rect(Screen.width - buttonExt, Screen.height - buttonExt, buttonExt, buttonExt), "Stop Date")) 45 | { 46 | HideNativeDatePicker(); 47 | _DatePickerShown = false; 48 | } 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /NativeIntegration/UI/OverlayUI/Assets/ShowDatePicker.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d01d34f663efc4c748e66b2707d6e0f6 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /NativeIntegration/UI/OverlayUI/Assets/TestDatePicker.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/UI/OverlayUI/Assets/TestDatePicker.unity -------------------------------------------------------------------------------- /NativeIntegration/UI/OverlayUI/Assets/TestDatePicker.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a9604cb63b114475d87aa1de6a51e877 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /NativeIntegration/UI/OverlayUI/Assets/TestMaterial.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/UI/OverlayUI/Assets/TestMaterial.mat -------------------------------------------------------------------------------- /NativeIntegration/UI/OverlayUI/Assets/TestMaterial.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1b36e5967c8a94246a30f37ba46b5226 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /NativeIntegration/UI/OverlayUI/ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/UI/OverlayUI/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /NativeIntegration/UI/OverlayUI/ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/UI/OverlayUI/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /NativeIntegration/UI/OverlayUI/ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/UI/OverlayUI/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /NativeIntegration/UI/OverlayUI/ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/UI/OverlayUI/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /NativeIntegration/UI/OverlayUI/ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/UI/OverlayUI/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /NativeIntegration/UI/OverlayUI/ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/UI/OverlayUI/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /NativeIntegration/UI/OverlayUI/ProjectSettings/NavMeshLayers.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/UI/OverlayUI/ProjectSettings/NavMeshLayers.asset -------------------------------------------------------------------------------- /NativeIntegration/UI/OverlayUI/ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/UI/OverlayUI/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /NativeIntegration/UI/OverlayUI/ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/UI/OverlayUI/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /NativeIntegration/UI/OverlayUI/ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/UI/OverlayUI/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /NativeIntegration/UI/OverlayUI/ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/UI/OverlayUI/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /NativeIntegration/UI/OverlayUI/ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/UI/OverlayUI/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /NativeIntegration/UI/OverlayUI/README.md: -------------------------------------------------------------------------------- 1 | # Integrating Unity and iOS native UI 2 | # Part 1: 3 | # Overlay native UI 4 | 5 | 6 | ## Description 7 | 8 | This sample shows how to overlay UIDatePicker on top of Unity app and send data back to Unity app. 9 | 10 | 11 | ##Prerequisites 12 | 13 | Unity: 4.2 14 | 15 | iOS: any 16 | 17 | 18 | ## How does it work 19 | 20 | There are three pieces of interest: ShowDatePicker.cs, Plugins/iOS/MyAppController.mm and Plugins/iOS/MyViewController.mm. 21 | 22 | In Plugins/iOS/MyAppController.mm we subclass Unity's AppController and provide our own view controller 23 | 24 | - (void)createViewHierarchyImpl; 25 | { 26 | _rootController = [[MyViewController alloc] init]; 27 | _rootView = _unityView; 28 | } 29 | 30 | Please note this line: 31 | 32 | IMPL_APP_CONTROLLER_SUBCLASS(MyAppController) 33 | 34 | You must add this, so Unity knows that you want your class as UIApplication delegate 35 | 36 | In Plugins/iOS/MyViewController.mm we implement out view controller: it is subclassed from UnityViewController and adds UIDatePicker handling on top. 37 | 38 | Please note, that in didRotateFromInterfaceOrientation we do call super's impl (so unity can handle the rotation) and tweak UIDatePicker's frame 39 | 40 | - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 41 | { 42 | [super didRotateFromInterfaceOrientation:fromInterfaceOrientation]; 43 | _datePicker.frame = self.view.bounds; 44 | } 45 | 46 | To pass date from obj-c to Unity we do these two things: 47 | in ShowDatePicker.cs 48 | 49 | private delegate void StringParamDelegate(string str); 50 | [DllImport("__Internal")] 51 | private static extern void ShowNativeDatePicker(StringParamDelegate dateSelected); 52 | 53 | [MonoPInvokeCallback(typeof(StringParamDelegate))] 54 | public static void DateSelectedCallback(string str) 55 | { 56 | _CurDate = str; 57 | } 58 | 59 | ... 60 | 61 | ShowNativeDatePicker(DateSelectedCallback); 62 | 63 | and in Plugins/iOS/MyViewController.mm 64 | 65 | extern "C" typedef void (*DateSelectedCallback)(const char *); 66 | extern "C" void ShowNativeDatePicker(DateSelectedCallback dateSelected) 67 | { 68 | [(MyViewController*)UnityGetGLViewController() showDatePicker:dateSelected]; 69 | } 70 | 71 | ... 72 | 73 | - (void)showDatePicker:(DateSelectedCallback)callback 74 | { 75 | _dateSelected = callback; 76 | [self showDatePickerView]; 77 | } 78 | 79 | ... 80 | 81 | - (void)dateChanged:(id)sender 82 | { 83 | NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init]; 84 | [dateFormatter setDateStyle:NSDateFormatterMediumStyle]; 85 | [dateFormatter setTimeStyle:NSDateFormatterNoStyle]; 86 | 87 | _dateSelected([[dateFormatter stringFromDate:_datePicker.date] UTF8String]); 88 | } 89 | 90 | -------------------------------------------------------------------------------- /NativeIntegration/UI/ResizedView/Assets/Plugins.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6ee938f5ef1ad4f099e87248698b69cc 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /NativeIntegration/UI/ResizedView/Assets/Plugins/iOS.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1e2d91b1d641045c1935814af5a65e31 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /NativeIntegration/UI/ResizedView/Assets/Plugins/iOS/MyAppController.mm.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c551981943de946f0bba3ec8c7c32698 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /NativeIntegration/UI/ResizedView/Assets/Plugins/iOS/ScreenshotCreator.h: -------------------------------------------------------------------------------- 1 | #include "RenderPluginDelegate.h" 2 | 3 | extern "C" typedef void (*ScreenshotComplete)(); 4 | 5 | @interface ScreenshotCreator : RenderPluginDelegate 6 | { 7 | NSString* screenshotPath; 8 | ScreenshotComplete callback; 9 | 10 | BOOL requestedScreenshot; 11 | BOOL creatingScreenshot; 12 | } 13 | - (id)init; 14 | 15 | - (void)onBeforeMainDisplaySurfaceRecreate:(struct RenderingSurfaceParams*)params; 16 | - (void)onFrameResolved; 17 | 18 | - (void)queryScreenshot:(NSString*)path callback:(ScreenshotComplete)callback; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /NativeIntegration/UI/ResizedView/Assets/Plugins/iOS/ScreenshotCreator.h.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 72b22bed9443d45f88377e261304736b 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /NativeIntegration/UI/ResizedView/Assets/Plugins/iOS/ScreenshotCreator.mm.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: eeb9cf93fec724abbab368cbb9a573cc 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /NativeIntegration/UI/ResizedView/Assets/Rotator.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class Rotator : MonoBehaviour 5 | { 6 | void Update() 7 | { 8 | transform.Rotate(Vector3.right * 10 * Time.deltaTime); 9 | transform.Rotate(Vector3.up * 10 * Time.deltaTime, Space.World); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /NativeIntegration/UI/ResizedView/Assets/Rotator.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8e3d8dd3b0edd4c7ea344f5d031ce377 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /NativeIntegration/UI/ResizedView/Assets/Screenshot.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System.Runtime.InteropServices; 4 | using AOT; 5 | 6 | public class Screenshot : MonoBehaviour 7 | { 8 | private static int screenshotIndex = 1; 9 | private static string curScreenshotName; 10 | 11 | private static string GenerateScreenshotName() 12 | { 13 | return "test" + screenshotIndex++ + ".png"; 14 | } 15 | 16 | private static bool savingScreenshot = false; 17 | 18 | #if UNITY_IPHONE && !UNITY_EDITOR 19 | [DllImport("__Internal")] 20 | private static extern void OnScreenshotDone(string filename); 21 | #endif 22 | 23 | 24 | private delegate void ScreenshotCompleteDelegate(); 25 | [MonoPInvokeCallback(typeof(ScreenshotCompleteDelegate))] 26 | public static void ScreenshotCompleteCallback() 27 | { 28 | // it might be called outside of player loop, so we shouldnt do anything funky 29 | savingScreenshot = false; 30 | #if UNITY_IPHONE && !UNITY_EDITOR 31 | OnScreenshotDone("test.png"); 32 | #endif 33 | } 34 | 35 | #if UNITY_IPHONE && !UNITY_EDITOR 36 | [DllImport("__Internal")] 37 | private static extern void CaptureScreenshot(ScreenshotCompleteDelegate completed, string filename); 38 | #endif 39 | 40 | void OnGUI() 41 | { 42 | if (!savingScreenshot && GUI.Button(new Rect(10, 10, 200, 200), "Screenshot")) 43 | { 44 | #if UNITY_IPHONE && !UNITY_EDITOR 45 | savingScreenshot = true; 46 | CaptureScreenshot(ScreenshotCompleteCallback, "test.png"); 47 | #else 48 | Application.CaptureScreenshot("test.png"); 49 | #endif 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /NativeIntegration/UI/ResizedView/Assets/Screenshot.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 24af9e5b700354147b8540e192cf9622 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /NativeIntegration/UI/ResizedView/Assets/Test.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/UI/ResizedView/Assets/Test.unity -------------------------------------------------------------------------------- /NativeIntegration/UI/ResizedView/Assets/Test.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 75d6ce996118644c383e16fdffe0d448 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /NativeIntegration/UI/ResizedView/Assets/TestOrientation.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System.Runtime.InteropServices; 4 | using AOT; 5 | 6 | public class TestOrientation : MonoBehaviour 7 | { 8 | #if UNITY_IPHONE && !UNITY_EDITOR 9 | [DllImport("__Internal")] 10 | private static extern int UnityInterfaceOrientation(); 11 | [DllImport("__Internal")] 12 | private static extern void UnityChangeInterfaceOrientation(int orient); 13 | #endif 14 | 15 | IEnumerator ChangeOrientation() 16 | { 17 | yield return new WaitForEndOfFrame(); 18 | #if UNITY_IPHONE && !UNITY_EDITOR 19 | ScreenOrientation orientation = (ScreenOrientation)UnityInterfaceOrientation(); 20 | bool isPortrait = orientation == ScreenOrientation.Portrait || orientation == ScreenOrientation.PortraitUpsideDown; 21 | 22 | UnityChangeInterfaceOrientation((int)(isPortrait ? ScreenOrientation.Landscape : ScreenOrientation.Portrait)); 23 | #endif 24 | } 25 | 26 | void OnGUI() 27 | { 28 | #if UNITY_IPHONE && !UNITY_EDITOR 29 | ScreenOrientation orientation = (ScreenOrientation)UnityInterfaceOrientation(); 30 | bool isPortrait = orientation == ScreenOrientation.Portrait || orientation == ScreenOrientation.PortraitUpsideDown; 31 | 32 | if (GUI.Button(new Rect(Screen.width - 210, 10, 200, 200), isPortrait ? "Landscape" : "Portrait")) 33 | StartCoroutine(ChangeOrientation()); 34 | #endif 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /NativeIntegration/UI/ResizedView/Assets/TestOrientation.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7cad9564c5e6c44ebbae20c65d483d51 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | assetBundleName: 10 | -------------------------------------------------------------------------------- /NativeIntegration/UI/ResizedView/ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/UI/ResizedView/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /NativeIntegration/UI/ResizedView/ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/UI/ResizedView/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /NativeIntegration/UI/ResizedView/ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/UI/ResizedView/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /NativeIntegration/UI/ResizedView/ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/UI/ResizedView/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /NativeIntegration/UI/ResizedView/ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/UI/ResizedView/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /NativeIntegration/UI/ResizedView/ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/UI/ResizedView/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /NativeIntegration/UI/ResizedView/ProjectSettings/NavMeshLayers.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/UI/ResizedView/ProjectSettings/NavMeshLayers.asset -------------------------------------------------------------------------------- /NativeIntegration/UI/ResizedView/ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/UI/ResizedView/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /NativeIntegration/UI/ResizedView/ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/UI/ResizedView/ProjectSettings/Physics2DSettings.asset -------------------------------------------------------------------------------- /NativeIntegration/UI/ResizedView/ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/UI/ResizedView/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /NativeIntegration/UI/ResizedView/ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/UI/ResizedView/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /NativeIntegration/UI/ResizedView/ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/UI/ResizedView/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /NativeIntegration/UI/ResizedView/ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/UI/ResizedView/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /NativeIntegration/Video/ReplayIt/Assets/Replay.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | using UnityEngine.iOS; 4 | 5 | public class Replay : MonoBehaviour { 6 | string lastError = ""; 7 | void OnGUI() 8 | { 9 | var recording = ReplayKit.isRecording; 10 | string caption = recording ? "Stop Recording" : "Start Recording"; 11 | if (GUI.Button(new Rect(10, 10, 500, 200), caption)) 12 | { 13 | try { 14 | recording = !recording; 15 | if (recording) 16 | ReplayKit.StartRecording(); 17 | else 18 | { 19 | ReplayKit.StopRecording(); 20 | } 21 | } 22 | catch (Exception e) { 23 | lastError = e.ToString(); 24 | } 25 | } 26 | 27 | GUI.Label(new Rect(10, 220, 500, 50), "Last error: " + ReplayKit.lastError); 28 | GUI.Label(new Rect(10, 280, 500, 50), "Last exception: " + lastError); 29 | 30 | if (ReplayKit.recordingAvailable) 31 | { 32 | if (GUI.Button(new Rect(10, 350, 500, 200), "Preview")) 33 | { 34 | ReplayKit.Preview(); 35 | } 36 | if (GUI.Button(new Rect(10, 560, 500, 200), "Discard")) 37 | { 38 | ReplayKit.Discard(); 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /NativeIntegration/Video/ReplayIt/Assets/Replay.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8887bf6cfa6ed4441a7bd544144d91db 3 | timeCreated: 1438773174 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /NativeIntegration/Video/ReplayIt/Assets/Spin.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class Spin : MonoBehaviour { 5 | 6 | // Use this for initialization 7 | void Start () { 8 | 9 | } 10 | 11 | // Update is called once per frame 12 | void Update () { 13 | GetComponent<Transform>().Rotate(Time.deltaTime * 60, Time.deltaTime * 60, Time.deltaTime * 60); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /NativeIntegration/Video/ReplayIt/Assets/Spin.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 399f941f3d0b74b6f91b4c522b137bc9 3 | timeCreated: 1438772908 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /NativeIntegration/Video/ReplayIt/Assets/SwitchScene.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class SwitchScene : MonoBehaviour { 5 | public int levelToLoad; 6 | 7 | void OnGUI() 8 | { 9 | if (GUI.Button(new Rect(Screen.width - 260, Screen.height - 110, 250, 100), "Switch scene")) 10 | Application.LoadLevel(levelToLoad); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /NativeIntegration/Video/ReplayIt/Assets/SwitchScene.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cfd7b5a5c9b954a5b98fd8a5bffe5a1f 3 | timeCreated: 1439196059 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /NativeIntegration/Video/ReplayIt/Assets/UnityReplayKit.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | namespace UnityEngine.iOS 5 | { 6 | 7 | delegate int internalCall(); 8 | 9 | public class ReplayKit { 10 | private static void doInternalCall(internalCall call) 11 | { 12 | int ret = call(); 13 | if (ret == 0) 14 | { 15 | string err = UnityReplayKitLastError(); 16 | if (err == null) 17 | err = "Unkown error occurred"; 18 | throw new Exception(err); 19 | } 20 | } 21 | 22 | public static bool recordingAvailable 23 | { 24 | get { 25 | #if UNITY_IOS && !UNITY_EDITOR 26 | return UnityReplayKitRecordingAvailable() > 0; 27 | #else 28 | return false; 29 | #endif 30 | } 31 | } 32 | 33 | [DllImport("__Internal")] 34 | private static extern int UnityReplayKitRecordingAvailable(); 35 | 36 | public static string lastError 37 | { 38 | get { 39 | #if UNITY_IOS && !UNITY_EDITOR 40 | return UnityReplayKitLastError(); 41 | #else 42 | return ""; 43 | #endif 44 | } 45 | } 46 | 47 | [DllImport("__Internal")] 48 | private static extern string UnityReplayKitLastError(); 49 | 50 | public static void StartRecording(bool enableMicrophone = false) 51 | { 52 | #if UNITY_IOS && !UNITY_EDITOR 53 | doInternalCall(() => { return UnityReplayKitStartRecording(enableMicrophone ? 1 : 0); }); 54 | #endif 55 | } 56 | 57 | [DllImport("__Internal")] 58 | private static extern int UnityReplayKitStartRecording(int enableMicrophone); 59 | 60 | public static void StopRecording() 61 | { 62 | #if UNITY_IOS && !UNITY_EDITOR 63 | doInternalCall(UnityReplayKitStopRecording); 64 | #endif 65 | } 66 | 67 | public static bool isRecording 68 | { 69 | get { 70 | bool recording = false; 71 | #if UNITY_IOS && !UNITY_EDITOR 72 | recording = UnityReplayKitIsRecording() > 0; 73 | #endif 74 | return recording; 75 | } 76 | } 77 | 78 | [DllImport("__Internal")] 79 | private static extern int UnityReplayKitIsRecording(); 80 | 81 | [DllImport("__Internal")] 82 | private static extern int UnityReplayKitStopRecording(); 83 | 84 | public static void Preview() 85 | { 86 | #if UNITY_IOS && !UNITY_EDITOR 87 | doInternalCall(UnityReplayKitPreview); 88 | #endif 89 | } 90 | 91 | [DllImport("__Internal")] 92 | private static extern int UnityReplayKitPreview(); 93 | 94 | public static void Discard() 95 | { 96 | #if UNITY_IOS && !UNITY_EDITOR 97 | doInternalCall(UnityReplayKitDiscard); 98 | #endif 99 | } 100 | 101 | [DllImport("__Internal")] 102 | private static extern int UnityReplayKitDiscard(); 103 | } 104 | 105 | } 106 | -------------------------------------------------------------------------------- /NativeIntegration/Video/ReplayIt/Assets/UnityReplayKit.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: abb8e0ad815fb411a90deffc0d0a29f4 3 | timeCreated: 1438773207 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /NativeIntegration/Video/ReplayIt/Assets/UnityReplayKit.h: -------------------------------------------------------------------------------- 1 | #ifndef UnityReplayKit_h 2 | #define UnityReplayKit_h 3 | 4 | 5 | @interface UnityReplayKit : NSObject<RPPreviewViewControllerDelegate, RPScreenRecorderDelegate> 6 | { 7 | } 8 | 9 | @property(nonatomic, readonly, getter=getLastError) NSString* lastError; 10 | 11 | @property(nonatomic, readonly, getter=getPreviewController) RPPreviewViewController* previewController; 12 | 13 | - (BOOL)screenRecordingAvailable; 14 | 15 | - (NSString*)getLastError; 16 | - (RPPreviewViewController*)getPreviewController; 17 | - (BOOL)startRecoring:(BOOL)enableMicrophone; 18 | - (BOOL)recording; 19 | - (BOOL)stopRecording; 20 | - (void)screenRecorder:(nonnull RPScreenRecorder*)screenRecorder didStopRecordingWithError:(nonnull NSError*)error previewViewController:(nullable RPPreviewViewController*)previewViewController; 21 | - (BOOL)preview; 22 | - (BOOL)discard; 23 | - (void)previewControllerDidFinish:(RPPreviewViewController*)previewController; 24 | @end 25 | 26 | 27 | 28 | #endif /* UnityReplayKit_h */ 29 | -------------------------------------------------------------------------------- /NativeIntegration/Video/ReplayIt/Assets/UnityReplayKit.h.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 26ba0255bfa324d01a044e2186164104 3 | timeCreated: 1442835966 4 | licenseType: Pro 5 | PluginImporter: 6 | serializedVersion: 1 7 | iconMap: {} 8 | executionOrder: {} 9 | isPreloaded: 0 10 | platformData: 11 | Any: 12 | enabled: 0 13 | settings: {} 14 | Editor: 15 | enabled: 0 16 | settings: 17 | CPU: AnyCPU 18 | DefaultValueInitialized: true 19 | OS: AnyOS 20 | Linux: 21 | enabled: 0 22 | settings: 23 | CPU: x86 24 | Linux64: 25 | enabled: 0 26 | settings: 27 | CPU: x86_64 28 | OSXIntel: 29 | enabled: 0 30 | settings: 31 | CPU: AnyCPU 32 | OSXIntel64: 33 | enabled: 0 34 | settings: 35 | CPU: AnyCPU 36 | Win: 37 | enabled: 0 38 | settings: 39 | CPU: AnyCPU 40 | Win64: 41 | enabled: 0 42 | settings: 43 | CPU: AnyCPU 44 | iOS: 45 | enabled: 1 46 | settings: 47 | CompileFlags: 48 | FrameworkDependencies: ReplayKit; 49 | userData: 50 | assetBundleName: 51 | assetBundleVariant: 52 | -------------------------------------------------------------------------------- /NativeIntegration/Video/ReplayIt/Assets/UnityReplayKit.mm.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3aad387650ca94f8d9c33ca4683189f5 3 | timeCreated: 1442835966 4 | licenseType: Pro 5 | PluginImporter: 6 | serializedVersion: 1 7 | iconMap: {} 8 | executionOrder: {} 9 | isPreloaded: 0 10 | platformData: 11 | Any: 12 | enabled: 0 13 | settings: {} 14 | Editor: 15 | enabled: 0 16 | settings: 17 | CPU: AnyCPU 18 | DefaultValueInitialized: true 19 | OS: AnyOS 20 | Linux: 21 | enabled: 0 22 | settings: 23 | CPU: x86 24 | Linux64: 25 | enabled: 0 26 | settings: 27 | CPU: x86_64 28 | OSXIntel: 29 | enabled: 0 30 | settings: 31 | CPU: AnyCPU 32 | OSXIntel64: 33 | enabled: 0 34 | settings: 35 | CPU: AnyCPU 36 | Win: 37 | enabled: 0 38 | settings: 39 | CPU: AnyCPU 40 | Win64: 41 | enabled: 0 42 | settings: 43 | CPU: AnyCPU 44 | iOS: 45 | enabled: 1 46 | settings: 47 | CompileFlags: 48 | FrameworkDependencies: ReplayKit; 49 | userData: 50 | assetBundleName: 51 | assetBundleVariant: 52 | -------------------------------------------------------------------------------- /NativeIntegration/Video/ReplayIt/Assets/capsule.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/ReplayIt/Assets/capsule.unity -------------------------------------------------------------------------------- /NativeIntegration/Video/ReplayIt/Assets/capsule.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2cf9c1db87ef44cf2aa12f78634f135d 3 | timeCreated: 1439195914 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /NativeIntegration/Video/ReplayIt/Assets/main.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/ReplayIt/Assets/main.unity -------------------------------------------------------------------------------- /NativeIntegration/Video/ReplayIt/Assets/main.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5ccb44b74831b461e9767cc3b233ce81 3 | timeCreated: 1438773145 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /NativeIntegration/Video/ReplayIt/ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/ReplayIt/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /NativeIntegration/Video/ReplayIt/ProjectSettings/ClusterInputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/ReplayIt/ProjectSettings/ClusterInputManager.asset -------------------------------------------------------------------------------- /NativeIntegration/Video/ReplayIt/ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/ReplayIt/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /NativeIntegration/Video/ReplayIt/ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/ReplayIt/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /NativeIntegration/Video/ReplayIt/ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/ReplayIt/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /NativeIntegration/Video/ReplayIt/ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/ReplayIt/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /NativeIntegration/Video/ReplayIt/ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/ReplayIt/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /NativeIntegration/Video/ReplayIt/ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/ReplayIt/ProjectSettings/NavMeshAreas.asset -------------------------------------------------------------------------------- /NativeIntegration/Video/ReplayIt/ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/ReplayIt/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /NativeIntegration/Video/ReplayIt/ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/ReplayIt/ProjectSettings/Physics2DSettings.asset -------------------------------------------------------------------------------- /NativeIntegration/Video/ReplayIt/ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/ReplayIt/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /NativeIntegration/Video/ReplayIt/ProjectSettings/ProjectVersion.txt: -------------------------------------------------------------------------------- 1 | m_EditorVersion: 5.2.0f3 2 | m_StandardAssetsVersion: 0 3 | -------------------------------------------------------------------------------- /NativeIntegration/Video/ReplayIt/ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/ReplayIt/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /NativeIntegration/Video/ReplayIt/ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/ReplayIt/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /NativeIntegration/Video/ReplayIt/ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/ReplayIt/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /NativeIntegration/Video/ReplayIt/ProjectSettings/UnityAdsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/ReplayIt/ProjectSettings/UnityAdsSettings.asset -------------------------------------------------------------------------------- /NativeIntegration/Video/ReplayIt/ProjectSettings/UnityAnalyticsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/ReplayIt/ProjectSettings/UnityAnalyticsManager.asset -------------------------------------------------------------------------------- /NativeIntegration/Video/ReplayIt/ProjectSettings/UnityConnectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/ReplayIt/ProjectSettings/UnityConnectSettings.asset -------------------------------------------------------------------------------- /NativeIntegration/Video/ReplayIt/README.md: -------------------------------------------------------------------------------- 1 | # ReplayKit Plugin 2 | 3 | 4 | ## Description 5 | 6 | This sample shows how one can create a native plugin in order to Utilize ReplayKit on iOS. 7 | 8 | ##Prerequisites 9 | 10 | Unity: 5.2 11 | 12 | iOS: 9.0 or later 13 | 14 | ## How does it work 15 | 16 | Native hooks are exposed that allow the Unity runtime to initiate native calls, and respond to callbacks within the ReplayKit framework. 17 | 18 | ## Notes 19 | 20 | There is one ReplayKit callback that doesn't seem to be working in `UnityReplayKit.mm` 21 | ``` 22 | [recorder discardRecordingWithHandler:^() 23 | { 24 | _previewController = nil; 25 | }]; 26 | // TODO - the above callback doesn't seem to be working at the moment. 27 | _previewController = nil; 28 | ``` -------------------------------------------------------------------------------- /NativeIntegration/Video/ReplayIt/ReplayIt.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 11.00 2 | # Visual Studio 2008 3 | 4 | Project("{6F743880-01E1-8CE7-199F-3BFB6FAC5EDF}") = "ReplayIt", "Assembly-CSharp.csproj", "{C78F5EEB-ADC0-9931-EA41-63C6A9259727}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Any CPU = Debug|Any CPU 9 | Release|Any CPU = Release|Any CPU 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {C78F5EEB-ADC0-9931-EA41-63C6A9259727}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 13 | {C78F5EEB-ADC0-9931-EA41-63C6A9259727}.Debug|Any CPU.Build.0 = Debug|Any CPU 14 | {C78F5EEB-ADC0-9931-EA41-63C6A9259727}.Release|Any CPU.ActiveCfg = Release|Any CPU 15 | {C78F5EEB-ADC0-9931-EA41-63C6A9259727}.Release|Any CPU.Build.0 = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | GlobalSection(MonoDevelopProperties) = preSolution 21 | StartupItem = Assembly-CSharp.csproj 22 | Policies = $0 23 | $0.TextStylePolicy = $1 24 | $1.inheritsSet = null 25 | $1.scope = text/x-csharp 26 | $0.CSharpFormattingPolicy = $2 27 | $2.inheritsSet = Mono 28 | $2.inheritsScope = text/x-csharp 29 | $2.scope = text/x-csharp 30 | $0.TextStylePolicy = $3 31 | $3.FileWidth = 120 32 | $3.TabWidth = 4 33 | $3.IndentWidth = 4 34 | $3.EolMarker = Unix 35 | $3.inheritsSet = Mono 36 | $3.inheritsScope = text/plain 37 | $3.scope = text/plain 38 | EndGlobalSection 39 | EndGlobal 40 | -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayer/Assets/Plugins.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6a61c4c7e8e3d4e55bd1431be8d5483a 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayer/Assets/Plugins/iOS.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ff8fd657bd8f647919a9f21aa0fb346b 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayer/Assets/Plugins/iOS/VideoPlayerInterface.mm: -------------------------------------------------------------------------------- 1 | #if UNITY_VERSION < 500 2 | #error this sample was upgraded to be compatible only with 5.x 3 | #endif 4 | 5 | #include "Unity/VideoPlayer.h" 6 | #include "UnityAppController.h" 7 | #import <UIKit/UIKit.h> 8 | 9 | #include <stdlib.h> 10 | #include <string.h> 11 | #include <stdint.h> 12 | 13 | @interface MyVideoPlayerView : VideoPlayerView 14 | { 15 | } 16 | - (void)onUnityUpdateViewLayout; 17 | @end 18 | @implementation MyVideoPlayerView 19 | - (void)onUnityUpdateViewLayout 20 | { 21 | self.center = GetAppController().rootView.center; 22 | } 23 | @end 24 | 25 | @interface VideoPlayerScripting : NSObject<VideoPlayerDelegate> 26 | { 27 | VideoPlayer* player; 28 | VideoPlayerView* view; 29 | } 30 | - (void)playVideo:(NSURL*)url; 31 | 32 | - (void)onPlayerReady; 33 | - (void)onPlayerDidFinishPlayingVideo; 34 | 35 | - (void)pause; 36 | - (void)resume; 37 | - (void)rewind; 38 | @end 39 | 40 | @implementation VideoPlayerScripting 41 | - (void)playVideo:(NSURL*)url 42 | { 43 | if (!player) 44 | { 45 | player = [[VideoPlayer alloc] init]; 46 | player.delegate = self; 47 | } 48 | [player loadVideo: url]; 49 | } 50 | 51 | - (void)onPlayerReady 52 | { 53 | if (!view) 54 | { 55 | CGSize videoExt = [player videoSize]; 56 | CGRect videoFrame = CGRectMake(0, 0, videoExt.width, videoExt.height); 57 | view = [[MyVideoPlayerView alloc] initWithFrame:videoFrame]; 58 | 59 | [GetAppController().rootView addSubview:view]; 60 | [GetAppController().rootView layoutSubviews]; 61 | } 62 | 63 | view.hidden = NO; 64 | 65 | [player playToView: view]; 66 | [player setAudioVolume: 1.0f]; 67 | } 68 | - (void)onPlayerDidFinishPlayingVideo 69 | { 70 | view.hidden = YES; 71 | } 72 | 73 | - (void)pause { [player pause]; } 74 | - (void)resume { [player resume]; } 75 | - (void)rewind { [player rewind]; } 76 | 77 | @end 78 | 79 | static VideoPlayerScripting* _Player = nil; 80 | 81 | extern "C" void VideoPlayer_PlayVideo(const char* filename) 82 | { 83 | if (!_Player) 84 | _Player = [[VideoPlayerScripting alloc] init]; 85 | 86 | NSURL* url = nil; 87 | if (::strstr(filename, "://")) 88 | url = [NSURL URLWithString:[NSString stringWithUTF8String:filename]]; 89 | else 90 | url = [NSURL fileURLWithPath:[[NSBundle mainBundle].bundlePath stringByAppendingPathComponent:[NSString stringWithUTF8String:filename]]]; 91 | 92 | [_Player playVideo:url]; 93 | } 94 | 95 | extern "C" void VideoPlayer_PauseVideo() { [_Player pause]; } 96 | extern "C" void VideoPlayer_ResumeVideo() { [_Player resume]; } 97 | extern "C" void VideoPlayer_RewindVideo() { [_Player rewind]; } 98 | -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayer/Assets/Plugins/iOS/VideoPlayerInterface.mm.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0231df34b74ec410a9ee27018ee10d27 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayer/Assets/StreamingAssets.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b40ce3ecd3f0e4c728b8171ed179ac05 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayer/Assets/StreamingAssets/big_buck_bunny.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/VideoPlayer/Assets/StreamingAssets/big_buck_bunny.mp4 -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayer/Assets/StreamingAssets/big_buck_bunny.mp4.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f70cb7cf953eb4e0894e16dde2179b07 3 | MovieImporter: 4 | serializedVersion: 1 5 | quality: .5 6 | linearTexture: 0 7 | userData: 8 | -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayer/Assets/TestVideoPlayer.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System.Runtime.InteropServices; 4 | 5 | public class TestVideoPlayer : MonoBehaviour 6 | { 7 | #if UNITY_IPHONE && !UNITY_EDITOR 8 | [DllImport("__Internal")] 9 | private static extern void VideoPlayer_PlayVideo(string url); 10 | [DllImport("__Internal")] 11 | private static extern void VideoPlayer_PauseVideo(); 12 | [DllImport("__Internal")] 13 | private static extern void VideoPlayer_ResumeVideo(); 14 | [DllImport("__Internal")] 15 | private static extern void VideoPlayer_RewindVideo(); 16 | #else // if UNITY_IPHONE && !UNITY_EDITOR 17 | private static void VideoPlayer_PlayVideo(string url) {} 18 | private static void VideoPlayer_PauseVideo() {} 19 | private static void VideoPlayer_ResumeVideo() {} 20 | private static void VideoPlayer_RewindVideo() {} 21 | #endif // if UNITY_IPHONE && !UNITY_EDITOR 22 | 23 | private string[] videoPath = new string[] 24 | { 25 | "Data/Raw/big_buck_bunny.mp4", 26 | "http://www.quirksmode.org/html5/videos/big_buck_bunny.mp4" 27 | }; 28 | private int curVideo = 0; 29 | 30 | private void PlayVideo() 31 | { 32 | VideoPlayer_PlayVideo(videoPath[curVideo]); 33 | curVideo = (curVideo + 1) % videoPath.Length; 34 | } 35 | 36 | void Start() 37 | { 38 | PlayVideo(); 39 | } 40 | 41 | void OnGUI() 42 | { 43 | int buttonW = Screen.width / 8; 44 | int buttonH = Screen.height / 8; 45 | int buttonX = 10; 46 | int buttonY = Screen.height - buttonH - 10; 47 | 48 | if (GUI.Button(new Rect(buttonX, buttonY, buttonW, buttonH), "Next")) 49 | PlayVideo(); 50 | 51 | buttonX += buttonW + 10; 52 | if (GUI.Button(new Rect(buttonX, buttonY, buttonW, buttonH), "Pause")) 53 | VideoPlayer_PauseVideo(); 54 | 55 | buttonX += buttonW + 10; 56 | if (GUI.Button(new Rect(buttonX, buttonY, buttonW, buttonH), "Resume")) 57 | VideoPlayer_ResumeVideo(); 58 | 59 | buttonX += buttonW + 10; 60 | if (GUI.Button(new Rect(buttonX, buttonY, buttonW, buttonH), "Rewind")) 61 | VideoPlayer_RewindVideo(); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayer/Assets/TestVideoPlayer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5dd6a852fe367433cb8455c63c35640a 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayer/Assets/TestVideoPlayer.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/VideoPlayer/Assets/TestVideoPlayer.unity -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayer/Assets/TestVideoPlayer.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9a33bbd41d8ed4026b8ea559cf205997 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayer/ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/VideoPlayer/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayer/ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/VideoPlayer/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayer/ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/VideoPlayer/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayer/ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/VideoPlayer/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayer/ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/VideoPlayer/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayer/ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/VideoPlayer/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayer/ProjectSettings/NavMeshLayers.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/VideoPlayer/ProjectSettings/NavMeshLayers.asset -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayer/ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/VideoPlayer/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayer/ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/VideoPlayer/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayer/ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/VideoPlayer/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayer/ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/VideoPlayer/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayer/ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/VideoPlayer/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayer/README.md: -------------------------------------------------------------------------------- 1 | # Using Unity VideoPlayer 2 | 3 | 4 | ## Description 5 | 6 | This is a sample of iOS VideoPlayer playing video in UIView. It shows playback of both mp4 from StreamingAssets folders (local) and streaming mp4 from internet. 7 | 8 | 9 | ##Prerequisites 10 | 11 | Unity: 4.2 12 | 13 | iOS: any 14 | 15 | 16 | ## How does it work 17 | 18 | There are two pieces of interest: TestVideoPlayer.cs and Plugins/iOS/VideoPlayerInterface.mm. 19 | 20 | VideoPlayerInterface.mm contains the simple delegate for VideoPlayer. 21 | 22 | Please notice that it also handles orientation, as we dont add to unity view controller: 23 | 24 | - (void)orientationDidChange:(NSNotification *)notification 25 | { 26 | CGRect bounds = UnityGetGLView().bounds; 27 | view.center = CGPointMake(bounds.size.width / 2, bounds.size.height / 2); 28 | } 29 | 30 | and 31 | 32 | if(!player) 33 | { 34 | player = [[VideoPlayerScripting alloc] init]; 35 | [[NSNotificationCenter defaultCenter] addObserver:player selector:@selector(orientationDidChange:) name:kUnityViewDidRotate object:nil]; 36 | } 37 | 38 | Also, playing video is 2-step process: 39 | 40 | first we load it: 41 | 42 | if(!player) 43 | { 44 | player = [[VideoPlayer alloc] init]; 45 | player.delegate = self; 46 | } 47 | 48 | [player loadVideo:url]; 49 | 50 | and start playing it only when it is ready: 51 | 52 | - (void)onPlayerReady 53 | { 54 | CGRect bounds = UnityGetGLView().bounds; 55 | 56 | if(!view) 57 | view = [[VideoPlayerView alloc] initWithFrame: bounds]; 58 | 59 | view.bounds = CGRectMake(0,0, [player videoSize].width, [player videoSize].height); 60 | view.center = CGPointMake(bounds.size.width / 2, bounds.size.height / 2); 61 | 62 | [UnityGetGLView() addSubview: view]; 63 | [player playToView:view]; 64 | [player setAudioVolume:0.5f]; 65 | } 66 | 67 | While in this sample we just center view, you have full control over this view. 68 | 69 | 70 | ## License Information 71 | 72 | big_buck_bunny.mp4 is the first minute from the cc-by licenced “open movie” [Big Buck Bunny](http://bigbuckbunny.org/) 73 | -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayerTexture/Assets/Plugins.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0b64e7af70e874c4cb4e162b805bd819 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayerTexture/Assets/Plugins/iOS.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ff8fd657bd8f647919a9f21aa0fb346b 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayerTexture/Assets/Plugins/iOS/VideoPlayerInterface.mm: -------------------------------------------------------------------------------- 1 | #include "Unity/VideoPlayer.h" 2 | 3 | #if UNITY_VERSION < 450 4 | #include "iPhone_View.h" 5 | #endif 6 | 7 | #import <UIKit/UIKit.h> 8 | 9 | #include <stdlib.h> 10 | #include <string.h> 11 | #include <stdint.h> 12 | 13 | @interface VideoPlayerScripting : NSObject<VideoPlayerDelegate> 14 | { 15 | @public VideoPlayer* player; 16 | @public BOOL playerReady; 17 | } 18 | - (void)playVideo:(NSURL*)url; 19 | 20 | - (void)onPlayerReady; 21 | - (void)onPlayerDidFinishPlayingVideo; 22 | @end 23 | 24 | @implementation VideoPlayerScripting 25 | - (void)playVideo:(NSURL*)url 26 | { 27 | if (!player) 28 | { 29 | player = [[VideoPlayer alloc] init]; 30 | player.delegate = self; 31 | } 32 | [player loadVideo: url]; 33 | } 34 | 35 | - (void)onPlayerReady 36 | { 37 | playerReady = YES; 38 | 39 | [player playToTexture]; 40 | [player setAudioVolume: 1.0f]; 41 | } 42 | 43 | - (void)onPlayerDidFinishPlayingVideo 44 | { 45 | playerReady = NO; 46 | } 47 | 48 | @end 49 | 50 | static VideoPlayerScripting* _GetPlayer() 51 | { 52 | static VideoPlayerScripting* _Player = nil; 53 | if (!_Player) 54 | _Player = [[VideoPlayerScripting alloc] init]; 55 | 56 | return _Player; 57 | } 58 | 59 | static NSURL* _GetUrl(const char* filename) 60 | { 61 | NSURL* url = nil; 62 | if (::strstr(filename, "://")) 63 | url = [NSURL URLWithString: [NSString stringWithUTF8String: filename]]; 64 | else 65 | url = [NSURL fileURLWithPath: [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent: [NSString stringWithUTF8String: filename]]]; 66 | 67 | return url; 68 | } 69 | 70 | extern "C" bool VideoPlayer_CanOutputToTexture(const char* filename) 71 | { 72 | return [VideoPlayer CanPlayToTexture: _GetUrl(filename)]; 73 | } 74 | 75 | extern "C" bool VideoPlayer_PlayerReady() 76 | { 77 | return [_GetPlayer()->player readyToPlay]; 78 | } 79 | 80 | extern "C" float VideoPlayer_DurationSeconds() 81 | { 82 | return [_GetPlayer()->player durationSeconds]; 83 | } 84 | 85 | extern "C" void VideoPlayer_VideoExtents(int* w, int* h) 86 | { 87 | CGSize sz = [_GetPlayer()->player videoSize]; 88 | *w = (int)sz.width; 89 | *h = (int)sz.height; 90 | } 91 | 92 | extern "C" intptr_t VideoPlayer_CurFrameTexture() 93 | { 94 | return [_GetPlayer()->player curFrameTexture]; 95 | } 96 | 97 | extern "C" void VideoPlayer_PlayVideo(const char* filename) 98 | { 99 | [_GetPlayer() playVideo: _GetUrl(filename)]; 100 | } 101 | -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayerTexture/Assets/Plugins/iOS/VideoPlayerInterface.mm.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b9964ca1c065b4c1fa4d87aa9dd8a5d1 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayerTexture/Assets/Rotator.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class Rotator : MonoBehaviour 5 | { 6 | public Transform target = null; 7 | 8 | void Update() 9 | { 10 | target.Rotate(Vector3.up * (8.0f * Time.deltaTime)); 11 | target.Rotate(Vector3.right * (-4.0f * Time.deltaTime)); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayerTexture/Assets/Rotator.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 157cbc3f4d6f6492d9dd9a6795dcc59f 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayerTexture/Assets/StreamingAssets.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c706e7409a7424964b1e2354fa65a8f6 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayerTexture/Assets/StreamingAssets/big_buck_bunny.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/VideoPlayerTexture/Assets/StreamingAssets/big_buck_bunny.mp4 -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayerTexture/Assets/StreamingAssets/big_buck_bunny.mp4.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f70cb7cf953eb4e0894e16dde2179b07 3 | MovieImporter: 4 | serializedVersion: 1 5 | quality: .5 6 | linearTexture: 0 7 | userData: 8 | -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayerTexture/Assets/TestVideo.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class TestVideo : MonoBehaviour 5 | { 6 | public Material videoMat = null; 7 | private bool videoMatTexAssigned = false; 8 | 9 | private VideoPlayerInterface _player = new VideoPlayerInterface(); 10 | 11 | 12 | void Start() 13 | { 14 | videoMat.mainTexture = null; 15 | _player.play("Data/Raw/big_buck_bunny.mp4"); 16 | } 17 | 18 | void Update() 19 | { 20 | if (!videoMatTexAssigned && _player.videoTexture) 21 | { 22 | videoMat.mainTexture = _player.videoTexture; 23 | videoMatTexAssigned = true; 24 | } 25 | if (videoMatTexAssigned && !_player.videoTexture) 26 | { 27 | videoMat.mainTexture = null; 28 | videoMatTexAssigned = false; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayerTexture/Assets/TestVideo.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c908389f4516d4723a7b8838b23bdc13 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayerTexture/Assets/TestVideo.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/VideoPlayerTexture/Assets/TestVideo.mat -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayerTexture/Assets/TestVideo.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2660daa5eda5d4d49ba3e798959b6475 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayerTexture/Assets/TestVideo.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/VideoPlayerTexture/Assets/TestVideo.unity -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayerTexture/Assets/TestVideo.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7d6a62bd81ca242ed9aaa3c48d4d831a 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayerTexture/Assets/VideoPlayerInterface.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b8d16d93956ee49c4b95f603d3cc1f23 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayerTexture/ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/VideoPlayerTexture/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayerTexture/ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/VideoPlayerTexture/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayerTexture/ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/VideoPlayerTexture/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayerTexture/ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/VideoPlayerTexture/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayerTexture/ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/VideoPlayerTexture/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayerTexture/ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/VideoPlayerTexture/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayerTexture/ProjectSettings/NavMeshLayers.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/VideoPlayerTexture/ProjectSettings/NavMeshLayers.asset -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayerTexture/ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/VideoPlayerTexture/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayerTexture/ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/VideoPlayerTexture/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayerTexture/ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/VideoPlayerTexture/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayerTexture/ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/VideoPlayerTexture/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayerTexture/ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/Video/VideoPlayerTexture/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /NativeIntegration/Video/VideoPlayerTexture/README.md: -------------------------------------------------------------------------------- 1 | # Using Unity VideoPlayer: render video to texture. 2 | 3 | 4 | ## Description 5 | 6 | This is a sample of iOS VideoPlayer playing video into unity texture. 7 | 8 | 9 | ##Prerequisites 10 | 11 | Unity: 4.2 12 | 13 | iOS: 5.0 14 | 15 | 16 | ## How does it work 17 | 18 | First of all, playing video into a texture have certain limitations: 19 | * OpenGL ES 2 must be used. 20 | * Only local video can be played. 21 | 22 | 23 | There are two pieces of interest: VideoPlayerInterface.cs and Plugins/iOS/VideoPlayerInterface.mm. 24 | 25 | VideoPlayerInterface.mm contains the simple delegate for VideoPlayer, and several functions that allows to query video information. 26 | 27 | Playing video is 2-step process: 28 | 29 | first we load it: 30 | 31 | if(!player) 32 | { 33 | player = [[VideoPlayer alloc] init]; 34 | player.delegate = self; 35 | } 36 | 37 | [player loadVideo:url]; 38 | 39 | and start playing it only when it is ready: 40 | 41 | - (void)onPlayerReady 42 | { 43 | playerReady = YES; 44 | 45 | [player playToTexture]; 46 | [player setAudioVolume:1.0f]; 47 | } 48 | 49 | VideoPlayerInterface.cs contains c# interface to native VideoPlayer. The main work is done inside videoTexture getter: 50 | 51 | public Texture2D videoTexture 52 | { 53 | get 54 | { 55 | if(videoReady) 56 | { 57 | int nativeTex = VideoPlayer_CurFrameTexture(); 58 | if(_videoTexture == null) 59 | { 60 | _videoTexture = Texture2D.CreateExternalTexture(videoWidth, videoHeight, TextureFormat.BGRA32, false, false, (System.IntPtr)nativeTex); 61 | _videoTexture.filterMode = FilterMode.Bilinear; 62 | _videoTexture.wrapMode = TextureWrapMode.Repeat; 63 | } 64 | 65 | _videoTexture.UpdateExternalTexture((System.IntPtr)nativeTex); 66 | } 67 | else 68 | { 69 | _videoTexture = null; 70 | } 71 | 72 | return _videoTexture; 73 | } 74 | } 75 | 76 | Please note, that Texture2D.UpdateExternalTexture must be used, so video playback to texture can be used only with Unity PRO. 77 | 78 | 79 | ## License Information 80 | 81 | big_buck_bunny.mp4 is the first minute from the cc-by licenced “open movie” [Big Buck Bunny](http://bigbuckbunny.org/) 82 | -------------------------------------------------------------------------------- /NativeIntegration/WWW/CustomConnection/Assets/Plugins.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 81309fa0cdd384c69ba2be8eac5aa9b5 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /NativeIntegration/WWW/CustomConnection/Assets/Plugins/iOS.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ff8fd657bd8f647919a9f21aa0fb346b 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /NativeIntegration/WWW/CustomConnection/Assets/Plugins/iOS/CustomConnection.mm: -------------------------------------------------------------------------------- 1 | #include "Unity/WWWConnection.h" 2 | 3 | @interface UnityWWWCustomRequestProvider : UnityWWWRequestDefaultProvider 4 | { 5 | } 6 | + (NSMutableURLRequest*)allocRequestForHTTPMethod:(NSString*)method url:(NSURL*)url headers:(NSDictionary*)headers; 7 | @end 8 | 9 | @implementation UnityWWWCustomRequestProvider 10 | + (NSMutableURLRequest*)allocRequestForHTTPMethod:(NSString*)method url:(NSURL*)url headers:(NSDictionary*)headers 11 | { 12 | NSMutableURLRequest* request = [super allocRequestForHTTPMethod: method url: url headers: headers]; 13 | 14 | // let's pretend for security reasons we dont want ANY cache nor cookies 15 | request.cachePolicy = NSURLRequestReloadIgnoringLocalCacheData; 16 | [request setHTTPShouldHandleCookies: NO]; 17 | 18 | // let's pretend we want special secret info in header 19 | [request setValue: @"123456789"forHTTPHeaderField: @"Secret"]; 20 | 21 | return request; 22 | } 23 | 24 | @end 25 | 26 | @interface UnityWWWCustomConnectionDelegate : UnityWWWConnectionDelegate 27 | { 28 | } 29 | @end 30 | 31 | @implementation UnityWWWCustomConnectionDelegate 32 | - (NSCachedURLResponse*)connection:(NSURLConnection*)connection willCacheResponse:(NSCachedURLResponse*)cachedResponse 33 | { 34 | // we dont want caching 35 | return nil; 36 | } 37 | 38 | - (void)connection:(NSURLConnection*)connection didReceiveResponse:(NSURLResponse*)response 39 | { 40 | // let's just print something here for test 41 | [super connection: connection didReceiveResponse: response]; 42 | if ([response isMemberOfClass: [NSHTTPURLResponse class]]) 43 | ::printf_console("We've got response with status: %d\n", [(NSHTTPURLResponse*)response statusCode]); 44 | } 45 | 46 | @end 47 | 48 | IMPL_WWW_DELEGATE_SUBCLASS(UnityWWWCustomConnectionDelegate); 49 | IMPL_WWW_REQUEST_PROVIDER(UnityWWWCustomRequestProvider); 50 | -------------------------------------------------------------------------------- /NativeIntegration/WWW/CustomConnection/Assets/Plugins/iOS/CustomConnection.mm.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e859a467eb0b944c0be08097712741ed 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /NativeIntegration/WWW/CustomConnection/Assets/TestMaterial.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/WWW/CustomConnection/Assets/TestMaterial.mat -------------------------------------------------------------------------------- /NativeIntegration/WWW/CustomConnection/Assets/TestMaterial.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fc517ec5765b24ba0a08a80654bc2fdb 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /NativeIntegration/WWW/CustomConnection/Assets/TestTextureSimple.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/WWW/CustomConnection/Assets/TestTextureSimple.unity -------------------------------------------------------------------------------- /NativeIntegration/WWW/CustomConnection/Assets/TestTextureSimple.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a5f8901cc44af4bbcbf7baf369406724 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /NativeIntegration/WWW/CustomConnection/Assets/TestWWWGetCustomConnection.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class TestWWWGetCustomConnection : MonoBehaviour 5 | { 6 | IEnumerator LoadStuff() 7 | { 8 | // sure, for testing reaction to custom "Secret" header you might need to have special scripts on your server, so we skip it 9 | WWW www = new WWW("http://unity3d.com/profiles/unity3d/themes/unity/images/company/brand/logos/pwrdby/pwrdby.jpg"); 10 | yield return www; 11 | 12 | renderer.material.mainTexture = www.texture; 13 | } 14 | 15 | void Start() 16 | { 17 | StartCoroutine(LoadStuff()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /NativeIntegration/WWW/CustomConnection/Assets/TestWWWGetCustomConnection.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4966cbcd9e8ab4620b5f1608743106be 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /NativeIntegration/WWW/CustomConnection/ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/WWW/CustomConnection/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /NativeIntegration/WWW/CustomConnection/ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/WWW/CustomConnection/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /NativeIntegration/WWW/CustomConnection/ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/WWW/CustomConnection/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /NativeIntegration/WWW/CustomConnection/ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/WWW/CustomConnection/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /NativeIntegration/WWW/CustomConnection/ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/WWW/CustomConnection/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /NativeIntegration/WWW/CustomConnection/ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/WWW/CustomConnection/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /NativeIntegration/WWW/CustomConnection/ProjectSettings/NavMeshLayers.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/WWW/CustomConnection/ProjectSettings/NavMeshLayers.asset -------------------------------------------------------------------------------- /NativeIntegration/WWW/CustomConnection/ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/WWW/CustomConnection/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /NativeIntegration/WWW/CustomConnection/ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/WWW/CustomConnection/ProjectSettings/Physics2DSettings.asset -------------------------------------------------------------------------------- /NativeIntegration/WWW/CustomConnection/ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/WWW/CustomConnection/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /NativeIntegration/WWW/CustomConnection/ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/WWW/CustomConnection/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /NativeIntegration/WWW/CustomConnection/ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/WWW/CustomConnection/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /NativeIntegration/WWW/CustomConnection/ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Unity-Technologies/iOSNativeCodeSamples/0c155b56b79649ed840e6cf35608040828e6d687/NativeIntegration/WWW/CustomConnection/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /NativeIntegration/WWW/CustomConnection/README.md: -------------------------------------------------------------------------------- 1 | # Tweaking the connection used in Unity WWW class. 2 | 3 | 4 | ## Description 5 | 6 | This sample shows how to tweak WWW connection to better suit your needs. 7 | 8 | 9 | ##Prerequisites 10 | 11 | Unity: 4.3.1 12 | 13 | iOS: any 14 | 15 | 16 | ## How does it work 17 | 18 | The place of interest is Plugins/iOS/CustomConnection.mm 19 | 20 | First, we subclass UnityWWWRequestDefaultProvider to tweak the NSURLRequest object used for connection. We could implement UnityWWWRequestProvider protocol, but we want to reuse base code. 21 | 22 | @interface UnityWWWCustomRequestProvider : UnityWWWRequestDefaultProvider 23 | { 24 | } 25 | + (NSMutableURLRequest*)allocRequestForHTTPMethod:(NSString*)method url:(NSURL*)url headers:(NSDictionary*)headers; 26 | @end 27 | 28 | @implementation UnityWWWCustomRequestProvider 29 | + (NSMutableURLRequest*)allocRequestForHTTPMethod:(NSString*)method url:(NSURL*)url headers:(NSDictionary*)headers 30 | { 31 | NSMutableURLRequest* request = [super allocRequestForHTTPMethod:method url:url headers:headers]; 32 | 33 | We sill disable any data caching by iOS: 34 | 35 | request.cachePolicy = NSURLRequestReloadIgnoringLocalCacheData; 36 | [request setHTTPShouldHandleCookies:NO]; 37 | 38 | And pretend we need some secret header that will be checked by our server: 39 | 40 | [request setValue:@"123456789"forHTTPHeaderField:@"Secret"]; 41 | 42 | And then we "register" our subclass for unity to use when creating NSURLRequest: 43 | 44 | IMPL_WWW_REQUEST_PROVIDER(UnityWWWCustomRequestProvider); 45 | 46 | Second, we subclass UnityWWWConnectionDelegate to have customized connection handling: 47 | 48 | @interface UnityWWWCustomConnectionDelegate : UnityWWWConnectionDelegate 49 | { 50 | } 51 | @end 52 | 53 | @implementation UnityWWWCustomConnectionDelegate 54 | 55 | We disable data caching: 56 | 57 | - (NSCachedURLResponse*)connection:(NSURLConnection*)connection willCacheResponse:(NSCachedURLResponse*)cachedResponse 58 | { 59 | // we dont want caching 60 | return nil; 61 | } 62 | 63 | And we hook up on receiving data. To not complicate code we just print to log. Please note that we call super method so unity actually gets data. 64 | 65 | - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response 66 | { 67 | // let's just print something here for test 68 | [super connection:connection didReceiveResponse:response]; 69 | if([response isMemberOfClass:[NSHTTPURLResponse class]]) 70 | ::printf_console("We've got response with status: %d\n", [(NSHTTPURLResponse*)response statusCode]); 71 | } 72 | 73 | And then we "register" our subclass for unity to use when creating connection delegate: 74 | 75 | IMPL_WWW_REQUEST_PROVIDER(UnityWWWCustomRequestProvider); 76 | 77 | That's it, in C# we simply use WWW class to download texture and it will use our implementation. You can easily check that by that log string we output in didReceiveResponse 78 | -------------------------------------------------------------------------------- /readme.markdown: -------------------------------------------------------------------------------- 1 | iOS Native Code Samples 2 | ======== 3 | 4 | These are native code samples for iOS maintained by the Unity iOS team. 5 | --------------------------------------------------------------------------------