Пример #1
0
    public static AITask LoadTask(string taskName)
    {
        var asset = Resources.Load <TextAsset>("ai_tasks/" + taskName);

        AITask newTask = ScriptableObject.CreateInstance(typeof(AITask)) as AITask;

        TextAsset taskAsset = asset as TextAsset;

        if (taskAsset != null)
        {
            newTask.Deserialise(taskAsset.text);
        }
        else
        {
            Debug.LogError("Failed to load task: " + taskName);
        }

        newTask.Name = taskName;

        return(newTask);
    }
Пример #2
0
    public void DoDeserialise()
    {
#if AI_LOGGING
        Debug.Log("<color=green>(AI)Deserialising Tasks</color>");
#endif

        m_tasks.Clear();
        var tasks = Resources.LoadAll("ai_tasks");


        foreach (var task in tasks)
        {
            TextAsset asset = task as TextAsset;

            if (asset == null)
            {
                continue;
            }
#if AI_LOGGING
            Debug.Log(asset.name);
#endif

            AITask newTask = ScriptableObject.CreateInstance(typeof(AITask)) as AITask;

            bool succeeded = newTask.Deserialise(asset.text);

            if (succeeded)
            {
                m_tasks.Add(newTask);

#if UNITY_EDITOR
                m_taskNames.Add(newTask.Name);
#endif
            }
            else
            {
                Debug.LogError("Failed to load " + asset.name);
            }
        }
    }