Unity URP材料脚本

发布于 2025-01-24 01:57:02 字数 827 浏览 0 评论 0原文

我刚刚开始使用UNITY的URP进行游戏。我正在做3D中的精灵,所以我在四边形上渲染了一些精灵纸。为此,我创建了一种带有精灵表的材料,并使用瓷砖/偏移来呈现适当的动画框架,通过拨打电话:

CombatMaterial?.SetTextureOffset("_BaseMap", new Vector2( (AnimationDefinitions[animationDefinition] % 16) * .0625f, CombatMaterial.mainTextureOffset.y));

我当前正在尝试在游戏中添加一些反馈通过忽略材料。因为基本的颜色始于白色并变成黑色,所以这真的不起作用。我似乎唯一可以使用的另一件事是排放,看起来很棒。使用0xaaaish颜色可以实现我想要的效果。我一直在使用感觉统一资产来执行此操作,但是我也尝试使用类似的东西:

CombatMaterial?.SetColor("_EmissionColor", Color.white);

问题是,一旦设置了_EmsisionColor,主纹理偏移量将不再更新在游戏中,破坏了所有动画。如果我在运行时通过检查器手动更改纹理偏移量,则动画不起作用,并且_EMSISSCOLOR闪烁停止工作。如果我在检查员中弄乱了_BASEMAP的颜色,则_EmsisionColor闪烁开始再次工作。

在我开始进行一些难看的颜色调整以尝试再次进行这项工作之前,我很想知道我是否正在做一些不受URP/材料/材料/其他任何不支持的事情,或者是否有其他选择可以选择我的东西。我这样做有点简单。

谢谢你!

I just started using URP in Unity for a game in progress. I'm doing a sort of sprites-in-3d thing, so I'm rendering some sprite sheets on quads. To do this, I create a Material with the sprite sheet and use tiling/offset to render the proper frame of animation by making a call like:

CombatMaterial?.SetTextureOffset("_BaseMap", new Vector2( (AnimationDefinitions[animationDefinition] % 16) * .0625f, CombatMaterial.mainTextureOffset.y));

I'm currently trying to add some feedback into my game for when characters use abilities or get hit by flickering the material. Because the base color starts at white and goes to black, that won't really work; the only other thing I seem to have available to me is emission, which looks great. Using a 0xAAAish color achieves the effect I'm looking for. I've been using the Feel Unity asset to do this, but I've also attempted using something like this:

CombatMaterial?.SetColor("_EmissionColor", Color.white);

The problem is, once I've set the _EmissionColor, the main texture offset no longer updates in game, thereby ruining all animations. If I change the texture offset manually through the inspector at runtime, animations don't work AND the _EmissionColor flickering stop working. If I mess around with the color of the _BaseMap in the inspector, _EmissionColor flickering starts working again.

Before I start diving into some unsightly color adjustments in an attempt to make this work again, I would love to know if I'm doing something that is simply unsupported by URP/Materials/whatever, or if there is some alternative to what I'm doing that's a little more straightforward.

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谁与争疯 2025-01-31 01:57:02

在尝试了一堆随机的东西之后,我没有“真正的”解决方案,但是游戏正在奏效我想要的。

对我有用的是在材料上设置_EmsisionColor至(1,1,1)。由于某种原因,当_EmsisionColor设置为(0,0,0)时,它是一个黑色(HA)孔,并且将不接受对_EMSOSSCOLOR的未来更改。我认为这是我显然不熟悉的一些着色器胡说八道(带有URP使用的基本照明着色器)。

希望这可以帮助任何人像我一样对谷物无意识地做某事!

After trying a bunch of random stuff, I don't have a "real" solution, but the game IS working how I want it to.

What worked for me was setting the _EmissionColor on the Material to (1,1,1). For some reason, when the _EmissionColor is set to (0,0,0) it's a black (ha) hole and won't accept future changes to the _EmissionColor. I assume this is some shader nonsense (with the base Lit Shader that URP uses) that I am clearly unfamiliar with.

Hopefully this helps anyone doing something as pointlessly against the grain as I am!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文