// /*=============================================================================== // Copyright (C) 2020 PhantomsXR Ltd. All Rights Reserved. // // This file is part of the AR-MOD SDK. // // The AR-MOD SDK cannot be copied, distributed, or made available to // third-parties for commercial purposes without written permission of PhantomsXR Ltd. // // Contact info@phantomsxr.com for licensing requests. // ===============================================================================*/ using System; using System.IO; using System.Linq; using System.Threading.Tasks; using UnityEngine; using UnityEngine.Audio; using UnityEngine.U2D; using UnityEngine.Video; using Object = UnityEngine.Object; namespace Phantom.XRMOD.XRMODPackageTools.Runtime { internal static class Utility { public static string SearchFolderByName(string _folderName) { var tmp_Directorys = Directory.GetDirectories(Application.dataPath, "*", SearchOption.AllDirectories); var tmp_DirectoryInfo = tmp_Directorys.FirstOrDefault(_folder => _folder.EndsWith(_folderName)); return tmp_DirectoryInfo; } public static string SearchFileByName(string _rootPath, string _fileName, string _suffix = "*") { switch (_suffix) { case "ScriptableObject": case "Mesh": _suffix = "asset"; break; case "Sprite": _suffix = "*"; break; case "AudioClip": _suffix = "*"; break; case "VideoClip": _suffix = "*"; break; } var tmp_FilesPaths = Directory.GetFiles(_rootPath, $"{_fileName}.{_suffix}", SearchOption.AllDirectories); return tmp_FilesPaths.Length > 0 ? tmp_FilesPaths[0] : null; } public static string ShortenPath(string _fullPath) { var tmp_AssetIdx = _fullPath.IndexOf("Assets", StringComparison.Ordinal); var tmp_ShortenPath = _fullPath.Substring(tmp_AssetIdx, _fullPath.Length - tmp_AssetIdx); return tmp_ShortenPath; } public static string TypeMapping() where T : UnityEngine.Object { var tmp_Type = typeof(T); string tmp_Suffix = "*"; if (tmp_Type == typeof(GameObject)) { tmp_Suffix = "prefab"; } else if (tmp_Type == typeof(Animator)) { tmp_Suffix = "controller"; } else if (tmp_Type == typeof(AnimationClip)) { tmp_Suffix = "ani"; } else if (tmp_Type == typeof(AudioClip)) { tmp_Suffix = "AudioClip"; } else if (tmp_Type == typeof(Material)) { tmp_Suffix = "Material"; } else if (tmp_Type == typeof(Texture2D)) { tmp_Suffix = "Texture2D"; } else if (tmp_Type == typeof(Mesh)) { tmp_Suffix = "Mesh"; } else if (tmp_Type == typeof(ScriptableObject) || tmp_Type.IsSubclassOf(typeof(ScriptableObject))) { tmp_Suffix = "ScriptableObject"; } else if (tmp_Type == typeof(Shader)) { tmp_Suffix = "Shader"; } else if (tmp_Type == typeof(VideoClip)) { tmp_Suffix = "VideoClip"; } else if (tmp_Type == typeof(Sprite)) { tmp_Suffix = "Sprite"; } else if (tmp_Type == typeof(SpriteAtlas)) { tmp_Suffix = "SpriteAtlas"; } else if (tmp_Type == typeof(AudioMixer)) { tmp_Suffix = "mixer"; } return tmp_Suffix; } internal static async void FixEditorAndroidShaders() { #if UNITY_ANDROID && UNITY_EDITOR await Task.Delay(500); var tmp_AllRenderers = Object.FindObjectsByType(FindObjectsInactive.Include, FindObjectsSortMode.None); foreach (Renderer tmp_Renderer in tmp_AllRenderers) { foreach (Material tmp_Mat in tmp_Renderer.materials) { tmp_Mat.shader = Shader.Find(tmp_Mat.shader.name); } } #else await Task.Yield(); #endif } } }