• 大小: 1.04MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-08-12
  • 语言: 其他
  • 标签: unity  

资源简介

在Unity中制作一款文字冒险游戏,示例项目,教程文章在https://blog.csdn.net/q764424567/article/details/93999779?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522159071391919195162511910%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=159071391919195162511910&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_v2~rank_blog_default-1-93999779.pc_v2_rank_blog_default&utm_term=%E6%95%85%E4%BA%8B

资源截图

代码片段和文件信息

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;

public class GameManager : MonoBehaviour
{
    public Text Description;
    public Button[] OptionButtons;

    public StoryItembase CurrentItem;

    private int _numButtons;
    private Text[] _buttonTexts;
    private string[] _optionTexts;
    private StoryItembase[] _optionItems;

    // Use this for initialization
    void Start()
    {
        _numButtons = OptionButtons.GetLength(0);

        GetButtonTexts();

        CurrentItem.Activate(this);
    }

    // Update is called once per frame
    void Update()
    {

    }

    private void GetButtonTexts()
    {
        _buttonTexts = new Text[_numButtons];

        for (int i = 0; i < _numButtons; i++)
        {
            _buttonTexts[i] =
              OptionButtons[i].GetComponentInChildren(true);
        }
    }

    public void SetCurrentStoryItem(StoryItembase item)
    {
        CurrentItem = item;
        CurrentItem.Activate(this);
    }

    public void OnButton(int index)
    {
        SetCurrentStoryItem(_optionItems[index]);
    }

    public void SetCardDetails(string desc string[] optionTexts
                               StoryItembase[] optionItems)
    {
        Description.text = desc;
        _optionTexts = optionTexts;
        _optionItems = optionItems;

        UpdateButtons();
    }

    public void UpdateButtons()
    {
        int numOptionTexts = _optionTexts == null ? 0 :
                                               _optionTexts.GetLength(0);
        int numOptionItems = _optionItems == null ? 0 :
                                               _optionItems.GetLength(0);

        int numActiveButtons = Math.Min(numOptionItems numOptionTexts);

        for (int i = 0; i < _numButtons; i++)
        {
            if (i < numActiveButtons)
            {
                OptionButtons[i].gameobject.SetActive(true);
                _buttonTexts[i].text = _optionTexts[i];
            }
            else
            {
                OptionButtons[i].gameobject.SetActive(false);
            }
        }
    }

}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2020-05-29 08:41  .vs\
     目录           0  2020-05-29 08:41  .vs\TextAdventure\
     目录           0  2020-05-29 08:56  .vs\TextAdventure\v16\
     文件       29696  2020-05-29 08:56  .vs\TextAdventure\v16\.suo
     目录           0  2020-05-29 08:42  .vs\TextAdventure\v16\Server\
     目录           0  2020-05-29 08:56  .vs\TextAdventure\v16\Server\sqlite3\
     文件           0  2020-05-29 08:42  .vs\TextAdventure\v16\Server\sqlite3\db.lock
     文件      536576  2020-05-29 08:56  .vs\TextAdventure\v16\Server\sqlite3\storage.ide
     文件        5403  2020-05-29 08:40  Assembly-CSharp.csproj
     目录           0  2017-03-25 18:27  Assets\
     文件         192  2017-03-25 18:27  Assets\_Scenes.meta
     目录           0  2020-05-29 08:56  Assets\_Scenes\
     文件       50988  2020-05-29 08:56  Assets\_Scenes\Adventure.unity
     文件         175  2017-03-25 18:26  Assets\_Scenes\Adventure.unity.meta
     文件       42832  2017-04-01 20:54  Assets\_Scenes\Basic.unity
     文件         175  2017-04-01 20:40  Assets\_Scenes\Basic.unity.meta
     文件         192  2017-03-25 18:27  Assets\scripts.meta
     目录           0  2020-05-29 08:56  Assets\scripts\
     文件        2234  2020-05-29 08:56  Assets\scripts\GameManager.cs
     文件         263  2017-03-25 17:29  Assets\scripts\GameManager.cs.meta
     文件         423  2017-04-02 05:47  Assets\scripts\StoryBranch.cs
     文件         263  2017-03-25 17:37  Assets\scripts\StoryBranch.cs.meta
     文件         816  2020-05-29 08:56  Assets\scripts\StoryCard.cs
     文件         263  2017-03-25 17:37  Assets\scripts\StoryCard.cs.meta
     文件         346  2020-05-29 08:42  Assets\scripts\StoryItembase.cs
     文件         263  2017-03-25 17:36  Assets\scripts\StoryItembase.cs.meta
     文件         149  2017-04-01 17:09  Assets\scripts\StoryState.cs
     文件         263  2017-04-01 17:02  Assets\scripts\StoryState.cs.meta
     目录           0  2020-05-29 08:56  Library\
     文件        4116  2017-03-25 17:22  Library\AnnotationManager
     文件     2925512  2020-05-29 08:56  Library\assetDatabase3
............此处省略465个文件信息

评论

共有 条评论