예제 #1
0
        [MenuItem("GameObject/Create Other/BulletForUnity/BSoftBody/BSoftBodyWMesh")]  //right click menu
        static void CreateBSoftWithMesh()
        {
            BAnyMeshSettings settings = new BAnyMeshSettings();

            settings.meshType      = PrimitiveMeshOptions.Bunny;
            Selection.activeObject = BSoftBodyWMesh.CreateNew(EditorHelpers.GetCameraRaycastPosition(), Quaternion.identity, settings.Build(), true, SBSettingsPresets.ShapeMatching);
            PostCreateObject();
        }
        void Update()
        {
            //Update presets if changed
            if (SBPresetSelect != lastSBPresetSelect)
            {
                SoftBodySettings.ResetToSoftBodyPresets(SBPresetSelect);
            }
            lastSBPresetSelect = SBPresetSelect;

            if (!enableRain)
            {
                return;
            }
            if ((Time.time - lastBunnyTime) > (1 / softBodiesPerSecond))
            {
                Vector3 pos = new Vector3(0, 0, 0);

                pos.x = startAreaOfRain.center.x + UnityEngine.Random.Range(-startAreaOfRain.width / 2, startAreaOfRain.width / 2);
                pos.z = startAreaOfRain.center.y + UnityEngine.Random.Range(-startAreaOfRain.height / 2, startAreaOfRain.height / 2);
                pos.y = fromHeight;

                GameObject     go    = BSoftBodyWMesh.CreateNew(pos, UnityEngine.Random.rotation, anyMeshSettings.Build(), false, SBPresetSelect);
                BSoftBodyWMesh bSoft = go.GetComponent <BSoftBodyWMesh>();

                bSoft.meshSettings.autoWeldVertices     = anyMeshSettings.autoWeldVertices;
                bSoft.meshSettings.autoWeldThreshold    = anyMeshSettings.autoWeldThreshold;
                bSoft.meshSettings.recalculateNormals   = anyMeshSettings.recalculateNormals;
                bSoft.meshSettings.addBackFaceTriangles = anyMeshSettings.addBackFaceTriangles;
                bSoft.meshSettings.recalculateBounds    = anyMeshSettings.recalculateBounds;
                //bSoft.meshSettings.optimize = anyMeshSettings.optimize;

                bSoft.SoftBodySettings = SoftBodySettings;                  //play with settings

                //bSoft.SoftBodySettings.config.Collisions = collisionMask;

                bSoft._BuildCollisionObject();

                //randomize color for effect
                go.GetComponent <MeshRenderer>().material.color =
                    new Color(UnityEngine.Random.Range(0.0f, 1.0f), UnityEngine.Random.Range(0.0f, 1.0f), UnityEngine.Random.Range(0.0f, 1.0f));

                Destroy(go, lifetime);

                lastBunnyTime = Time.time;
            }
        }
예제 #3
0
        /// <summary>
        /// Create new SoftBody object using a Mesh
        /// </summary>
        /// <param name="position">World position</param>
        /// <param name="rotation">rotation</param>
        /// <param name="mesh">Need to provide a mesh</param>
        /// <param name="buildNow">Build now or configure properties and call BuildSoftBody() after</param>
        /// <param name="sBpresetSelect">Use a particular softBody configuration pre select values</param>
        /// <returns></returns>
        public static GameObject CreateNew(Vector3 position, Quaternion rotation, Mesh mesh, bool buildNow, SBSettingsPresets sBpresetSelect = SBSettingsPresets.ShapeMatching)
        {
            GameObject go = new GameObject("SoftBodyWMesh");

            go.transform.position = position;
            go.transform.rotation = rotation;
            BSoftBodyWMesh BSoft = go.AddComponent <BSoftBodyWMesh>();

            BSoft.meshSettings.UserMesh = mesh;
            MeshRenderer meshRenderer = go.GetComponent <MeshRenderer>();

            UnityEngine.Material material = new UnityEngine.Material(Shader.Find("Standard"));
            meshRenderer.material = material;

            BSoft.SoftBodySettings.ResetToSoftBodyPresets(sBpresetSelect); //Apply SoftBody settings presets

            if (buildNow)
            {
                BSoft._BuildCollisionObject();  //Build the SoftBody
            }
            go.name = "BSoftBodyWMesh";
            return(go);
        }
 [MenuItem("GameObject/Create Other/BulletForUnity/BSoftBody/BSoftBodyWMesh")]  //right click menu
 static void CreateBSoftWithMesh()
 {
     Selection.activeObject = BSoftBodyWMesh.CreateNew(EditorHelpers.GetCameraRaycastPosition(), Quaternion.identity, BAnyMeshSettingsForEditor.Instance.Build(), true);
     PostCreateObject();
 }