Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@anchan828
Created October 2, 2013 04:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anchan828/e9f2817bfea113257753 to your computer and use it in GitHub Desktop.
Save anchan828/e9f2817bfea113257753 to your computer and use it in GitHub Desktop.
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