Zoubidub Posted August 27, 2015 Report Share Posted August 27, 2015 Hello, First of all I'm french so sorry for my bad English :) I've got Spriter a little while ago with SpriteLamp and try to integrate both in Unity. The only issue I found is to create a material with SpriteLampShaders assigned with a normal map for each sprite of the animation. This is fastidious and I found a most easier way to do this. I'm not a pro coder so it must exist a better way to do this but I want to share this. For information, i didn't try it with a more complex animation, my project only have one animation, I will test it later with more anim. 1: Create your animation in Spriter. In my case, I use two balls rotating arround the center. 2: Create your SpriteLamp normal map and save it. Warning: the normal map must be in the same folder that the sprite AND has the same name following by '_Normal'. Repeat the operation for each sprite. Even if the normal map are the same for the two balls, we must duplicate it to assign the normal map to the correct sprite with the name. 3: Create a new Unity 5.x project and import the packages Spriter2UnityDX and SpriteLampShaders. Open the script PrefabBuilder.cs in Spriter2UnityDX>Editor. Line 28, before the foreach loop, add: var path_normal = new Dictionary<int, string>(); var folder_name = new Dictionary<int, string>(); Line 35, before the bracket, add: path_normal[file.id] = path.Replace(".png", ""); // We save the path of the sprite (without the '.png' to check if the '_Normal.png' file exist) folder_name[file.id] = folder.name; // We save the folder where the sprite is store Line 54, change the called function TryBuild to: TryBuild (entity, prefab, instance, directory, prefabPath, folders, path_normal, folder_name); // Add the two Dictionary that we created Line 64, change the function TryBuild to: private void TryBuild (Entity entity, GameObject prefab, GameObject instance, string directory, string prefabPath, IDictionary<int, IDictionary<int, Sprite>> folders, Dictionary<int, string> path_normal, Dictionary<int, string> folder_name) { // Add the two Dictionary in argument Line 150, after 'if (!firstAnim) child.gameObject.SetActive (false);', add : var folder = Directory.CreateDirectory(directory+"/"+folder_name[spriteInfo.file]+"/Materials_Normal"); // Create the folder for the material in the sprite location folder if(System.IO.File.Exists(path_normal[spriteInfo.file]+"_Normal.png")){ // Only if normal map exist for this sprite var mat = new Material(Shader.Find("SpriteLamp/Standard")); // We create the material with the Standard SpriteLamp shader Texture norm = (Texture)AssetDatabase.LoadAssetAtPath (path_normal[spriteInfo.file]+"_Normal.png", typeof(Texture)); // We load the texture AssetDatabase.CreateAsset(mat, directory+"/"+folder_name[spriteInfo.file]+"/Materials_Normal/"+child.name+"_Normal.mat"); // We save the material as Prefab mat.SetTexture("_NormalDepth", norm); child.GetComponent<SpriteRenderer>().material = mat; // We assign the material to the sprite } 4: This must work. When you import your Spriter project, a new folder must appear in location of your sprites with all the materials inside and each material must be assign to the proper sprites in the prefab. Like this : If you press the Play button, the animation play properly with a correct lighting. I think I don't miss any part. I tried with a more complex prefab and it works. I hope this will help and serve at someone more qualified to find a better way to do this :). RunnerPack 1 Quote Link to comment Share on other sites More sharing options...
Mike at BrashMonkey Posted August 28, 2015 Report Share Posted August 28, 2015 Cool stuff Zoubidub! Thanks very much for posting. Cheers. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.