Пример #1
0
        internal void RebuildShape()
        {
            RecalculateBounds();

            if (m_Bounds.size.sqrMagnitude < .01f ||
                Mathf.Abs(m_Bounds.extents.x) < 0.001f ||
                Mathf.Abs(m_Bounds.extents.z) < 0.001f)
            {
                if (m_ProBuilderShape != null &&
                    m_ProBuilderShape.mesh.vertexCount > 0)
                {
                    m_ProBuilderShape.mesh.Clear();
                    m_ProBuilderShape.mesh.Rebuild();
                    ProBuilderEditor.Refresh(true);
                }
                return;
            }

            if (!m_IsShapeInit)
            {
                var shapeComponent = currentShapeInOverlay;
                EditorShapeUtility.CopyLastParams(shapeComponent.shape, shapeComponent.shape.GetType());
                shapeComponent.gameObject.hideFlags         = HideFlags.HideInHierarchy;
                shapeComponent.mesh.renderer.sharedMaterial = EditorMaterialUtility.GetUserMaterial();
                UndoUtility.RegisterCreatedObjectUndo(shapeComponent.gameObject, "Draw Shape");
                m_IsShapeInit = true;
            }

            m_ProBuilderShape.Rebuild(m_Bounds, m_PlaneRotation);
            ProBuilderEditor.Refresh(false);

            SceneView.RepaintAll();
        }
        /// <summary>
        /// Initialize this object with the various editor-only parameters, and invoke the object creation callback.
        /// </summary>
        /// <param name="pb"></param>
        internal static void InitObject(ProBuilderMesh pb)
        {
            MoveToActiveScene(pb.gameObject);

            ScreenCenter(pb.gameObject);

            SetPivotLocationAndSnap(pb);

            pb.renderer.shadowCastingMode = s_ShadowCastingMode;
            pb.renderer.sharedMaterial    = EditorMaterialUtility.GetUserMaterial();

            GameObjectUtility.SetStaticEditorFlags(pb.gameObject, s_StaticEditorFlags);

            switch (s_ColliderType.value)
            {
            case ColliderType.BoxCollider:
                pb.gameObject.AddComponent <BoxCollider>();
                break;

            case ColliderType.MeshCollider:
                pb.gameObject.AddComponent <MeshCollider>().convex = s_MeshColliderIsConvex;
                break;
            }

            pb.unwrapParameters = new UnwrapParameters(Lightmapping.s_UnwrapParameters);

            pb.Optimize();

            if (meshCreated != null)
            {
                meshCreated(pb);
            }
        }
        /// <summary>
        /// Initialize this object with the various editor-only parameters, and invoke the object creation callback.
        /// </summary>
        /// <param name="pb"></param>
        internal static void InitObject(ProBuilderMesh pb)
        {
            MoveToActiveRoot(pb.gameObject);

            GameObjectUtility.EnsureUniqueNameForSibling(pb.gameObject);
            ScreenCenter(pb.gameObject);
            SnapInstantiatedObject(pb);

#if UNITY_2019_1_OR_NEWER
            ComponentUtility.MoveComponentRelativeToComponent(pb, pb.transform, false);
#endif

            pb.renderer.shadowCastingMode = s_ShadowCastingMode;
            pb.renderer.sharedMaterial    = EditorMaterialUtility.GetUserMaterial();

            GameObjectUtility.SetStaticEditorFlags(pb.gameObject, s_StaticEditorFlags);

            switch (s_ColliderType.value)
            {
            case ColliderType.BoxCollider:
                if (!pb.gameObject.TryGetComponent <BoxCollider>(out _))
                {
                    Undo.AddComponent(pb.gameObject, typeof(BoxCollider));
                }
                break;

            case ColliderType.MeshCollider:
                MeshCollider collider;
                if (!pb.gameObject.TryGetComponent <MeshCollider>(out collider))
                {
                    collider = Undo.AddComponent <MeshCollider>(pb.gameObject);
                }
                // This little dance is required to prevent the Prefab system from detecting an overridden property
                // before ProBuilderMesh.RefreshCollisions has a chance to mark the MeshCollider.sharedMesh property
                // as driven. "AddComponent<MeshCollider>" constructs the MeshCollider and simultaneously assigns
                // the "m_Mesh" property, marking the property dirty. So we undo that change, here then assign the
                // mesh through our own method.
                collider.sharedMesh = null;
                collider.convex     = s_MeshColliderIsConvex;
                pb.Refresh(RefreshMask.Collisions);
                break;
            }

            pb.unwrapParameters = new UnwrapParameters(Lightmapping.s_UnwrapParameters);

            pb.Optimize();

            if (meshCreated != null)
            {
                meshCreated(pb);
            }
        }
Пример #4
0
 public void SetDefaultValues()
 {
     array = new Material[10]
     {
         EditorMaterialUtility.GetUserMaterial(),
             null,
             null,
             null,
             null,
             null,
             null,
             null,
             null,
             null
     };
 }
Пример #5
0
        static ActionResult MenuBooleanOperation(BooleanOperation operation, ProBuilderMesh lhs, ProBuilderMesh rhs)
        {
            if (lhs == null || rhs == null)
            {
                return(new ActionResult(ActionResult.Status.Failure, "Must Select 2 Objects"));
            }

            string op_string = operation == BooleanOperation.Union ? "Union" : (operation == BooleanOperation.Subtract ? "Subtract" : "Intersect");

            ProBuilderMesh[] sel = new ProBuilderMesh[] { lhs, rhs };

            UndoUtility.RecordSelection(sel, op_string);

            Mesh c;

            switch (operation)
            {
            case BooleanOperation.Union:
                c = CSG.Union(lhs.gameObject, rhs.gameObject);
                break;

            case BooleanOperation.Subtract:
                c = CSG.Subtract(lhs.gameObject, rhs.gameObject);
                break;

            default:
                c = CSG.Intersect(lhs.gameObject, rhs.gameObject);
                break;
            }

            GameObject go = new GameObject();

            go.AddComponent <MeshRenderer>().sharedMaterial = EditorMaterialUtility.GetUserMaterial();
            go.AddComponent <MeshFilter>().sharedMesh       = c;

            ProBuilderMesh pb = InternalMeshUtility.CreateMeshWithTransform(go.transform, false);

            DestroyImmediate(go);

            Selection.objects = new Object[] { pb.gameObject };

            return(new ActionResult(ActionResult.Status.Success, op_string));
        }