### Rokid Device Camera Configuration Example Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/HMD/How-to-Create-EasyAR-HMD-Extension Example of device camera setup within RokidFrameSource, fetching image dimensions and initializing DeviceFrameSourceCamera with specific parameters. ```csharp private DeviceFrameSourceCamera deviceCamera; protected override List DeviceCameras => new List { deviceCamera }; { var imageDimensions = new int[2]; RokidExtensionAPI.RokidOpenXR_API_GetImageDimensions(imageDimensions); size = new Vector2Int(imageDimensions[0], imageDimensions[1]); deviceCamera = new DeviceFrameSourceCamera(CameraDeviceType.Back, 0, size, new Vector2(50, 50), new DeviceFrameSourceCamera.CameraExtrinsics(Pose.identity, true), AxisSystemType.Unity); started = true; } ``` -------------------------------- ### Initialize and Start AR Session - C# Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/ApiReference/ARSession Demonstrates how to manually start an AR session using the StartSession method. This is necessary if AutoStart is set to false. EasyAR functionalities are available only after the session starts. ```csharp public class MyARController : MonoBehaviour { public ARSession arSession; void Start() { if (arSession != null && !arSession.AutoStart) { arSession.StartSession(); } } } ``` -------------------------------- ### ImageTrackerFrameFilter - C# Code Examples Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/ApiReference/ImageTrackerFrameFilter This section presents C# code examples related to the ImageTrackerFrameFilter class. It demonstrates the usage of its fields, properties, events, and methods to configure and manage image tracking within a Unity AR session. These examples are crucial for understanding how to manipulate the tracker's behavior, manage target loading and unloading, and handle motion tracking. ```C# public ImageTrackerMode TrackerMode 跟踪模式,在session启动前修改才有效. ``` ```C# public bool enabled { get; set; } ARSession 运行时开始/停止跟踪。在session启动后, MonoBehaviour .enabled为true时才会开始跟踪. ``` ```C# public List< ImageTargetController > Targets { get; } 已加载的 ImageTargetController 。 ``` ```C# public int SimultaneousNum { get; set; } 最大可被tracker跟踪的目标个数。可随时修改,立即生效。 ``` ```C# public bool EnableMotionFusion { get; set; } 启用运动跟踪。会覆盖 ImageTrackerFrameFilter.SetResultPostProcessing 。 ``` ```C# public event Action< ImageTargetController , bool> TargetLoad Target加载完成的事件。bool值表示加载是否成功。 ``` ```C# public event Action< ImageTargetController , bool> TargetUnload Target卸载完成的事件。bool值表示卸载是否成功。 ``` ```C# public void SetResultPostProcessing(bool enablePersistentTargetInstance) 设置结果后处理。会覆盖 ImageTrackerFrameFilter.EnableMotionFusion 。在session启动前修改才有效。 ``` -------------------------------- ### Rokid-Specific Camera Initialization and Data Handling Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/HMD/How-to-Create-EasyAR-HMD-Extension This C# code snippet provides a Rokid-specific implementation for camera initialization within EasyAR. It waits for specific tracking status, retrieves focal length, principal point, distortion, and image dimensions using Rokid SDK APIs. It then configures EasyAR's camera parameters and starts the camera preview, indicating readiness by setting `started` to true. ```csharp private IEnumerator InitializeCamera() { yield return new WaitUntil(() => (RokidTrackingStatus)RokidExtensionAPI.RokidOpenXR_API_GetHeadTrackingStatus() >= RokidTrackingStatus.Detecting && (RokidTrackingStatus)RokidExtensionAPI.RokidOpenXR_API_GetHeadTrackingStatus() < RokidTrackingStatus.Tracking_Paused); var focalLength = new float[2]; RokidExtensionAPI.RokidOpenXR_API_GetFocalLength(focalLength); var principalPoint = new float[2]; RokidExtensionAPI.RokidOpenXR_API_GetPrincipalPoint(principalPoint); var distortion = new float[5]; RokidExtensionAPI.RokidOpenXR_API_GetDistortion(distortion); var imageDimensions = new int[2]; RokidExtensionAPI.RokidOpenXR_API_GetImageDimensions(imageDimensions); size = new Vector2Int(imageDimensions[0], imageDimensions[1]); var cameraParamList = new List { focalLength[0], focalLength[1], principalPoint[0], principalPoint[1] }.Concat(distortion.ToList().GetRange(1, 4)).ToList(); cameraParameters = CameraParameters.tryCreateWithCustomIntrinsics(size.ToEasyARVector(), cameraParamList, CameraModelType.OpenCV_Fisheye, CameraDeviceType.Back, 0).Value; deviceCamera = new DeviceFrameSourceCamera(CameraDeviceType.Back, 0, size, new Vector2(50, 50), new DeviceFrameSourceCamera.CameraExtrinsics(Pose.identity, true), AxisSystemType.Unity); RokidExtensionAPI.RokidOpenXR_API_OpenCameraPreview(OnCameraDataUpdate); started = true; } ``` -------------------------------- ### Initialize AR Session on Session Start Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/HMD/How-to-Create-EasyAR-HMD-Extension This C# code snippet shows how to override the `OnSessionStart` method in an EasyAR component. It performs essential AR initialization tasks, including starting a coroutine to acquire camera data and ensuring base class initialization is called first. This is crucial for delayed initialization and device-specific setup. ```csharp protected override void OnSessionStart(ARSession session) { base.OnSessionStart(session); StartCoroutine(InitializeCamera()); // NOTE: Start to do initialization for acquiring camera data, and / or wait for device ready. } ``` -------------------------------- ### Rokid UXR Session Origin Example Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/HMD/How-to-Create-EasyAR-HMD-Extension Example implementation of session origin definition within the RokidFrameSource, demonstrating conditional origin type based on UXR component availability. ```csharp protected override DeviceOriginType OriginType => #if EASYAR_HAVE_ROKID_UXR hasUXRComponents ? DeviceOriginType.None : #endif DeviceOriginType.XROrigin; ``` -------------------------------- ### Unity: Input Render Frame Motion Data Example Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/HMD/How-to-Create-EasyAR-HMD-Extension 在Unity中输入渲染帧运动数据的示例代码。此代码展示了如何获取渲染帧的时间戳、设备位姿和跟踪状态,并将其传递给EasyAR Sense。实际应用中,此数据用于设置3D相机的transform以渲染当前帧。请注意,此代码仅为简化示例,实际应用需参考com.easyar.sense.ext.hmdtemplate模板。 ```csharp private void InputRenderFrameMotionData() { double timestamp = 0e-9; var headPose = new Pose(); MotionTrackingStatus trackingStatus = (MotionTrackingStatus)(-1); HandleRenderFrameData(timestamp, headPose, trackingStatus); } ``` -------------------------------- ### Unity: Input Camera Frame Data Example Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/HMD/How-to-Create-EasyAR-HMD-Extension 在Unity中输入相机帧数据的示例代码。此代码展示了如何获取时间戳、相机图像数据、设备位姿和跟踪状态,并将其传递给EasyAR Sense。请注意,此代码仅为简化示例,实际应用需参考com.easyar.sense.ext.hmdtemplate模板。 ```csharp void TryInputCameraFrameData() { double timestamp; if (timestamp == curTimestamp) { return; } curTimestamp = timestamp; PixelFormat format; Vector2Int size; Vector2Int pixelSize; int bufferSize; var bufferO = TryAcquireBuffer(bufferSize); if (bufferO.OnNone) { return; } var buffer = bufferO.Value; IntPtr imageData; buffer.tryCopyFrom(imageData, 0, 0, bufferSize); var historicalHeadPose = new Pose(); MotionTrackingStatus trackingStatus = (MotionTrackingStatus)(-1); using (buffer) using (var image = Image.create(buffer, format, size.x, size.y, pixelSize.x, pixelSize.y)) { HandleCameraFrameData(deviceCamera, timestamp, image, cameraParameters, historicalHeadPose, trackingStatus); } } ``` -------------------------------- ### FrameRecorder.Configuration in C# Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/ApiReference/FrameRecorder This C# code demonstrates the Configuration field of the FrameRecorder class. This field allows setting up recording configurations before recording starts, specifically during the OnEnable or ARSession.StartSession phase. It allows the user to configure the recording parameters. ```C# public FrameRecorder.RecordingConfiguration Configuration 录制配置。可以在录制前设置(OnEnable或 ARSession.StartSession 之前)。 ``` -------------------------------- ### Setup Image Tracker (C#) Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/ApiReference/ARSessionFactory Configures an image tracker component within a filter to match the specified ARSessionPreset. Ensures the tracker functions correctly for image-based AR experiences. ```csharp public static void SetupImageTracker( GameObject filter, ARSessionFactory.ARSessionPreset preset) { // Configures the image tracker to meet preset requirements. } ``` -------------------------------- ### ARKitFrameSource Methods in C# Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/ApiReference/ARKitFrameSource This snippet outlines the methods available in the ARKitFrameSource class: Open and Close. It explains that Open initiates the device and will be called automatically if not manually invoked before ARSession starts. Close is used to shut down the device. ```C# public void Open() public void Close() ``` -------------------------------- ### Initialize EasyAR on Startup (C#) Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/ApiReference/EasyARSettings Controls whether EasyAR is initialized automatically when the application starts. It's generally recommended to keep this enabled as initialization has minimal performance impact. ```csharp public bool InitializeOnStartup // In startup, initialize EasyAR. EasyAR's initialization does not cause significant additional resource consumption, so it is usually possible to keep this option on. ``` -------------------------------- ### Setup Mega Tracker (C#) Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/ApiReference/ARSessionFactory Configures the Mega Tracker component within a filter based on the provided ARSessionPreset. This is suitable for more complex tracking scenarios. ```csharp public static void SetupMegaTracker( GameObject filter, ARSessionFactory.ARSessionPreset preset) { // Configures the Mega tracker to meet preset requirements. } ``` -------------------------------- ### FrameRecorder.AutoStart in C# Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/ApiReference/FrameRecorder This code snippet defines the AutoStart field in the FrameRecorder class within the C# programming language. The AutoStart field is a boolean that indicates whether recording should begin automatically after the ARSession starts. It affects the recording behavior of the application. ```C# public bool AutoStart Session启动后自动启动录制. ``` -------------------------------- ### EasyAR Sense Unity Plugin 文件结构和下载包内容 Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/GettingStarted/PluginIntroduction 展示EasyAR Sense Unity Plugin的三种下载包及其内部文件结构。包括标准版本、Mega版本和XR设备扩展包。每个包中包含具体的tgz文件和说明文档,用户可根据需求选择下载。 ```text . ├── EasyARSenseUnityPlugin_**.7z // EasyAR Sense Unity Plugin,不使用Mega时下载 │ ├── com.easyar.sense-**.tgz EasyAR Sense Unity Plugin(包含AVP及XREAL设备支持) │ ├── readme.cn.txt │ └── readme.en.txt ├── EasyARSenseUnityPluginForMega_**.7z // EasyAR Sense Unity Plugin (for Mega),使用Mega时下载 │ ├── com.easyar.mega-**.tgz EasyAR Mega Support(Mega Studio) │ ├── com.easyar.sense-**.tgz EasyAR Sense Unity Plugin(包含AVP及XREAL设备支持) │ ├── readme.cn.txt │ └── readme.en.txt └── EasyARSenseUnityPluginExtensions_**.7z // EasyAR Unity XR设备扩展包,使用Pico或Rokid时补充下载 ├── com.easyar.sense.ext.hmdtemplate-**.tgz 实现头显设备扩展的参考模板,不能直接运行 ├── com.easyar.sense.ext.pico-**.tgz Pico 扩展 ├── com.easyar.sense.ext.rokid-**.tgz Rokid 扩展 ├── readme.cn.txt └── readme.en.txt ``` -------------------------------- ### EasyARSettings.TargetGizmoConfig Class Overview Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/ApiReference/EasyARSettings.TargetGizmoConfig This documentation provides an overview of the EasyARSettings.TargetGizmoConfig class and its related configurations for Target Gizmos, including ImageTarget and ObjectTarget configurations. ```APIDOC ## EasyARSettings.TargetGizmoConfig Class ### Description Target的 Gizmos 配置。 ### Classes public class EasyARSettings.TargetGizmoConfig.ImageTargetConfig | ImageTarget 的 Gizmos 配置. --- public class EasyARSettings.TargetGizmoConfig.ObjectTargetConfig | ObjectTarget 的 Gizmos 配置. ### Fields #### ImageTarget - **ImageTarget** (EasyARSettings.TargetGizmoConfig.ImageTargetConfig) - ImageTarget 的 Gizmos 配置. #### ObjectTarget - **ObjectTarget** (EasyARSettings.TargetGizmoConfig.ObjectTargetConfig) - ObjectTarget 的 Gizmos 配置. ``` -------------------------------- ### Get Map Info - C# Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/ApiReference/SparseSpatialMapController Accesses information about the sparse map, such as its status and metadata. This property is only available after the MonoBehaviour's Start method has been called. ```csharp public SparseSpatialMapController.SparseSpatialMapInfo Info { get; } ``` -------------------------------- ### 在Awake中获取SparseSpatialMapBuilderFrameFilter实例 Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/GettingStarted/UpgradeGuide/SpatialMap_Sparse_Building_4000 使用Session.StateChanged事件监听器在ARSession准备就绪时,通过Assembly.FrameFilters的LINQ查询获取SparseSpatialMapBuilderFrameFilter实例。同时配置TouchControl的输入参数。 ```csharp Session.StateChanged += (state) => { if (state == ARSession.SessionState.Ready) { sparse = Session.Assembly.FrameFilters.Where(f => f is SparseSpatialMapBuilderFrameFilter).FirstOrDefault() as SparseSpatialMapBuilderFrameFilter; TouchControl.TurnOn(TouchControl.gameObject.transform, Session.Assembly.Camera, false, false, true, false); } }; ``` -------------------------------- ### ReceivedFrameCount C# Example Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/ApiReference/Extensions/PicoFrameSource This C# code snippet defines the 'ReceivedFrameCount' property within the PicoFrameSource class. It's an integer property used to get the number of received frames, often used for debugging. If this value stops increasing, it may indicate a hardware issue. ```C# public int ReceivedFrameCount { get; } ``` -------------------------------- ### 在Update中实现触摸点击测试功能 Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/GettingStarted/UpgradeGuide/SpatialMap_Sparse_Building_4000 处理触摸输入,获取屏幕坐标的视图点,使用sparse.Target的HitTest方法进行射线测试,并根据返回的点更新TouchControl的位置。需要检查sparse和sparse.Target的有效性。 ```csharp private void Update() { if (Input.touchCount == 1 && !EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId)) { var touch = Input.touches[0]; if (touch.phase == TouchPhase.Moved) { var viewPoint = new Vector2(touch.position.x / Screen.width, touch.position.y / Screen.height); if (sparse && sparse.Target) { var points = sparse.Target.HitTest(viewPoint); foreach (var point in points) { TouchControl.transform.position = sparse.Target.transform.TransformPoint(point); break; } } } } } ``` -------------------------------- ### FramePlayer Properties - C# Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/ApiReference/FramePlayer Exposes properties to control and query the state of frame playback. Includes properties for enabling/disabling playback, checking if playback has started or completed, getting the total length and current time, and determining if seeking or speed changes are possible. ```csharp public bool enabled { get; set; } // ARSession 运行时播放/暂停eif文件。在session启动后, MonoBehaviour .enabled为true时才会开始播放。 public bool IsStarted { get; } // 是否已启动播放。 public bool IsCompleted { get; } // 是否已完成播放。 public Optional Length { get; } // 预期的总播放时间。单位为秒。 public double Time { get; } // 已经播放的时间。 public bool IsSeekable { get; } // 是否可定位当前播放时刻。录制过程非正常中断时,可能导致缺少索引数据,而无法设定当前播放时间。 public bool IsSpeedChangeable { get; } // 是否可修改播放速度。 public double Speed { get; set; } // 当前的播放速度。 public Camera CameraCandidate { get; set; } // FramePlayer.Camera 的备选,仅当未使用Unity XR Origin时有效,如未设置会使用Camera.main。 ``` -------------------------------- ### 声明SparseSpatialMapBuilderFrameFilter变量 Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/GettingStarted/UpgradeGuide/SpatialMap_Sparse_Building_4000 在MapBuilding_SparseSample脚本中声明SparseSpatialMapBuilderFrameFilter类型的私有变量,用于替换旧版本的SparseSpatialMapWorkerFrameFilter。此变量存储对稀疏空间地图构建器的引用。 ```csharp private SparseSpatialMapBuilderFrameFilter sparse; ``` -------------------------------- ### Import Sample StreamingAssets for EasyAR Unity Plugin Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/GettingStarted/UpgradeGuide/ImageTracking_Targets_4000 Ensures necessary image target assets are imported into the StreamingAssets folder. It checks if specific files are missing and imports the 'ImageTargets.unitypackage' if they are and the package exists. This is crucial for sample functionality. ```csharp private static readonly string[] streamingAssetsFiles = new string[] { "EasyARSamples/ImageTargets/idback.etd", "EasyARSamples/ImageTargets/namecard.jpg", }; [UnityEditor.InitializeOnLoadMethod] static void ImportSampleStreamingAssets() { var pacakge = $"Packages/{UnityPackage.Name}/Samples~/StreamingAssets/ImageTargets/ImageTargets.unitypackage"; if (streamingAssetsFiles.Where(f => !System.IO.File.Exists(System.IO.Path.Combine(Application.streamingAssetsPath, f))).Any() && System.IO.File.Exists(System.IO.Path.GetFullPath(pacakge))) { UnityEditor.AssetDatabase.ImportPackage(pacakge, false); } } ``` -------------------------------- ### FrameRecorder.enabled Property in C# Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/ApiReference/FrameRecorder The C# code demonstrates the enabled property of the FrameRecorder class. It allows starting and stopping the recording during ARSession runtime. The recording begins when MonoBehaviour.enabled is true after the session starts. ```C# public bool enabled { get; set; } ARSession 运行时开始/停止录制。在session启动后, MonoBehaviour .enabled为true时才会开始录制。 MonoBehaviour .enabled默认为false,且会在 ARSession .Awake中设置为 FrameRecorder.AutoStart 。 ``` -------------------------------- ### FrameRecorder.OnRecording in C# Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/ApiReference/FrameRecorder This C# code provides the OnRecording event from the FrameRecorder class. The event, of type RecordStartEvent, is triggered when recording starts, with the file name as a callback parameter. It is used to notify when a recording is started. ```C# public FrameRecorder.RecordStartEvent OnRecording 录制启动的事件。 ``` -------------------------------- ### ARCoreFrameSource Class: enabled Property in C# Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/ApiReference/ARCoreFrameSource Manages the start and stop of video stream acquisition during ARSession runtime. Data acquisition begins only when the ARSession is started and the MonoBehaviour.enabled property is true. This allows for controlling camera feed based on the component's active state. ```csharp public bool enabled { get; set; } ``` -------------------------------- ### Generic Camera Initialization and Data Input Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/HMD/How-to-Create-EasyAR-HMD-Extension This C# code demonstrates a generic coroutine for initializing camera parameters and setting up the device camera for EasyAR. It includes placeholders for device calibration data, such as image size, camera parameters, device type, and orientation. It also initiates a coroutine to continuously input device data into EasyAR. ```csharp private IEnumerator InitializeCamera() { yield return new WaitUntil(() => false); // NOTE: Wait until device initialized, so don't forget to change this endless waiting sample. var cameraModel = (CameraModelType)(-1); // NOTE: Replace with device calibration data. Use CameraModelType.Pinhole if camera model is pinhole. var imageSize = new Vector2Int(); // NOTE: Replace with device calibration data. var cameraParamList = new List(); // NOTE: Replace with device calibration data. When using Mega, CLS v3 or later is required to support non-pinhole. var cameraDeviceType = CameraDeviceType.Back; // NOTE: Must set to Back. var cameraOrientation = 0; // NOTE: Replace with device calibration data. Acceptable value: 0, 90, 180, 270. var parameters = CameraParameters.tryCreateWithCustomIntrinsics(imageSize.ToEasyARVector(), cameraParamList, cameraModel, cameraDeviceType, cameraOrientation); // NOTE: If online optimize exists, generate in TryInputCameraFrameData instead. if (parameters.OnNone) { throw new InvalidOperationException("Invalid intrinsics in CameraParameters.tryCreateWithCustomIntrinsics"); } cameraParameters = parameters.Value; var frameRateRange = new Vector2(0, 0); // NOTE: Replace with device calibration data. Set lower bound and upper bound to the same value if fps is constant. var axisSystem = AxisSystemType.Unity; // NOTE: Replace with the one you need. All poses and extrinsics should use the same axis system. var extrinsics = new DeviceFrameSourceCamera.CameraExtrinsics(new Pose(), true); // NOTE: Replace with device calibration data, using above axis system. deviceCamera = new DeviceFrameSourceCamera(cameraDeviceType, cameraOrientation, imageSize, frameRateRange, extrinsics, axisSystem); started = true; // NOTE: If you need to control start/stop in other timing, make sure to set started there. StartCoroutine(InputDeviceData()); // NOTE: Start to input data into EasyAR. throw new NotImplementedException("Please finish this method using your device SDK API"); } ``` -------------------------------- ### AREngineFrameSource Methods Documentation Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/ApiReference/AREngineFrameSource This snippet details the core methods for managing the AREngineFrameSource device. 'Open' initiates the device, and 'Close' terminates it. The device will automatically open upon ARSession start if neither 'Open' nor 'Close' is manually invoked. ```csharp public void Open() // Opens the device. If AREngineFrameSource.Open and AREngineFrameSource.Close are not manually called, the device will automatically open upon ARSession start. public void Close() // Closes the device. ``` -------------------------------- ### FramePlayer Methods - C# Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/ApiReference/FramePlayer Provides methods to control the playback of eif files. Includes Play to start playback, Stop to halt it, and Seek to set a specific playback time. Playback may start automatically after ARSession initialization if not manually controlled. ```csharp public bool Play() // 播放eif文件。如果未手动调用 FramePlayer.Play 和 FramePlayer.Stop , ARSession 启动后会自动 FramePlayer.Play 。 // 在session启动后才能使用。 public void Stop() // 停止播放eif文件。 public bool Seek(double time) // 设定当前播放时刻。单位为秒。如果缺少索引数据,则返回false。 ``` -------------------------------- ### C# - OnSessionStart Method Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/ApiReference/ExternalDeviceMotionFrameSource Handles session startup, invoked during ARSession.StartSession. This method is designed for deferred initialization and is where AR-specific initialization should occur. ```C# protected override void OnSessionStart( ARSession session) ``` -------------------------------- ### Get and Set Name in C# (EasyAR) Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/ApiReference/Sense/ImageTargetParameters This code snippet shows how to get and set the name of an ImageTargetParameters object in C#. The target name is used to differentiate between various targets within the EasyAR system. It is important for identifying and managing different targets in augmented reality applications. ```C# public virtual string name() 获取target名字。名字用来区分target。 public virtual void setName(string name) 设置target名字。 ``` -------------------------------- ### Get and Set Meta Data in C# (EasyAR) Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/ApiReference/Sense/ImageTargetParameters Shows how to get and set metadata associated with an ImageTargetParameters object in C#. Metadata provides additional information about the target, which can be utilized for various purposes within the augmented reality application. This is useful for storing extra information related to the image target. ```C# public virtual string meta() 获取meta data。 public virtual void setMeta(string meta) 设置meta data。 ``` -------------------------------- ### Get and Set Image in C# (EasyAR) Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/ApiReference/Sense/ImageTargetParameters Demonstrates how to get and set the image associated with an ImageTargetParameters object in C#. It retrieves or sets the image data, which is crucial for defining the visual representation of the target. This functionality is essential for loading and manipulating images for augmented reality experiences within the EasyAR framework. ```C# public virtual Image image() 获取图像。 public virtual void setImage( Image image) 设置图像. ``` -------------------------------- ### Unity Package Structure for Headset Extension Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/HMD/How-to-Create-EasyAR-HMD-Extension This illustrates the recommended file layout for a Unity package, commonly used for headset extensions. It highlights key directories like Runtime, Samples, Editor, and the package.json manifest file. Modifying scripts within the Runtime directory is central to developing the extension. ```json { ".", "├── CHANGELOG.md", "├── Documentation~", "├── Editor", "├── LICENSE.md", "├── package.json", "├── Runtime", "└── Samples~", "└── Combination_BasedOn_HMD" } ``` -------------------------------- ### Get and Set Scale in C# (EasyAR) Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/ApiReference/Sense/ImageTargetParameters Demonstrates getting and setting the scale of an image within the ImageTargetParameters class in C#. The scale represents the ratio between the image's physical width and 1 meter, with a default value of 1. It is critical to also set the model scale in the rendering engine for proper visual representation. ```C# public virtual float scale() 图像的缩放比例。其值为图像宽度的物理大小与1米的比值,默认值为1。 public virtual void setScale(float scale) 设置图像的缩放比例。其值为图像宽度的物理大小与1米的比值,默认值为1。 还需要在渲染引擎中单独设置此模型缩放。 ``` -------------------------------- ### Enable Target Data File Gizmos (C#) Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/ApiReference/EasyARSettings.TargetGizmoConfig.ImageTargetConfig Enables gizmos for Image Targets sourced from target data files (ImageTargetController.TargetDataFileSourceData). This loads and displays the gizmo in the Unity Editor. Excessive use can affect editor startup performance but not runtime performance on devices. ```csharp public bool EnableTargetDataFile ``` -------------------------------- ### Configure AREngine SDK (C#) Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/ApiReference/EasyARSettings Sets the AREngine SDK configuration. Options include using EasyAR's AREngineInterop, an external AREngine distribution, or disabling AREngine entirely. ```csharp public EasyARSettings.AREngineType AREngineSDK // AREngine SDK configuration. To use EasyAR AREngineInterop and the AREngine distributed with it, set it to EasyARSettings.AREngineType.AREngineInterop. To use other AREngine distributions, set it to EasyARSettings.AREngineType.External. If you do not want AREngine to be packaged into the app, set it to EasyARSettings.AREngineType.Disabled. ``` -------------------------------- ### C# - CameraFrameStarted Property Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/ApiReference/ExternalDeviceMotionFrameSource Indicates whether the camera frame input has started. This property is accessed throughout the ARSession lifecycle. ```C# protected virtual abstract bool CameraFrameStarted { } ``` -------------------------------- ### C# - Display Property Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/ApiReference/ExternalDeviceMotionFrameSource Provides display system information. You can use Display.DefaultSystemDisplay or Display.DefaultHMDDisplay to get default display information. ```C# protected virtual abstract IDisplay Display { } ``` -------------------------------- ### Get Default Component Name (C#) Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/ApiReference/ARSessionFactory Returns the default name for a component. This method is useful for consistent naming conventions across components. ```csharp public static string DefaultName() { // Returns the default name of a component. } ``` -------------------------------- ### Log Image Target Loading Status with Debug Output - C# Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/GettingStarted/UpgradeGuide/ImageTracking_Targets_4000 Logs detailed information about loading an image target into the tracker using Debug.LogFormat. Outputs target runtime ID, name, size, tracker name, and loading status. Handles null target references gracefully by checking if target exists before accessing its runtime ID. ```C# Debug.LogFormat("Load target {{id = {0}, name = {1}, size = {2}}} into {3} => {4}", controller.Target == null? controller.Target.runtimeID():string.Empty, controller.Target.name(), controller.Size, controller.Tracker.name, status); ``` -------------------------------- ### ImageMaterial Class Overview Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/ApiReference/ImageMaterial Provides an overview of the ImageMaterial class, including its purpose, properties, and methods for managing image rendering. ```APIDOC ## ImageMaterial Class ### Description 用于渲染 Image 的材质。 (Material for rendering Images.) ### Properties #### Material * **Type**: `Material` * **Description**: The material used for rendering. ### Methods #### Constructor * **Signature**: `public ImageMaterial(Image image)` * **Description**: Creates a material suitable for rendering the given image. #### Dispose * **Signature**: `public void Dispose()` * **Description**: Releases resources associated with the ImageMaterial. #### CanReplace * **Signature**: `public bool CanReplace(Image image)` * **Description**: Checks if the image used in the material can be replaced with the provided image. * **Parameters**: * `image` (Image) - The image to check for replacement compatibility. * **Returns**: `bool` - True if the image can be replaced, false otherwise. #### Replace * **Signature**: `public void Replace(Image image)` * **Description**: Replaces the current Image in the material with the provided image. This operation only supports images of the same format, size, and pixel dimensions. * **Parameters**: * `image` (Image) - The new image to set for the material. ``` -------------------------------- ### GET IsTracked Property Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/ApiReference/SurfaceTargetController Checks whether the surface target is currently being tracked by the system. Returns a boolean value indicating the tracking status of the target. ```APIDOC ## GET IsTracked ### Description Determines whether the target is currently being tracked in the AR scene. ### Method GET (Property) ### Property Signature ```csharp public bool IsTracked { get; } ``` ### Returns - **bool** - True if the target is being tracked, false otherwise ### Usage Notes - Use this property to check tracking status before performing target-dependent operations - Returns false when tracking is lost or target is not visible ``` -------------------------------- ### Enable Texture2D Gizmos (C#) Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/ApiReference/EasyARSettings.TargetGizmoConfig.ImageTargetConfig Enables gizmos for Image Targets sourced from Texture2D objects (ImageTargetController.Texture2DSourceData). This displays the gizmo in the Unity Editor. Too many such targets may slow down editor startup but will not affect runtime performance on devices. ```csharp public bool EnableTexture2D ``` -------------------------------- ### Get Motion Input Data Timestamp (C#) Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/ApiReference/Sense/MotionInputData Retrieves the timestamp of the motion input data in seconds. This is a virtual method. ```csharp public virtual double timestamp() ``` -------------------------------- ### Configure Target Gizmos (C#) Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/ApiReference/EasyARSettings Manages the Gizmos configuration for ImageTarget and ObjectTarget, used for visualization in the Unity editor. ```csharp public EasyARSettings.TargetGizmoConfig GizmoConfig // Gizmos configuration for ImageTarget and ObjectTarget. ``` -------------------------------- ### Setup Object Tracker (C#) Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/ApiReference/ARSessionFactory Configures an object tracker component within a filter according to the specified ARSessionPreset. This is used for object recognition and tracking in AR. ```csharp public static void SetupObjectTracker( GameObject filter, ARSessionFactory.ARSessionPreset preset) { // Configures the object tracker to meet preset requirements. } ``` -------------------------------- ### GET ActiveController Property Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/ApiReference/SurfaceTargetController Retrieves the ActiveController that manages the GameObject activation state of the surface target. This property allows control over whether the target is active through MonoBehaviour.enabled settings. ```APIDOC ## GET ActiveController ### Description Gets the GameObject.activeSelf controller for the surface target. Control target activation by setting MonoBehaviour.enabled to false. ### Method GET (Property) ### Property Signature ```csharp public ActiveController ActiveController { get; } ``` ### Returns - **ActiveController** (ActiveController) - Controller for managing GameObject active state ### Usage Notes - Setting MonoBehaviour.enabled to false will deactivate the controller - Use this property to programmatically control target visibility and processing ``` -------------------------------- ### SparseSpatialMapController Methods Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/ApiReference/SparseSpatialMapController This section details the methods available in the SparseSpatialMapController class, including the HitTest method for performing raycasts against the point cloud. ```APIDOC ## SparseSpatialMapController Methods ### HitTest * **Description**: Performs a Hit Test against the current point cloud, returning a list of coordinates (n >= 0) along a ray from near to far from the camera. `pointInView` must be normalized to `[0, 1]^2`. Available only when `SparseSpatialMapController.IsDirectlyTracked` is true. * **Method**: `public List HitTest(Vector2 pointInView)` * **Parameters**: * **pointInView** (Vector2) - Required - The normalized 2D point in the view. * **Returns**: `List` - A list of hit points. ``` -------------------------------- ### Get Default Component Name by Type (C#) Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/ApiReference/ARSessionFactory Returns the default name for a component based on its type. This overloaded method provides flexibility in obtaining default names. ```csharp public static string DefaultName(Type type) { // Returns the default name of a component. } ``` -------------------------------- ### Setup Frame Filters (C#) Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/ApiReference/ARSessionFactory Configures a list of frame filters to meet the requirements of a specified ARSessionPreset. This method helps align filters with desired AR functionalities. ```csharp public static void SetupFrameFilters(List< GameObject > filters, ARSessionFactory.ARSessionPreset preset) { // Configures frame filters to meet preset requirements. } ``` -------------------------------- ### Control MegaBlockTracker Enable/Disable Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/Samples/Mega/MegaBlock_Basic Demonstrates the method to control the activation and deactivation of the `MegaBlockTracker`. By setting `MegaTrackerFrameFilter.enabled`, the tracking can be started or stopped, which affects the behavior of the Block tracking and its visual output. ```csharp // Implied: `MegaTrackerFrameFilter.enabled = true/false;` // This controls the overall tracking state. ``` -------------------------------- ### VideoRecorder Class Methods Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/ApiReference/VideoRecorder Includes methods for controlling the video recording process: StartRecording to begin recording, StopRecording to end it, and RecordFrame to input a single frame for recording. StartRecording requires callbacks for success and errors. ```csharp public void StartRecording(Action onStart, Action onRecordError) /* 开始录屏。录制的视频数据需要通过 VideoRecorder.RecordFrame 不断传入。 */ public bool StopRecording() /* 停止录屏。 */ public void RecordFrame(RenderTexture texture) /* 使用 texture 录制一帧数据。 */ ``` -------------------------------- ### Enable Image File Gizmos (C#) Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/ApiReference/EasyARSettings.TargetGizmoConfig.ImageTargetConfig Enables gizmos for Image Targets sourced from image files (ImageTargetController.ImageFileSourceData). This loads and displays the image gizmo in the Unity Editor. Overuse may impact editor performance but not runtime performance on devices. ```csharp public bool EnableImageFile ``` -------------------------------- ### Update CreateTargets() with New API for EasyAR Unity Plugin Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/GettingStarted/UpgradeGuide/ImageTracking_Targets_4000 This function is refactored to utilize the updated API for dynamically loading image targets. It demonstrates creating targets from both `.etd` files and JSON string definitions, specifying path types and source data. The code also includes instantiating associated GameObjects for each target. ```csharp private void CreateTargets() { // dynamically load from image (*.jpg, *.png) var targetController = CreateTargetNode("ImageTarget-argame00"); targetController.Tracker = imageTracker; targetController.Source = new ImageTargetController.TargetDataFileSourceData { PathType = PathType.StreamingAssets, Path = "idback.etd", }; //targetController.SourceType = ImageTargetController.DataSource.ImageFile; //targetController.ImageFileSource.PathType = PathType.StreamingAssets; //targetController.ImageFileSource.Path = "sightplus/argame00.jpg"; //targetController.ImageFileSource.Name = "argame00"; //targetController.ImageFileSource.Scale = 0.1f; GameObject duck02 = Instantiate(Resources.Load("duck02")) as GameObject; duck02.transform.parent = targetController.gameObject.transform; // dynamically load from json string ... foreach (var image in imageJson.images) { targetController = CreateTargetNode("ImageTarget-" + image.name); targetController.Tracker = imageTracker; //targetController.ImageFileSource.PathType = PathType.StreamingAssets; //targetController.ImageFileSource.Path = image.image; //targetController.ImageFileSource.Name = image.name; //targetController.ImageFileSource.Scale = image.scale; targetController.Source = new ImageTargetController.ImageFileSourceData { Path = image.image, Name = image.name, Scale = 0.1f, }; var duck03 = Instantiate(Resources.Load("duck03")) as GameObject; duck03.transform.parent = targetController.gameObject.transform; } } ``` -------------------------------- ### ARCoreFrameSource Class: Open Method in C# Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/ApiReference/ARCoreFrameSource Manually opens the ARCore camera device. If ARCoreFrameSource.Open and ARCoreFrameSource.Close are not called manually, the ARSession will automatically call ARCoreFrameSource.Open upon starting. ```csharp public void Open(); ``` -------------------------------- ### Update Sparse Map Localization Callbacks in C# Source: https://help.easyar.cn/EasyAR%20Sense%20Unity%20Plugin/latest/GettingStarted/UpgradeGuide/SpatialMap_Sparse_Localizing_4000 This code snippet demonstrates how to update the local sparse map localization callbacks in the Start method. It replaces the old status printing with new event handlers for MapController.TargetFound and MapController.TargetLost, essential for compatibility with newer EasyAR versions. ```csharp private void Start() { var launcher = "AllSamplesLauncher"; if (Application.CanStreamedLevelBeLoaded(launcher)) { var button = BackButton.GetComponent