继承:会继承基类的所有对象,但是私有的无法访问,这就是体现了封装性!基类保护自己的成员,对面给你一个public函数,让你获得,但是成员的处理都封装起来
class A {
private int a = 1;
public int GetA()
{
return a;
}
public A() {
Console.WriteLine("a ");
}
}
class B : A {
public B() {
Console.WriteLine("b");
}
}
Main函数
B b = new B();
Console.WriteLine( b.GetA());
Console.ReadKey();
先跑基类的构造函数,然后是子类, 私有成员,类外通过类的对象无法访问,只能让类对外提供接口
2
异步加载场景,unity使用中间过渡场景,在过渡场景加载比较大的场景
using UnityEngine;
using System.Collections;
public class LoadingAsy : MonoBehaviour {
public UILabel _text;
// Use this for initialization
AsyncOperation asy;
int Frame_rate = 0;
void Start () {
asy=Application.LoadLevelAsync("Fish");
asy.allowSceneActivation = false; //加载到90%不让他自动进入
}
// Update is called once per frame
void Update () {
Frame_rate++;
if (Frame_rate > 10)
{
Frame_rate = 0;
Debug.Log("rate");// 每10帧输出一次
}
_text.text = asy.progress * 100 + "%";// 场景太快,瞬间进去了
}
}
3 get set方法
namespace TestWhile
{
class TestGetSetFunc
{
public int Id{get;set;}
}
}
TestGetSetFunc testGet = new TestGetSetFunc();
testGet.Id = 122;
Console.WriteLine(testGet.Id);
Console.ReadKey();
getset方法 ,定义了一个内在变量,直接给其赋值,直接取出变量,通过类似函数指针的Id方法