Unity 理论-技术代码验证

  1.7 C#, 3.2 游戏引擎技术
  • 本篇博客主要记录在理论和一些遇到新技术的内容中,编写的一些代码测试以验证其正确性or如何使用。

理论类

Struct和普通值引用类型的深拷贝

public struct ValueReferenceNode
{
    public int value;
}

public class ValueReference : MonoBehaviour
{
    public ValueReferenceNode a;
    public ValueReferenceNode b;

    public int c;
    public int d;

    void Start()
    {
        a = new ValueReferenceNode();
        a.value = 1;
        b = a;
        a.value++;
        Debug.Log(a.value + ":" + b.value);

        c = 10;
        d = c;
        c = c + 10;
        Debug.Log(c + ":" + d);
    }
}

技术类

LinkedList

  • 该类型即为纯指针的链式链表类型,可以在头尾进行直接插入,而想选择第x个数则需要遍历,不能直接使用[x]。
    //LinkedList 没有[]索引,但是是按顺序存储
    public LinkedList<int> list = new LinkedList<int>();

    void Start()
    {
        list.AddFirst(1);
        list.AddLast(2);
        list.AddLast(3);
        list.AddFirst(4);

        int i = 0;
        foreach(var l in list)
            Debug.Log(++i + ":" + l);
    }

throw new ArgumentNullException

//类似于打一个报错日志,我在没有继承MonoBehaviour的类中使用该方法抛出报错(个人应用场面无需做try catch,只起一个代码定位作用)
void Start()
{
        throw new ArgumentNullException("123");
}

LEAVE A COMMENT