[Unity] Bug: 【Filter功能】Struct类型在执行完【BindingMode FilterMethods】后,使用构造函数会无效。
Open
@chexiongsheng is already working on this.
Since Feb 14, 2025.
bug
Unity
- Dominant language
- C++
- Stars
- 6.2k
- Forks
- 862
- Avg merge
- 3d 9h
- Merged PRs (30d)
- 2
Description
前置阅读 | Pre-reading
Puer的版本 | Puer Version
2.1.1(Master Clone)
Unity的版本 | Unity Version
6000.0.37f1
发生在哪个平台 | Platform
Editor(mac)
错误信息 | Error Message
Struct类型执行完Fillter后,用构造函数创建对象,构造函数功能失效,无法赋值。
问题重现 | Bug reproduce
重现方法:
1、添加Filter方法,使变量可以正常绑定,其他方法隐藏。
[Filter]
static Puerts.BindingMode FilterMethods(System.Reflection.MemberInfo memberInfo)
{
if (memberInfo.DeclaringType == typeof(PuertsTest.TestStructFilter)
|| memberInfo.DeclaringType == typeof(PuertsTest.TestClassFilter))
{
if (memberInfo is FieldInfo)
{
return BindingMode.FastBinding;
}
return BindingMode.DontBinding;
}
return BindingMode.FastBinding;
}
2、创建TestStructFilter和TestClassFilter,分别有a,b,c三个参数和一个构造函数;执行d.ts生成。
(Struct和Class进行对比)
C#的测试类:
public struct TestStructFilter
{
public int a;
public int b;
public int c;
public TestStructFilter(int a, int b, int c)
{
this.a = a;
this.b = b;
this.c = c;
}
}
public class TestClassFilter
{
public int a;
public int b;
public int c;
public TestClassFilter(int a, int b, int c)
{
this.a = a;
this.b = b;
this.c = c;
}
}
生成d.ts后,结构基本一样
class TestStructFilter extends System.ValueType
{
protected [__keep_incompatibility]: never;
public a : number
public b : number
public c : number
public constructor ($a: number, $b: number, $c: number)
public constructor ()
}
class TestClassFilter extends System.Object
{
protected [__keep_incompatibility]: never;
public a : number
public b : number
public c : number
public constructor ($a: number, $b: number, $c: number)
public constructor ()
}
3、执行测试代码,发现Class可以正常创建;Struct创建失败,无法获取值。
const testStruct_1 = new CS.PuertsTest.TestStructFilter(100,200,300)
console.log("testStruct_1="+testStruct_1.a + " " + testStruct_1.b + " " + testStruct_1.c)
//打印testStruct_1的a、b、c为0,Struct创建失败。
const testClass_1 = new CS.PuertsTest.TestClassFilter(900,800,700)
console.log("testClass_1="+testClass_1.a + " " + testClass_1.b + " " + testClass_1.c)
//打印testClass_1的a、b、c为正常值,Class正常创建。
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.