Пример #1
0
 public static void DestroyIfExists()
 {
     if (ExistsInScene)
     {
         Octave3DWorldBuilder.DestroyImmediate(ObjectPlacementGuide.Instance.gameObject);
     }
 }
        public void DisposeMesh(Mesh mesh)
        {
            int meshIndex = _meshes.FindIndex(item => item == mesh);

            if (meshIndex >= 0)
            {
                Octave3DWorldBuilder.DestroyImmediate(_meshes[meshIndex]);
                _meshes.RemoveAt(meshIndex);
            }
        }
Пример #3
0
 private static void DestroyGameObject(GameObject gameObject, bool allowUndoRedo)
 {
     if (allowUndoRedo)
     {
         UndoEx.DestroyObjectImmediate(gameObject);
     }
     else
     {
         Octave3DWorldBuilder.DestroyImmediate(gameObject);
     }
 }
 public void DisposeTextures()
 {
     foreach (var pair in _prefabToPreviewTexture)
     {
         if (pair.Value != null)
         {
             Octave3DWorldBuilder.DestroyImmediate(pair.Value, true);
         }
     }
     _prefabToPreviewTexture.Clear();
 }
 public void DisposeMeshes()
 {
     foreach (Mesh mesh in _meshes)
     {
         if (mesh != null)
         {
             Octave3DWorldBuilder.DestroyImmediate(mesh);
         }
     }
     _meshes.Clear();
 }
Пример #6
0
        private static void SetNoLoLongerGroup()
        {
            Octave3DWorldBuilder octave3D = Octave3DWorldBuilder.ActiveInstance;

            if (octave3D == null)
            {
                Debug.LogWarning("There is no Octave3D object in the scene. Please create an empty game object and attach the Octave3D World Builder script to it.");
                return;
            }

            octave3D.PlacementObjectGroupDatabase.MakeNoLongerGroup(Selection.activeGameObject);
        }
Пример #7
0
        public static ObjectPlacementGuide InstantiateObjectPlacementGuide(Prefab prefab, string name)
        {
            GameObject guideObject = Octave3DWorldBuilder.Instantiate(prefab.UnityPrefab) as GameObject;

            guideObject.name = name;
            ObjectPlacementGuide objectPlacementGuide = guideObject.AddComponent <ObjectPlacementGuide>();

            guideObject.transform.parent = Octave3DWorldBuilder.ActiveInstance.transform;

            guideObject.SetSelectedHierarchyWireframeHidden(ObjectPlacementSettings.Get().HideWireframeWhenPlacingObjects);
            return(objectPlacementGuide);
        }
        private void OnEnable()
        {
            _octave = target as Octave3DWorldBuilder;
            _octave.OnInspectorEnabled();

            // Note: Just ensure that the Inspector will be redrawn on Undo/Redo.
            Undo.undoRedoPerformed -= Repaint;
            Undo.undoRedoPerformed += Repaint;

            // Let the world know that the tool was selected :)
            ToolWasSelectedMessage.SendToInterestedListeners();

            ToolSupervisor.Get().RemoveNullPrefabReferences();

            _octave.RepaintAllEditorWindows();
        }
        /* private Texture2D ClonePrefabPreviewAndStore(Prefab prefab, Texture2D prefabPreview)
         * {
         *   if (prefabPreview != null)
         *   {
         *       Texture2D clonedPreviewTexture = prefabPreview.Clone(true);
         *       if (clonedPreviewTexture != null)
         *       {
         *           _prefabToPreviewTexture.Add(prefab, clonedPreviewTexture);
         *           return clonedPreviewTexture;
         *       }
         *   }
         *
         *   return null;
         * }*/

        private Dictionary <Prefab, Texture2D> GenerateNewDictionaryExcludingPairsWithNullPrefabReferences()
        {
            var newPrefabPreviewTextureDictionary = new Dictionary <Prefab, Texture2D>();

            foreach (KeyValuePair <Prefab, Texture2D> pair in _prefabToPreviewTexture)
            {
                if ((pair.Key == null || pair.Key.UnityPrefab == null) && pair.Value != null)
                {
                    Octave3DWorldBuilder.DestroyImmediate(pair.Value);
                }
                else
                {
                    newPrefabPreviewTextureDictionary.Add(pair.Key, pair.Value);
                }
            }

            return(newPrefabPreviewTextureDictionary);
        }
Пример #10
0
        public void RemoveNullPrefabEntries()
        {
            _prefabs.RemoveWithPredicate(item => item == null);
            List <Prefab> prefabsWithNullUnityPrefabs = _prefabs.GetEntitiesByPredicate(item => item.UnityPrefab == null);

            if (prefabsWithNullUnityPrefabs.Count != 0)
            {
                foreach (Prefab prefab in prefabsWithNullUnityPrefabs)
                {
                    _prefabs.RemoveEntity(prefab);
                    PrefabWasRemovedFromCategoryMessage.SendToInterestedListeners(this, prefab);

                    Octave3DWorldBuilder.DestroyImmediate(prefab);
                }

                EnsureActivePrefabIndexIsNotOutOfRange();
                EnsureActivePrefabPassesPrefabFilter();
            }
        }
Пример #11
0
        public static Prefab CreateFromSelectedObjects(Pivot prefabPivot)
        {
            // Ensure that all necessary data is in place
            ObjectSelectionPrefabCreationSettings prefabCreationSettings = ObjectSelectionPrefabCreationSettings.Get();

            if (string.IsNullOrEmpty(prefabCreationSettings.PrefabName) || string.IsNullOrEmpty(prefabCreationSettings.DestinationFolder))
            {
                return(null);
            }
            if (ObjectSelection.Get().NumberOfSelectedObjects == 0)
            {
                return(null);
            }

            List <GameObject> allSelectedObjects = ObjectSelection.Get().GetAllSelectedGameObjects();

            if (allSelectedObjects.Count == 0)
            {
                return(null);
            }

            // Check if a prefab with the same name already exists
            bool       shouldPrefabBeCreated = true;
            GameObject prefabWithSameName    = ProjectAssetDatabase.LoadPrefabWithNameInFolder(prefabCreationSettings.PrefabName, prefabCreationSettings.DestinationFolder, false);

            if (prefabWithSameName != null)
            {
                if (EditorUtility.DisplayDialog("Are you sure?", "A prefab with the specified name already exists in the specified folder. Would you like to overwrite it?", "Yes", "No"))
                {
                    // If the user chose 'Yes', we have to remove the existing prefab from its category
                    PrefabCategory categoryWhichContainsSamePrefab = PrefabCategoryDatabase.Get().GetPrefabCategoryWhichContainsPrefab(prefabWithSameName);
                    if (categoryWhichContainsSamePrefab != null)
                    {
                        categoryWhichContainsSamePrefab.RemoveAndDestroyPrefab(prefabWithSameName);
                    }
                }
                else
                {
                    shouldPrefabBeCreated = false;
                }
            }
            if (!shouldPrefabBeCreated)
            {
                return(null);
            }

            // Create all the objects which will reside in the prefab hierarchy
            GameObject prefabRoot = new GameObject(prefabCreationSettings.PrefabName);
            Box        objectCollectionWorldBox    = Box.GetInvalid();
            var        allObjectsInPrefabHierarchy = new List <GameObject>();

            foreach (GameObject gameObject in allSelectedObjects)
            {
                Transform  gameObjectTransform = gameObject.transform;
                GameObject gameObjectClone     = Octave3DWorldBuilder.Instantiate(gameObject, gameObjectTransform.position, gameObjectTransform.rotation) as GameObject;
                allObjectsInPrefabHierarchy.Add(gameObjectClone);

                Transform cloneTransform = gameObjectClone.transform;
                gameObjectClone.name      = gameObject.name;
                cloneTransform.localScale = gameObjectTransform.lossyScale;

                if (objectCollectionWorldBox.IsValid())
                {
                    objectCollectionWorldBox.Encapsulate(gameObjectClone.GetWorldBox());
                }
                else
                {
                    objectCollectionWorldBox = gameObjectClone.GetWorldBox();
                }
            }

            // Now calculate the root object's position based on the specified pivot point
            Transform prefabRootTransform = prefabRoot.transform;

            if (prefabPivot == Pivot.Center)
            {
                prefabRootTransform.position = objectCollectionWorldBox.Center;
            }
            else if (prefabPivot == Pivot.BottomCenter)
            {
                prefabRootTransform.position = objectCollectionWorldBox.GetBoxFaceCenter(BoxFace.Bottom);
            }

            // Now that the root object's position is in place, attach all objects as children of the root
            foreach (GameObject gameObject in allObjectsInPrefabHierarchy)
            {
                gameObject.transform.parent = prefabRootTransform;
            }

            // Create the prefab and assign it to the chosen category
            GameObject createdUnityPrefab = ProjectAssetDatabase.CreatePrefab(prefabRoot, prefabCreationSettings.PrefabName, prefabCreationSettings.DestinationFolder);

            if (createdUnityPrefab == null)
            {
                return(null);
            }

            UndoEx.RecordForToolAction(prefabCreationSettings.DestinationCategory);
            Prefab createdPrefab = PrefabFactory.Create(createdUnityPrefab);

            prefabCreationSettings.DestinationCategory.AddPrefab(createdPrefab);

            Octave3DWorldBuilder.DestroyImmediate(prefabRoot);
            PrefabManagementWindow.Get().RepaintOctave3DWindow();

            return(createdPrefab);
        }
Пример #12
0
 public void OnInspectorEnabled()
 {
     _lastActiveInstance = this;
 }
Пример #13
0
        public void HandleSceneViewEvent(Event e)
        {
            if (e.IsUndoRedo())
            {
                SceneViewCamera.Instance.SetObjectVisibilityDirty();
                UndoRedoWasPerformedMessage.SendToInterestedListeners(e);

                // Last step necessary. We have to ensure that all objects have their wireframe hidden.
                // Otherwise, rendering with the 'Gizmos' API becomes corrupted (meshes are not rendered
                // anymore and some other entities like the snap grid becomes darker). Possibly a bug.
                if (ObjectPlacementSettings.Get().HideWireframeWhenPlacingObjects)
                {
                    Octave3DWorldBuilder.ActiveInstance.HideWireframeForSceneObjectsAndPlacementGuide();
                }

                return;
            }

            switch (e.type)
            {
            case EventType.Ignore:

                MouseButtonStates.Instance.ClearStates();
                break;

            case EventType.Repaint:

                HandleRepaintEvent(e);
                break;

            case EventType.MouseMove:

                MouseCursor.Instance.HandleMouseMoveEvent(e);
                HandleMouseMoveEvent(e);
                break;

            case EventType.MouseDrag:

                HandleMouseDragEvent(e);
                break;

            case EventType.MouseDown:

                // Always disable the left mouse button down event in order to avoid deselecting the Octave3D object.
                MouseButtonStates.Instance.OnMouseButtonPressed((MouseButton)e.button);
                if (!e.alt && e.type == EventType.MouseDown && e.button == (int)MouseButton.Left && MouseButtonStates.Instance.GetNumberOfPressedButtons() <= 1)
                {
                    e.DisableInSceneView();
                }

                HandleMouseButtonDownEvent(e);
                break;

            case EventType.MouseUp:

                MouseButtonStates.Instance.OnMouseButtonReleased((MouseButton)e.button);
                HandleMouseButtonUpEvent(e);
                break;

            case EventType.ScrollWheel:

                HandleMouseScrollWheelEvent(e);
                break;

            case EventType.KeyDown:

                KeyboardButtonStates.Instance.OnKeyboardButtonPressed(e.keyCode);
                if (HandleGeneralShortcutKeys(e))
                {
                    return;
                }

                // Always disable the 'Delete' key in order to avoid deleting the Octave3D object from the scene.
                if (e.type == EventType.KeyDown && e.keyCode == KeyCode.Delete)
                {
                    e.DisableInSceneView();
                }

                if (e.keyCode == KeyCode.F)
                {
                    Octave3DWorldBuilder activeInstance = Octave3DWorldBuilder.ActiveInstance;
                    if (activeInstance != null)
                    {
                        List <GameObject> selectedObjects = new List <GameObject>(activeInstance.ObjectSelection.GetAllSelectedGameObjects());
                        Selection.objects = selectedObjects.ToArray();
                        if (SceneView.lastActiveSceneView != null)
                        {
                            SceneView.lastActiveSceneView.FrameSelected();
                        }

                        activeInstance.OnCamFocused();
                    }
                    break;
                }

                HandleKeyboardButtonDownEvent(e);
                break;

            case EventType.KeyUp:

                KeyboardButtonStates.Instance.OnKeyboardButtonReleased(e.keyCode);
                HandleKeyboardButtonUpEvent(e);
                break;

            case EventType.ExecuteCommand:

                HandleExecuteCommandEvent(e);
                break;
            }
        }