예제 #1
0
        public SBSettings softBodySettings = new SBSettings();      //SoftBodyEditor will display this when needed

        void Start()
        {
            //Vector3 centerPos = transform.position;  //place at this transform position

            Vector3 stickStartPos = new Vector3(
                (centerPos.x - (numSticksXDir * stickSpacing) / 2),
                centerPos.y,
                centerPos.z - ((numSticksZDir * stickSpacing) / 2));

            for (int x = 0; x < numSticksXDir; x++)
            {
                for (int z = 0; z < numSticksZDir; z++)
                {
                    Vector3 stickPos = new Vector3(
                        (stickStartPos.x + stickSpacing * x),
                        centerPos.y,
                        (stickStartPos.z + stickSpacing * z));

                    //create but dont build yet
                    GameObject go = BSoftBodyRope.CreateNew(Vector3.zero, Quaternion.identity, false);
                    go.transform.parent = transform;

                    BSoftBodyRope bRope = go.GetComponent <BSoftBodyRope>();

                    //copy relavent settings
                    bRope.meshSettings.numPointsInRope = ropeSettings.numPointsInRope;
                    bRope.meshSettings.width           = ropeSettings.width;
                    bRope.meshSettings.startColor      = ropeSettings.startColor;
                    bRope.meshSettings.endColor        = ropeSettings.endColor;

                    bRope.meshSettings.startPoint = stickPos;
                    bRope.meshSettings.endPoint   = new Vector3(stickPos.x, stickPos.y + stickHeight, stickPos.z);

                    //Anchor the start node
                    Array.Resize(ref bRope.ropeAnchors, 2);
                    bRope.ropeAnchors[0] = new RopeAnchor();
                    bRope.ropeAnchors[0].anchorNodePoint = 0f;  //start node point

                    bRope.ropeAnchors[1] = new RopeAnchor();
                    bRope.ropeAnchors[1].anchorNodePoint = 1f / ropeSettings.numPointsInRope;

                    //bRope.SoftBodySettings.ResetToSoftBodyPresets(SBSettingsPresets.ropeStick);
                    bRope.SoftBodySettings = softBodySettings;

                    //now build it
                    bRope._BuildCollisionObject();
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Create new SoftBody object
        /// </summary>
        /// <param name="position"></param>
        /// <param name="rotation"></param>
        /// <param name="buildNow">Build now or configure properties and call BuildSoftBody() after</param>
        /// <returns></returns>
        public static GameObject CreateNew(Vector3 position, Quaternion rotation, bool buildNow = true)
        {
            GameObject go = new GameObject("SoftBodyRope");

            go.transform.position = position;
            go.transform.rotation = rotation;
            BSoftBodyRope bRope = go.AddComponent <BSoftBodyRope>();

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


            bRope.lr.sharedMaterial = material;

            bRope.SoftBodySettings.ResetToSoftBodyPresets(SBSettingsPresets.Rope);
            if (buildNow)
            {
                bRope._BuildCollisionObject();
            }
            go.name = "BSoftBodyRope";
            return(go);
        }
 [MenuItem("GameObject/Create Other/BulletForUnity/BSoftBody/Rope")]  //right click menu
 static void CreateBCube()
 {
     Selection.activeObject = BSoftBodyRope.CreateNew(EditorHelpers.GetCameraRaycastPosition(), Quaternion.identity);
     PostCreateObject();
 }