zoukankan      html  css  js  c++  java
  • Unity PhysicsScene测试

    应该是unity 2018.3中加入的功能,对象可以放置于不同的物理场景中。

    一个Scene对应一个物理场景(PhysicsScene),若想放入独立的物理场景测试创建一个Scene即可。见下图gif。

    若测试模拟功能,须在Physics中关闭自动模拟。脚本如下:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.SceneManagement;
    
    public class PhysicsSceneDemo : MonoBehaviour
    {
        public GameObject[] simulationObjects;
        public float physicsSceneTime;
    
        float mLastPhysicsSceneTime;
        Scene mPhysicsTestScene;
        PhysicsScene mPhysicsScene;
    
    
        void Start()
        {
            mPhysicsTestScene = SceneManager.CreateScene("PhysicsTestScene");
            mPhysicsScene = mPhysicsTestScene.GetPhysicsScene();
    
            for (int i = 0; i < simulationObjects.Length; i++)
                SceneManager.MoveGameObjectToScene(simulationObjects[i], mPhysicsTestScene);
    
            Physics.autoSimulation = false;
        }
    
        void Update()
        {
            if (physicsSceneTime != mLastPhysicsSceneTime)
            {
                mPhysicsScene.Simulate(physicsSceneTime);
                mLastPhysicsSceneTime = physicsSceneTime;
            }
        }
    
        void OnDestroy()
        {
            SceneManager.UnloadSceneAsync(mPhysicsTestScene);
            Physics.autoSimulation = true;
        }
    }

    测试仓库:

    https://gitee.com/Hont/PhysicsSceneDemo

  • 相关阅读:
    IDL---ENVI
    IDL基础
    IDL_GUI
    .Net MVC+bootstrap Table学习
    .Net中的加密解密
    Linux服务器上安装织梦CMS
    数据仓储之DLL层接口设计
    js获取新浪天气接口
    js动态生成二维码图片
    Jquery点击发送按钮后,按钮文本倒计时
  • 原文地址:https://www.cnblogs.com/hont/p/10961977.html
Copyright © 2011-2022 走看看