// Copyright (c) Pixel Crushers. All rights reserved. using UnityEngine; using System.Collections.Generic; namespace PixelCrushers.DialogueSystem { /// /// The base class of all assets such as actors, conversations, items, locations and /// variables found in a DialogueDatabase. /// [System.Serializable] public class Asset { /// /// Every asset has an ID number. Internally, the Dialogue System works like Chat Mapper /// and references assets by ID number. /// public int id = 0; /// /// The asset's fields. An Actor asset may have fields such as Age and IsPlayer, while a /// DialogueEntry asset may have fields such as Menu Text, Dialogue Text, and Video File. /// public List fields = null; /// /// Gets or sets the Name field. /// /// /// The value of the asset's Name field. /// public string Name { get { return Field.LookupValue(fields, DialogueSystemFields.Name); } set { Field.SetValue(fields, DialogueSystemFields.Name, value); } } /// /// Gets the localized Name field. /// /// The value of the localized Name field. public string localizedName { get { return Field.LookupLocalizedValue(fields, DialogueSystemFields.Name); } } /// /// Gets or sets the Description field, which is optional and may not exist. /// public string Description { get { return Field.LookupValue(fields, DialogueSystemFields.Description); } set { Field.SetValue(fields, DialogueSystemFields.Description, value); } } /// @cond FOR_V1_COMPATIBILITY public string LocalizedName { get { return localizedName; } } /// @endcond /// /// Initializes a new DialogueAsset. /// public Asset() { } /// /// Copy constructor. /// /// Source asset. public Asset(Asset sourceAsset) { this.id = sourceAsset.id; this.fields = Field.CopyFields(sourceAsset.fields); } /// /// Initializes a new DialogueAsset copied from a Chat Mapper asset. /// /// /// The Chat Mapper asset's ID. /// /// /// The Chat Mapper asset's fields. /// public Asset(int chatMapperID, List chatMapperFields) { Assign(chatMapperID, chatMapperFields); } /// /// Copies a Chat Mapper asset. /// /// /// Chat Mapper asset's ID. /// /// /// The Chat Mapper asset's fields. /// public void Assign(int chatMapperID, List chatMapperFields) { id = chatMapperID; fields = Field.CreateListFromChatMapperFields(chatMapperFields); } /// /// Checks whether a field exists. /// /// /// true if the field exists; otherwise false. /// /// /// Title of the field. /// public bool FieldExists(string title) { return Field.FieldExists(fields, title); } /// /// Looks up the value of a field. /// /// /// The string value of the field with the specified title, or null if no field /// matches. /// /// /// The title of the field to look up. /// public string LookupValue(string title) { return Field.LookupValue(fields, title); } /// /// Looks up the localized value of a field for the current language. /// /// The localized value. /// The title of the field to look up. public string LookupLocalizedValue(string title) { return Field.LookupLocalizedValue(fields, title); } /// /// Looks up the value of a field. /// /// /// The int value of the field with the specified title, or 0 if no field matches. /// /// /// The title of the field to look up. /// public int LookupInt(string title) { return Field.LookupInt(fields, title); } /// /// Looks up the value of a field. /// /// /// The float value of the field with the specified title, or 0 if no field matches. /// /// /// The title of the field to look up. /// public float LookupFloat(string title) { return Field.LookupFloat(fields, title); } /// /// Looks up the value of a field. /// /// /// The bool value of the field with the specified title, or false if no field matches. /// /// /// The title of the field to look up. /// public bool LookupBool(string title) { return Field.LookupBool(fields, title); } /// /// Checks whether a field exists and has non-empty text. /// /// /// true if the field is assigned; otherwise, false. /// /// /// Title of the field. /// public bool IsFieldAssigned(string title) { return Field.IsFieldAssigned(fields, title); } /// /// Returns a field if it exists and has non-empty text. /// /// /// The field, or null if it doesn't exist or has empty text. /// /// /// Title of the field. /// public Field AssignedField(string title) { return Field.AssignedField(fields, title); } } }