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
相关推荐
不伤欣19 小时前
游戏设计模式 - 子类沙箱
游戏·unity·设计模式
Magnum Lehar21 小时前
vulkan游戏引擎test文件memory实现
游戏引擎
Magnum Lehar21 小时前
vulkan游戏引擎test_manager实现
java·算法·游戏引擎
快乐觉主吖1 天前
Unity的日志管理类
android·unity·游戏引擎
WarPigs1 天前
Unity性能优化笔记
笔记·unity·游戏引擎
T.D.C2 天前
【业务框架】3C-相机-Cinemachine
unity
一线灵2 天前
跨平台游戏引擎 Axmol-2.6.1 发布
游戏引擎
Clank的游戏栈2 天前
Unity基于GraphView的可视化关卡编辑器开发指南
unity·编辑器·游戏引擎
海尔辛2 天前
Unity UI 性能优化--Sprite 篇
ui·unity·性能优化
三巧3 天前
Godot 敌人生成半径和围墙不匹配,导致敌人错误的生成在围墙外的解决代码
游戏引擎·godot