Exemplo n.º 1
0
    private void ParsePrefab(ConversationFileDataPrefab data)
    {
        GameObject obj;

        if (preLoadedPrefabs.TryGetValue(data.prefabName, out obj))
        {
            GameObject pre = Instantiate(obj);
            pre.transform.SetParent(UIManager.Instance.Canvas.transform);
            pre.transform.localPosition = obj.transform.localPosition;
            pre.transform.localScale    = Vector3.one;

            Transform parent = convText.transform.parent;
            parent.SetSiblingIndex(parent.GetSiblingIndex() + 10);

            parent = talkerText.transform.parent;
            parent.SetSiblingIndex(parent.GetSiblingIndex() + 10);

            parent = clickTrigger.transform;
            parent.SetSiblingIndex(parent.GetSiblingIndex() + 10);

            if (distracterPopup != null)
            {
                parent = distracterPopup.transform.GetComponent <RectTransform>();
                parent.SetSiblingIndex(parent.GetSiblingIndex() + 10);
            }
        }
        else
        {
            Debug.LogError("Prefab " + data.prefabName + " Is NOT LOADED");
        }
    }
Exemplo n.º 2
0
    private void ParseCodes(string code, ref string fileData, int startIndex, ref int curIndex, ref int openedBracket)
    {
        while (openedBracket > 0 && curIndex < fileData.Length && fileData[curIndex] == '>')
        {
            curIndex      += 1;
            openedBracket -= 1;
        }

        switch (code)
        {
        case "Conversation":
            ParseConversation(ref fileData, curIndex, out curIndex, ref openedBracket);

            break;

        case "Background":
            ParseBackground(fileData, curIndex, out curIndex);

            break;

        case "Parameter":
            ParseParameters(ref fileData, startIndex, curIndex, out curIndex, ref openedBracket);
            break;

        case "End":
            ConversationFileDataBase data = new ConversationFileDataBase();
            data.firstCode = "End";

            convDatas.Add(data);
            break;

        case "Align":
            ConversationFileDataAlign aData = new ConversationFileDataAlign();
            aData.firstCode = "Align";
            while (fileData[curIndex] != '<')
            {
                curIndex += 1;
            }
            while (fileData[curIndex] == '<')
            {
                curIndex      += 1;
                openedBracket += 1;
            }

            aData.align = ReadUntilTagEnd(fileData, curIndex, out curIndex);
            while (fileData[curIndex] == '>')
            {
                curIndex      += 1;
                openedBracket -= 1;
            }

            convDatas.Add(aData);
            break;

        case "Prefab":
            ConversationFileDataPrefab pData = new ConversationFileDataPrefab();
            pData.firstCode = "Prefab";
            while (fileData[curIndex] != '<')
            {
                curIndex += 1;
            }
            while (fileData[curIndex] == '<')
            {
                curIndex      += 1;
                openedBracket += 1;
            }

            pData.prefabName = ReadUntilTagEnd(fileData, curIndex, out curIndex);
            while (fileData[curIndex] == '>')
            {
                curIndex      += 1;
                openedBracket -= 1;
            }

            GameObject obj = Resources.Load <GameObject>("Prefabs/Conversations/Events/" + pData.prefabName);
            preLoadedPrefabs.Add(pData.prefabName, obj);

            convDatas.Add(pData);

            break;

        case "If":
            ParseCondition(ref fileData, ref curIndex, ref openedBracket);

            break;

        case "Comp":
            ParseComp(ref fileData, ref curIndex, startIndex);
            //Debug.Log("str " + fileData[curIndex - 1] + fileData[curIndex] + fileData[curIndex + 1]);
            openedBracket -= 1;

            break;

        case "File":
            while (fileData[curIndex] != '<')
            {
                curIndex += 1;
            }

            string link = ReadUntilTagEnd(fileData, curIndex + 1, out curIndex);

            ConversationFileDataFile fData = new ConversationFileDataFile();
            fData.firstCode = "File";
            fData.fileName  = link;

            convDatas.Add(fData);

            curIndex += 1;
            break;

        case "Standing":
            ParseStandingCG(fileData, ref curIndex);

            curIndex += 1;
            break;

        case "Bgm":
            ConversationFileDataBGM bgmData = new ConversationFileDataBGM();
            bgmData.firstCode = "Bgm";

            while (fileData[curIndex] != '<')
            {
                curIndex += 1;
            }

            string musicName = ReadUntilTagEnd(fileData, curIndex + 1, out curIndex);

            bgmData.musicName = musicName;

            convDatas.Add(bgmData);

            break;

        default:
            Debug.LogWarning("CAN'T PARSE TAG " + code);

            break;
        }
    }