Comments (6)
This answer assumes you're using the Unity plugin.
I suggest the most obvious approach would be modifying the SpriterImporter, more specifically the part where the assets get loaded (provided you can get a Sprite reference from your atlas):
Also, I'll close this as it is not an actual issue (although we can continue this conversation). In the future, it would be better to ask such questions on the forum thread and open actual issues here.
from spriterdotnet.
Thanks for the pointer. I was able to get this working fairly easily. Here's a quick example of anyone else needs to do this:
private static T LoadContent<T>(string path) where T : UnityEngine.Object
{
T asset;
//Try and load from TexturePacker
var atlasPaths = new List<string> {
"Assets/_Internal/Textures/Enemies/Enemies",
"Assets/_Internal/Textures/Followers/Followers"
};
var imageSuffix = ".png";
var splitPath = path.Split('/').ToList();
var spriteNames = new List<string>();
while (splitPath.Count > 0) {
spriteNames.Add(string.Join("-", splitPath.ToArray()));
splitPath.RemoveAt(0);
}
foreach (var p in atlasPaths) {
var sprites = AssetDatabase.LoadAllAssetsAtPath(p + imageSuffix).OfType<Sprite>().ToList();
var material = AssetDatabase.LoadAssetAtPath<Material>(p + ".mat");
//Check each possible match, across each sprite
foreach (var name in spriteNames) {
foreach (var s in sprites) {
if ((s.name + imageSuffix) == name) {
currentMaterial = material;
return s as T;
}
}
}
}
asset = AssetDatabase.LoadAssetAtPath<T>(path);
if (asset == null) Debug.Log("Missing Asset: " + path);
return asset;
}
The only trick, for our use case (Normal Map support) is that we still need to apply the matching material. So we store off currentMaterial in the LoadContent() function. and then apply it in CreateSprites()
private static void CreateSprites(){
...
var r = child.AddComponent<SpriteRenderer>();
if (currentMaterial != null) {
r.material = currentMaterial;
}
}
from spriterdotnet.
Hmm, looks like I spoke too soon. Everything works great, until I close the editor and re-open. The scriptable object seems to lose all references to the sprites, and is just full of null entries...
from spriterdotnet.
Ok, figured it out. For some reason, the asset does not get marked as dirty, so the new sprites are not saved. Just had to add this to CreateSpriterData():
EditorUtility.SetDirty(data);
from spriterdotnet.
I'm glad you managed to get it working. Based on your code, I don't see a way of making this work in a generic way. Also, I'm not happy with the library user needing to change the importer to customise the behaviour. Probably something like a Chain of Command would be good here. Having a default way of getting assets and allowing users to customise this behaviour by plugging in custom importers. Something similar as with the parsers:
https://github.com/loodakrawa/SpriterDotNet/blob/master/SpriterDotNet/SpriterParser.cs#L28
What do you think?
from spriterdotnet.
Yep this sounds ideal, as long as we can plugin somehow, and swap the images with images from another texture in Unity, be it 2dToolkit or TexturePacker, or NGUI, they all work pretty much the same, they pack the sprites for you, and the end result is just a standard Unity Texture w/ sub sprites.
from spriterdotnet.
Related Issues (20)
- random access to character maps HOT 1
- Adding SpriterDotNet to an Android project HOT 5
- Total bounding area HOT 2
- cannot read scml file HOT 1
- Find name of sprite that sprite transform applies to HOT 4
- Sprite Object pixel coordinate snapping in pixel mode HOT 1
- SpriterDotNet NuGet packages broken in latest release of MonoGame. HOT 1
- Animator always null in Start method(Unity) HOT 2
- More of a question than an issue about the project HOT 4
- Regarding the creation of bounding boxes, and collision boxes. HOT 4
- Stack overflow when using cyclic character map
- Changing sprites of prefab e.g. when switching armor or weapons
- Bone manipulation at runtime.
- General codestyle issues. HOT 6
- Remove Linq. HOT 3
- Simplify public interface. HOT 3
- unity 2019.2.1 constant hourglass when clicking generated prefabs HOT 2
- Enter Safe Mode at open
- Example please HOT 1
- Transitions do not play the full animation HOT 15
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spriterdotnet.