Unity 安卓日志

https://blog.csdn.net/sdfdzx/article/details/79594461

Unity开发AR,打包成Android工程,然后再集成到主Android工程里

.max转fbx

创建场景

http://gad.qq.com/article/detail/34681

保存场景:E:\Users\LENOVO\Unity\New Unity Project\Assets

Unity导出安卓工程

https://blog.csdn.net/Gavin_today/article/details/49497479

https://wenku.baidu.com/view/15a22363f524ccbff021847a.html

https://blog.csdn.net/qq393830887/article/details/70470460

File / Build Setting,将平台设置为Android

报错:Please set the Package Name in the Player Settings.The value must follow the convention ’’ and can contain alphanumeric character and underscore. Each segment must not start with a numeric character or underscore.:

打开File=>build settings => player settings=>在Inspector找到Bundle Identifier 选项,原来是:com.YourCompanyName.YourProductName

后两项改个名字就行了

 

EasyAR显示

http://forum.easyar.cn/portal.php?mod=view&aid=2

 

Unity3D嵌套在ANDROID的视图

https://blog.csdn.net/a396901990/article/details/38052223

https://blog.csdn.net/qinyuanpei/article/details/39380717

https://blog.csdn.net/qq_22780533/article/details/51908906

https://blog.csdn.net/u014230923/article/details/51363556

UI

https://blog.csdn.net/u014230923/article/details/51371767

Unity移动

https://jingyan.baidu.com/article/3c343ff7c117bc0d377963b0.html

手指拖动

https://blog.csdn.net/q764424567/article/details/80665453

脚本

https://blog.csdn.net/qq_37936677/article/details/77916052

使用C#脚本控制游戏对象https://blog.csdn.net/zzlyw/article/details/54175881

脚本里定义一个MoveSpeed变量作为速度调节变量,通过input来监听按键wsad通过transform.Translate设置更新物体位置,Vector3.forward是前进、back后退、left是左移、right是右移。

if(Input.GetKey(KeyCode.W)){

this.transform.Translate(Vector3.forward*Time.deltaTime*MoveSpeed);

}

绑定脚本的方式很简单,直接用鼠标把脚本拖动到Hierarchy视图或者Scene视图中对应的物体上即可。也可以先选中物体,然后把脚本拖动到该物体Inspector视图(右方)的空白处。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Move : MonoBehaviour {
    public int MoveSpeed=8;
    // Use this for initialization
    void Start () {
        
    }
    
    // Update is called once per frame
    void Update () {
        if(Input.GetKey(KeyCode.W)){
            this.transform.Translate(Vector3.forward*Time.deltaTime*MoveSpeed);
        }else if(Input.GetKey(KeyCode.S)){
            this.transform.Translate(Vector3.back*Time.deltaTime*MoveSpeed);
        }else if(Input.GetKey(KeyCode.A)){
            this.transform.Translate(Vector3.left*Time.deltaTime*MoveSpeed);
        }else if(Input.GetKey(KeyCode.D)){
            this.transform.Translate(Vector3.right*Time.deltaTime*MoveSpeed);
        }
    }

}

unity3D中,给物体添加刚体后,为什么不是掉在地面上,而是穿过地形一直往下落

添加刚体后,你还必须给该物体添加一个碰撞。
并且该碰撞不能是meshCollider。
如果非要是MeshCollider,那你还必须给Convex打上勾

也就是你的物体么有了collider属性,比如Box Collider、Sphere Collider

https://blog.csdn.net/xu20082100226/article/details/49883781

创建地面:

https://blog.csdn.net/zomeelee/article/details/47035133

在左栏CREAT

TransformComponent, 它有三个属性PositionRotationScale,分别表示对象的位置、旋转角度、缩放比例。我们将Scale中的XZ值修改为2,这意味着我们将Ground沿XZ方向均拉伸到了原来的两倍。

Failed to create Convex Mesh from source mesh "default". Source mesh is likely have too many smooth surface regions. Please reduce the surface smoothness of the source mesh. Alternatively turn on Inflate Mesh and increase the Skin Width sufficiently for this mesh.

删除凸面过多的物体

This action will break the prefab instance.Are you sure you wish to continue

手指拖动

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

 

public class Drag : MonoBehaviour

{

    //偏移值

    Vector3 m_Offset;

    //当前物体对应的屏幕坐标

    Vector3 m_TargetScreenVec;

 

    private IEnumerator OnMouseDown()

    {

        //当前物体对应的屏幕坐标

        m_TargetScreenVec = Camera.main.WorldToScreenPoint(transform.position);

        //偏移值=物体的世界坐标,减去转化之后的鼠标世界坐标(z轴的值为物体屏幕坐标的z值)

        m_Offset = transform.position - Camera.main.ScreenToWorldPoint(new Vector3

        (Input.mousePosition.x, Input.mousePosition.y, m_TargetScreenVec.z));

        //当鼠标左键点击

        while (Input.GetMouseButton(0))

        {

            //当前坐标等于转化鼠标为世界坐标(z轴的值为物体屏幕坐标的z值)+ 偏移量

            transform.position = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x,

             Input.mousePosition.y, m_TargetScreenVec.z)) + m_Offset;

            //等待固定更新

            yield return new WaitForFixedUpdate();

        }

    }

}

 

显示渲染

https://www.jianshu.com/p/89d88b364d7d

只有能网格化的模型,绑定拖拽事件才有效

刚体组件的具体参数。

 

1.mass 质量,以千克计算。

2.drag 空气阻力,当物体受力运动时空气的阻力,以牛顿计算。

3.angular drag 空气角阻力,当物体受扭矩力选择时空气的阻力,以牛顿计算。

4.use gravity 使用重力,当开启此项,物体会受到重力作用。

5.is kinematic 是否开启动力学,开启此项,物体不受力的作用。

6.constrants:约束。用于控制刚体运动的约束。

添加按钮点击事件

https://jingyan.baidu.com/article/af9f5a2d7fdb6443150a4571.html

https://www.cnblogs.com/jiangyuzhen/p/7136881.html

Button组件下有on Click()列表

先把脚本添加到按钮,再设置on Click方法

判断unity物体是否显示状态

https://blog.csdn.net/qq_38655924/article/details/80898941

控制组件激活

https://blog.csdn.net/Testiness_Wind/article/details/78952775

showGround.GetComponent<MeshRenderer>().enabled

是变量,可直接获取当前值

修改记录

修改摄像机背景颜色,大小

床、柜子增加碰撞组件、刚体组件

控制地板图像渲染但保持对象激活(透明)

改进自定义碰撞器,加快渲染速度

控制mass重量,大物件100,小物件20

添加物品隐藏显示按钮栏

颜色表:

金黄:ECBF00FF

奶白:E1E1E1FF

黑色:323232FF

阴影透明度A75

场景切换 

场景切换:https://jingyan.baidu.com/article/a3aad71a1f50bdb1fb009626.html

public string sceneName="Bedroom";

    public void ChangeScene(){
        SceneManager.LoadScene (sceneName);
    }

 发布选项改变开始动画:https://blog.csdn.net/u010989951/article/details/52130490

 问题:场景跳转后光线变暗:https://blog.csdn.net/qq_29412103/article/details/82713777

 

更新记录:下载字体文件更换起始页字体

根据JSON数据动态创建物品栏

FurniturePanel放置按钮布局

按钮

按钮背景:E1E1E1FF

阴影透明度A75

在布置界面添加返回菜单场景链接

参考原数据与jsonjson参数名为程序中声明名)

 修改记录:

分离逻辑代码与数据,文件和数据库连接放到java

Unity传输JSON,点击按钮,动态下载预制件,展示

控制物体被拖出地板作为丢弃,按钮只新增物体实例化对象

java接口:http://localhost:8080/ARDesign/AllRoomDataServlet

UI栏:room[]-type[]-furniture

点击按钮时,删除原typebuttonpool中按钮,显示furniture按钮,和返回按钮

点击返回按钮,删除furniturepool和返回按钮,显示原按钮

按钮脚本handleCLick调用Gamecontroller方法

assetBundle

按钮调用函数不能传入参数

修改思路

或另加一透明地板,带颜色地板只是非刚体

 

数据增加物品初始化位置,获得对象引用以便再次实例化禁用(直接用data中的变量存储数据和引用)

如果引用中没有存储对象,就加载,否则用存储的对象

Json中存实例化高度(Vector3.up*spawnHeight),文件路径(与typeText保持一致)、文件名(与furnitureText保持一致)、对象名在data另存

实例化:

Instantiate(prefab, new Vector3(i * 2.0F, 0, 0), Quaternion.identity);

FurnitureButtonSetup设置按钮脚本组件的属性(type string另作为第二个参数传入):

public string type;
    public string assetBundleName;
    public string objectName;
    public float spawnHeight;

 

最后记得修改按钮点击事件,并应用到预制件

 

实例化时记得添加datacontroller中的gameobject引用,而不再使用临时引用

 

怎样确定当前类型下标,保证按钮点击不影响数据,数据存储在Type上级才稳妥。如果存在room级,返回菜单页再进入会出问题,只能存在dataController

typeIndexfurniture级数据维护容易出错(颠倒增删时修改很麻烦)用type级数据维护

 

在按钮组件中加载对象,卸载场景后对象不存在,但AssetBundle还存在。解决:data保存ab引用,而非对象引用,对象临时加载

Dataab一样是持久不卸载的,但gameController是随Scene加载卸载的,或许ab存在data中才能保证ab引用不丢失

SetUp中要把引用接回

卸载场景时卸载AB:怎么判断场景卸载了(点击按钮?),从哪里,怎么找到button脚本调用AssetBundle.Unload(false)

Error while getting Asset Bundle: The AssetBundle can't be loaded because another AssetBundle with the same files is already loaded.

function Start ()

{

    var www = WWW.LoadFromCacheOrDownload ("http://myserver.com/myassetBundle.unity3d", 5);

 

    yield www;

 

    if (www.error != null)

    {

        Debug.Log (www.error);

        return;

    }

    var myLoadedAssetBundle = www.assetBundle;

 

    var asset = myLoadedAssetBundle.mainAsset;

}

没有destroy加载的对象,有游离对象时,无法unloadunusedAsset

Monodevelop不能打开时可能缺少GTKSharp坏境,在安装目录下的GTK文件夹中找到安装包重装即可

 

数据库unity

allRoomData表,存room类型(roomText=bedroom)和代号1(代号字段和code重了,就不要了,直接用id

Bedroom表(表名=roomText),存types id

types表存idid比真实使用数组id1,typeText,roomtype类型为bedroom=1typecode

furnitures表,存typeid furnitureText(要显示在按钮上,如果不与uri耦合,则不传递上层typeText字段,但要在furnitures中加uri字段),objectNamespawnHeight

尝试一下后台给出的json是否能有多余字段(应该没有问题

暂时只需要一个servlet接口,从这里面调用其它的嵌套查询

获取后台json数据:

private IEnumerator SendUrl(string url)

    {

        using (UnityWebRequest www = UnityWebRequest.Get(url))

        {

            yield return www.Send();

            if (www.error != null)

            {

                Debug.Log(www.error);

            }

            else

            {

                if (www.responseCode == 200)//200表示接受成功

                {

                    Debug.Log(www.downloadHandler.text);

                }

            }

        }

    }

UnityWebRequestsentUrl接收json,因为是协程,在获取字符串之前就有可能往下运行,这时可能造成处理的字符串为空

接口:http://localhost:8080/ARDesign/AllRoomDataServlet

导出Android包时关联sdkhttps://blog.csdn.net/koukou0929/article/details/46743163

 

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值