using System using System Collections using System Collections Generic

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using Object = UnityEngine.Object;
public class ComponentInjector : MonoBehaviour {
private void Start() {
AssetDatabase.StartAssetEditing();
string[] guids = AssetDatabase.FindAssets(" t:GameObject", new string[] {"Assets/Prefabs"});
foreach (string g in guids) {
string path = AssetDatabase.GUIDToAssetPath(g);
Object prefab = AssetDatabase.LoadAssetAtPath(path, typeof(GameObject));
GameObject prefabAsObject = prefab as GameObject;
prefabAsObject.AddComponent<SpriteRenderer>();
}
AssetDatabase.StopAssetEditing();
AssetDatabase.SaveAssets();
}
}