Ejemplo n.º 1
0
    public virtual void AddSprite(Sprite[] sp, Dictionary<string, Vector2> allPivot)
    {
        if (null == sp)
            return;

        List<SpritePair> ls = new List<SpritePair>();
        if (null == sprites)
        {
            sprites = new SpritePair[0];
        }

        for (int i = 0; i < sp.Length; i++)
        {
            bool found = false;
            for (int j = 0; j < sprites.Length; ++j)
            {
                if (sprites[j].sprite == sp[i])
                {
                    ls.Add(new SpritePair(sprites[j].name, sp[i], GetPivot(sp[i].name, allPivot)));
                    found = true;
                    break;
                }
            }

            if (!found)
            {
                Vector2 pivot = GetPivot(sp[i].name, allPivot);
                SpritePair pair = new SpritePair(sp[i].name, sp[i], pivot);
                ls.Add(pair);
            }
        }

        // 移除不存在的数据
        for (int i = 0; i < ls.Count; ++i)
        {
            if (null == ls[i].sprite)
                ls.Remove(sprites[i]);
        }

        sprites = ls.ToArray();
    }
Ejemplo n.º 2
0
    // Start is called before the first frame update
    void Start()
    {
        lines = responses.text.Split('\n').ToList();
        foreach (string line in lines)
        {
            string[] currentLine = line.Split('|');
            if (currentLine.Length == 3)
            {
                dialogueNode test = new dialogueNode(nodes.Count, currentLine[0], currentLine[1], currentLine[2]);
                nodes.Add(test);
                if (speakers.Contains(currentLine[0]) == false)
                {
                    speakers.Add(currentLine[0]);
                }
            }
            else
            {
                throw new FormatException('"' + line + '"' + " is not formatted correctly");
            }
        }
        foreach (string speaker in speakers)
        {
            SpritePair current = new SpritePair(speaker, null);
            spritePairs.Add(current);
        }
        for (int i = 0; i < nodes.Count; i++)
        {
            foreach (int j in nodes[i].getResponseIndices())
            {
                nodes[i].updateDict(j, nodes[j].getText());
            }
            //print(nodes[i].ToString());
        }
        currentSpeaker = nodes[0].getSpeaker();
        currentText    = nodes[0].getText();

        currentResponses = nodes[0].getResponses().ToList();
        updateScreen();
    }