Search Unity

Creating editor window for weapon management

Discussion in 'Scripting' started by Disaster, Aug 9, 2011.

  1. Disaster

    Disaster

    Joined:
    Oct 31, 2009
    Posts:
    43
    I'm trying to create custom editor window which will allow us to create and manage a list of different available weapons. Each of my games weapons is represented by my WeaponVO class:


    Code (csharp):
    1. [System.Serializable]
    2. public class WeaponVO{
    3.     public string name;
    4.     public GameObject prefab;
    5.     public GameObject pickupModel;
    6.     public enum Slot { Melee, SideArm, Main }
    7.     public Slot slot = Slot.Melee;
    8. }
    I want to represent the list of weapons in the editor window as an array:

    Code (csharp):
    1. using UnityEditor;
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class WeaponEditor : EditorWindow {
    6.  
    7.     [MenuItem ("Window/Weapons")]
    8.     static void Init () {
    9.         WeaponEditor window = (WeaponEditor)EditorWindow.GetWindow (typeof (WeaponEditor));
    10.     }
    11.    
    12.     public WeaponVO[] weaponList = new WeaponVO[50];
    13.    
    14.     void OnGUI () {
    15.    
    16.         EditorGUILayout.Space ();
    17.         EditorGUILayout.BeginVertical ();
    18.  
    19.         foreach(WeaponVO w in weaponList){
    20.             // Serialize object here somehow?
    21.         }
    22.  
    23.         EditorGUILayout.EndVertical ();
    24.     }
    25. }
    It seems there is no way to serialize my WeaponVO class so we can input new weapons. Is there anyway to do what I am trying to do?