/// <summary> /// /// </summary> private void OnActiveObjectTypeChanged() { if (null != _previewGO) { UtilUnity.Destroy(_previewGO); _previewGO = null; } _previewGO = GameObject.Instantiate( ActiveObjectPrefab, Vector3.zero, Quaternion.identity); if (null != _previewGO.GetComponent<BoxCollider>()) { _previewGO.AddComponent<PlacementGuides>(); } m_application.m_leftControllerText.text = ActiveObjectPrefabDefinition.Name; m_application.m_leftControllerText.gameObject.SetActive(true); var pi = _previewGO.GetComponent<PickInitializable>(); if (pi == null) { m_application.m_leftControllerText.color = Color.red; pi = _previewGO.AddComponent<PickInitializable>(); pi.PickInitializationTypes.Add(PickInitializable.PickInitializationType.Default); } else { m_application.m_leftControllerText.color = Color.black; } }
/// <summary> /// <see cref="ApplicationState{T}.Exit"/> implementation. /// </summary> public override void Exit() { Pause(); //m_application.LocomotionEnabled = true; // Enable only R pickray. m_application.RPickRay.gameObject.SetActive(false); m_application.HudInfoPanel.SetActive(false); m_application.HudInfoText.text = ""; foreach (var box in _selectBoxes) { UtilUnity.Destroy(box.gameObject); } _selectBoxes.Clear(); if (null != _hoverBoxGO) { UtilUnity.Destroy(_hoverBoxGO); _hoverBoxGO = null; _hoverBox = null; } m_application.SaveProjectData(); }
/// <summary> /// <see cref="ApplicationState{T}.Exit"/> implementation. /// </summary> public override void Exit() { //m_application.LocomotionEnabled = true; // Enable only R pickray. m_application.RPickRay.gameObject.SetActive(false); m_application.HudInfoPanel.SetActive(false); m_application.HudInfoText.text = ""; if (null != _previewGO) { UtilUnity.Destroy(_previewGO); } }
private void OnPropertiesChanged() { foreach (var panel in _propertyPanels) { panel.transform.SetParent(null); UtilUnity.Destroy(panel); } _propertyPanels.Clear(); _yOffset = 0; foreach (var property in _properties.Properties) { CreateProperyPanel(property); } }
/// <summary> /// Deletes the selected objects. /// </summary> public void Delete() { var selectedObjects = new List<GameObject>(_selectedObjects); OnHover(null); OnSelect(null); foreach (var selectedObject in selectedObjects) { foreach (var editData in m_application.EditDatas) { if (editData.GameObjects.Contains(selectedObject)) { editData.GameObjects.Remove(selectedObject); } UtilUnity.Destroy(selectedObject); } } }
/// <summary> /// Create an instance of the active prefab, /// position it at the location of the preview, /// and add it persistently to the project content. /// </summary> private void CreateObject() { // Create the new editable object. var objectGO = GameObject.Instantiate( ActiveObjectPrefab, _previewGO.transform.position, _previewGO.transform.rotation); var editable = objectGO.GetComponent<E>(); if (editable is IPrefabInstantiation prefabInstantiation) { prefabInstantiation.PrefabPath = ActiveObjectPrefabDefinition.PrefabPath; } else { m_application.Logger.Error("Trying to create an editable that is not an IPrefabInstantiation!" + editable.ToString()); UtilUnity.Destroy(objectGO); return; } if (editable is ILayerContent layerContent) { layerContent.LayerName = m_application.EstimateLayer(objectGO); } // Give the new editable object a unique name. objectGO.name = ActiveObjectPrefab.name + " (" + Guid.NewGuid().ToString() + ")"; // Add the new editable object to the project content. EditData.Add(objectGO); // Clear the picked points. _pickedInfos.Clear(); }
private void OnSelect(GameObject gameObject) { // Remove bounding boxes from current selection. foreach (var box in _selectBoxes) { UtilUnity.Destroy(box.gameObject); } _selectBoxes.Clear(); // Update selection. if (_addToSelection) { if (null != gameObject) { if (_selectedObjects.Contains(gameObject)) { _selectedObjects.Remove(gameObject); } else { _selectedObjects.Add(gameObject); } } } else { _selectedObjects.Clear(); if (null != gameObject) { _selectedObjects.Add(gameObject); } } // Add bounding boxes for current selection. foreach (var selectedObject in _selectedObjects) { var selectedObjectBoundingBoxGO = new GameObject("SelectedObjectBoundingBox"); var selectedObjectBoundingBox = selectedObjectBoundingBoxGO.AddComponent<LineRendererBox>(); selectedObjectBoundingBox.Color = m_application.SelectionColor; selectedObjectBoundingBoxGO.SetActive(true); selectedObjectBoundingBoxGO.transform.SetParent(selectedObject.transform, false); var bounds = UtilUnity.CalculateBounds(selectedObject); if (bounds.HasValue) { selectedObjectBoundingBoxGO.transform.position = bounds.Value.center; selectedObjectBoundingBox.Size = selectedObject.transform.InverseTransformVector(bounds.Value.size); } _selectBoxes.Add(selectedObjectBoundingBox); } bool autoShowPropertiesOnSingleObjectSelected = false; if (autoShowPropertiesOnSingleObjectSelected) { ShowProperties(); } }