Esempio n. 1
0
        public void ConfigureSelectionMode(GrabbitSettings settings,
                                           ColliderMeshContainer colliderMeshContainer = null)
        {
            if (!Body)
            {
                Body = GetComponent <Rigidbody>();

                if (!Body)
                {
                    Body = gameObject.AddComponent <Rigidbody>();
                    WasRigidBodyAdded = true;
                }
                else
                {
                    RigidBodySave.RegisterRigidBody(Body);
                }
            }

            UndoState = new UndoState(Body);

            if (settings.UseDynamicNonConvexColliders && colliderMeshContainer)
            {
                //averaging the estimated added convex mesh colliders to 3
                AddedDynamicConvexColliders = new List <MeshCollider>(AddedStaticConvexColliders.Count * 3);

                foreach (var watcher in AddedCollidersList)
                {
                    foreach (var col in watcher.AddedStaticColliders)
                    {
                        if (!colliderMeshContainer.IsMeshDefined(col.sharedMesh))
                        {
                            //then it needs to be generated first
                            colliderMeshContainer.RegisterCollidersFromSelection(col, settings);
                        }

                        var meshes = colliderMeshContainer.GetMeshListAndRegenerateIfNeeded(col.sharedMesh, settings);

                        if (meshes.Count > 0)
                        {
                            foreach (var mesh in meshes)
                            {
                                AddMeshColliderToDynamicColliders(settings, col, mesh, watcher);
                            }
                        }
                        else
                        {
                            AddMeshColliderToDynamicColliders(settings, col, col.sharedMesh, watcher);
                        }
                    }
                }
            }
            else
            {
                AddedDynamicConvexColliders = new List <MeshCollider>(0);
            }

            SelectionConfigured = true;
        }
Esempio n. 2
0
        public void RecordUndoBodyMove(Rigidbody body, bool force = false)
        {
            var transform = body.transform;

            if (Position == transform.position && Rotation == transform.rotation && !force)
            {
                return;
            }

            var current = new UndoState {
                Position = transform.position, Rotation = transform.rotation
            };

            transform.position = Position;
            transform.rotation = Rotation;

            Undo.RegisterCompleteObjectUndo(body.transform, body.name);

            transform.position = current.Position;
            transform.rotation = current.Rotation;
            Position           = transform.position;
            Rotation           = transform.rotation;
            Undo.FlushUndoRecordObjects();
        }