Как определить переменные в пользовательском редакторе, нужно определить массив?

1

Мне нужна помощь, поскольку я не понимаю сериализованные пути свойств и тому подобное. Я написал 2 скрипта один настраиваемый редактор и один обычный скрипт. Если кто-нибудь знает, как я могу ссылаться на переменную slotContents в первом скрипте из сценария редактора, сохраняя его разборчивым. Спасибо

    using UnityEngine;
using System.Collections;

public class Inventory : MonoBehaviour {
    public GUISkin mainDesignSkin;
    public GUISkin craftDesignSkin;
    public bool enableCraftingMenu = true;
    public int craftSlot1;
    public int craftSlot2;
    public int craftResult; //Make this private users do not need to see this it will clutter editor.
    public int [] slotContents;
}

И второй сценарий.

using UnityEngine;
using System.Collections;
using UnityEditor;
//Decalres type for editor.
[CustomEditor(typeof(Inventory))]
public class InventoryUiCustomEditor : Editor {
    public override void OnInspectorGUI ()
    {
        base.OnInspectorGUI ();
        Inventory ItemReference = (Inventory)target;
        EditorGUILayout.LabelField("First we need to set our skin look in the skins folder or assign your own designs.");
        EditorGUILayout.LabelField("Please assign even if crafting is disabled to avoid accidental null reference errors.");
        EditorGUILayout.Separator();
        ItemReference.mainDesignSkin = (GUISkin) EditorGUILayout.ObjectField("Apply the skin entitled 'Main' here.", ItemReference.mainDesignSkin, typeof (GUISkin), false);
        ItemReference.craftDesignSkin = (GUISkin) EditorGUILayout.ObjectField("Apply the skin entitled 'Craft' here.", ItemReference.craftDesignSkin, typeof (GUISkin), false);
        EditorGUILayout.Separator();
        EditorGUILayout.LabelField("Should the crafting menu be enabled in this Scene?");
        EditorGUILayout.Separator();
        ItemReference.enableCraftingMenu = EditorGUILayout.Toggle("Enable Crafting", ItemReference.enableCraftingMenu); 
        if (ItemReference.enableCraftingMenu == true){
            EditorGUILayout.Separator();
            EditorGUILayout.LabelField("The below fields are for your testing only they will be automatically overridden.");
            EditorGUILayout.LabelField("The following fields can be used as a tester however will only work on valid recipes check the");
            EditorGUILayout.LabelField("documentation video for a tutorial on this.");
            EditorGUILayout.Separator();
            ItemReference.craftSlot1 = EditorGUILayout.IntField("Item 1", ItemReference.craftSlot1);
            ItemReference.craftSlot2 = EditorGUILayout.IntField("Item 2", ItemReference.craftSlot2);
            ItemReference.craftResult = EditorGUILayout.IntField("Result of mixing above two items.", ItemReference.craftResult);


        }
    }
}
  • 0
    Вы пытались использовать [Serializable] перед массивом slotContents ?
  • 0
    Спасибо за то, что поделились этим замечательным фрагментом кода. Я искал способ настроить представление инспектора, выбрав значение enum, и ваш код указал мне правильное направление. Здорово!
Теги:
arrays
unity3d
unity3d-editor

1 ответ

0

Проверьте эту ссылку: http://answers.unity3d.com/questions/571411/is-it-possible-to-make-ac-script-variable-changea.html

Это ссылка, которую вы должны прочитать, поскольку она содержит детали вашего ответа: http://docs.unity3d.com/ScriptReference/Serializable.html, а также поиск Serialize.Field

Пользователь Varaquilex закрыл его, если не заметил:

Вот как выглядит ваш код:

using UnityEngine;
using System.Collections;

[System.Serializable]
public class Inventory : MonoBehaviour 
{
    public GUISkin mainDesignSkin;
    public GUISkin craftDesignSkin;
    public bool enableCraftingMenu = true;
    public int craftSlot1;
    public int craftSlot2;
    public int craftResult; //Make this private users do not need to see this it will clutter editor.
    [SerializeField] 
    public int [] slotContents;
}
  • 0
    Но тогда как мне ссылаться в редакторе, все, что он говорит, это то, что вы сказали мне, что это только основной сценарий, а не сторона редактора ??

Ещё вопросы

Сообщество Overcoder
Наверх
Меню