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
相关推荐
真鬼12317 小时前
【Unity 6】Unity6快捷下载,快速下载
unity·游戏引擎
会潜水的小火龙19 小时前
unity打包apk报错Failure to initialize问题解决方法
unity·游戏引擎
平行云21 小时前
实时云渲染平台数据通道,支持3D应用文件上传下载分享无缝交互
linux·unity·云原生·ue5·gpu算力·实时云渲染·像素流送
Sator11 天前
unity仅用粒子系统实现拖尾
unity·游戏引擎
游乐码1 天前
Unity基础(五)四元数相关
unity·游戏引擎
想做后端的前端1 天前
Unity热更新 - HybridCLR & YooAsset
unity·游戏引擎
鹿野素材屋1 天前
Unity预加载:减少游戏中首次加载资源时的卡顿
windows·游戏·unity
RPGMZ1 天前
RPGMZ游戏引擎事件技巧大全
javascript·游戏引擎·事件·rpgmz·rpgmakermz
天若有情6731 天前
Superpowers 游戏引擎核心应用场景与落地指南
游戏引擎·superpowers
winlife_1 天前
嵌入式 MCP server vs 外挂桥接进程:引擎编辑器自动化的架构取舍
架构·自动化·编辑器·游戏引擎·架构设计·mcp·编辑器自动化