コード例 #1
0
    public void AddEntry(
        string nameId,
        string text,
        DateTime timestamp,
        string headline
        )
    {
        Script_Entry existingEntry = GetExistingEntry(nameId);

        if (existingEntry != null)
        {
            EditEntry(existingEntry, text, timestamp);
            return;
        }

        // instantiate Entry
        Script_Entry e = Instantiate(entryPrefab, Vector3.zero, Quaternion.identity);

        e.transform.SetParent(entriesParent, false);

        int Id = game.entries.Length;

        print($"adding headline: {headline}; my Id: {Id}");
        e.Setup(Id, nameId, text, timestamp, headline);
        e.GetComponent <Script_EntryOnSelect>().Setup(entriesViewController);

        // update game refs to entries
        Script_Entry[] newEntries = new Script_Entry[game.entries.Length + 1];
        newEntries = Script_Utils.CopyArrayElements(game.entries, newEntries);
        newEntries[newEntries.Length - 1] = e;
        game.UpdateEntries(newEntries);

        // set explicit navigation and container sizing
        LinkNavigationWithPrevious(Id, entriesParent);
        HandleContainerSizing(e);

        // update EntriesCanvasState if was empty canvas before
        entriesViewController.UpdateCanvasState();
    }