Beispiel #1
0
        public void ComposeShape()
        {
            ColliderShapeChanged = false;

            if (ColliderShape != null)
            {
                if (!ColliderShape.IsPartOfAsset)
                {
                    ColliderShape.Dispose();
                    ColliderShape = null;
                }
                else
                {
                    ColliderShape = null;
                }
            }

            CanScaleShape = true;

            if (ColliderShapes.Count == 1) //single shape case
            {
                if (ColliderShapes[0] == null)
                {
                    return;
                }
                if (ColliderShapes[0].GetType() == typeof(ColliderShapeAssetDesc))
                {
                    CanScaleShape = false;
                }

                ColliderShape = PhysicsColliderShape.CreateShape(ColliderShapes[0]);

                ColliderShape?.UpdateLocalTransformations();
            }
            else if (ColliderShapes.Count > 1) //need a compound shape in this case
            {
                var compound = new CompoundColliderShape();
                foreach (var desc in ColliderShapes)
                {
                    if (desc == null)
                    {
                        continue;
                    }
                    if (desc.GetType() == typeof(ColliderShapeAssetDesc))
                    {
                        CanScaleShape = false;
                    }

                    var subShape = PhysicsColliderShape.CreateShape(desc);
                    if (subShape != null)
                    {
                        compound.AddChildShape(subShape);
                    }
                }

                ColliderShape = compound;

                ColliderShape.UpdateLocalTransformations();
            }
        }
Beispiel #2
0
        public void ComposeShape()
        {
            ColliderShapeChanged = false;

            if (ColliderShape != null)
            {
                if (!ColliderShape.IsPartOfAsset)
                {
                    ColliderShape.Dispose();
                    ColliderShape = null;
                }
                else
                {
                    ColliderShape = null;
                }
            }

            try
            {
                CanScaleShape = true;

                if (ColliderShapes.Count == 1) //single shape case
                {
                    if (ColliderShapes[0] != null)
                    {
                        if (ColliderShapes[0].GetType() == typeof(ColliderShapeAssetDesc))
                        {
                            CanScaleShape = false;
                        }

                        ColliderShape = CreateShape(ColliderShapes[0]);

                        if (ColliderShape == null)
                        {
                            return;
                        }

                        ColliderShape.UpdateLocalTransformations();
                    }
                }
                else if (ColliderShapes.Count > 1) //need a compound shape in this case
                {
                    var compound = new CompoundColliderShape();
                    foreach (var desc in ColliderShapes)
                    {
                        if (desc != null)
                        {
                            if (desc.GetType() == typeof(ColliderShapeAssetDesc))
                            {
                                CanScaleShape = false;
                            }

                            var subShape = CreateShape(desc);
                            if (subShape != null)
                            {
                                compound.AddChildShape(subShape);
                            }
                        }
                    }

                    ColliderShape = compound;

                    ColliderShape.UpdateLocalTransformations();
                }
            }
            catch (DllNotFoundException)
            {
                //during pre process and build process we often don't have the physics native engine running.
            }
        }