-
-
Save anchan828/e9f2817bfea113257753 to your computer and use it in GitHub Desktop.
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; | |
public class Question7_practical : ScriptableObject | |
{ | |
public string enemyName; | |
public int hp; | |
} |
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; | |
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()); | |
} | |
} | |
} | |
} |
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 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