Beispiel #1
0
        private void CalculateProxyBounds(bool ignoreSpriteRendererBounds, Vector3 upVector)
        {
            Bounds bounds = UnityUtil.CalculateObjectBounds(Prefab, true, ignoreSpriteRendererBounds);

            // Since ProBuilder objects don't have a mesh until they're instantiated, we have to calculate the bounds manually
            if (ProBuilderObjectType != null)
            {
                foreach (var pbObject in Prefab.GetComponentsInChildren(ProBuilderObjectType))
                {
                    Vector3 min = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
                    Vector3 max = new Vector3(float.MinValue, float.MinValue, float.MinValue);

                    Vector3[] vertices = (Vector3[])ProBuilderObjectType.GetProperty("vertices").GetValue(pbObject, null);

                    foreach (var vert in vertices)
                    {
                        min = Vector3.Min(min, vert);
                        max = Vector3.Max(max, vert);
                    }

                    Vector3 size   = Prefab.transform.TransformDirection(max - min);
                    Vector3 center = Prefab.transform.TransformPoint(min) + size / 2;
                    bounds.Encapsulate(new Bounds(center, size));
                }
            }

            bounds       = UnityUtil.CondenseBounds(bounds, Prefab.GetComponentsInChildren <Doorway>(true));
            bounds.size *= 0.99f;

            var collider = Proxy.AddComponent <BoxCollider>();

            collider.center = bounds.center;
            collider.size   = bounds.size;
        }