Unity-各种小技巧
发表于|更新于|Unity学习记录
|浏览量:
一、片段——使代码更加美观
visual studio里通过选择代码片段 -> 右击 -> 片段 -> region 可以插入片段,为代码分块
1 | #region int |
文章作者: 星辰微光
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 星辰微光的博客!
相关推荐

2022-01-17
Unity学习记录3-String字符串的截取,分割,格式化
Unity学习记录3-String字符串的截取,分割,格式化 一、字符串的截取 语法: 变量名=欲截取变量名.Substring(开始位置,长度); 注意:字符串上的位置从0开始 示例: 1234567private string str01;public string str02;str01 = "Sakura and Sakura";//字符串赋值str02 = str01.Substring(0, 6);//字符串截取//str02结果为Sakura 二、字符串的分割 语法: 字符串数组名=欲分割字符串.Split(’标志字符‘); 注意:分割为取标志字符左右,标志字符会被忽略 示例: 123str01 = "Sakura and Sakura";//字符串赋值public string[] strarry;strarry = str01.Split('a');//字符串分离 运行结果: 三、字符串的格式化 示例: 12a += Time.deltaTime;texter02.text =...

2022-02-27
C#学习记录-ref和out
C#学习记录-ref和out 两者都是对参数进行引用传递 ref参考: 关键字使参数按引用传递。其效果是,当控制权传递回调用方法时,在方法中对参数的任何更改都将反映在该变量中。若要使用 ref 参数,则方法定义和调用方法都必须显式使用 ref 关键字 out参考: out 关键字会导致参数通过引用来传递。这与 ref 关键字类似,不同之处在于 ref 要求变量必须在传递之前进行初始化。若要使用 out 参数,方法定义和调用方法都必须显式使用 out 关键字 示例: 12345678910111213141516171819202122232425262728293031323334353637383940using System;namespace ref和out练习{ class Program { void ChangeValue(int a) { a = 114514; } void ChangeValueWithRef(ref int a) ...

2022-07-19
C#学习记录-各种数组的定义
C#学习记录-各种数组的定义 一维数组的定义 123456789101112int[] array1;array1 = new int[5];int[] array2 = new int[5];//推荐int[] array3 = new int[5]{1,2,3,4,5};int[] array4 = new iny[]{1,2,3,4,5};int[] array5 = {1,2,3,4,5};//推荐 二维数组的定义 12345678910111213141516171819int[,] array1;array1={{1,2}, {3,4}};int[,] array2 = new int[3,3];//推荐int[,] array3 = new int[3,3]{{1,2,3}, {4,5,6}, ...

2022-07-20
C#学习记录-拓展方法
C#学习记录-拓展方法 拓展方法,即对现有的 非静态 变量类型添加新的方法 拓展方法可以为别人封装好的类型写额外的方法,提升程序的扩展性 必须写在静态类中 一定是一个静态函数 第一个参数用this修饰,后面跟上拓展的变量类型,作为拓展目标 注意拓展方法的访问修饰符 示例: 1234567public static class ToolBox{ public static void Printit(this int value) { Console.WriteLine(value); }} 这里为int类型拓展了一个新方法。注意写在静态类中,是一个静态函数 123456789101112namespace 拓展方法{ class Program { static void Main(string[] args) { Console.WriteLine("Hello World!"); ...

2022-07-18
C#学习记录-索引器
C#学习记录-索引器 索引器可以让对象像数组一样访问其中的元素。让程序看起来更加直观。比较适用于类中有数组变量时使用,可以方便地访问和调整 语法 访问修饰符+返回值类型+this+【参数】 例: 12345678910111213141516171819202122232425class Person{ public int[] array = new int[10]; //索引器 public int this[int index] { get { if (index < array.Length) { return array[index]; } else return -1; } set { if (index < array.Length) ...

2022-07-21
C#学习记录—密封类和密封方法
C#学习记录—密封类和密封方法 密封类 密封类,关键字 sealed 1234sealed class Son::Father{ } 其作用是让类无法再被继承 加强了面向对象程序设计的规范性,结构性,安全性 密封方法 密封方法可以使一个方法不能再被重写 12345678910111213abstract class Person{ public void Eat();}class Man:Person{ public sealed override void Eat() { } //使用sealed关键字密封方法,让方法不能再被重写}
公告
This is my Blog