C# 使用字符串进行纹理加载以int替换问题
根据我的调试日志,问题是我的int计数没有问题,但是int-to-string转换继续应用于原始值,而不是运行时更新的计数器。这里有一些未使用的私有测试&帧值都很好。 我的调试日志的屏幕截图:-你可以看到计数器增加了,但“frame”没有 希望这是不言自明的C# 使用字符串进行纹理加载以int替换问题,c#,unity3d,resource-loading,C#,Unity3d,Resource Loading,根据我的调试日志,问题是我的int计数没有问题,但是int-to-string转换继续应用于原始值,而不是运行时更新的计数器。这里有一些未使用的私有测试&帧值都很好。 我的调试日志的屏幕截图:-你可以看到计数器增加了,但“frame”没有 希望这是不言自明的 using UnityEngine; using System.Collections; public class imagecycle : MonoBehaviour { public string Startingframe;
using UnityEngine;
using System.Collections;
public class imagecycle : MonoBehaviour
{
public string Startingframe;
private string Nextframe;
private int framecomp = 0;
private int frameint;
private int framestep = 1;
private int maxframe = 119;
private string framestring;
// Use this for initialization
void Start ()
{
Nextframe = ("frame_000");
frameint = 20; // currently adding one to this and resetting on update
}
// Update is called once per frame
void Update ()
{
frameint += framestep;
//Converts framestring to int of frameint -updating frame
framestring = frameint.ToString();
Debug.Log (frameint);
// replaces loaded texture recourse with frame string:
Nextframe = Nextframe.Replace ("000", framestring);
// Loads texture into Currentframe:
Texture Currentframe = Resources.Load (Nextframe) as Texture;
// Applies texture:
renderer.material.mainTexture = Currentframe;
Debug.Log (Currentframe);
if (frameint > 119)
{
frameint = 1;
}
}
void LateUpdate()
{
}
}
这是因为在第一个帧中,下一帧是frame_000,因此替换方法将用21替换000,正如您所看到的,但在这之后,下一帧变量是frame_21,因此字符串中没有000,因此替换方法不会执行任何操作,因此下一帧将保留在frame_21
Nextframe=Nextframe.Replace 000,framestring;在第一次替换后不会做任何事情,因为它的字符串不包含000,非常感谢,所以我对替换函数的理解是不正确的,我假设每次更新时它都会重置为第000帧。非常感谢各位。 是的,我会努力提高效率。
还有,很抱歉我还不能投票;没有足够的“代表”。请参阅和。请不要在您的帖子中包含指向外部资源的链接。如果你想引用像截图这样的图片,直接将它们插入你的帖子。你不打算从磁盘加载!每帧都有纹理,对吗?如果需要,请阅读有关如何在Unity中创建纹理动画的教程。您的方法将导致性能问题。根据纹理的大小,它可能在0.016秒内无法加载,即将fos降至60以下。最终,一个60 fps的纹理动画是非常浪费的。rgr这与链接有关。是的,我选择这种方法,因为纹理是超低分辨率的,我考虑将它们组合成一个纹理,然后更改矩形,但至少在我的测试中,我没有看到性能上的差异。如果有替代方案,请告诉我:每次只构建下一个框架可能比从当前框架构建更容易。。。NextFrame=frame_u+frameint.ToStringD3ah是的,如果我没有119个纹理,我通常会这么做:-正在考虑使用数组调用,只是想更新一下,我已经解决了这个问题,并且对结果非常满意:…现在要与DEAP和perlin noise一起玩\o/关于效率;现在维护这个方法:可能从活动内存中删除资源吗?