Unity 笔试题分享

1. 请回答以下代码片段执行时是否会产生堆内存分配

a.

csharp 复制代码
  void SetChar(string s)
    {
        s.Replace('b', 'd');
    }

b.

csharp 复制代码
void Update(Transform t)
    {
        t.localPosition = new Vector3(0, 0, 0);
    }

c、

csharp 复制代码
    int Sum(List<int> l)
    {
        int total = 0;
        foreach (int i in l)
        {
            total += i;
        }      
        return total;
	}

d、

csharp 复制代码
 void SetValueAt(List<object> l, int index, int value)
    {
        if (index < 0 || index >= l.Count) {
            return;
        }

        l[index] = value;
	}
  1. A 会产生新的字符串 ,会产生
  2. B 用了New关键字 ,会产生
  3. C 会创建迭代器 ,会产生
  4. D 产生装箱操作 ,会产生

2、以下代码会产生什么样的输出

csharp 复制代码
 IEnumerator Test1()
    {
        Debug.Log("A");
        yield return Test2(); 
       
        Debug.Log("B");
        yield return null;

        Debug.Log("C");
    }

    IEnumerator Test2()
    {
        Debug.Log("D");
        yield break;

        Debug.Log("E");
    }

    void Start()
    {
        StartCoroutine(Test1());
	}

ADBC

3、请用数学公式描述如何计算向量V的反射向量R(V和N都是单位向量)

做如下辅助线

  1. V · N = |V||N|cos(θ ) = cos(θ )
  2. P = |V| * cos(θ ) * N =( V · N)* N
  3. R = R' = 2P - V = 2(V · N)N - V
相关推荐
切韵9 天前
Unity编辑器扩展:UI绑定复制工具
ui·unity·编辑器
10 天前
Lua复习之何为闭包
开发语言·unity·游戏引擎·lua·交互
深空数字孪生10 天前
2025年小程序地图打车的5大技术革新:实时路况预测与智能调度升级
大数据·人工智能·unity·性能优化·小程序·游戏引擎
RPGMZ10 天前
RPGMZ 游戏引擎如何与lua进行互相调用 初探
开发语言·javascript·游戏引擎·lua·rpgmz
程序猿多布10 天前
Unity Addressable使用之检测更新流程
unity·addressable
Bunny Chen11 天前
Unity中的物理单位是真实的吗?
unity·游戏引擎
benben04411 天前
Unity3D仿星露谷物语开发69之动作声音
游戏·ui·unity·c#·游戏引擎
徐子竣11 天前
Unity Shader开发-着色器变体(1)-着色器变体概述
unity·游戏引擎·着色器
playmak3r12 天前
某手游cocos2dlua反编译
游戏引擎·lua·cocos2d
Magnum Lehar12 天前
wpf3d游戏引擎ProjectLayoutView实现
游戏引擎·wpf