コード例 #1
0
    void IActivatable.Activate(GameObject target)
    {
        // Get the dialog component of the listener, so we can use it's NpcRecord
        player = target.GetComponent <Character>();

        // Get the npc greeting, as if there is no greeting, the Npc can't be talked to.
        var greeting = DialogRecord.GetDialogInfo(DialogType.Greeting, Npc, player);

        if (greeting == null)
        {
            return;
        }

        // Check if the listener knows the current topic, otherwise it will not be available
        // This could be done within the same loop as getting the dialog topic
        topics = DialogRecord.GetDialog(Npc, player);

        var knownTopics = new List <DialogRecord>();

        foreach (var topic in topics)
        {
            // Only show topics that the player knows
            if (player.Journal.Topics.ContainsKey(topic.name))
            {
                knownTopics.Add(topic);
            }
        }

        // Display services
        var services = GetComponents <CharacterService>();

        // Load the dialog and instantiate
        dialogView = DialogView.Create(this, record.FullName, knownTopics, services, Npc.GetDisposition(player));

        // Process the greeting after getting topics, or there will be no topics to check against
        DisplayInfo(null, greeting);

        // Set this last, so it isn't true the first time the player talks to an Npc.
        GetComponent <Character>().HasTalkedToPlayer = true;
    }