private void ReadCSV_StagingDirection(System.IO.TextReader reader)
    {
        string line;
        float  totalBeatCount            = 0;
        float  repeatPosition            = 0;
        List <StagingDirection> sequence = new List <StagingDirection>();

        while ((line = reader.ReadLine()) != null)
        {
            string[] lineCells = line.Split(',');
            switch (lineCells[0])
            {
            case "regionParameters":
                totalBeatCount = float.Parse(lineCells[2]);
                repeatPosition = float.Parse(lineCells[3]);
                break;

            case "AllBandMemberDefaultAnimation":
            {
                foreach (GameObject member in GameObject.FindGameObjectsWithTag("BandMember"))
                {
                    StagingDirection_SetBandMemberDefaultAnimation defaultAnimationSet
                        = new StagingDirection_SetBandMemberDefaultAnimation();
                    defaultAnimationSet.triggerBeatTiming    = float.Parse(lineCells[1]);
                    defaultAnimationSet.m_memberName         = member.name;
                    defaultAnimationSet.m_animationFromIndex = int.Parse(lineCells[2]);
                    defaultAnimationSet.m_animationToIndex   = int.Parse(lineCells[3]);
                    sequence.Add(defaultAnimationSet);
                }
            }
            break;

            case "SetAllBandMemberAction":
            {
                foreach (GameObject member in GameObject.FindGameObjectsWithTag("BandMember"))
                {
                    StagingDirection_SetBandMemberAction actionSet = new StagingDirection_SetBandMemberAction();
                    actionSet.triggerBeatTiming = float.Parse(lineCells[1]);
                    actionSet.m_memberName      = member.name;
                    actionSet.m_actionName      = lineCells[2];
                    sequence.Add(actionSet);
                }
            }
            break;

            case "stagingDirectionSequenceRegion-End":
            {
                for (float repeatOffest = 0; repeatOffest < totalBeatCount;)
                {
                    foreach (StagingDirection stagingDirection in sequence)
                    {
                        if (stagingDirection.triggerBeatTiming + repeatOffest > totalBeatCount)
                        {
                            break;
                        }
                        StagingDirection cloned = stagingDirection.GetClone() as StagingDirection;
                        cloned.triggerBeatTiming += m_stagingDirectoionRegionOffset + repeatOffest;
                        songInfo.stagingDirectionSequence.Add(cloned);
                    }
                    repeatOffest += repeatPosition;
                }
                m_stagingDirectoionRegionOffset += totalBeatCount;
            }
                return;

            // ↑已经有 return 所以这个 break 不会被执行
            //break;
            default:
            {
                StagingDirection stagingDirection
                    = StagingDirectionFactory.CreateStagingDirectionFromEnum(
                          (StagingDirectionEnum)System.Enum.Parse(typeof(StagingDirectionEnum), lineCells[0])
                          );
                if (stagingDirection != null)
                {
                    stagingDirection.ReadCustomParameterFromString(lineCells);
                    stagingDirection.triggerBeatTiming = float.Parse(lineCells[1]);
                    sequence.Add(stagingDirection);
                }
            }
            break;
            }
            ;
        }
        Debug.LogError("StagingDirectionSequenceRegion.ReadCSV: ParseError - missing stagingDirectionSequenceRegion-End");
    }
Example #2
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="reader"></param>
    private void ReadCSV_StagingDirection(System.IO.TextReader reader)
    {
        string line;
        float  totalBeatCount            = 0;
        float  repeatPosition            = 0;
        List <StagingDirection> sequence = new List <StagingDirection>();

        while ((line = reader.ReadLine()) != null)
        {
            string[] lineCells = line.Split(',');
            switch (lineCells[0])
            {
            case "regionParameters":            //-当前区域。第一个参数没用 Ready1。
                //-regionParameters,Intro,32,4
                //-在这个例子中,部分的长度是32拍,重复单位是4拍,所以相同的方向将在32÷4总共重复8次。
                totalBeatCount = float.Parse(lineCells[2]); //-这个区间有多少拍
                repeatPosition = float.Parse(lineCells[3]); //-重复拍子
                break;

            case "AllBandMemberDefaultAnimation":            //-全部乐手一起设置默认动画
            {
                foreach (GameObject member in GameObject.FindGameObjectsWithTag("BandMember"))
                {
                    StagingDirection_SetBandMemberDefaultAnimation defaultAnimationSet
                        = new StagingDirection_SetBandMemberDefaultAnimation();
                    defaultAnimationSet.triggerBeatTiming    = float.Parse(lineCells[1]);  //-时间(节拍数)
                    defaultAnimationSet.m_memberName         = member.name;                //-乐手的名字
                    defaultAnimationSet.m_animationFromIndex = int.Parse(lineCells[2]);    //-动画起始帧
                    defaultAnimationSet.m_animationToIndex   = int.Parse(lineCells[3]);    //-动画结束帧
                    sequence.Add(defaultAnimationSet);
                }
            }
            break;

            case "SetAllBandMemberAction":            //-全部乐手一起播放动画
            {
                foreach (GameObject member in GameObject.FindGameObjectsWithTag("BandMember"))
                {
                    StagingDirection_SetBandMemberAction actionSet = new StagingDirection_SetBandMemberAction();
                    actionSet.triggerBeatTiming = float.Parse(lineCells[1]); //-时间(节拍数)
                    actionSet.m_memberName      = member.name;               //-乐手的名字
                    actionSet.m_actionName      = lineCells[2];              //-动画的名字,actionA,actionB,跳
                    sequence.Add(actionSet);
                }
            }
            break;

            case "stagingDirectionSequenceRegion-End":                                          //-舞台活动结束,返回
            {
                for (float repeatOffest = 0; repeatOffest < totalBeatCount;)                    //-计算要循环几次
                {
                    foreach (StagingDirection stagingDirection in sequence)                     //-变量所有的动作
                    {
                        if (stagingDirection.triggerBeatTiming + repeatOffest > totalBeatCount) //-如果当前动作的执行时间加上循环时间超过区域的总时间,则抛弃这个时间
                        {
                            break;
                        }
                        StagingDirection cloned = stagingDirection.GetClone() as StagingDirection;
                        cloned.triggerBeatTiming += m_stagingDirectoionRegionOffset + repeatOffest;                            //-重新计算出事件真正的触发时间
                        songInfo.stagingDirectionSequence.Add(cloned);
                    }
                    repeatOffest += repeatPosition;
                }
                m_stagingDirectoionRegionOffset += totalBeatCount;
            }
                return;

            // 因为↑有return,所以这个break不被执行.
            //break;

            default://-其他非全体成员的动作通过工厂类创建自动初始化
            {
                StagingDirection stagingDirection
                    = StagingDirectionFactory.CreateStagingDirectionFromEnum(
                          (StagingDirectionEnum)System.Enum.Parse(typeof(StagingDirectionEnum), lineCells[0]));
                if (stagingDirection != null)
                {
                    stagingDirection.ReadCustomParameterFromString(lineCells);
                    stagingDirection.triggerBeatTiming = float.Parse(lineCells[1]);                        //-通用的在第几拍
                    sequence.Add(stagingDirection);
                }
            }
            break;
            }
            ;
        }
        Debug.LogError("StagingDirectionSequenceRegion.ReadCSV: ParseError - missing stagingDirectionSequenceRegion-End");
    }