Adding custom Sprites - AnduoGames/ThirdCrisisModding GitHub Wiki
To load a png into the game, use the SpriteResolver on your instanced manifest:
var sprite = manifest.SpriteResolver.Resolve("test.png");
The path to the png is a local path from your manifest.json. If your file was in a folder called Sprites, use "Sprites\\test.png".
To display the sprite in the overworld:
var sprite = manifest.SpriteResolver.Resolve("Sprites\\test.png");
var spriteRenderer = new GameObject().AddComponent<SpriteRenderer>();
spriteRenderer.sprite = sprite;
// Move 2 meters to the right
spriteRenderer.transform.position = new Vector3(2, 0);
// Scale to half size
spriteRenderer.transform.localScale = new Vector3(0.5f, 0.5f);
// Rotate 20 degrees
spriteRenderer.transform.eulerAngles = new Vector3(0f, 0f, 20f);
Note that the SpriteResolver already handles caching. Calling the Resolve method with the same path twice, does not load the image twice and instead returns the cached Sprite.
To show an image in a dialogue, it needs to be resolved as an ANResource. An ANResource is a resource with extra logic to load and unload it from memory. In modded ANResourceSprites however, this loading and unloading logic is disabled, sprites will always be loaded when created this way.
// load the image as a resource
var resource = manifest.SpriteResolver.ResolveAsResource("Sprites\\test.png");
// create the dialogue line and add the resource to it
var line = new DialogueLine() {
BackgroundSpriteResource = resource,
Character = Character.Get("Jenna"),
Text = "This is a line showing my sprite!",
LineID = "line_0"
};
var dialogue = ScriptableObject.CreateInstance<Dialogue>();
dialogue.Lines.Add(line);
DialogueManager.StartDialogue(dialogue);