예제 #1
0
    public override void OnInspectorGUI()
    {
        // Update the state of the serializedObject to the current values of the target.
        serializedObject.Update();

        GUILayout.BeginHorizontal();
        //Renaming
        targetQuestsList.name = EditorGUILayout.TextField("Quests List Project Name", targetQuestsList.name as string);
        if (GUILayout.Button(" Rename ", GUILayout.ExpandWidth(false)))
        {
            string assetPath = AssetDatabase.GetAssetPath(targetQuestsList.GetInstanceID());
            AssetDatabase.RenameAsset(assetPath, targetQuestsList.name);
            AssetDatabase.SaveAssets();
        }
        GUILayout.EndHorizontal();

        targetQuestsList.questsListName = EditorGUILayout.TextField("Quests List Game Name", targetQuestsList.questsListName as string);

        GUILayout.Space(10);

        // Description property
        EditorGUILayout.LabelField("Quests List Description", EditorStyles.boldLabel);
        GUILayout.BeginHorizontal();

        targetQuestsList.questsListDescription =
            EditorGUILayout.TextArea(targetQuestsList.questsListDescription, EditorStyles.textArea, GUILayout.Height(EditorGUIUtility.singleLineHeight * 5));
        GUILayout.EndHorizontal();

        GUILayout.Space(10);

        GUILayout.BeginHorizontal();
        newQuestName = EditorGUILayout.TextField("New Quest Name", newQuestName);
        // Change default Unity Editor array elements management
        if (EditorTools.createListButton(" Add Quest ", false, GUILayout.ExpandWidth(false)))
        {
            AddQuest(newQuestName);
        }

        GUILayout.EndHorizontal();

        GUILayout.Space(10);


        if (targetQuestsList.quests.Length > 0)
        {
            EditorGUILayout.LabelField("Total Quests: " + targetQuestsList.quests.Length, EditorStyles.boldLabel);
        }
        else
        {
            GUILayout.Label("This Quests List is Empty.");
        }


        // If there are different number of editors to Items, create them afresh.
        if (questsEditors.Length != targetQuestsList.quests.Length)
        {
            // Destroy all the old editors.
            for (int i = 0; i < questsEditors.Length; i++)
            {
                DestroyImmediate(questsEditors[i]);
            }

            // Create new editors.
            CreateEditors();
        }

        // Display all the items.
        for (int i = 0; i < questsEditors.Length; i++)
        {
            questsEditors[i].OnInspectorGUI();
        }


        if (GUI.changed)
        {
            EditorUtility.SetDirty(targetQuestsList);
        }

        // Push data back from the serializedObject to the target.
        serializedObject.ApplyModifiedProperties();
    }