小编zyo*_*neo的帖子

如何将文件转换为Base64?

此处报告包含路径(sdcard中的路径名,以字符串格式)

File dir = Environment.getExternalStorageDirectory();
File yourFile = new File(dir, report);
String encodeFileToBase64Binary = encodeFileToBase64Binary(yourFile);

private static String encodeFileToBase64Binary(File fileName) throws IOException {
    byte[] bytes = loadFile(fileName);
    byte[] encoded = Base64.encodeBase64(bytes);

    String encodedString = new String(encoded);
    return encodedString;
}
Run Code Online (Sandbox Code Playgroud)

在byte []编码行中得到此错误.对于Base64类型,方法encodeBase64(byte [])是未定义的

base64 android

14
推荐指数
3
解决办法
3万
查看次数

如何将数据从一个活动传递到另一个活动而不使用意图?

我已经在使用一个待定的意图.所以,如果我使用另一个意图并启动该意图,它会转到一个新的活动.我想避免这种情况.因此,如果不使用意图,我想将数据从一个活动传递到另一个活动?

android android-intent android-activity

5
推荐指数
1
解决办法
1万
查看次数

Application.streamingAssetsPath 和 Application.persistentDataPath 有什么区别?它们如何使用?

我对这两者之间的某些概念存有疑问。对于Application.streamingAssetsPath,我应该在项目中创建一个 StreamingAssets 文件夹,以便我可以将文件保存到其中并稍后重新加载。那么 的作用Application.persistentDataPath和作用是什么呢Application.streamingAssetsPath

如果我要保存资产和数据(位置、生命值等),然后将它们重新加载到移动设备(Android 和 IOS)和 PC 中。哪个是最好的选择?

下面我保存使用Application.streamingAssetsPath

using (FileStream fs = new FileStream(Application.streamingAssetsPath + "/Position.json", FileMode.Create))
    {
        BinaryWriter filewriter = new BinaryWriter(fs);
        filewriter.Write(JsonString);
        fs.Close();


    }
Run Code Online (Sandbox Code Playgroud)

c# unity-game-engine

4
推荐指数
1
解决办法
2909
查看次数

如何调整纵向和横向模式的屏幕,以便可以看到所有 UI 元素?

我正在构建一个应用程序。我将我的参考分辨率游戏视图设置保留为 (800 x 1200)。画布设置如下所示 画布设置 当我检查 Iphone6(750 x 1334) 分辨率时,我可以看到内容,但某些组件会根据宽度进行裁剪。游戏视图如下所示。我在我的应用程序中使用面板、垂直布局组、水平布局组许多 UI 组件。

Iphone6 分辨率()750 x 1334

现在我将我的游戏视图分辨率更改为 ipad pro(2224 x 1668)。现在我看不到我的图像。游戏视图如下所示 Ipad pro 分辨率 (2224 x 1668)

我不知道如何根据不同的屏幕尺寸调整 UI 元素。我观察到的一些答案是我应该将设置保持为按屏幕尺寸缩放,匹配宽度或高度并将滑块匹配到 0.5。我保留了这些设置(见第一张图片)。它仍然没有根据不同的屏幕尺寸而改变。

我在父元素(Showdata)中尝试了Aspect ratio fitter但没有用。根据不同的屏幕尺寸我应该怎么做来改变屏幕?是不是因为我没有以正确的方式锚定UI元素?你将如何锚定这样的东西(画布>面板(沿 XY 拉伸)>面板(垂直布局)>许多 UI 元素)

我看过很多关于如何将锚用于图像和按钮的教程,但如何用于嵌套元素,或者当我们使用垂直或水平布局并且它包含许多 UI 元素时。

下面给出了每个 UI 元素的 Rect 变换。 等级制度

android screen-resolution unity-game-engine ios

3
推荐指数
1
解决办法
1850
查看次数

为什么错误显示“ArgumentException:索引超出范围。” 当我在Unity中获得触摸增量位置时?

我正在尝试使用光线投射旋转游戏对象。当我运行 Unity 编辑器时出现错误

ArgumentException:索引越界。UnityEngine.Input.GetTouch(Int32索引)(位于/Users/builduser/buildslave/unity/build/artifacts/ generated/bindings_old/common/Core/InputBindings.gen.cs:619)AdjustTransform.Update()(位于Assets/AdjustTransform) .cs:27)

第 27 行 Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition; 位于下面的代码中。我在这里做错了什么?

 void Update()
{
    Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    RaycastHit hit;

    Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition;

    if (Physics.Raycast(ray,out hit,100))
    {

        Debug.Log(" GO Name "+hit.collider.gameObject.name);
    }

if(  Input.touchCount == 2 && !EventSystem.current.IsPointerOverGameObject() )
    {


            hit.collider.gameObject.transform.Rotate(Vector3.up, -touchDeltaPosition.x * rotspeed * Time.deltaTime, Space.World);
            hit.collider.gameObject.transform.Rotate(Vector3.right, touchDeltaPosition.y * rotspeed * Time.deltaTime, Space.World);


    }
Run Code Online (Sandbox Code Playgroud)

c# unity-game-engine

1
推荐指数
1
解决办法
6683
查看次数

如何在Unity中显示类似于Android中的Toast消息?

Unity中是否有类似Toast的消息,类似于GUI,而与android类似。在android中,只需一行代码就很容易。

public void buttonclick()
{
// Message to show
}
Run Code Online (Sandbox Code Playgroud)

c# unity-game-engine

1
推荐指数
2
解决办法
5071
查看次数

如何从C#UNity以JSON格式编写的文件中删除特殊字符或不需要的符号?

编写后阅读时的JSON格式如下

?[{"SaveValues":[{"id":1,"allposition":{"x":-5.12429666519165,"y":4.792403697967529},"allrotation":{"x":0.0,"y":0.0,"z":0.0,"w":1.0},"allscale":{"x":1.0,"y":1.0},"linepos0":{"x":0.0,"y":0.0,"z":0.0},"linepos1":{"x":0.0,"y":0.0,"z":0.0},"movetype":1},{"id":1,"allposition":{"x":-4.788785934448242,"y":-3.4373996257781984},"allrotation":{"x":0.0,"y":0.0,"z":0.0,"w":1.0},"allscale":{"x":1.0,"y":1.0},"linepos0":{"x":0.0,"y":0.0,"z":0.0},"linepos1":{"x":0.0,"y":0.0,"z":0.0},"movetype":1}],"NoteValues":[{"movenumber":1,"notemsg":"Move One"}]},{"SaveValues":[{"id":1,"allposition":{"x":-5.12429666519165,"y":4.792403697967529},"allrotation":{"x":0.0,"y":0.0,"z":0.0,"w":1.0},"allscale":{"x":1.0,"y":1.0},"linepos0":{"x":0.0,"y":0.0,"z":0.0},"linepos1":{"x":0.0,"y":0.0,"z":0.0},"movetype":2},{"id":1,"allposition":{"x":-4.788785934448242,"y":-3.4373996257781984},"allrotation":{"x":0.0,"y":0.0,"z":0.0,"w":1.0},"allscale":{"x":1.0,"y":1.0},"linepos0":{"x":0.0,"y":0.0,"z":0.0},"linepos1":{"x":0.0,"y":0.0,"z":0.0},"movetype":2},{"id":2,"allposition":{"x":5.185188293457031,"y":4.803859233856201},"allrotation":{"x":0.0,"y":0.0,"z":0.0,"w":1.0},"allscale":{"x":1.0,"y":1.0},"linepos0":{"x":0.0,"y":0.0,"z":0.0},"linepos1":{"x":0.0,"y":0.0,"z":0.0},"movetype":2},{"id":2,"allposition":{"x":5.154441833496094,"y":-4.023111343383789},"allrotation":{"x":0.0,"y":0.0,"z":0.0,"w":1.0},"allscale":{"x":1.0,"y":1.0},"linepos0":{"x":0.0,"y":0.0,"z":0.0},"linepos1":{"x":0.0,"y":0.0,"z":0.0},"movetype":2}],"NoteValues":[{"movenumber":2,"notemsg":"Move Two"}]}]
Run Code Online (Sandbox Code Playgroud)

下面提供了我用于保存为JSON格式的代码。

 ListContainer container = new ListContainer(getAlldata,playerNotes);

    var temp = container;
    //--Adding data in container into List<string> jsonstring
    jsonstring.Add(JsonUtility.ToJson(temp));

 //--Combing list of string into a single string
    string jsons = "[" +string.Join(",", jsonstring)+"]";

    //Writing into a JSON file in the persistent path
    using (FileStream fs = new FileStream( Path.Combine(Application.persistentDataPath , savedName+".json"), FileMode.Create))
    {
        BinaryWriter filewriter = new BinaryWriter(fs);

        filewriter.Write(jsons);
        fs.Close();

    }
Run Code Online (Sandbox Code Playgroud)

在这里,我希望删除JSON格式起始处的特殊字符。我正在尝试通过使用以下代码来读取JSON

 using (FileStream fs = new FileStream(Application.persistentDataPath + "/" + filename, FileMode.Open))
        {


            fs.Dispose();
            string dataAsJson …
Run Code Online (Sandbox Code Playgroud)

c# json unity-game-engine

1
推荐指数
1
解决办法
51
查看次数