Hi everybody !!
First off all, Tank you for your course and excuse me if my english isn’t as good as i want
After viewing this lecture, i can’t build my project. I’ve got this error :
Assets/Dialogue/Dialogue.cs(56,13): error CS0103: The name ‘Undo’ does not exist in the current context
And this one too :
Assets/Dialogue/Dialogue.cs(88,17): error CS0103: The name ‘AssetDatabase’ does not exist in the current context
Here is the code after the lecture :
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
namespace RPG.Dialogue
{
[CreateAssetMenu(fileName = "NewDialogue", menuName = "Dialogue", order = 0)]
public class Dialogue : ScriptableObject, ISerializationCallbackReceiver
{
[SerializeField] List<DialogueNode> nodes = new List<DialogueNode>();
Dictionary<string, DialogueNode> nodeLookup = new Dictionary<string, DialogueNode>();
#if UNITY_EDITOR
private void Awake()
{
}
#endif
private void OnValidate()
{
nodeLookup.Clear();
foreach (DialogueNode node in GetAllNodes())
{
nodeLookup[node.name] = node;
}
}
public IEnumerable<DialogueNode> GetAllNodes()
{
return nodes;
}
public DialogueNode GetRootNode()
{
return nodes[0];
}
public IEnumerable<DialogueNode> GetAllChildren(DialogueNode parentNode)
{
List<DialogueNode> result = new List<DialogueNode>();
foreach (string childID in parentNode.children)
{
if (nodeLookup.ContainsKey(childID))
{
yield return nodeLookup[childID];
}
}
}
public void CreateNode(DialogueNode parent)
{
DialogueNode newNode = CreateInstance<DialogueNode>();
newNode.name = Guid.NewGuid().ToString();
Undo.RegisterCreatedObjectUndo(newNode, "Created Dialogue Node");
if (parent != null)
{
parent.children.Add(newNode.name);
}
nodes.Add(newNode);
OnValidate();
}
public void DeleteNode(DialogueNode nodeToDelete)
{
nodes.Remove(nodeToDelete);
OnValidate();
CleanDanglingChildren(nodeToDelete);
Undo.DestroyObjectImmediate(nodeToDelete);
}
private void CleanDanglingChildren(DialogueNode nodeToDelete)
{
foreach (DialogueNode node in GetAllNodes())
{
node.children.Remove(nodeToDelete.name);
}
}
public void OnBeforeSerialize()
{
if (nodes.Count == 0)
{
CreateNode(null);
}
if (AssetDatabase.GetAssetPath(this) != "")
{
foreach (DialogueNode node in GetAllNodes())
{
if (AssetDatabase.GetAssetPath(node) == "")
{
AssetDatabase.AddObjectToAsset(node, this);
}
}
}
}
public void OnAfterDeserialize()
{
}
}
}
Excuse me if i’m not clear but if you can get me on the good way ?
Thank you and continue doing a great job !!