// // /*=============================================================================== // // Copyright (C) 2024 PhantomsXR Ltd. All Rights Reserved. // // // // This file is part of the Phantom.XRMOD.PackageTools.Editor. // // // // The Snake 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.IO; using System.Linq; using UnityEditor; using UnityEngine; namespace Phantom.XRMOD.UnityFusion.Editor { public class FindMissingScriptsUtility { [MenuItem("Tools/XR-MOD/Fix XRMOD Scripts Missing")] static void FindMissingScriptsMenuItem() { string[] tmp_PrefabPaths = AssetDatabase.GetAllAssetPaths() .Where(_path => _path.EndsWith(".prefab", System.StringComparison.OrdinalIgnoreCase)).ToArray(); foreach (string tmp_PrefabPath in tmp_PrefabPaths) { GameObject tmp_Prefab = AssetDatabase.LoadAssetAtPath(tmp_PrefabPath); FixMissingScripts(tmp_Prefab); } } private static void FixMissingScripts(GameObject obj) { foreach (Component component in obj.GetComponentsInChildren()) { if (component == null) { var tmp_TargetPath = AssetDatabase.GetAssetPath(obj); tmp_TargetPath = tmp_TargetPath.Replace("Assets", Application.dataPath); if (File.Exists($"{tmp_TargetPath}")) { var tmp_MetaData = File.ReadAllText($"{tmp_TargetPath}"); tmp_MetaData = tmp_MetaData.Replace("ea3532afe7eb7451b801ba78a08a9fad", "d4693dad2f205416d91c259338d750af"); tmp_MetaData = tmp_MetaData.Replace("ea3532afe7eb7451b801ba78a08a9fad", "97b473716bb7b42df9db8364c573e021"); tmp_MetaData = tmp_MetaData.Replace("d4693dad2f205416d91c259338d750af", "97b473716bb7b42df9db8364c573e021"); var tmp_EditedMetaData = tmp_MetaData.Replace("759573810", "11500000"); File.WriteAllText($"{tmp_TargetPath}", tmp_EditedMetaData); AssetDatabase.Refresh(); AssetDatabase.ImportAsset($"{tmp_TargetPath}.prefab"); Debug.Log($"Missing Component in {obj.name}"); } } } } } }