0

I have created an asset bundle with emission maps in Unity it is working fine in Editor but when I build for mobile, Everything except emission maps work properly but it seems emission maps are having no effect at all. Here is the code to create the asset bundle can you and works fine in desktop.

using UnityEditor;
using System.IO;
using UnityEngine;

public class CreateAssetBundles {

    public static string assetBundleDirectory = "Assets/AssetBundles/";

    [MenuItem("Assets/Build AssetBundles")]
    static void BuildAllAssetBundles() {

        //if main directory doesnt exist create it
        if (Directory.Exists(assetBundleDirectory)) {
            Directory.Delete(assetBundleDirectory, true);
        }
        
        Directory.CreateDirectory(assetBundleDirectory);
        
        //create bundles for all platform (use IOS for editor support on MAC but must be on IOS build platform)
        BuildPipeline.BuildAssetBundles(assetBundleDirectory,BuildAssetBundleOptions.None, BuildTarget.iOS);
        AppendPlatformToFileName("IOS");
        Debug.Log("IOS bundle created...");

        BuildPipeline.BuildAssetBundles(assetBundleDirectory, BuildAssetBundleOptions.None, BuildTarget.Android);
        AppendPlatformToFileName("Android");
        Debug.Log("Android bundle created...");

        RemoveSpacesInFileNames();

        AssetDatabase.Refresh();
        Debug.Log("Process complete!");
    }

    static void RemoveSpacesInFileNames() {
        foreach (string path in Directory.GetFiles(assetBundleDirectory)) {
            string oldName = path;
            string newName = path.Replace(' ', '-');
            File.Move(oldName, newName);
        }
    }

        static void AppendPlatformToFileName(string platform) {
        foreach (string path in Directory.GetFiles(assetBundleDirectory)) {
            //get filename
            string[] files = path.Split('/');
            string fileName = files[files.Length - 1];

            //delete files we dont need
            if (fileName.Contains(".") || fileName.Contains("Bundle")) {
                File.Delete(path);
            } else if (!fileName.Contains("-")){
                //append platform to filename
                FileInfo info = new FileInfo(path);
                info.MoveTo(path + "-" + platform);
            }
        }
    }
}

1 Answers1

0

My problems was solved via the following step.

  1. Create a new shader graph
  2. Add emission map in the graph.
  3. Create asset bundle now.
  4. Vallah!!! working

Default unity shader was not working for some reason.