private void RandomizePuzzle() { _tangram = GenerateTangram(); _tangram.LogInfo(_bombModule); _chip = Instantiate(_tangram.Grid.Chip, transform); _chip.UnderlayTexture = _tangram.Grid.UnderlayTexture; _chip.Code = _tangram.ChipCode; KMSelectable chipSelectable = _chip.Selectable; _selectable.ChildRowLength = chipSelectable.ChildRowLength; _selectable.Children = chipSelectable.Children; for (int contactPointIndex = 0; contactPointIndex < chipSelectable.transform.childCount; ++contactPointIndex) { KMSelectable contactPoint = chipSelectable.transform.GetChild(contactPointIndex).GetComponent <KMSelectable>(); contactPoint.Parent = _selectable; } _selectable.DefaultSelectableIndex = chipSelectable.DefaultSelectableIndex; _selectable.UpdateChildren(_selectable.Children[_selectable.DefaultSelectableIndex]); _chip.OnPinInteract += OnPinInteract; }
public override void OnInspectorGUI() { TangramGrid tangramGrid = (TangramGrid)target; TangramGrid.ConnectionJSON json = JsonConvert.DeserializeObject <TangramGrid.ConnectionJSON>(tangramGrid.AllConnections); tangramGrid.Connections = json.Connections; tangramGrid.ExternalConnections = json.ExternalConnections; TangramChip oldChip = tangramGrid.Chip; tangramGrid.Chip = (TangramChip)EditorGUILayout.ObjectField("Chip Prefab", oldChip, typeof(TangramChip), false); if (tangramGrid.Chip != oldChip) { EditorUtility.SetDirty(target); } string oldCode = tangramGrid.Code; tangramGrid.Code = EditorGUILayout.TextField("Code", oldCode); if (tangramGrid.Code != oldCode) { EditorUtility.SetDirty(target); } Texture oldTexture = tangramGrid.UnderlayTexture; tangramGrid.UnderlayTexture = (Texture)EditorGUILayout.ObjectField("Underlay Texture", oldTexture, typeof(Texture), false); EditorGUILayout.LabelField("Cells", EditorStyles.boldLabel); ArraySizeField("Cell Count", ref tangramGrid.Cells, target); if (tangramGrid.Cells != null) { EditorGUI.indentLevel++; for (int cellIndex = 0; cellIndex < tangramGrid.Cells.Length; ++cellIndex) { TangramShape oldShape = tangramGrid.Cells[cellIndex]; tangramGrid.Cells[cellIndex] = (TangramShape)EditorGUILayout.EnumPopup(string.Format("Cell {0}", cellIndex + 1), oldShape); if (tangramGrid.Cells[cellIndex] != oldShape) { EditorUtility.SetDirty(target); } } EditorGUI.indentLevel--; } EditorGUILayout.LabelField("Connections", EditorStyles.boldLabel); ArraySizeField("Connection Count", ref tangramGrid.Connections, target); if (tangramGrid.Connections != null) { EditorGUI.indentLevel++; for (int connectionIndex = 0; connectionIndex < tangramGrid.Connections.Length; ++connectionIndex) { TangramGridConnection connection = tangramGrid.Connections[connectionIndex]; if (connection == null) { connection = new TangramGridConnection() { PointA = new TangramGridConnectionPoint(), PointB = new TangramGridConnectionPoint() }; EditorUtility.SetDirty(target); } else { if (connection.PointA == null) { connection.PointA = new TangramGridConnectionPoint(); EditorUtility.SetDirty(target); } if (connection.PointB == null) { connection.PointB = new TangramGridConnectionPoint(); EditorUtility.SetDirty(target); } } EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(string.Format("Connection {0}", connectionIndex + 1)); IntField(ref connection.PointA.CellIndex, target); IntField(ref connection.PointA.CellPointIndex, target); IntField(ref connection.PointB.CellIndex, target); IntField(ref connection.PointB.CellPointIndex, target); EditorGUILayout.EndHorizontal(); } EditorGUI.indentLevel--; } EditorGUILayout.LabelField("External Connections", EditorStyles.boldLabel); ArraySizeField("Connection Count", ref tangramGrid.ExternalConnections, target); if (tangramGrid.ExternalConnections != null) { EditorGUI.indentLevel++; for (int connectionIndex = 0; connectionIndex < tangramGrid.ExternalConnections.Length; ++connectionIndex) { TangramGridConnectionPoint connectionPoint = tangramGrid.ExternalConnections[connectionIndex]; if (connectionPoint == null) { connectionPoint = new TangramGridConnectionPoint(); EditorUtility.SetDirty(target); } EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(string.Format("Connection {0}", connectionIndex + 1)); IntField(ref connectionPoint.CellIndex, target); IntField(ref connectionPoint.CellPointIndex, target); EditorGUILayout.EndHorizontal(); } EditorGUI.indentLevel--; } json = new TangramGrid.ConnectionJSON() { Connections = tangramGrid.Connections, ExternalConnections = tangramGrid.ExternalConnections }; tangramGrid.AllConnections = JsonConvert.SerializeObject(json); }