Пример #1
0
    public static void GenBulletBatch()
    {
        if (!GenerateBullet.CheckCanGenBulletBatch())
        {
            return;
        }
        string[] strs    = Selection.assetGUIDs;
        string   topPath = AssetDatabase.GUIDToAssetPath(strs[0]);

        string[] findFolder = new string[] { topPath };

        string[] models = AssetDatabase.FindAssets("t:Model", findFolder);
        foreach (string guid in models)
        {
            string assetPath = AssetDatabase.GUIDToAssetPath(guid);
            string newPath   = "Assets/RawResources/Scene/FBX/Bullet/" + Path.GetFileName(assetPath);
            AssetDatabase.MoveAsset(assetPath, newPath);
        }

        string[] materials = AssetDatabase.FindAssets("t:Material", findFolder);
        foreach (string guid in materials)
        {
            string assetPath = AssetDatabase.GUIDToAssetPath(guid);
            string newPath   = "Assets/RawResources/Scene/Material/Bullet/" + Path.GetFileName(assetPath);
            AssetDatabase.MoveAsset(assetPath, newPath);
        }

        string[] textures = AssetDatabase.FindAssets("t:Texture", findFolder);
        foreach (string guid in textures)
        {
            string assetPath = AssetDatabase.GUIDToAssetPath(guid);
            string newPath   = "Assets/RawResources/Scene/Texture/Bullet/" + Path.GetFileName(assetPath);
            AssetDatabase.MoveAsset(assetPath, newPath);
        }

        string[] shaders = AssetDatabase.FindAssets("t:Shader", findFolder);
        foreach (string guid in shaders)
        {
            string assetPath = AssetDatabase.GUIDToAssetPath(guid);
            string newPath   = "Assets/Shaders/" + Path.GetFileName(assetPath);
            AssetDatabase.MoveAsset(assetPath, newPath);
        }

        string[] prefabs = AssetDatabase.FindAssets("t:Prefab", findFolder);
        foreach (string guid in prefabs)
        {
            string     assetPath = AssetDatabase.GUIDToAssetPath(guid);
            GameObject prefabObj = AssetDatabase.LoadAssetAtPath <GameObject>(assetPath);

            GameObject bullet = new GameObject(prefabObj.name);
            bullet.transform.position = Vector3.zero;

            GameObject obj = GameObject.Instantiate <GameObject>(prefabObj);
            obj.name = "mesh";
            obj.transform.SetParent(bullet.transform);
            obj.transform.localPosition = Vector3.zero;

            EffectController effectCtrl = bullet.AddMissingComponent <EffectController>();
            effectCtrl.autoRemove = false;

            PrefabUtility.SaveAsPrefabAssetAndConnect(bullet, "Assets/RawResources/Scene/Prefab/Bullet/" + prefabObj.name + ".prefab", InteractionMode.AutomatedAction);

            GameObject.DestroyImmediate(bullet);

            AssetDatabase.DeleteAsset(assetPath);
        }
    }
Пример #2
0
 public static bool CheckGenBulletBatch()
 {
     return(GenerateBullet.CheckCanGenBulletBatch());
 }