安静如鸡

  • Home
  • About Me
  • Contact Me
  • 东京女子篮球活动记录
一个博客
  1. 首页
  2. Tech
  3. Unity
  4. 正文

【Unity小Tips】如何从一个assembly访问另一个assembly的internal类

2025-03-04 0人点赞 0条评论

用户想要用SetTexture设置pcache文件作为输入内容。
https://docs.unity3d.com/Packages/com.unity.visualeffectgraph@17.0/manual/point-cache-in-vfx-graph.html

虽然不知道为什么,但是查了一下,如果能获取到PointCacheAsset就可以用它的Property来达到目的。
Surface里面装的就是attribute maps,获取到对应attribute map后就可以利用VisualEffect.SetTexture来传入。
https://docs.unity3d.com/Packages/com.unity.visualeffectgraph@17.0/manual/point-cache-asset.html

PropertyDescription
ScriptSpecifies the importer Unity uses to import the .pCache file.
Point CountThe number of particles this Point Cache represents.
SurfaceA list of textures that represent the attribute maps for the particles. The name of the texture in each index of the array is the same as the name of the attribute the map is for.

但是PointCacheAsset这个class本身是一个internal class,无法从外部access。

这就涉及到如何从外部的assembly去访问它。

C#提供了一个叫InternalsVisibleTo的attribute让你能指定特定的assembly,使他们能从外部访问一般来说不能被访问的目标。

Specifies that types that are ordinarily visible only within the current assembly are visible to a specified assembly.

https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.internalsvisibletoattribute?view=net-9.0

打开Visual Effect Graph/Editor/PackageInfo.cs 可以看到里面设定了一些指令集,我们可以自己添加一个指令集例如Build.in.Editor.Test也可以直接命名一个已经设定的指令集,只要不冲突就行。

然后再让创建的Assembly参照VisualEffectGraph的相关Assembly

这样就可以在Build.in.Editor.Test里面的脚本访问PointCacheAsset类了。

标签: 暂无
最后更新:2025-03-04

Ellison

什么都懂点,什么都不精。属于混吃等死,享受生活,过一天算一天的享乐主义。喜欢电影,阅读,以及游戏和美食。

点赞
< 上一篇

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

COPYRIGHT © 2024 安静如鸡. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang