// -------------------------------------------------------------------------------------------------------------------- // // Copyright (c) VRMADA, All rights reserved. // // -------------------------------------------------------------------------------------------------------------------- using System; using UnityEngine; namespace UltimateXR.Manipulation { /// /// Enables nicer formatting of the grab point this shape is bound to in the editor. It will show strings like Main, /// Additional 0, /// Additional 1... etc. because there is an CustomPropertyDrawer for this class (see GrabPointIndexDrawer). /// [Serializable] public class UxrGrabPointIndex { #region Inspector Properties/Serialized Fields [SerializeField] private int _index; #endregion #region Constructors & Finalizer /// /// Constructor. /// /// Grab point index public UxrGrabPointIndex(int index) { _index = index; } #endregion #region Public Methods /// /// Gets the display name of a given grabbable object index. /// /// Grabbable object /// Grab point index /// Display name public static string GetIndexDisplayName(UxrGrabbableObject grabbableObject, int index) { // If we have a custom name set up in the editor, use it UxrGrabPointInfo grabPointInfo = grabbableObject.GetGrabPoint(index); if (grabPointInfo != null && !string.IsNullOrEmpty(grabPointInfo.EditorName)) { return grabPointInfo.EditorName; } // Use better formatted default name if (index == 0) { return MainGrabPointName; } return AdditionalGrabPointPrefix + " " + (index - 1); } /// /// Gets the grab point index of a given display name. /// /// Display name to get the index for /// Grab point index public static int GetIndexFromDisplayName(string name) { if (name == MainGrabPointName) { return 0; } if (name.StartsWith(AdditionalGrabPointPrefix)) { return int.Parse(name.Remove(0, AdditionalGrabPointPrefix.Length + 1)) + 1; } return -1; } #endregion #region Event Handling Methods /// /// Converts from to integer. /// /// Grab point index object /// Integer public static implicit operator int(UxrGrabPointIndex grabPointIndex) { return grabPointIndex._index; } /// /// Converts from integer to . /// /// Grab point index /// Grab point index object public static implicit operator UxrGrabPointIndex(int index) { return new UxrGrabPointIndex(index); } #endregion #region Private Types & Data private const string MainGrabPointName = "Main Grab Point"; private const string AdditionalGrabPointPrefix = "Additional Grab Point"; #endregion } }