Last active
August 18, 2019 06:24
-
-
Save tsubaki/babf56c50941ce8044ca to your computer and use it in GitHub Desktop.
Load Multiple Sprite with scriptableObject
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 (); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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