private void CreateFlowerButtons(List <Flower> flowers) { GridObjectCollection buttonCollection = commandPanel.GetComponentInChildren <GridObjectCollection>(); ScrollingObjectCollection buttonCollectionScroll = commandPanel.GetComponentInChildren <ScrollingObjectCollection>(); float n = 0.0f; foreach (Flower flower in flowers) { GameObject button = GameObject.Instantiate <GameObject>(flowerButtonPrefab, buttonCollection.transform.position, Quaternion.identity); button.transform.parent = buttonCollection.transform; FlowerProperties buttonFlowerProperties = button.GetComponentInChildren <FlowerProperties>(); buttonFlowerProperties.Name = flower.Name; buttonFlowerProperties.PlantingRadius = flower.PlantingRadius; TextMeshPro[] buttonText = button.GetComponentsInChildren <TextMeshPro>(); foreach (TextMeshPro text in buttonText) { text.text = flower.Name; } Interactable buttonInteractable = button.GetComponentInChildren <Interactable>(); buttonInteractable.OnClick.AddListener(() => SelectRadius(button)); n += 0.05f; } buttonCollection.UpdateCollection(); buttonCollectionScroll.UpdateContent(); buttonCollectionScroll.gameObject.SetActive(false); }
public void OnPointerUp(MixedRealityPointerEventData eventData) { // get all the grid collections created in the scene // parent = DraggableContainer or DraggableModel // parent.parent = Containers GridObjectCollection[] collections = initialCollection.parent.parent.GetComponentsInChildren <GridObjectCollection>(); // find closest collection float distance = 1f; GameObject closestCollection = null; foreach (GridObjectCollection collection in collections) { GameObject go = collection.gameObject; float dist = Vector3.Distance(go.transform.position, objectToMove.transform.position); if (dist < distance) { distance = dist; closestCollection = go; } } // update the parent to the closest collection if (closestCollection != null) { // set the closest collection as parent objectToMove.transform.parent = closestCollection.transform; // update the closest collection GridObjectCollection goc = closestCollection.GetComponent <GridObjectCollection>(); goc.UpdateCollection(); if (!isPartOfGraphController) { // update the initial collection when no model GridObjectCollection gocInitial = initialCollection.GetComponent <GridObjectCollection>(); gocInitial.UpdateCollection(); } } else { if (isPartOfGraphController) { // remove duplicated item since no closest collection was found GameObject.Destroy(objectToMove); } else { // set back to the initial collection objectToMove.transform.parent = initialCollection; // update the initial collection GridObjectCollection gocInitial = initialCollection.GetComponent <GridObjectCollection>(); gocInitial.UpdateCollection(); } } }
public void MakeScrollingList() { if (scrollView == null) { GameObject newScroll = new GameObject("Scrolling Object Collection"); newScroll.transform.parent = scrollPositionRef ? scrollPositionRef : transform; newScroll.transform.localPosition = Vector3.zero; newScroll.transform.localRotation = Quaternion.identity; newScroll.SetActive(false); scrollView = newScroll.AddComponent <ScrollingObjectCollection>(); // Prevent the scrolling collection from running until we're done dynamically populating it. scrollView.CellWidth = cellWidth; scrollView.CellHeight = cellHeight; scrollView.CellDepth = cellDepth; scrollView.CellsPerTier = cellsPerTier; scrollView.TiersPerPage = tiersPerPage; } gridObjectCollection = scrollView.GetComponentInChildren <GridObjectCollection>(); if (gridObjectCollection == null) { GameObject collectionGameObject = new GameObject("Grid Object Collection"); collectionGameObject.transform.position = scrollView.transform.position; collectionGameObject.transform.rotation = scrollView.transform.rotation; gridObjectCollection = collectionGameObject.AddComponent <GridObjectCollection>(); gridObjectCollection.CellWidth = cellWidth; gridObjectCollection.CellHeight = cellHeight; gridObjectCollection.SurfaceType = ObjectOrientationSurfaceType.Plane; gridObjectCollection.Layout = LayoutOrder.ColumnThenRow; gridObjectCollection.Columns = cellsPerTier; gridObjectCollection.Anchor = LayoutAnchor.UpperLeft; scrollView.AddContent(collectionGameObject); } if (!lazyLoad) { for (int i = 0; i < numItems; i++) { MakeItem(dynamicItem); } scrollView.gameObject.SetActive(true); gridObjectCollection.UpdateCollection(); } else { if (loader != null) { loader.SetActive(true); } StartCoroutine(UpdateListOverTime(loader, itemsPerFrame)); } }
/// <summary> /// Prints the coordinates of every child in the grid /// </summary> private void PrintGrid(GridObjectCollection grid, string prefix, string path, StringBuilder builder) { Debug.Log(prefix); var i = 0; foreach (Transform child in grid.gameObject.transform) { builder.AppendLine($" new Vector3({child.localPosition.x:F2}f, {child.localPosition.y:F2}f, {child.localPosition.z:F2}f), // {prefix} index {i}"); i++; } }
private void Awake() { if (avatarParent == null) { SpecialDebugMessages.LogMissingReferenceError(this, nameof(avatarParent)); } else { EnsureAvatarConfigController(); // deactivate the spine controller spineController = avatarParent.GetComponentInChildren <AvatarSpineController>(); spineController.enabled = false; } if (categoryToggles == null) { SpecialDebugMessages.LogMissingReferenceError(this, nameof(categoryToggles)); } else { categoryObjectCollection = categoryToggles.gameObject.GetComponent <GridObjectCollection>(); if (categoryObjectCollection == null) { SpecialDebugMessages.LogComponentNotFoundError(this, nameof(GridObjectCollection), gameObject); } } if (categoryButtonPrefab == null) { SpecialDebugMessages.LogMissingReferenceError(this, nameof(categoryButtonPrefab)); } if (modelSelector == null) { SpecialDebugMessages.LogMissingReferenceError(this, nameof(modelSelector)); } if (materialSelector == null) { SpecialDebugMessages.LogMissingReferenceError(this, nameof(materialSelector)); } if (colorSelector == null) { SpecialDebugMessages.LogMissingReferenceError(this, nameof(colorSelector)); } InitializeCategories(); modelSelector.ItemSelected += ModelItemSelected; materialSelector.ItemSelected += MaterialItemSelected; colorSelector.ItemSelected += ColorItemSelected; }
public static int GetLastUsedGridObjectCollectionIndex() { //try to find the last used brush collection and return it if (EditorPrefs.HasKey(lastGridObjectCollectionEditPrefsKey)) { string guid = EditorPrefs.GetString(lastGridObjectCollectionEditPrefsKey, ""); string path = AssetDatabase.GUIDToAssetPath(guid); GridObjectCollection lastUsedCollection = AssetDatabase.LoadAssetAtPath <GridObjectCollection>(path); return(lastUsedCollection.GetIndex()); } else { return(0); } }
public void CreateTrelloBoard() { boardObj = Instantiate(trelloBoard, new Vector3(0, 0, 2), Quaternion.identity); GridObjectCollection boardOrganiser = boardObj.GetComponent <GridObjectCollection>(); Dictionary <string, List <string> > isListEmpty = new Dictionary <string, List <string> >(); foreach (List list in lists) { isListEmpty.Add(list.id, new List <string>()); } foreach (Card card in cards) { isListEmpty[card.idList].Add(card.id); } int count = 0; try { foreach (KeyValuePair <string, List <string> > kvp in isListEmpty) { if (kvp.Value.Count != 0) { foreach (List list in lists) { if (list.id == kvp.Key) { StartCoroutine(CreateList(list, boardObj.transform)); break; } } count++; } } } catch (MissingReferenceException) { Debug.Log("TrelloBoard was destroyed before instantiation was complete"); } boardOrganiser.Radius = (float)((count * 2) / (2 * Math.PI)); boardOrganiser.UpdateCollection(); }
public void OnPointerUp(MixedRealityPointerEventData eventData) { // determine if there is a nearby collection GridObjectCollection[] objects = initialCollection.parent.GetComponentsInChildren <GridObjectCollection>(); float distance = 1f; GameObject closedObject = null; foreach (GridObjectCollection obj in objects) { GameObject go = obj.gameObject; float dist = Vector3.Distance(go.transform.position, gameObject.transform.position); if (dist < distance) { distance = dist; closedObject = go; } } // update the parent to the closest collection if (closedObject != null) { gameObject.transform.parent = closedObject.transform; } else { gameObject.transform.parent = initialCollection; } // update the collection it is attached to GridObjectCollection goc = gameObject.transform.parent.GetComponent <GridObjectCollection>(); if (goc != null) { goc.UpdateCollection(); } }
public override void OnPaintInspectorGUI() { if (m_GridObjectBrush.pickedObject) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Currently Picked Objects (Pick Tool)", EditorStyles.boldLabel); if (GUILayout.Button("Unpick Objects")) { m_GridObjectBrush.ResetPick(); return; } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(7.5f); int rowLength = 1; int maxRowLength = m_GridObjectBrush.size.x; var previewSize = Mathf.Min(((Screen.width - 35) / maxRowLength), 100); _scrollViewScrollPosition = EditorGUILayout.BeginScrollView(_scrollViewScrollPosition, false, false); if (maxRowLength < 1) { maxRowLength = 1; } foreach (TilePaletteGridObjectBrush.BrushCell tileBrush in m_GridObjectBrush.cells) { //check if row is longer than max row length if (rowLength > maxRowLength) { rowLength = 1; EditorGUILayout.EndHorizontal(); } //begin row if rowLength == 1 if (rowLength == 1) { EditorGUILayout.BeginHorizontal(); } GUIContent btnContent = tileBrush != null && tileBrush.gridObject != null ? new GUIContent(AssetPreview.GetAssetPreview(tileBrush.gridObject.gameObject), tileBrush.gridObject.gameObject.name) : new GUIContent("", "There is no tile at this position."); if (GUILayout.Button(btnContent, GUILayout.Width(previewSize), GUILayout.Height(previewSize))) { } rowLength++; } //check if row is longer than max row length if (rowLength > maxRowLength) { rowLength = 1; EditorGUILayout.EndHorizontal(); } if (rowLength == 1) { EditorGUILayout.BeginHorizontal(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.EndScrollView(); } else { // If there is no tile picked show the collections GUI #region GridTile Collection SerializedObject serializedObject_brushObject = null; int prevSelectedGridTileCollectionIndex = m_SelectedGridObjectCollectionIndex; if (m_Collection != null) { serializedObject_brushObject = new SerializedObject(m_Collection); } EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Active GridTile Collection:"); GridObjectCollection.GridObjectCollectionList gridObjectCollectionList = GridObjectCollection.GetGridObjectCollectionsInProject(); m_SelectedGridObjectCollectionIndex = EditorGUILayout.Popup(m_SelectedGridObjectCollectionIndex, gridObjectCollectionList.GetNameList()); if (prevSelectedGridTileCollectionIndex != m_SelectedGridObjectCollectionIndex || m_Collection == null) //select only when brush collection changed or is null { m_Collection = gridObjectCollectionList.brushCollections[m_SelectedGridObjectCollectionIndex]; m_Collection.SetLastUsedGridObjectCollection(); m_GridObjectBrush.ClearCellFromEditor(); var tileBrush = m_Collection.m_SelectedGridObjectBrush; if (tileBrush != null) { m_GridObjectBrush.SetCellFromEditor(Vector3Int.zero, tileBrush.m_GridObject, tileBrush.m_InitialOrientation); } } if (GUILayout.Button("+")) { Debug.Log("Create a new collection"); } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(7.5f); int rowLength = 1; int maxRowLength = Mathf.FloorToInt((Screen.width - 15) / 100); int columns = Mathf.CeilToInt((m_Collection.m_GridObjectBrushes.Count / maxRowLength)) * 3; _scrollViewScrollPosition = EditorGUILayout.BeginScrollView(_scrollViewScrollPosition, false, false); if (maxRowLength < 1) { maxRowLength = 1; } foreach (GridObjectBrush tileBrush in m_Collection.m_GridObjectBrushes) { //check if brushObject is null, if so skip this brush if (tileBrush == null || tileBrush.m_GridObject == null) { continue; } //check if row is longer than max row length if (rowLength > maxRowLength) { rowLength = 1; EditorGUILayout.EndHorizontal(); } //begin row if rowLength == 1 if (rowLength == 1) { EditorGUILayout.BeginHorizontal(); } //change color Color guiColor = GUI.backgroundColor; if (m_Collection.m_SelectedGridObjectBrush != null && m_Collection.m_SelectedGridObjectBrush.m_GridObject != null && m_Collection.m_SelectedGridObjectBrush.m_GridObject == tileBrush.m_GridObject) { GUI.backgroundColor = PrimarySelectedColor; if (m_GridObjectBrush.editorCell != null && m_GridObjectBrush.editorCell.gridObject != tileBrush.m_GridObject) { m_GridObjectBrush.SetCellFromEditor(Vector3Int.zero, tileBrush.m_GridObject, tileBrush.m_InitialOrientation); } } //Create the brush entry in the scroll view and check if the user clicked on the created button (change the currently selected/edited brush accordingly and add it to the current brushes if possible) GUIContent btnContent = new GUIContent(AssetPreview.GetAssetPreview(tileBrush.m_GridObject.gameObject), tileBrush.m_GridObject.gameObject.name); if (GUILayout.Button(btnContent, GUILayout.Width(100), GUILayout.Height(100))) { //select the currently edited brush and deselect all selected brushes if (m_Collection.m_SelectedGridObjectBrush != tileBrush) { m_Collection.m_SelectedGridObjectBrushIndex = m_Collection.m_GridObjectBrushes.IndexOf(tileBrush); m_GridObjectBrush.SetCellFromEditor(Vector3Int.zero, tileBrush.m_GridObject, tileBrush.m_InitialOrientation); } else { //m_Collection.m_SelectedGridTileBrush = null; m_Collection.m_SelectedGridObjectBrushIndex = -1; m_GridObjectBrush.ClearCellFromEditor(); } } GUI.backgroundColor = guiColor; rowLength++; } //check if row is longer than max row length if (rowLength > maxRowLength) { rowLength = 1; EditorGUILayout.EndHorizontal(); } if (rowLength == 1) { EditorGUILayout.BeginHorizontal(); } //add button if (GUILayout.Button(new GUIContent("+", "Add a GridObject to the collection."), GUILayout.Width(100), GUILayout.Height(100))) { AddGridObjectBrushPopup.Initialize(m_Collection.m_GridObjectBrushes); } Color guiBGColor = GUI.backgroundColor; EditorGUILayout.EndHorizontal(); EditorGUILayout.EndScrollView(); EditorGUILayout.BeginHorizontal(); GUI.backgroundColor = green; if (GUILayout.Button(new GUIContent("Add GridObject", "Add a GridObject to the collection."))) { AddGridObjectBrushPopup.Initialize(m_Collection.m_GridObjectBrushes); } EditorGUI.BeginDisabledGroup(m_Collection.m_SelectedGridObjectBrush == null || m_Collection.m_SelectedGridObjectBrush.m_GridObject == null); GUI.backgroundColor = red; //remove selected brushes button if (GUILayout.Button(new GUIContent("Remove Selected GridObject", "Removes the selected gridobject from the collection."))) { if (m_Collection.m_SelectedGridObjectBrush != null) { m_Collection.RemoveObject(m_Collection.m_SelectedGridObjectBrush); m_Collection.m_SelectedGridObjectBrushIndex = -1; m_Collection.Save(); } } EditorGUI.EndDisabledGroup(); //remove all brushes button EditorGUI.BeginDisabledGroup(m_Collection.m_GridObjectBrushes.Count == 0); if (GUILayout.Button(new GUIContent("Remove All GridObjects", "Removes all tiles from the collection.")) && RemoveAllBrushes_Dialog(m_Collection.m_GridObjectBrushes.Count)) { m_Collection.RemoveAllObjects(); m_Collection.Save(); } EditorGUI.EndDisabledGroup(); EditorGUILayout.EndHorizontal(); GUI.backgroundColor = guiBGColor; if (m_Collection.m_GridObjectBrushes != null && m_Collection.m_GridObjectBrushes.Count > 0 && m_Collection.m_SelectedGridObjectBrush != null && m_Collection.m_SelectedGridObjectBrush.m_GridObject != null) { EditorGUILayout.Space(10f); EditorGUILayout.BeginHorizontal(); EditorGUI.BeginChangeCheck(); EditorGUILayout.LabelField("GridObject Settings:" + " (" + m_Collection.m_SelectedGridObjectBrush.m_GridObject.gameObject.name + ")", EditorStyles.boldLabel); if (GUILayout.Button(new GUIContent("Reset Settings", "Restores the settings for the current GridObject."), GUILayout.MaxWidth(120))) { m_Collection.m_SelectedGridObjectBrush.ResetParameters(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(5f); EditorGUILayout.BeginHorizontal(); m_Collection.m_SelectedGridObjectBrush.m_InitialOrientation = (Orientations)EditorGUILayout.EnumPopup(new GUIContent("Initial Orientation", "Changes the initial orientation of the gridobject."), m_Collection.m_SelectedGridObjectBrush.m_InitialOrientation); EditorGUILayout.EndHorizontal(); if (EditorGUI.EndChangeCheck()) { // Update the cell's settings m_GridObjectBrush.SetCellFromEditor(Vector3Int.zero, m_Collection.m_SelectedGridObjectBrush.m_GridObject, m_Collection.m_SelectedGridObjectBrush.m_InitialOrientation); } } EditorGUILayout.Space(10f); /* * if (GUI.changed && m_Collection != null) * { * m_Collection.Save(); * } */ #endregion } }
void OnEnable() { Instance = this; Undo.undoRedoPerformed += ClearLastPreview; m_SelectedGridObjectCollectionIndex = GridObjectCollection.GetLastUsedGridObjectCollectionIndex(); }