zoukankan      html  css  js  c++  java
  • Unity坑之 传递默认枚举类型参数

    今天在编写一个通用模块的时候,遇到一个奇怪的问题,vs编译时没有任何问题,但是轮到unity编译时,却报错:

     error CS0103: The name `PrintInt' does not exist in the current context

    出问题的代码片段如下:

     1   public void MovePoker(Vector3 startPos, Vector3 endPos, float moveTime, Ease ease = Ease.Flash)
     2   {
     3       view.MoveSelf(startPos, endPos, moveTime, ease);
     4 
     5       PrintInt(FUNC.One);
     6   }
     7 
     8    public void PrintInt(FUNC fUNC)
     9    {
    10        view.PrintInt(fUNC);
    11    }

    报错提示在代码的第 5行,提示说在当前上下文中不存在PrintInt这个签名,但是一看代码,不对啊,PrintInt不就是在第8行定义的么?

    但是仔细观察却会发现一个问题,那就是说 报错提示不存在PrintInt这个签名,如果是方法找不到的话,应该是报错找不到方法,这里却

    报找不到名字?那么很有可能是其它莫名其妙的问题引起的。

    经过排查,最终发现问题出在代码第1 行的参数上,MovePoker共有3个参数,第三个参数为DoTween的枚举类型,并且指定了默认值。经过试验

    当将枚举值传入到其他方法时,如果该方法指定了默认值,那么unity就会报错,因此只需要将枚举值的默认值取消掉即可。因此将代码改为:

    public void MovePoker(Vector3 startPos, Vector3 endPos, float moveTime, Ease ease )
    {
         view.MoveSelf(startPos, endPos, moveTime, ease);
    
         PrintInt(FUNC.One);
    }
    
    public void PrintInt(FUNC fUNC)
    {
         view.PrintInt(fUNC);
    }

    问题就解决了。unity版本为 5.3.6f1 64位

  • 相关阅读:
    Spring boot mybatis : Error creating bean with name 'com.github.pagehelper.autoconfigure.MapperAutoConfiguration': Invocation of init method failed;
    方法调用
    初识MQ
    Shell 变量
    Eclipse 导入本地 Git 项目
    IDEA 常用快捷键
    Xshell 配色方案
    冒泡排序
    递归
    安卓服务Service详解
  • 原文地址:https://www.cnblogs.com/leiGameDesigner/p/8926691.html
Copyright © 2011-2022 走看看