/**************************************************************************** * Copyright 2019 Nreal Techonology Limited. All rights reserved. * * This file is part of NRSDK. * * https://www.nreal.ai/ * *****************************************************************************/ namespace NRKernal { using System; using UnityEngine; #if UNITY_EDITOR using UnityEditor; using System.IO; #endif /// Hold the total infomation of a image data base item. [Serializable] public struct NRTrackingImageDatabaseEntry { /// The name assigned to the tracked image. public string Name; /// The width of the image in meters. public float Width; /// The height of the image in meters. public float Height; /// The quality of the image. public string Quality; /// The Unity GUID for this entry. public string TextureGUID; /// Contructs a new Augmented Image database entry. /// The image name. /// The image width in meters or 0 if the width is unknown. /// The height of the image in meters. public NRTrackingImageDatabaseEntry(string name, float width, float height) { Name = name; TextureGUID = string.Empty; Width = width; Height = height; Quality = string.Empty; TextureGUID = string.Empty; } #if UNITY_EDITOR /// Contructs a new Augmented Image database entry. /// The image name. /// The texture. /// The image width in meters or 0 if the width is unknown. /// The height of the image in meters. public NRTrackingImageDatabaseEntry(string name, Texture2D texture, float width, float height) { Name = name; TextureGUID = string.Empty; Width = width; Quality = string.Empty; Height = height; Texture = texture; } /// Contructs a new Augmented Image database entry. /// The image name. /// The texture. public NRTrackingImageDatabaseEntry(string name, Texture2D texture) { Name = name; TextureGUID = string.Empty; Width = 0; Quality = string.Empty; Height = 0; Texture = texture; } /// Contructs a new Augmented Image database entry. /// The texture. public NRTrackingImageDatabaseEntry(Texture2D texture) { Name = "Unnamed"; TextureGUID = string.Empty; Width = 0; Quality = string.Empty; Height = 0; Texture = texture; } /// Gets or sets the texture. /// The texture. public Texture2D Texture { get { return AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(TextureGUID)); } set { string path = AssetDatabase.GetAssetPath(value); TextureGUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(value)); var fileName = Path.GetFileName(path); Name = fileName.Replace(Path.GetExtension(fileName), string.Empty); } } /// Convert this object into a string representation. /// A string that represents this object. public override string ToString() { return string.Format("Name:{0} Quality:{1}", Name, Quality); } #endif } }