Instantly share code, notes, and snippets.

Embed
What would you like to do?
using UnityEngine;
public class Question7_practical : ScriptableObject
{
public string enemyName;
public int hp;
}
using UnityEngine;
using System.Collections;
public class Question7_Runtime_practical : MonoBehaviour
{
private Object[] assets;
void Start()
{
assets = Resources.LoadAll("Question7_practical");
}
void OnGUI()
{
foreach (Object asset in assets)
{
if (asset is Texture2D)
{
GUILayout.Label((Texture2D)asset);
}
if (asset is Question7_practical)
{
Question7_practical data = (Question7_practical)asset;
GUILayout.Label(data.enemyName);
GUILayout.Label(data.hp.ToString());
}
}
}
}
using System.IO;
using UnityEditor;
using UnityEngine;
using System.Collections;
public class Question7Editor_practical : ScriptableWizard
{
public string enemyName;
public int hp;
public Texture texture;
[MenuItem("Window/Question7Editor_practical")]
static void Open()
{
DisplayWizard<Question7Editor_practical>("Create Data");
}
void OnWizardUpdate()
{
isValid = texture && !string.IsNullOrEmpty(enemyName) && hp != 0;
}
void OnWizardCreate()
{
Question7_practical question7Practical = CreateInstance<Question7_practical>();
question7Practical.enemyName = enemyName;
question7Practical.hp = hp;
Directory.CreateDirectory("Assets/Question7_practical/Resources");
string path = "Assets/Question7_practical/Resources/Question7_practical.asset";
AssetDatabase.CreateAsset(question7Practical, path);
AssetDatabase.AddObjectToAsset(Instantiate(texture), path);
AssetDatabase.ImportAsset(path);
EditorUtility.UnloadUnusedAssets();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment