返回「计算机、信息技术与工程」

小知识点与小工具

小知识点与小工具 创建时间:2020/7/17 18:41

更多
Markdown 结构化数据
本文目录 5 个章节

小知识点与小工具

创建时间:2020/7/17 18:41

Gizmos

Gizmos 在编辑模式下Gizmos可以提供可视化的提示。它们只在Scene场景中显示不在Play模式下显示,但是你可以通过工具栏调整它们。

Gizmos公共类 允许你绘制图标,线条,和其他的东西。Gizmos在OnDrawGizmos方法中执行绘制,它被Unity编辑器自动调用。另一个可选的方法是OnDrawGizmosSelected,它只能被可选的对象调用。

Demo: 绘制顶点的位置,利用OnDrawGizmos在每个顶点绘制一个小球。

class Program
{
    static void Main(string[] args)
    {
        dynamic dyn = 1;
        object obj = 1;
        dyn = dyn + 3;
        //obj = obj + 3; 报错

        // Rest the mouse pointer over dyn and obj to see their
        // types at compile time.
        System.Console.WriteLine(dyn.GetType());
        System.Console.WriteLine(obj.GetType());
    }
}

OnValidate

调用时机:

  • 脚本被加载时
  • Inspector 中的任何值被修改时

Cases: 设置循环值

class Program
{
    static void Main(string[] args)
    {
        dynamic dyn = 1;
        object obj = 1;
        dyn = dyn + 3;
        //obj = obj + 3; 报错

        // Rest the mouse pointer over dyn and obj to see their
        // types at compile time.
        System.Console.WriteLine(dyn.GetType());
        System.Console.WriteLine(obj.GetType());
    }
}

需要设计人员输入 16 到 4096 之间 2的整数次幂时。 Unity提供了ClosestPowerOfTwo函数,方便我们取得最接近的值。同时我们使用RangeAttribute 属性来限定一下输入数值的区间,同时能更好的看出来处理后的值跟原始输入值的区别。

class Program
{
    static void Main(string[] args)
    {
        dynamic dyn = 1;
        object obj = 1;
        dyn = dyn + 3;
        //obj = obj + 3; 报错

        // Rest the mouse pointer over dyn and obj to see their
        // types at compile time.
        System.Console.WriteLine(dyn.GetType());
        System.Console.WriteLine(obj.GetType());
    }
}

使用场景 -需要“Nitro”车的速度比其他车的速度大至少20mph.

class Program
{
    static void Main(string[] args)
    {
        dynamic dyn = 1;
        object obj = 1;
        dyn = dyn + 3;
        //obj = obj + 3; 报错

        // Rest the mouse pointer over dyn and obj to see their
        // types at compile time.
        System.Console.WriteLine(dyn.GetType());
        System.Console.WriteLine(obj.GetType());
    }
}

动态添加tag

class Program
{
    static void Main(string[] args)
    {
        dynamic dyn = 1;
        object obj = 1;
        dyn = dyn + 3;
        //obj = obj + 3; 报错

        // Rest the mouse pointer over dyn and obj to see their
        // types at compile time.
        System.Console.WriteLine(dyn.GetType());
        System.Console.WriteLine(obj.GetType());
    }
}

关于enable=false

When a Behaviour is disabled, it will still be on the object and you can even change its properties and call its methods, but the engine will no longer call its Update method. When a Renderer is disabled, the object turns invisible. When a Collider is disabled, it won't cause any collision events to happen. When an UI component is disabled, the player can't interact with it anymore, but it will still be rendered, unless you also deactivate its renderer.

获取场景点数和面数

class Program
{
    static void Main(string[] args)
    {
        dynamic dyn = 1;
        object obj = 1;
        dyn = dyn + 3;
        //obj = obj + 3; 报错

        // Rest the mouse pointer over dyn and obj to see their
        // types at compile time.
        System.Console.WriteLine(dyn.GetType());
        System.Console.WriteLine(obj.GetType());
    }
}