zoukankan      html  css  js  c++  java
  • 2d GUI的上层显示3d模型

    我们的游戏选择角色的时候需要在2d GUI的上层显示3d模型,默认3d模型是显示在2d GUI下面的,所以需要另外创建一个Camera,并且把新建的Camera 设置 target 到 RenderTexture,然后把这个RenderTexture显示到GUI上就行了。

    代码如下:

    Create Camera:

    _myObject = new GameObject(_Name, typeof(Camera), typeof(Skybox));
    _myCamera = _myObject.camera;
    _myCamera .depth = 2;
    _myCamera .clearFlags = CameraClearFlags.Skybox;
    _myCamera .backgroundColor = Color.clear;//Color.black;
    _myCamera .nearClipPlane = 0.3f;
    _myCamera .fieldOfView = 60;
    _myCamera .orthographicSize = 100.0f;

    Create RenderTexture:

    private static void InitTexture(int with, int height)
    {
    // _myTexture = new RenderTexture(with, height, 2);

    _myTexture= RenderTexture.GetTemporary(with, height, 0, RenderTextureFormat.ARGB32);
    _myTexture.name = "storyTexture" + _myObject .GetInstanceID();
    _myTexture.isPowerOfTwo = false;
    _myCamera .targetTexture = _storyTexture;
    }

    Draw RenderTexture:

    //GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), _myTexture,ScaleMode.StretchToFill);

    GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), _myTexture,ScaleMode.ScaleToFit);

    移动端有一些需要注意的地方:

    1、创建RenderTexture的时候,如果直接new到iphone上背景就是黑的,晚上找到解决办法如下:

    When setting up the Camera object, a RenderTexture is needed as the targetTexture for rendering. If you use a dynamically created Camera, you have one by default whose depth is 24. But it seems iOS devices only support depth = 0, so there are some problems.

    To walk around, add a statement like this:

    myCamera.targetTexture = RenderTexture.GetTemporary(myWidth, myHeight, 0, myFormat);

    where the third parameter is the depth of the RenderTexture.

    2、把RenderTexture画到屏幕上的时候,如果选择StretchToFill,手机上模型就会被缩放,需要选择ScaleToFit

  • 相关阅读:
    Centos 环境变量
    Centos 多线程下载工具-axel
    【Sprint3冲刺之前】项目可行性研究报告
    【Sprint3冲刺之前】TDzhushou软件项目测试计划书
    【Sprint3冲刺之前】日历表的事件处理和管理(刘铸辉)
    【Sprint3冲刺之前】项目完成时间表
    【Sprint3冲刺之前】敏捷团队绩效考核(刘铸辉)
    【每日Scrum】第八天(4.29) TD学生助手Sprint2
    【每日Scrum】第七天(4.28)Sprint2总结性会议
    需求分析
  • 原文地址:https://www.cnblogs.com/88999660/p/2940203.html
Copyright © 2011-2022 走看看