Exemplo n.º 1
0
        public void DragPerform(SceneView sceneView)
        {
            try
            {
                InternalCSGModelManager.skipCheckForChanges = true;
                if (visualDragGameObject == null)
                {
                    CreateVisualObjects(sceneView != null);
                }

                if (sceneView && haveNoParent && !containsModel)
                {
                    var model = SelectionUtility.LastUsedModel;
                    if (!model)
                    {
                        model = OperationsUtility.CreateModelInstanceInScene(selectModel: false);
                        InternalCSGModelManager.EnsureInitialized(model);
                        InternalCSGModelManager.CheckTransformChanged();
                        InternalCSGModelManager.OnHierarchyModified();
                    }
                    var parent = model.transform;

                    int counter = 0;
                    foreach (var obj in visualDragGameObject)
                    {
                        if (!obj)
                        {
                            continue;
                        }
                        if (obj.activeSelf)
                        {
                            obj.transform.SetParent(parent, false);
                            obj.transform.SetSiblingIndex(hoverSiblingIndex + counter);
                            counter++;
                        }
                    }
                }

                if (visualDragGameObject != null)
                {
                    var selection = new List <GameObject>();
                    for (int i = visualDragGameObject.Count - 1; i >= 0; i--)
                    {
                        if (!visualDragGameObject[i])
                        {
                            continue;
                        }
                        if (visualDragGameObject[i].activeSelf)
                        {
                            Undo.RegisterCreatedObjectUndo(visualDragGameObject[i], "Instantiated prefab");
                            selection.Add(visualDragGameObject[i]);
                        }
                        else
                        {
                            GameObject.DestroyImmediate(visualDragGameObject[i]);
                        }
                    }
                    visualDragGameObject = null;

                    if (selection.Count > 0)
                    {
                        UnityEditor.Selection.objects = selection.ToArray();
                    }
                }

                if (sceneView)
                {
                    for (int i = 0; i < SceneView.sceneViews.Count; i++)
                    {
                        var sceneview = SceneView.sceneViews[i] as SceneView;
                        if (!sceneview)
                        {
                            continue;
                        }

                        if (sceneview.camera.pixelRect.Contains(Event.current.mousePosition))
                        {
                            sceneview.Focus();
                        }
                    }
                }
                visualDragGameObject = null;

                InternalCSGModelManager.CheckForChanges(forceHierarchyUpdate: true);
            }
            finally
            {
                InternalCSGModelManager.skipCheckForChanges = false;
                RealtimeCSG.CSGGrid.ForcedGridCenter        = prevForcedGridCenter;
                RealtimeCSG.CSGGrid.ForcedGridRotation      = prevForcedGridRotation;
                RealtimeCSG.CSGGrid.ForceGrid = false;
            }
        }