CreateExternalTexture - bắn cá săn thưởng

Mục lục

VIẾT PHỤ CỨU IOS CHO UNITY

WKWebView <-- MTLTexture <--> Texture2d --> Unity

Tuy nhiên, vẫn còn rất nhiều tính năng khác mà chúng ta có thể khai thác. Ví dụ, Unity hiện dường như chưa hỗ trợ Compute Shader chạy trên điện thoại di động. Nhưng iOS có khả năng thực hiện tính toán GPGPU, và về hiệu suất, mã native thường vượt trội so với Mono runtime. Điều này có thể là một hướng thử nghiệm trong tương lai.

Cách Unity gọi phương thức iOS:

Test.cs
----------------
using UnityEngine;
using System;
using System.Runtime.InteropServices;

public class Test : MonoBehaviour 
{
    void Start ()
    {
        Hello ();
    }

    #region [bắn cá máy [cách xem kèo bóng đá](/post/2021-12-29/)  xèng online](/post/moneymaketheworldgoround/)  Phương thức extern
    
    [DllImport ("__Internal")]
    public static extern void Hello();
    
    #endregion
}
Test.h
----------------
#import <Foundation/Foundation.h>

@interface Test : NSObject
@end

extern "C" void Hello();
Test.mm
----------------
#import "Test.h"

@implementation Test [ban ca 3d online](/post/did-i-adequately-answer-your-condescending-question/) 
@end

void Hello()
{
    NSLog(@"Xin chào");
}

Lấy con trỏ kết cấu từ iOS

Bạn có thể tham khảo các hàm Texture.GetNativeTexturePtrTexture2D.CreateExternalTexture. Hàm GetNativeTexturePtr giúp bạn lấy địa chỉ kết cấu trên nền tảng tương ứng sau khi Unity tạo kết cấu. Trong khi đó, CreateExternalTexture cho phép bạn truyền một con trỏ kết cấu từ nền tảng bên ngoài vào Unity để tạo Texture2D. Trên nền tảng Metal, GetNativeTexturePtr sẽ trả về một con trỏ kiểu id<MTLTexture>, và bạn có thể truy cập nó từ phần mã iOS bằng cách sau:

Test.cs
----------------
public class Test : MonoBehaviour 
{
    private Texture2D webViewTexture;

    void Start ()
    {
        webViewTexture = new Texture2D (512, 512, TextureFormat.ARGB32, false);
        SetWebViewTexturePtr(webViewTexture.GetNativeTexturePtr ());
    }

    [DllImport ("__Internal")]
    public static extern void SetWebViewTexturePtr(IntPtr ptr);
}
Test.h
----------------
extern "C" void SetWebViewTexturePtr(uintptr_t ptr);
Test.mm
----------------
void SetWebViewTexturePtr(uintptr_t ptr)
{
    id<MTLTexture> ptrToMetalTexture = (__bridge_transfer id<MTLTexture>)(void*) ptr;
}