用到的语法(一)

using S_Random = System.Random;

// 系统的随机数方法和Unity引擎的不一样,所以重命名一下
S_Random rm = new S_Random();
int random = rm.Next(1, 3);  // 取整数1或2,不包括3

.ToString() // 转字符串
long.Parse();
(int)
Convert.ToInt32(sendGift.giftNum);   转整型

List<long> arrList = new List<long>();
List<long> arrList2 = new List<long>{1,2,3,4,5};
List<float> arr = new List<float>(){260f, 200f, 140f};
string[] ls = new string[] {"红","蓝"};

arrList2.Contains(2);  // 判断是否包含元素
arrList.Add(3);
arr.Remove(140f);
Dictionary<long, string> uidPersonName = new Dictionary<long, string>();

public void addUidPersonName(long uid, string userName){
		string sValue = "";
                // 安全判断字典是否中是否包含
		if(this.uidPersonName.TryGetValue(uid, out sValue)){

		}else{
                        // 字典添加
			this.uidPersonName.Add(uid, userName);
		}
	}
using System.Text.RegularExpressions;

// 正则
if(Regex.IsMatch(dm.msg, @"^加入\d+红")){
  string number = Regex.Replace(Regex.Replace(dm.msg, @"^加入", ""), "红", "");
}
using System.Threading;
// 延迟3秒执行
Invoke("changeAimPosition", 3.0f);

// 没有入参
private void changeAimPosition(){
    this.aimPosition = new Vector3(-55f, 122f, 298f);
}

// 开启携程5.0秒后执行,入参dm.uid
StartCoroutine(removeJinzhi(dm.uid, 5.0f));

IEnumerator removeJinzhi(long uid, float second){
    yield return new WaitForSeconds(second);
    CC.GetComponent<FightController>().jinzhiList.Remove(uid);
}
// 判断字符串是否纯数字
private bool IsNumber(string s)
{
	if (string.IsNullOrWhiteSpace(s)) return false;
	const string pattern = "^[0-9]*$";
	Regex rx = new Regex(pattern);
	bool RET = rx.IsMatch(s);
	return rx.IsMatch(s);
}
// 实例化一个物体
GameObject bot = GameObject.Instantiate(emo, new Vector3(x, 40f, z), Quaternion.Euler(new Vector3(0, 0, 0)));
bot.name = uid.ToString() + "_init";
Transform body = bot.transform.Find("Emo");
body.transform.rotation = Quaternion.Euler(rotationsList[rm.Next(0, 2)]);
// 子元素调整转向 rm.Next(0, 2)
// 子元素下的Name下的name文本组件中内容更改
GameObject.Find(bot.name + "/Name/name").GetComponent<UnityEngine.UI.Text>().text = n;
// 物体下的第一个子物体
GameObject.Find(uid.ToString()).transform.GetChild(0).transform.rotation = Quaternion.Euler(new Vector3(0, 0, 0));
// 键值对List
public List<KeyValuePair<long, int>> uidJF = new List<KeyValuePair<long, int>>();

// 添加
uidJF.Add(new KeyValuePair<long, int>(uid, getJiFen(uid)));

// 排序
uidJF.Sort(delegate (KeyValuePair<long, int> s1, KeyValuePair<long, int> s2)
{
    return s2.Value.CompareTo(s1.Value);
});

uidJF[i].Key;
uidJF[i].Value;
// 从一个范围内随机取count个数返回数组
public static int[] GetRandomArray(int count, int minNum, int maxNum)
    {

        int[] randomArr = new int[count];
        S_Random r = new S_Random();
        for (int j = 0; j < count; j++)
        {
            int i = r.Next(minNum, maxNum + 1);
            int num = 0;
            for (int k = 0; k < j; k++)
            {
                if (randomArr[k] == i) num = num + 1;
            }
            if (num == 0)
                randomArr[j] = i;
            else
                j = j - 1;
        }
        return randomArr;
    }

GetRandomArray(1, 0, emoList.Count - 1)[0];
// 每隔n秒做什么
public float time = 0;

void Update()
{
	time += Time.deltaTime;
        if (time >= 5f)//5秒
        {
            time = 0;
	    // 自动攻击每5s
		foreach(long uid in zidongList){
			uidSort.Add(uid);
		}
        }
}
// 获取未激活的元素并激活**
GameObject.Find("MainView").transform.Find("paihangbang/bg/bluewin").transform.gameObject.SetActive(true);
// 两个List取并集
private List<long> aUb(List<long> a, List<long> b)
	{
		List<long> c = new List<long>();
		foreach (long item in a)
		{
			if (!c.Contains(item))
			{
				c.Add(item);
			}
		}
		foreach (long item in b)
		{
			if (!c.Contains(item))
			{
				c.Add(item);
			}
		}
		this.abList = c;
		return c;
	}

public ArrayList fightingPersons = new ArrayList();
// 取补集
private ArrayList aBb(ArrayList a, List<long> b){
        ArrayList c = new ArrayList();
        foreach(long item in a){
            if(!b.Contains(item)){
                c.Add(item);
            }
        }
        return c;
    }

private List<long> aBb(List<long> a, List<long> b)
	{
		List<long> c = new List<long>();
		foreach (long item in a)
		{
			if (!b.Contains(item))
			{
				c.Add(item);
			}
		}
		return c;
	}

// 克隆
private List<long> clone(List<long> a){
		List<long> b = new List<long>();
		// a => b
		foreach(long item in a){
			b.Add(item);
		}
		return b;
	}
// 获取头像
public List<KeyValuePair<long, Sprite>> uidSpriteList = new List<KeyValuePair<long, Sprite>>();

// 获取各个阵营中选手的头像图片保存起来
foreach(long item in CC.GetComponent<WaitController>().alreadyChooseZhenYing){
     StartCoroutine(setImage(item, this.uidSpriteList));
}

public IEnumerator setImage(long uid, List<KeyValuePair<long, Sprite>> uidSpriteList){
        var url = CC.GetComponent<WaitController>().uidPersonFace[uid];
        WWW www = new WWW(url);//用WWW加载网络图片
        yield return www;
        if (www != null && string.IsNullOrEmpty(www.error))
        {
            //获取Texture
            Texture2D texture = www.texture;
            //因为我们定义的是Image,所以这里需要把Texture2D转化为Sprite
            Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
            uidSpriteList.Add(new KeyValuePair<long, Sprite>(uid, sprite));
        }
    }

张贴在C#