// --------------------------------------------------------------------------------------------------------------------
//
// Copyright (c) VRMADA, All rights reserved.
//
// --------------------------------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using UltimateXR.Avatar;
using UltimateXR.Avatar.Controllers;
using UltimateXR.Core;
using UltimateXR.Devices;
using UltimateXR.Manipulation;
using UnityEditor;
using Object = UnityEngine.Object;
namespace UltimateXR.Editor
{
///
/// Static class containing utilities for use in the Unity Editor.
///
public static partial class UxrEditorUtils
{
#region Public Methods
///
/// Shows an error message window telling the user the selected folder must be in the current project.
///
public static void ShowFolderNotInProjectError()
{
EditorUtility.DisplayDialog(UxrConstants.Editor.Error, "Folder must be in the current project.", UxrConstants.Editor.Ok);
}
///
/// Checks for the presence of in scene.
///
/// Boolean telling the result
public static bool CheckManagerInScene()
{
return Object.FindObjectOfType() != null;
}
///
/// Checks for the presence of an in scene.
///
/// Boolean telling the result
public static bool CheckAvatarInScene()
{
return Object.FindObjectOfType() != null;
}
///
/// Checks for the presence of an in scene that has
/// components set up.
///
/// Boolean telling the result
public static bool CheckAvatarInSceneWithGrabbing()
{
UxrAvatar avatar = Object.FindObjectOfType();
if (avatar == null)
{
return false;
}
return avatar.GetComponentInChildren() != null;
}
///
/// Checks for the presence of an in scene that has
/// components set up and a controller that has grab events.
///
/// Boolean telling the result
public static bool CheckAvatarInSceneWithGrabController()
{
UxrAvatar avatar = Object.FindObjectOfType();
if (avatar == null)
{
return false;
}
if (avatar.GetComponentInChildren() == null)
{
return false;
}
UxrStandardAvatarController controller = avatar.GetComponentInChildren();
foreach (UxrAvatarControllerEvent controllerEvent in controller.LeftControllerEvents.Concat(controller.RightControllerEvents))
{
if (controllerEvent.TypeOfAnimation == UxrAnimationType.LeftHandGrab || controllerEvent.TypeOfAnimation == UxrAnimationType.RightHandGrab)
{
return true;
}
}
return false;
}
///
/// Returns a list of button names to be used in inspector components (EditorGUI.MaskField specifically).
///
/// List with names of available buttons
public static List GetControllerButtonNames()
{
List buttonNames = new List(Enum.GetNames(typeof(UxrInputButtons)));
buttonNames.Remove(UxrInputButtons.None.ToString());
buttonNames.Remove(UxrInputButtons.Any.ToString());
buttonNames.Remove(UxrInputButtons.Everything.ToString());
return buttonNames;
}
///
/// Returns a list of avatar render modes removing composition flags
///
/// List of available buttons
public static List GetAvatarRenderModeNames()
{
List renderModeNames = new List(Enum.GetNames(typeof(UxrAvatarRenderModes)));
renderModeNames.Remove(UxrAvatarRenderModes.None.ToString());
renderModeNames.Remove(UxrAvatarRenderModes.AllControllers.ToString());
renderModeNames.Remove(UxrAvatarRenderModes.AllControllersAndAvatar.ToString());
return renderModeNames;
}
#endregion
}
}