Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Last active August 18, 2019 06:24
Show Gist options
  • Save tsubaki/babf56c50941ce8044ca to your computer and use it in GitHub Desktop.
Save tsubaki/babf56c50941ce8044ca to your computer and use it in GitHub Desktop.
Load Multiple Sprite with scriptableObject
using UnityEngine;
using System.Collections;
using UnityEditor;
public class ExportSprites {
[MenuItem("Assets/Create/SpriteScriptableObject")]
static void Export()
{
foreach (var sprite in Selection.objects) {
if( sprite is Sprite == false){
continue;
}
SpriteScriptableObject sp = ScriptableObject.CreateInstance<SpriteScriptableObject>();
sp.sprite = sprite as Sprite;
AssetDatabase.CreateAsset(sp, "Assets/" + sprite.name + ".asset");
}
AssetDatabase.SaveAssets ();
}
}
using UnityEngine;
using System.Collections;
using System;
public class LoadAB : MonoBehaviour {
IEnumerator Start ()
{
WWW www = new WWW ("file://" + Application.streamingAssetsPath + "/player");
yield return www;
var spriteScriptable = www.assetBundle.LoadAsset<SpriteScriptableObject> ("SpriteJump");
www.assetBundle.Unload (false);
var spriteRenderer = gameObject.AddComponent<SpriteRenderer> ();
spriteRenderer.sprite = spriteScriptable.sprite;
Resources.UnloadAsset (spriteScriptable);
}
}
using UnityEngine;
[CreateAssetMenu()]
public class SpriteScriptableObject : ScriptableObject
{
public Sprite sprite;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment