/// <summary> /// 指定アセットにMissingのプロパティがあれば、それをmissingListに追加する /// </summary> /// <param name="path">Path.</param> private static void SearchMissing(string path) { // 指定パスのアセットを全て取得 IEnumerable <UnityEngine.Object> assets = AssetDatabase.LoadAllAssetsAtPath(path); // 各アセットについて、Missingのプロパティがあるかチェック foreach (UnityEngine.Object obj in assets) { if (obj == null) { continue; } if (obj.name == "Deprecated EditorExtensionImpl") { continue; } // SerializedObjectを通してアセットのプロパティを取得する SerializedObject sobj = new SerializedObject(obj); SerializedProperty property = sobj.GetIterator(); while (property.Next(true)) { // プロパティの種類がオブジェクト(アセット)への参照で、 // その参照がnullなのにもかかわらず、参照先インスタンスIDが0でないものはMissing状態! if (property.propertyType == SerializedPropertyType.ObjectReference && property.objectReferenceValue == null && property.objectReferenceInstanceIDValue != 0) { // Missing状態のプロパティリストに追加する AssetParameterData assetParameterData = new AssetParameterData(); assetParameterData.obj = obj; assetParameterData.path = path; assetParameterData.name = property.displayName; m_MissingList.Add(assetParameterData); } } } }
private static void checkObject(UnityEngine.Object obj, string path) { if (obj == null) { return; } if (obj.name == "Deprecated EditorExtensionImpl") { return; } Debug.Log("LOG OF " + obj.name); string log = obj.name; if (obj is GameObject) { var go = obj as GameObject; List <SerializedObject> sObjs = new List <SerializedObject>(); sObjs.AddRange(go.GetComponents <Component>() .Where(x => x != null) .Select(x => new SerializedObject(x))); foreach (SerializedObject so in sObjs) { log += "\ntarget: " + so.targetObject; SerializedProperty property = so.GetIterator(); while (property.Next(true)) { log += "\n" + property.displayName + " (" + property.propertyType + ")"; // プロパティがオブジェクト参照 かつ // 参照の値がnull かつ // 参照のインスタンスIDが0以外 であれば、「Missing」と判定 if (property.propertyType == SerializedPropertyType.ObjectReference && property.objectReferenceValue == null && property.objectReferenceInstanceIDValue != 0) { Debug.Log("<color=red>MISSING!!</color>\nobj: " + obj.name + "\nproperty displayname: " + property.displayName + "\n" + "\nproperty name: " + property.name); // Missing状態のプロパティリストに追加する AssetParameterData data = new AssetParameterData() { obj = obj, path = path, property = property }; // そのままだとPrefab Parent Objectがnullのものまで返して見づらいので、省く if (data.property.displayName == "Prefab Parent Object") { continue; } missingList.Add(data); break; } } } } Debug.Log(log); }