SHARE
TWEET

Untitled

a guest Jul 27th, 2017 115 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [System.Serializable]
  2. public class Item : ScriptableObject
  3. {
  4.     public Item instance;
  5.     public int id;
  6.     public string name;
  7.  
  8.     public Texture icons;
  9.     public Material material;
  10.  
  11.  
  12.  
  13.     public Item()
  14.     {
  15.         instance = this;
  16.     }
  17.  
  18.     public void Draw(List<Item> items)
  19.     {
  20.         GUILayout.BeginVertical("Box", GUILayout.Width(300), GUILayout.Height(100));
  21.  
  22.         id = EditorGUILayout.IntField(id);
  23.         name = EditorGUILayout.TextField(name);
  24.  
  25.         icons = EditorGUILayout.ObjectField(icons, typeof(Texture), false) as Texture;
  26.         material = EditorGUILayout.ObjectField(material, typeof(Material), false) as Material;
  27.  
  28.         string delete = "Delete";
  29.         if (GUILayout.Button(delete, GUILayout.Height(25)))
  30.         {
  31.             GUI.FocusControl(delete);
  32.             items.Add(this);
  33.         }
  34.  
  35.         GUILayout.EndVertical();
  36.  
  37.     }
  38.  
  39. }
  40.  
  41. [System.Serializable]
  42. public class Items : ScriptableObject
  43. {
  44.     [SerializeField]
  45.     public List<Item> items;
  46. }
  47.  
  48. // Tu jak tworze te obiekty
  49.  
  50.    void OnEnable()
  51.     {
  52.         items = AssetDatabase.LoadAssetAtPath<Items>("Assets/Items.asset");
  53.  
  54.         Debug.Log("Items: " + items);
  55.  
  56.         if (items == null)
  57.         {
  58.             items = CreateInstance<Items>();
  59.             items.items = new List<Item>();
  60.             AssetDatabase.CreateAsset(items, PATH);
  61.             AssetDatabase.SaveAssets();
  62.             EditorUtility.SetDirty(items);
  63.         }
  64.     }
  65.  
  66.     private void AddItem()
  67.     {
  68.         Item item = ScriptableObject.CreateInstance<Item>();
  69.         items.items.Add(item);
  70.  
  71.         AssetDatabase.AddObjectToAsset(item, items);
  72.         AssetDatabase.SaveAssets();
  73.         EditorUtility.SetDirty(items);
  74.         EditorUtility.SetDirty(item);
  75.         AssetDatabase.Refresh();
  76.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top