OpenXR開發(fā)實(shí)戰(zhàn)項(xiàng)目之VR 節(jié)奏光劍

一匪蟀、框架視圖

二、關(guān)鍵代碼

ViewMusic

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

public class ViewMusic : MonoBehaviour
{
    public Transform[] boxTransforms = new Transform[64];

    public int isRight = 1;

    public AudioSource audioSource;

    public float[] sepctrumData = new float[64];

    public MeshRenderer[] meshRenderers = new MeshRenderer[64];

    public int UpLerp = 12;

    void Start()
    {
        SetCunbeInfo();
    }

    // Update is called once per frame
    void Update()
    {
        audioSource.GetSpectrumData(sepctrumData, 0, FFTWindow.BlackmanHarris);
        SetScale();
        SetColor();
    }


    public void SetCunbeInfo()
    {
        Array.Clear(boxTransforms, 0, 64);
        Array.Clear(meshRenderers, 0, 64);

        for(int i=0;i<64;i++)
        {
            transform.GetChild(i).position = new Vector3(5 * isRight, 2.5f, 6.5f + 0.25f * i);
            transform.GetChild(i).localScale = new Vector3(0.2f, 3f, 0.01f);
            boxTransforms[i] = transform.GetChild(i);
            meshRenderers[i] = transform.GetChild(i).GetComponent<MeshRenderer>();
        }
    }

   public void SetScale()
    {
        for(int i=0;i<64;i++)
        {
            Vector3 _v3 = boxTransforms[i].transform.localScale;

            float a = sepctrumData[i] * 100000;

            Vector3 _v4 = new Vector3(0.2f, Mathf.Clamp(a, 0.1f, 3), 0.01f);

            boxTransforms[i].localScale = Vector3.Lerp(boxTransforms[i].localScale, _v4, Time.deltaTime * UpLerp);
        }
    }


    public void SetColor()
    {


        for (int i = 0; i < 64; i++)
        {
           
            
            if (boxTransforms[i].localScale.y <= 0.4f)
            {
                meshRenderers[i].material.SetColor("_EmissionColor", new Color(0.2f, 0.5f, 0.5f));
            }
            else if (boxTransforms[i].localScale.y <= 0.8f)
            {
                meshRenderers[i].material.SetColor("_EmissionColor", new Color(0.12f, 0.84f, 0.38f));
            }
            else if (boxTransforms[i].localScale.y <= 1.2f)
            {
                meshRenderers[i].material.SetColor("_EmissionColor", new Color(0.12f, 0.84f, 0.38f));
            }
            else if (boxTransforms[i].localScale.y <= 1.6f)
            {
                meshRenderers[i].material.SetColor("_EmissionColor", new Color(0.23f, 0.89f, 0.05f));
            }


            else if (boxTransforms[i].localScale.y <= 2f)
            {
                meshRenderers[i].material.SetColor("_EmissionColor", new Color(0.63f, 0.56f, 0.04f));
            }

            else if (boxTransforms[i].localScale.y <= 2.4f)
            {
                meshRenderers[i].material.SetColor("_EmissionColor", new Color(0.92f, 0.27f, 0.02f));
            }

            else if (boxTransforms[i].localScale.y <= 2.8f)
            {
                meshRenderers[i].material.SetColor("_EmissionColor", new Color(0.92f, 0.27f, 0.02f));
            }
            else
            {
                meshRenderers[i].material.SetColor("_EmissionColor", new Color(0.90f, 0.01f, 0.1f));
            }
            
        }
    }
}



Spawn

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

public class Spawn : MonoBehaviour
{
    public List<Box> boxList;
    public List<Transform> transfromList;

    public float boxSpeed;

    public GameObject boomPrefab;
    public void Init()
    {
        boxSpeed = 5;
    }


    private void Start()
    {
        Init();
    }


    public void CreateBox()
    {
        GameObject temp = GameObject.Instantiate(boxList[Random.Range(0, boxList.Count)]).gameObject;
        temp.transform.position = transfromList[Random.Range(0, transfromList.Count)].position;

        Box box = temp.GetComponent<Box>();
        BoxType type = BoxType.Up;

        int num = Random.Range(0, 4);

        switch (num)
        {

            case 0:
                type = BoxType.Up; break;
            case 1:
                type = BoxType.Left; break;
            case 2:
                type = BoxType.Down; break;
            case 3:
                type = BoxType.Right; break;

        }

        box.Init(boxSpeed, type);
        box.SetRotationBaseType();
    }

    public void CreateBoom()
    {

        GameObject temp = GameObject.Instantiate(boomPrefab);
        temp.transform.position= transfromList[Random.Range(0, transfromList.Count)].position;

        Boom boom=temp.GetComponent<Boom>();
        boom.Init(boxSpeed);
    }
    
}

SortPannel

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

public class SortPannel : MonoBehaviour
{
    public Text sortText;


    private void Start()
    {
        sortText = GetComponentInChildren<Text>();
        ShowInfo();
    }

    public void ShowInfo()
    {
        DataMgr.Instance.ReadDate();

        if(DataMgr.Instance.saveScore.Count==0)
        {
            sortText.text = "_";
        }
        else
        {
            DataMgr.Instance.saveScore.Sort((x, y) => -x.CompareTo(y));
            sortText.text = "BestScore:" + DataMgr.Instance.saveScore[0];
        }
    }
}

Slice

using EzySlice;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.Tracing;
using System.IO;
using UnityEngine;
using Valve.VR;

public class Slice : MonoBehaviour
{
    public GameObject source;

    public Material material;

    public AudioSource audioSource;

    public AudioClip clip;

    public Saber saber;
    public int saberID;


    public GameObject hitEffect;

    
    private void Start()
    {
        audioSource=GetComponent<AudioSource>();
        saberID = saber.saberColor;
    }
    public void OnTriggerEnter(Collider other)
    {
        if(other.tag!="Box")
        {
            return;
        }

        source = other.gameObject;

        SlicedHull slicedHull = source.Slice(transform.position, transform.right,material);

        if(source==null)
        {
            return;
        }

        if(slicedHull==null)
        {
            return;
        }

        audioSource.PlayOneShot(clip);
        Shake();

        GameObject temp = GameObject.Instantiate(hitEffect, transform.position, Quaternion.identity);
        GameObject.Destroy(temp, 0.5f);
        if(saber.saberColor==other.gameObject.transform.root.GetComponent<Box>().boxColor)
        {
            //
            GameMgr.Instance.UpdateScore(1);
            GameMgr.Instance.UpdateCombom();

           
            GameMgr.Instance.lv.AddLV();
        }


        GameObject upGo = slicedHull.CreateUpperHull(source,material);
        GameObject lowerGo = slicedHull.CreateLowerHull(source, material);


        Vector3 location = this.transform.position;
        Vector3 closetPosition = other.ClosestPoint(location);
        upGo.transform.position = closetPosition;
        lowerGo.transform.position = closetPosition;
        GameObject.Destroy(other.transform.parent.gameObject);


        upGo.AddComponent<Rigidbody>();
        lowerGo.AddComponent<Rigidbody>();

       
        upGo.GetComponent<Rigidbody>().AddExplosionForce(500, upGo.transform.position - transform.right, 3);
        lowerGo.GetComponent<Rigidbody>().AddExplosionForce(500, lowerGo.transform.position + transform.right, 3);

        GameObject.Destroy(upGo.gameObject, 0.5f);
        GameObject.Destroy(lowerGo.gameObject, 0.5f);
    }


    public void Shake()
    {
        SteamVR_Actions.default_Haptic.Execute(0, 0.5f, 100, 200,saber.pose.inputSource);
       

    }
}

Player

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Valve.VR.Extras;

public class Player : MonoBehaviour
{
    public GameObject swordRed;
    public GameObject swordBlue;


    public GameObject ControllerLeft;
    public GameObject ControllerRight;

    public InteractUI interactLeft;
    public InteractUI interactRight;


    public void Awake()
    {

        interactLeft = ControllerLeft.GetComponent<InteractUI>();
        interactRight = ControllerLeft.GetComponent<InteractUI>();
    }
    public void ShowOrHideSaber(bool isShow)
    {
        swordRed.gameObject.SetActive(isShow);
        swordBlue.gameObject.SetActive(isShow);

    }
}

MusicEvent

using SonicBloom.Koreo;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Random = UnityEngine.Random;

public class MusicEvent : MonoBehaviour
{
    public string eventCreate;

    public Spawn spawn;


    public string eventGameOver;

    
    private void Start()
    {
        eventCreate = "Create";
        Koreographer.Instance.RegisterForEvents(eventCreate, Create);

        spawn = GameObject.Find("Spawn").GetComponent<Spawn>();

        eventGameOver = "SongOver";

        Koreographer.Instance.RegisterForEvents(eventGameOver, SongOver);
    }

    private void SongOver(KoreographyEvent koreoEvent)
    {
        GameMgr.Instance.gameState = GameState.gameEnd;
    }

    private void Create(KoreographyEvent koreoEvent)
    {
        int num =Random.Range(0, 10);
        if(num<=8)
        {
            spawn.CreateBox();
        }
        else
        {
            spawn.CreateBoom();
        }
    }
}

GameMgr

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


public enum GameState
{
    gamePrepare,
    gameStart,
    gameEnd,


}

public class GameMgr : MonoBehaviour
{
    private static GameMgr instance;

    public static GameMgr Instance
    {
        get
        {
            if (instance != null)
            {
                return instance;
            }
            else
            {
                //為了防止腳本還未掛到物體上划鸽,找不到的異常情況架忌,可以自行創(chuàng)建空物體掛上去
                instance = Object.FindFirstObjectByType<GameMgr>();
                if (instance == null)
                {
                    //如果創(chuàng)建對(duì)象,則會(huì)在創(chuàng)建時(shí)調(diào)用其身上腳本的Awake
                    //所以此時(shí)無需為instance賦值,其會(huì)在Awake中賦值拘央,自然也會(huì)初始化所以無需init()
                    GameObject go = new GameObject("GameMgr");
                    go.AddComponent<GameMgr>();
                }
                instance.Init();
            }
            return instance;
        }
    }


    public int currentCombo;
    public int currentScore;

    public ScorePannel scorePannel;
    public bool isInterrupt=false;

    public int currentLV;
    public LV lv;
    public LVPannel lVPannel;

    public Dictionary<int, AudioClip> songDic = new Dictionary<int, AudioClip>();
    public AudioClip clip1;
    public AudioClip clip2;
    public AudioSource audioSource;

    public GameState gameState;

    public GameObject musicPlayer;
    public DataMgr datamgr;
    public MainPannel mainPannel;
    public Player player;

    private void Awake()
    {
        instance = this;
        scorePannel=GameObject.Find("ScoreBg").GetComponent<ScorePannel>();
        lVPannel= GameObject.Find("LVBg").GetComponent<LVPannel>();
        mainPannel= GameObject.Find("MainBg").GetComponent<MainPannel>();
        musicPlayer = GameObject.Find("MusicPlayer");
        player = GameObject.Find("XR Origin").GetComponent<Player>();
        Init();
    }

    public void Init()
    {
        gameState = GameState.gamePrepare;
        songDic.Clear();
        songDic.Add(1, clip1);
        songDic.Add(2,clip2);

        currentCombo = 0;
        currentLV = 0;
        currentScore = 0;

        isInterrupt = false;
    }

    private void Start()
    {
        Prepare();
    }
    public void UpdateScore(int score)
    {
        currentScore += score;
        if(currentScore<=0)
        {
            currentScore = 0;
        }

        scorePannel.UpdateScore(currentScore);
    }

    public void UpdateCombom()
    {
        if(isInterrupt)
        {
            currentCombo = 0;
            scorePannel.UpdateCombo(0);
            isInterrupt = false;
        }
        else
        {
            currentCombo++;
            scorePannel.UpdateCombo(currentCombo);
        }
    }

    public AudioClip SetSong(int index)
    {
        AudioClip clip;
        songDic.TryGetValue(index, out clip);

        if(clip==null)
        {
            clip = clip1;
        }

        return clip;
    }
    
    public void Prepare()
    {

      
        AudioClip clip = SetSong(DataMgr.Instance.currentIndex);
        audioSource.clip = clip;

        audioSource.Play();


       

        player.ShowOrHideSaber(true);

        mainPannel.gameObject.SetActive(false);

        scorePannel.Init();
        lVPannel.Init();

        gameState = GameState.gameStart;

    }


    private void Update()
    {
        if (gameState==GameState.gameEnd)
        {
            GameOver();
        }
    }

    public void GameOver()
    {
        mainPannel.gameObject.SetActive(true);
        mainPannel.ShowScore(currentScore);

        audioSource.Stop();
        player.ShowOrHideSaber(false);
    }
}

MainPannel

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

public class MainPannel : MonoBehaviour
{
    public Text totalText;
    public Button btn_Restart;
    public Button btn_Back;


    private void Awake()
    {
        totalText=transform.Find("Text_Total").GetComponentInChildren<Text>();
        btn_Back=transform.Find("Btn_Back").GetComponentInChildren<Button>();
        btn_Restart=transform.Find("Btn_Restart").GetComponentInChildren<Button>();

        btn_Back.onClick.AddListener(() => { Back(); });
        btn_Restart.onClick.AddListener(() => { Restart(); });
    }


    public void Back()
    {
       
        //
        DataMgr.Instance.currentScore = GameMgr.Instance.currentScore;
        //
        DataMgr.Instance.WriteData(DataMgr.Instance.currentScore);
        SceneManager.LoadScene(0);
    }

    public void Restart()
    {
        GameMgr.Instance.Init();
        GameMgr.Instance.Prepare();
    }

    public void ShowScore(int score)
    {
        totalText.text = "Score:" + score;
    }
}

LVPannel

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

public class LVPannel : MonoBehaviour
{
    public Text textLV;
    public Text healthText;

    public int maxHealth;
    public int currentHealth;
    private void Awake()
    {
        textLV= transform.Find("Text_LV").GetComponent<Text>();
        healthText = transform.Find("Text_Health").GetComponent<Text>();
        maxHealth = currentHealth = 100;
    }


    public void Init()
    {
        textLV.text = "LV:1";
        healthText.text = "Health:100";
    }


    private void Start()
    {
        Init();
    }

    public void CalculateDamage(int lv)
    {
        int baseCount = 10;
        float damage = maxHealth / (baseCount * 1.5f + lv - 1);
        int damage1 = Convert.ToInt32(damage);

        currentHealth -= damage1;
        if(currentHealth<=0)
        {
            currentHealth = 0;
        }

        healthText.text = "Health:" + currentHealth;
    }

   

    public void UpdateLV(int lv)
    {
        textLV.text = "LV:" + lv;
    }
}

LV

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

public class LV : MonoBehaviour
{
    public int nextLevelScore;
    public Dictionary<int, int> lvScoreDic = new Dictionary<int, int>();
    void Awake()
    {
        Init();
    }

    private void Init()
    {
        lvScoreDic.Clear();
        lvScoreDic.Add(1, 3);
        lvScoreDic.Add(2, 5);
        lvScoreDic.Add(3, 7);
        lvScoreDic.Add(4, 10);
        lvScoreDic.Add(5, 14);
        lvScoreDic.Add(6, 18);
        lvScoreDic.Add(7, 25);
    }

    public void LimitLV()
    {
        if (GameMgr.Instance.currentLV <= 1)
        {
            GameMgr.Instance.currentLV = 1;
        }
        if (GameMgr.Instance.currentLV >= 8)
        {
            GameMgr.Instance.currentLV = 8;
        }
    }

    public void CalculateLV()
    {
        if (GameMgr.Instance.currentLV >= 1 && GameMgr.Instance.currentLV <= 7)
        {
            nextLevelScore = lvScoreDic[GameMgr.Instance.currentLV];

        }
    }

    public void AddLV()
    {
        CalculateLV();
        if (GameMgr.Instance.currentScore >= nextLevelScore)
        {
            GameMgr.Instance.currentLV += 1;
            LimitLV();
            GameMgr.Instance.lVPannel.UpdateLV(GameMgr.Instance.currentLV);
        }
    }

    public void ReduceLV()
    {
        GameMgr.Instance.currentLV -= 1;
        LimitLV();
        GameMgr.Instance.lVPannel.UpdateLV(GameMgr.Instance.currentLV);
    }

}

CheckMiss

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

public class CheckMiss : MonoBehaviour
{
    public void OnTriggerEnter(Collider other)
    {
        
        if(other.tag=="Box")
        {
            GameMgr.Instance.isInterrupt = true;
            GameMgr.Instance.UpdateCombom();
           
        }

        GameObject.Destroy(other.gameObject);
    }
}

Box

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

public enum BoxType
{ 
    Up,
    Down,
    Left,
    Right,

}

public class Box : MonoBehaviour
{
    public float boxSpeed;
    public BoxType boxType;
    public int boxColor;

    private void Start()
    {
        GameObject.Destroy(this.gameObject, 8f);
    }
    public void Init(float speed,BoxType type)
    {
        boxSpeed = speed;
        boxType = type;
    }

    public void SetRotationBaseType()
    {
        switch(boxType)
        {

            case BoxType.Up:
                transform.rotation = Quaternion.Euler(0, 0, 0);
                break;
                case BoxType.Left:
                transform.rotation = Quaternion.Euler(0, 0, 90);
                break;
                     case BoxType.Down:
                transform.rotation = Quaternion.Euler(0, 0, 180);
                break;
                      case BoxType.Right:
                transform.rotation = Quaternion.Euler(0, 0, 270); ;
                break;

        }
    }


    public void Update()
    {
        transform.Translate(-transform.forward * Time.deltaTime * boxSpeed);
        if(GameMgr.Instance.gameState==GameState.gameEnd)
        {
            GameObject.Destroy(this.gameObject);
        }
    }

}

Boom

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

public class Boom : MonoBehaviour
{
    public float Speed;
    public GameObject hitEffect;
    private void Start()
    {
        GameObject.Destroy(this.gameObject, 8f);
    }
    public void Init(float speed=5)
    {
        Speed = speed;
    }

    public void Update()
    {
        transform.Translate(-transform.forward * Time.deltaTime *Speed);
        if (GameMgr.Instance.gameState == GameState.gameEnd)
        {
            GameObject.Destroy(this.gameObject);
        }
    }

    public void OnTriggerEnter(Collider other)
    {
        if(other.tag=="Slice")
        {
            GameMgr.Instance.lv.ReduceLV();
            GameMgr.Instance.lVPannel.CalculateDamage(GameMgr.Instance.currentLV);
            GameMgr.Instance.UpdateScore(-2);
            GameObject go=  GameObject.Instantiate(hitEffect, transform.position, Quaternion.identity);
            GameObject.Destroy(go, 0.5f);
            GameObject.Destroy(gameObject);

        }
    }

    
}

StartUI

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

//給按鈕點(diǎn)擊注冊(cè)事件 選中哪個(gè)歌,就記錄該首歌 书在,跳轉(zhuǎn)目標(biāo)場景 
public class StartUI : MonoBehaviour
{
    public List<SongSlot> btnSongList;

    private void Start()
    {
        SetSlotUI();
    }
    public void SetSlotUI()
    {
        for (int i = 0; i < btnSongList.Count; i++)
        {
            //注數(shù)組越界 完整的應(yīng)寫無限滾動(dòng)列表
            //注意i 可能在字典里越界
            btnSongList[i].slotIndex = i;
            btnSongList[i].SetUI(DataMgr.Instance.songNameDic[i]);
        }
    }
}

SongSlot

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

public class SongSlot : MonoBehaviour
{
    public Text song;
    public string songName;

    //格子索引
    public int slotIndex;



    private void Awake()
    {
        song = GetComponentInChildren<Text>();
        GetComponent<Button>().onClick.AddListener(() => { LoadGame(); });
    }

    //設(shè)置UI信息 安全校驗(yàn)
    public void SetUI(string name)
    {
        if (string.IsNullOrEmpty(name))
        {
           
          
            return;
        }
        songName = name;
        song.text = songName;
    }

    //如果當(dāng)前格子沒有顯示歌曲名 不跳轉(zhuǎn)場景
    public void LoadGame()
    {
        if (string.IsNullOrEmpty(song.text))
        {
            return;
        }

        SceneManager.LoadScene(1);
    }
}

InteractUI

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Valve.VR.Extras;

[RequireComponent(typeof(SteamVR_LaserPointer))]
public class InteractUI : MonoBehaviour
{

    private SteamVR_LaserPointer laser;
    void Start()
    {
        laser = GetComponent<SteamVR_LaserPointer>();
        laser.PointerClick += Laser_PointerClick;
        laser.PointerIn += Laser_PointerIn;
        laser.PointerOut += Laser_PointerOut;
    }

    private void Laser_PointerOut(object sender, PointerEventArgs e)
    {
        
    }

    private void Laser_PointerIn(object sender, PointerEventArgs e)
    {
       
    }

    private void Laser_PointerClick(object sender, PointerEventArgs e)
    {
        Button btn = e.target.GetComponent<Button>();
        if(btn!=null)
        {
          SongSlot slot=  btn.GetComponentInChildren<SongSlot>();
            if(slot!=null)
            {
                DataMgr.Instance.currentIndex = slot.slotIndex;
            }

            btn.onClick.Invoke();
        }
    }

    void Update()
    {
        
    }
}

DataMgr

using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;

//數(shù)據(jù)管理類 單例
public class DataMgr : MonoBehaviour
{
    private static DataMgr instance;
    //歌曲名字典 
    public Dictionary<int, string> songNameDic = new Dictionary<int, string>();

    public static DataMgr Instance
    {
        get
        {
            if (instance != null)
            {
                return instance;
            }
            else
            {
                //為了防止腳本還未掛到物體上灰伟,找不到的異常情況,可以自行創(chuàng)建空物體掛上去
                instance = Object.FindFirstObjectByType<DataMgr>();
                if (instance == null)
                {
                    //如果創(chuàng)建對(duì)象,則會(huì)在創(chuàng)建時(shí)調(diào)用其身上腳本的Awake
                    //所以此時(shí)無需為instance賦值栏账,其會(huì)在Awake中賦值帖族,自然也會(huì)初始化所以無需init()
                    GameObject go = new GameObject("DataMgr");
                    go.AddComponent<DataMgr>();
                }
                instance.Init();
            }
            return instance;
        }
    }

    public int currentIndex;
    public int currentScore;

    public string dataPath;
    public List<int> saveScore=new List<int>();
    private void Awake()
    {
        
        if(instance!=null)
        {
            GameObject.Destroy(this.gameObject);
            return;
        }
        else
        {
            instance = this;
        }
        Init();
        DontDestroyOnLoad(gameObject);
        dataPath = Application.persistentDataPath + "/SaveScore.txt";
        CreateDataFile();

    }


    private void Start()
    {
       
        
    }
    public void Init()
    {
        //假數(shù)據(jù)
        songNameDic.Clear();
        songNameDic.Add(0, "Night");
        songNameDic.Add(1, "");
        songNameDic.Add(2, "");
        songNameDic.Add(3, "");
    }

    public void CreateDataFile()
    {
        Debug.Log(dataPath);
        if(!File.Exists(dataPath))
        {
            Debug.Log("不存在該文件");
            File.Create(dataPath);
            Debug.Log("該文件已創(chuàng)建");
            return;
        }
    }
    
    public void WriteData(int currentScore)
    {
        CreateDataFile();
        using(StreamWriter sw = new StreamWriter(dataPath, true)) { sw.WriteLine(currentScore); }
    }

    public void ReadDate()
    {
        saveScore.Clear();
        string str = string.Empty;
        using(StreamReader sr = new StreamReader(dataPath))
        {

            while((str= sr.ReadLine()) != null)
            {
                if(string.IsNullOrWhiteSpace(str))
                {
                    continue;
                }
                int score = int.Parse(str);
                saveScore.Add(score);
            }


        }
    }
}

三、效果圖

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末挡爵,一起剝皮案震驚了整個(gè)濱河市竖般,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌茶鹃,老刑警劉巖涣雕,帶你破解...
    沈念sama閱讀 206,214評(píng)論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異闭翩,居然都是意外死亡挣郭,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,307評(píng)論 2 382
  • 文/潘曉璐 我一進(jìn)店門疗韵,熙熙樓的掌柜王于貴愁眉苦臉地迎上來兑障,“玉大人,你說我怎么就攤上這事蕉汪×饕耄” “怎么了?”我有些...
    開封第一講書人閱讀 152,543評(píng)論 0 341
  • 文/不壞的土叔 我叫張陵者疤,是天一觀的道長福澡。 經(jīng)常有香客問我,道長宛渐,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 55,221評(píng)論 1 279
  • 正文 為了忘掉前任眯搭,我火速辦了婚禮窥翩,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘鳞仙。我一直安慰自己寇蚊,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,224評(píng)論 5 371
  • 文/花漫 我一把揭開白布棍好。 她就那樣靜靜地躺著仗岸,像睡著了一般。 火紅的嫁衣襯著肌膚如雪借笙。 梳的紋絲不亂的頭發(fā)上扒怖,一...
    開封第一講書人閱讀 49,007評(píng)論 1 284
  • 那天,我揣著相機(jī)與錄音业稼,去河邊找鬼盗痒。 笑死,一個(gè)胖子當(dāng)著我的面吹牛低散,可吹牛的內(nèi)容都是我干的俯邓。 我是一名探鬼主播骡楼,決...
    沈念sama閱讀 38,313評(píng)論 3 399
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼稽鞭!你這毒婦竟也來了鸟整?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 36,956評(píng)論 0 259
  • 序言:老撾萬榮一對(duì)情侶失蹤朦蕴,失蹤者是張志新(化名)和其女友劉穎篮条,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體梦重,經(jīng)...
    沈念sama閱讀 43,441評(píng)論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡兑燥,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 35,925評(píng)論 2 323
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了琴拧。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片降瞳。...
    茶點(diǎn)故事閱讀 38,018評(píng)論 1 333
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖蚓胸,靈堂內(nèi)的尸體忽然破棺而出挣饥,到底是詐尸還是另有隱情,我是刑警寧澤沛膳,帶...
    沈念sama閱讀 33,685評(píng)論 4 322
  • 正文 年R本政府宣布扔枫,位于F島的核電站,受9級(jí)特大地震影響锹安,放射性物質(zhì)發(fā)生泄漏短荐。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,234評(píng)論 3 307
  • 文/蒙蒙 一叹哭、第九天 我趴在偏房一處隱蔽的房頂上張望忍宋。 院中可真熱鬧,春花似錦风罩、人聲如沸糠排。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,240評(píng)論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽入宦。三九已至,卻和暖如春室琢,著一層夾襖步出監(jiān)牢的瞬間乾闰,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,464評(píng)論 1 261
  • 我被黑心中介騙來泰國打工盈滴, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留汹忠,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 45,467評(píng)論 2 352
  • 正文 我出身青樓,卻偏偏與公主長得像宽菜,于是被迫代替她去往敵國和親谣膳。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,762評(píng)論 2 345