/// <summary> /// Create camera texture and set it to the camera plane /// </summary> /// <returns> /// true when texture is created, else false /// </returns> public bool createTexture(uint enforceSize) { uint requiredSize; if (enforceSize > 0) { requiredSize = enforceSize; } else { requiredSize = MetaioSDKUnity.getRequiredTextureSize(); } if (requiredSize <= 0) { return(false); } // Reuse old texture if required size didn't change if (textureCreated && currentTextureSize == requiredSize) { return(true); } // Create the texture that will hold camera frames // Android and OSX TextureFormat textureFormat = TextureFormat.RGBA32; if (Application.platform == RuntimePlatform.IPhonePlayer) { // iOS textureFormat = TextureFormat.BGRA32; } else if (Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.WindowsEditor) { // Windows textureFormat = TextureFormat.RGB24; } Debug.Log("Creating texture with size " + requiredSize + " and format " + textureFormat); texture = new Texture2D((int)requiredSize, (int)requiredSize, textureFormat, false); if (texture == null) { return(false); } currentTextureSize = requiredSize; cameraPlane.GetComponent <Renderer>().material.mainTexture = texture; textureID = texture.GetNativeTextureID(); Debug.Log("Texture ID: " + textureID); return(true); }