public Block(BlockOrientation orientation, int row, int col, int length) { _orientation = orientation; _row = row; _col = col; _length = length; }
public void SetBlockOrientation(BlockOrientation orientation, bool refresh) { if (this.orientation == (int)orientation && !refresh) { return; } Hide(); //Remove this. This is just so i can... look. O_O if (orientation != BlockOrientation.Default) { this.orientation = (int)orientation; } BlockSet chosenSet = GetSetForOrientation(orientation, false); if (chosenSet == null) { BlockSet d = GetDefaultSet(); if (d != null) { chosenSet = d; } else { // //#if UNITY_4_0 gameObject.SetActive(true); //#else // gameObject.active = true; //#endif // return; } } if (!chosenSet.HasBlocks()) { if (orientation == BlockOrientation.Default) { } else { SetBlockOrientation(BlockOrientation.Default, true); } return; } chosenSet.Show(); //#if UNITY_4_0 gameObject.SetActive(true); //#else // gameObject.active = true; //#endif BindChildrenToBlock(); }
public Placement(Block block, Vector2Int position, BlockOrientation orientation, BlockMaterial material) { Block = block; Position = position; Orientation = orientation; Material = material; }
public GameObject Editor_RemoveFromBlockSet(BlockOrientation orientation, GameObject blockObject) { BlockSet targetSet = GetSetForOrientation(orientation, true); if (targetSet == null) { return(null); } GameObject returnObject = targetSet.Editor_RemoveFromBlockSet(blockObject); if (!targetSet.HasBlocks()) { targetSet.SetIsDefault(false); BlockSet[] bs = GetBlockSetsAsArray(); for (int i = 0; i < bs.Length; i++) { if (bs[i].HasBlocks()) { bs[i].SetIsDefault(true); break; } } } return(returnObject); }
private HashSet <KinematicBlock> GenerateCircle() { var kinematicBlocks = new HashSet <KinematicBlock>(); int sizeX = 12; int sizeY = 12; // Get midpoint var gridSize = new Vector2(sizeX, sizeY); var midpoint = gridSize * 0.5f; List <Block> blocksBySize = new List <Block>(BlockRegistry.Blocks); blocksBySize.Sort((b1, b2) => - (b1.Width * b1.Height).CompareTo(b2.Width * b2.Height)); foreach (var block in blocksBySize) { for (int i = 0; i < 50; i += 1) { int x = Random.Range(0, sizeX); int y = Random.Range(0, sizeY); BlockOrientation orientation = (BlockOrientation)(Random.Range(0, 8) * 0); var blockCopy = block.Clone(); var blockKine = CreateBlockCb(blockCopy, orientation, x, y, GetRandomMaterial(), true); if (blockKine) { kinematicBlocks.Add(blockKine); } } } return(kinematicBlocks); }
public static Quaternion OrientationToRotation(BlockOrientation block) { switch (block) { case BlockOrientation.O0: return(Quaternion.Euler(0, 0, 0)); case BlockOrientation.O90: return(Quaternion.Euler(0, 0, -270)); case BlockOrientation.O180: return(Quaternion.Euler(0, 0, -180)); case BlockOrientation.O270: return(Quaternion.Euler(0, 0, -90)); case BlockOrientation.M0: return(Quaternion.Euler(0, 180, 0)); case BlockOrientation.M90: return(Quaternion.Euler(0, 180, 270)); case BlockOrientation.M180: return(Quaternion.Euler(0, 180, 180)); case BlockOrientation.M270: return(Quaternion.Euler(0, 180, 90)); } return(default);
private void OnGenerateClick(object sender, RoutedEventArgs e) { Pixelart pixelart; BlockOrientation orientation = BlockOrientation.TOP; if (topRadio.IsChecked.Value) { orientation = BlockOrientation.TOP; } if (bottomRadio.IsChecked.Value) { orientation = BlockOrientation.BOTTOM; } if (vertRadio.IsChecked.Value) { orientation = BlockOrientation.VERTICAL; } int width = 0, height = 0; if (int.TryParse(WidthTextBox.Text, out width) && int.TryParse(HeightTextBox.Text, out height)) { pixelart = new Pixelart(data, width, height, image, DitherCheckBox.IsChecked.Value, orientation); } else { pixelart = new Pixelart(data, image, DitherCheckBox.IsChecked.Value, orientation); } Result resultWindow = new Result(pixelart, data, this); resultWindow.Show(); }
/// <summary> /// Places a block at the given position and orientation. /// </summary> public int PlaceBlock(Block block, BlockOrientation orientation, Color color, int x, int y, bool initial = false) { block.Rotate(orientation); if (!CanPlaceBlock(block, x, y)) { throw new InvalidOperationException("No block can be placed here! Use CanPlaceBlock() first!"); } int blockId = _idCounter++; _blocks.Add(blockId, new BlockPlacement() { BlockId = blockId, Block = block, Orientation = orientation }); for (int iX = 0; iX < block.Width; iX++) { for (int iY = 0; iY < block.Height; iY++) { if (block.IsFieldSet(iX, iY)) { Debug.Log("Place Block [" + x + ", " + y + "] + [" + iX + ", " + iY + "] @ " + ((y + iY) * Width + (x + iX))); _blockGrid[(y + iY) * Width + (x + iX)] = blockId; if (initial || !scoreHandler) { _blockGridBackground[(y + iY) * Width + (x + iX)] = new BlockPoint() { Valid = true, Color = color }; } else { BlockPoint bp = _blockGridBackground[y * Width + x]; if (bp.Valid) { if (bp.Color == color) { scoreHandler.BlockScore += 25; } else { scoreHandler.BlockScore += 5; } } else { scoreHandler.BlockScore -= 2; } } } } } return(blockId); }
public void Rotate(BlockOrientation orientation) { CheckModifyable(); Array.Copy(originalFields, fields, fields.Length); width = originalWidth; height = originalHeight; Rotate((int)orientation); }
public override void OnInspectorGUI() { // EditorGUILayout.PropertyField() SerializedProperty widthProperty = serializedObject.FindProperty("width"); SerializedProperty heightProperty = serializedObject.FindProperty("height"); EditorGUILayout.PropertyField(widthProperty); EditorGUILayout.PropertyField(heightProperty); EditorGUILayout.PropertyField(serializedObject.FindProperty("Prefab")); int width = Mathf.Clamp(widthProperty.intValue, 1, 8); int height = Mathf.Clamp(heightProperty.intValue, 1, 8); if (width != widthProperty.intValue) { widthProperty.intValue = width; } if (height != heightProperty.intValue) { heightProperty.intValue = height; } SerializedProperty fieldsProperty = serializedObject.FindProperty("fields"); fieldsProperty.arraySize = width * height; EditorGUI.indentLevel += 1; for (int y = 0; y < height; y += 1) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Line " + y); for (int x = 0; x < width; x += 1) { var element = fieldsProperty.GetArrayElementAtIndex(y * width + x); var b = EditorGUILayout.Toggle(element.boolValue, GUILayout.Width(30)); element.boolValue = b; } EditorGUILayout.EndHorizontal(); } EditorGUI.indentLevel -= 1; serializedObject.ApplyModifiedProperties(); blockOrientation = (BlockOrientation)EditorGUILayout.EnumPopup("Orientation preview", blockOrientation); Block rotblock = (target as Block).Clone(); rotblock.Rotate(blockOrientation); GUI.enabled = false; width = rotblock.Width; height = rotblock.Height; for (int y = 0; y < height; y += 1) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Line " + y); for (int x = 0; x < width; x += 1) { EditorGUILayout.Toggle(rotblock.IsFieldSet(x, y), GUILayout.Width(30)); } EditorGUILayout.EndHorizontal(); } GUI.enabled = true; }
public Pixelart(Data data, Uri imagePath, bool dithering, BlockOrientation orientation) { bitmap = new Bitmap(imagePath.AbsolutePath); width = bitmap.Width; height = bitmap.Height; dithered = dithering; this.data = data; this.orientation = orientation; Generate(); }
public static BlockOrientation Previous(this BlockOrientation orientation) { int enumLength = System.Enum.GetNames(typeof(BlockOrientation)).Length;; int index = (int)orientation - 1; if (index < 0) { index = enumLength - 1; } return((BlockOrientation)index); }
public static BlockOrientation Next(this BlockOrientation orientation) { int enumLength = System.Enum.GetNames(typeof(BlockOrientation)).Length;; int index = (int)orientation + 1; if (index >= enumLength) { index = 0; } return((BlockOrientation)index); }
public Pixelart(Data data, int w, int h, Uri imagePath, bool dithering, BlockOrientation orientation) { width = w; height = h; string path = imagePath.LocalPath; bitmap = new Bitmap(path); bitmap = ResizeImage(bitmap, width, height); dithered = dithering; this.data = data; this.orientation = orientation; Generate(); }
public void Editor_AddToBlockSet(BlockOrientation orientation, GameObject blockObject) { BlockSet targetSet = GetSetForOrientation(orientation, true); if (targetSet.rootObject == null) { //targetSet.rootObject = new GameObject(orientation.ToString()); //targetSet.rootObject.transform.parent = transform; //targetSet.rootObject.transform.localPosition = Vector3.zero; targetSet.rootObject = this.gameObject; } //PREFAB //blockObject.SetActiveRecursively(false); targetSet.Editor_AddToBlockSet(blockObject, this); }
public void PlaceBlock(KinematicBlock kinematicBlock, bool initial = false) { var block = kinematicBlock.GetOrientedBlock(out Vector2Int pos); sfxPlaceBlock.Play(); BlockOrientation orientation = kinematicBlock.CurrentRotationToOrientation(); if (LevelPatternSaveAsset && IsEditor) { LevelPatternSaveAsset.Add(block, orientation, kinematicBlock.BlockMaterial, pos); } pos.y = Height - pos.y; Debug.Log("Place @ " + pos.x + ", " + pos.y); var color = kinematicBlock.GetComponent <MeshRenderer>().sharedMaterial.color; kinematicBlock.BlockID = simulator.PlaceBlock(block, orientation, color, pos.x, pos.y, initial); kinematicBlocks.Add(kinematicBlock); }
private KinematicBlock InstantiateBlock(Block block, BlockOrientation orientation, int x, int y, BlockMaterial m, bool place = true) { Vector3 position = new Vector3(x, y, 0); Vector3 worldSpacePos = transform.TransformPoint(position); var go = Instantiate(block.Prefab, worldSpacePos, KinematicBlock.OrientationToRotation(orientation), transform); var kblock = go.AddComponent <KinematicBlock>(); kblock.Initialize(this, block, m, BlockMaterial); Vector2Int simPos = kblock.GetTopLeftPoint(); var localpos = go.transform.localPosition; localpos.x += x - simPos.x; localpos.y += y - simPos.y; go.transform.localPosition = localpos; Debug.DrawLine(Vector3.zero, worldSpacePos); Debug.Log($"InstantiateBlock [{x}, {y}] => {worldSpacePos} => {simPos}"); if (!place) { return(kblock); } if (!CanPlace(kblock)) { Destroy(go); return(null); } PlaceBlock(kblock, true); var goBackground = Instantiate(block.Prefab, go.transform.position - new Vector3(0, 0, -0.25f), go.transform.rotation, transform); goBackground.GetComponent <MeshRenderer>().sharedMaterial = m.MaterialPrefab; return(kblock); }
public static Vector3Int TransformCoordinate(Vector3Int coordinate, BlockOrientation orientation) { Vector3Int transformedCoordinate = Vector3Int.zero; switch (orientation) { case BlockOrientation.Normal: transformedCoordinate = coordinate; break; case BlockOrientation.QuarterTurn: transformedCoordinate = new Vector3Int(coordinate.z, coordinate.y, -coordinate.x); break; case BlockOrientation.HalfTurn: transformedCoordinate = new Vector3Int(-coordinate.x, coordinate.y, -coordinate.z); break; case BlockOrientation.ThreeQuaterTurn: transformedCoordinate = new Vector3Int(-coordinate.z, coordinate.y, coordinate.x); break; } return(transformedCoordinate); }
public static Vector3 ToRotation(this BlockOrientation orientation) { Vector3 rotation = Vector3.zero; switch (orientation) { case BlockOrientation.Normal: rotation = Vector3.zero; break; case BlockOrientation.QuarterTurn: rotation = new Vector3(0f, 90f, 0f); break; case BlockOrientation.HalfTurn: rotation = new Vector3(0f, 180f, 0f); break; case BlockOrientation.ThreeQuaterTurn: rotation = new Vector3(0f, 270f, 0f); break; } return(rotation); }
public BlockSet GetSetForOrientation(BlockOrientation orientation, bool includeEmptySets){ BlockSet targetSet = null; switch(orientation){ case BlockOrientation.Bottom_Alone:{ targetSet = Bottom_Alone; break; } case BlockOrientation.Bottom_Left:{ targetSet = Bottom_Left; break; } case BlockOrientation.Bottom_Right:{ targetSet = Bottom_Right; break; } case BlockOrientation.Bottom_Surrounded:{ targetSet = Bottom_Surrounded; break; } case BlockOrientation.Centre_Alone:{ targetSet = Centre_Alone; break; } case BlockOrientation.Centre_Horizontal_Surrounded:{ targetSet = Centre_Horizontal_Surrounded; break; } case BlockOrientation.Centre_Surrounded:{ targetSet = Centre_Surrounded; break; } case BlockOrientation.Centre_Vertical_Surrounded:{ targetSet = Centre_Vertical_Surrounded; break; } case BlockOrientation.Left_Alone:{ targetSet = Left_Alone; break; } case BlockOrientation.Left_Surrounded:{ targetSet = Left_Surrounded; break; } case BlockOrientation.Right_Alone:{ targetSet = Right_Alone; break; } case BlockOrientation.Right_Surrounded:{ targetSet = Right_Surrounded; break; } case BlockOrientation.Top_Alone:{ targetSet = Top_Alone; break; } case BlockOrientation.Top_Left:{ targetSet = Top_Left; break; } case BlockOrientation.Top_Right:{ targetSet = Top_Right; break; } case BlockOrientation.Top_Surrounded:{ targetSet = Top_Surrounded; break; } case BlockOrientation.Bottom_Left_Inner_Corner:{ targetSet = Bottom_Left_Inner_Corner; break; } case BlockOrientation.Bottom_Right_Inner_Corner:{ targetSet = Bottom_Right_Inner_Corner; break; } case BlockOrientation.Top_Left_Inner_Corner:{ targetSet = Top_Left_Inner_Corner; break; } case BlockOrientation.Top_Right_Inner_Corner:{ targetSet = Top_Right_Inner_Corner; break; } case BlockOrientation.Left_Diagonal:{ targetSet = Left_Diagonal; break; } case BlockOrientation.Right_Diagonal:{ targetSet = Right_Diagonal; break; } case BlockOrientation.Lower_Left_Filled_Diagonal:{ targetSet = Lower_Left_Filled_Diagonal; break; } case BlockOrientation.Lower_Right_Filled_Diagonal:{ targetSet = Lower_Right_Filled_Diagonal; break; } case BlockOrientation.Upper_Left_Filled_Diagonal:{ targetSet = Upper_Left_Filled_Diagonal; break; } case BlockOrientation.Upper_Right_Filled_Diagonal:{ targetSet = Upper_Right_Filled_Diagonal; break; } case BlockOrientation.Cross_Hub:{ targetSet = Cross_Hub; break; } case BlockOrientation.Downward_T_Hub:{ targetSet = Downward_T_Hub; break; } case BlockOrientation.Upward_T_Hub:{ targetSet = Upward_T_Hub; break; } case BlockOrientation.Leftward_T_Hub:{ targetSet = Leftward_T_Hub; break; } case BlockOrientation.Rightward_T_Hub:{ targetSet = Rightward_T_Hub; break; } //Gee. Regrets //There was probably a better way to do this //But here we are case BlockOrientation.Border_Bottom_Left:{ targetSet = Border_Bottom_Left; break; } case BlockOrientation.Border_Bottom_Right:{ targetSet = Border_Bottom_Right; break; } case BlockOrientation.Border_Top_Left:{ targetSet = Border_Top_Left; break; } case BlockOrientation.Border_Top_Right:{ targetSet = Border_Top_Right; break; } case BlockOrientation.Diagonal_Gate_Left:{ targetSet = Diagonal_Gate_Left; break; } case BlockOrientation.Diagonal_Gate_Right:{ targetSet = Diagonal_Gate_Right; break; } case BlockOrientation.Fork_Bottom_Left:{ targetSet = Fork_Bottom_Left; break; } case BlockOrientation.Fork_Bottom_Right:{ targetSet = Fork_Bottom_Right; break; } case BlockOrientation.Fork_Top_Left:{ targetSet = Fork_Top_Left; break; } case BlockOrientation.Fork_Top_Right:{ targetSet = Fork_Top_Right; break; } case BlockOrientation.Funnel_Bottom:{ targetSet = Funnel_Bottom; break; } case BlockOrientation.Funnel_Left:{ targetSet = Funnel_Left; break; } case BlockOrientation.Funnel_Right:{ targetSet = Funnel_Right; break; } case BlockOrientation.Funnel_Top:{ targetSet = Funnel_Top; break; } case BlockOrientation.Taper_Bottom_Left:{ targetSet = Taper_Bottom_Left; break; } case BlockOrientation.Taper_Bottom_Right:{ targetSet = Taper_Bottom_Right; break; } case BlockOrientation.Taper_Left_Bottom:{ targetSet = Taper_Left_Bottom; break; } case BlockOrientation.Taper_Left_Top:{ targetSet = Taper_Left_Top; break; } case BlockOrientation.Taper_Right_Bottom:{ targetSet = Taper_Right_Bottom; break; } case BlockOrientation.Taper_Right_Top:{ targetSet = Taper_Right_Top; break; } case BlockOrientation.Taper_Top_Left:{ targetSet = Taper_Top_Left; break; } case BlockOrientation.Taper_Top_Right:{ targetSet = Taper_Top_Right; break; } } if(targetSet == null || !targetSet.HasBlocks() && !includeEmptySets){ targetSet = GetDefaultSet(); } return targetSet; }
public BlockSet GetSetForOrientation(BlockOrientation orientation, bool includeEmptySets) { BlockSet targetSet = null; switch (orientation) { case BlockOrientation.Bottom_Alone: { targetSet = Bottom_Alone; break; } case BlockOrientation.Bottom_Left: { targetSet = Bottom_Left; break; } case BlockOrientation.Bottom_Right: { targetSet = Bottom_Right; break; } case BlockOrientation.Bottom_Surrounded: { targetSet = Bottom_Surrounded; break; } case BlockOrientation.Centre_Alone: { targetSet = Centre_Alone; break; } case BlockOrientation.Centre_Horizontal_Surrounded: { targetSet = Centre_Horizontal_Surrounded; break; } case BlockOrientation.Centre_Surrounded: { targetSet = Centre_Surrounded; break; } case BlockOrientation.Centre_Vertical_Surrounded: { targetSet = Centre_Vertical_Surrounded; break; } case BlockOrientation.Left_Alone: { targetSet = Left_Alone; break; } case BlockOrientation.Left_Surrounded: { targetSet = Left_Surrounded; break; } case BlockOrientation.Right_Alone: { targetSet = Right_Alone; break; } case BlockOrientation.Right_Surrounded: { targetSet = Right_Surrounded; break; } case BlockOrientation.Top_Alone: { targetSet = Top_Alone; break; } case BlockOrientation.Top_Left: { targetSet = Top_Left; break; } case BlockOrientation.Top_Right: { targetSet = Top_Right; break; } case BlockOrientation.Top_Surrounded: { targetSet = Top_Surrounded; break; } case BlockOrientation.Bottom_Left_Inner_Corner: { targetSet = Bottom_Left_Inner_Corner; break; } case BlockOrientation.Bottom_Right_Inner_Corner: { targetSet = Bottom_Right_Inner_Corner; break; } case BlockOrientation.Top_Left_Inner_Corner: { targetSet = Top_Left_Inner_Corner; break; } case BlockOrientation.Top_Right_Inner_Corner: { targetSet = Top_Right_Inner_Corner; break; } case BlockOrientation.Left_Diagonal: { targetSet = Left_Diagonal; break; } case BlockOrientation.Right_Diagonal: { targetSet = Right_Diagonal; break; } case BlockOrientation.Lower_Left_Filled_Diagonal: { targetSet = Lower_Left_Filled_Diagonal; break; } case BlockOrientation.Lower_Right_Filled_Diagonal: { targetSet = Lower_Right_Filled_Diagonal; break; } case BlockOrientation.Upper_Left_Filled_Diagonal: { targetSet = Upper_Left_Filled_Diagonal; break; } case BlockOrientation.Upper_Right_Filled_Diagonal: { targetSet = Upper_Right_Filled_Diagonal; break; } case BlockOrientation.Cross_Hub: { targetSet = Cross_Hub; break; } case BlockOrientation.Downward_T_Hub: { targetSet = Downward_T_Hub; break; } case BlockOrientation.Upward_T_Hub: { targetSet = Upward_T_Hub; break; } case BlockOrientation.Leftward_T_Hub: { targetSet = Leftward_T_Hub; break; } case BlockOrientation.Rightward_T_Hub: { targetSet = Rightward_T_Hub; break; } //Gee. Regrets //There was probably a better way to do this //But here we are case BlockOrientation.Border_Bottom_Left: { targetSet = Border_Bottom_Left; break; } case BlockOrientation.Border_Bottom_Right: { targetSet = Border_Bottom_Right; break; } case BlockOrientation.Border_Top_Left: { targetSet = Border_Top_Left; break; } case BlockOrientation.Border_Top_Right: { targetSet = Border_Top_Right; break; } case BlockOrientation.Diagonal_Gate_Left: { targetSet = Diagonal_Gate_Left; break; } case BlockOrientation.Diagonal_Gate_Right: { targetSet = Diagonal_Gate_Right; break; } case BlockOrientation.Fork_Bottom_Left: { targetSet = Fork_Bottom_Left; break; } case BlockOrientation.Fork_Bottom_Right: { targetSet = Fork_Bottom_Right; break; } case BlockOrientation.Fork_Top_Left: { targetSet = Fork_Top_Left; break; } case BlockOrientation.Fork_Top_Right: { targetSet = Fork_Top_Right; break; } case BlockOrientation.Funnel_Bottom: { targetSet = Funnel_Bottom; break; } case BlockOrientation.Funnel_Left: { targetSet = Funnel_Left; break; } case BlockOrientation.Funnel_Right: { targetSet = Funnel_Right; break; } case BlockOrientation.Funnel_Top: { targetSet = Funnel_Top; break; } case BlockOrientation.Taper_Bottom_Left: { targetSet = Taper_Bottom_Left; break; } case BlockOrientation.Taper_Bottom_Right: { targetSet = Taper_Bottom_Right; break; } case BlockOrientation.Taper_Left_Bottom: { targetSet = Taper_Left_Bottom; break; } case BlockOrientation.Taper_Left_Top: { targetSet = Taper_Left_Top; break; } case BlockOrientation.Taper_Right_Bottom: { targetSet = Taper_Right_Bottom; break; } case BlockOrientation.Taper_Right_Top: { targetSet = Taper_Right_Top; break; } case BlockOrientation.Taper_Top_Left: { targetSet = Taper_Top_Left; break; } case BlockOrientation.Taper_Top_Right: { targetSet = Taper_Top_Right; break; } } if (targetSet == null || !targetSet.HasBlocks() && !includeEmptySets) { targetSet = GetDefaultSet(); } return(targetSet); }
public void Editor_AddToBlockSet(BlockOrientation orientation, GameObject blockObject){ BlockSet targetSet = GetSetForOrientation(orientation,true); if(targetSet.rootObject == null){ //targetSet.rootObject = new GameObject(orientation.ToString()); //targetSet.rootObject.transform.parent = transform; //targetSet.rootObject.transform.localPosition = Vector3.zero; targetSet.rootObject = this.gameObject; } //PREFAB //blockObject.SetActiveRecursively(false); targetSet.Editor_AddToBlockSet(blockObject, this); }
private TestBlock(BlockModel model, int x, int y, BlockOrientation orientation) : base(model, x, y, orientation) { }
//Dictionary<string,Rect> outlineRects = new Dictionary<string, Rect>(); void DrawBlockSet(BlockSet blocks, BlockOrientation orientation) { string orientationName = orientation.ToString(); if (!scrollPositions.ContainsKey(orientationName)) { scrollPositions.Add(orientationName, Vector2.zero); } EditorGUILayout.BeginHorizontal(GUILayout.ExpandWidth(false)); EditorGUILayout.BeginVertical(GUILayout.Width(150)); EditorGUILayout.BeginHorizontal(GUILayout.ExpandWidth(false)); Texture2D icon = GetIcon(orientation.ToString()); GUILayout.Label(new GUIContent("", orientationName), GUILayout.ExpandWidth(false), GUILayout.MinWidth(100), GUILayout.MinHeight(100)); GUI.DrawTexture(GUILayoutUtility.GetLastRect(), icon, ScaleMode.ScaleAndCrop, false); bool isDefault = GUILayout.Toggle(blocks.IsDefault(), new GUIContent("", TidyMessages.BLOCK_EDITOR_BLOCKSET_IS_DEFAULT_TOOLTIP), GUILayout.Height(25)); if (isDefault && !blocks.IsDefault()) { workingBlock.ClearDefault(); blocks.SetIsDefault(true); SetBlockDirty(workingBlock); hasWorkingBlockChanged = true; if (!initialPreviewGenerated) { //there will be no other opportunity to refresh GetPreviewForGameObject(workingBlock.GetDefaultBlock(), true); initialPreviewGenerated = true; } } if (!isDefault && blocks.IsDefault()) { workingBlock.ClearDefault(); hasWorkingBlockChanged = true; SetBlockDirty(workingBlock); if (!initialPreviewGenerated) { //there will be no other opportunity to refresh GetPreviewForGameObject(workingBlock.GetDefaultBlock(), true); initialPreviewGenerated = true; } } EditorGUILayout.EndHorizontal(); if (!newObjects.ContainsKey(orientationName)) { newObjects.Add(orientationName, null); } newObjects[orientationName] = EditorGUILayout.ObjectField(newObjects[orientationName], typeof(GameObject), false, GUILayout.Width(150)) as GameObject; //Change as at 30/12/2011: No more button, automatic addition if (GUILayout.Button(new GUIContent(TidyMessages.BLOCK_EDITOR_BLOCKSET_ADD_VARIANT, TidyMessages.BLOCK_EDITOR_BLOCKSET_ADD_VARIANT_TOOLTIP)) && (newObjects[orientationName] != null && !newObjects[orientationName].Equals(workingBlock.gameObject))) { //GameObject newBlock = EditorUtility.InstantiatePrefab(newObjects[orientationName]) as GameObject; //PREFAB //GameObject newBlock = PrefabUtility.InstantiatePrefab(newObjects[orientationName]) as GameObject; //newBlock.name = newObjects[orientationName].name; //newBlock.SetActiveRecursively(false); workingBlock.Editor_AddToBlockSet(orientation, newObjects[orientationName]); if (workingBlock.GetDefaultSet() == null) { blocks.SetIsDefault(true); } hasWorkingBlockChanged = true; if (!initialPreviewGenerated) { //there will be no other opportunity to refresh GetPreviewForGameObject(workingBlock.GetDefaultBlock(), true); initialPreviewGenerated = true; } SetBlockDirty(workingBlock); newObjects[orientationName] = null; mapCreator.RefreshAllMaps(); } EditorGUILayout.EndVertical(); Vector2 scrollPos = scrollPositions[orientationName]; //scrollPos = GUILayout.BeginScrollView(scrollPos,GUILayout.MinHeight(130),GUILayout.ExpandWidth(true)); Rect r = EditorGUILayout.BeginHorizontal(GUILayout.ExpandWidth(true), GUILayout.MinHeight(130)); GUI.Box(r, ""); if (blocks != null && blocks.blockSet != null) { for (int i = 0; i < blocks.blockSet.Length; i++) { DrawObjectPreview(blocks.blockSet[i], orientation); } } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); //GUILayout.EndScrollView(); //GUI.Box(GUILayoutUtility.GetLastRect(),""); scrollPositions[orientationName] = scrollPos; EditorGUILayout.EndHorizontal(); }
void DrawObjectPreview(GameObject o, BlockOrientation orientation){ if(o == null){ return; } GUILayout.BeginVertical(); Texture2D preview = GetPreviewForGameObject(o,false); GUILayout.BeginHorizontal(GUILayout.Width(100)); string name = o.name; if(name.Length >= 12){ name = name.Substring(0,9); name += "..."; } GUILayout.Label(name); bool deleted = false; if(GUILayout.Button(new GUIContent(icons.GetTexture(TidyFileNames.ICON_DELETE_BLOCKPART),TidyMessages.BLOCK_EDITOR_BLOCKSET_REMOVE_VARIANT_TOOLTIP),GUILayout.Width(18),GUILayout.Height(18))){ workingBlock.Editor_RemoveFromBlockSet(orientation,o); //PREFAB /*if(destroyObject != null){ Editor.DestroyImmediate(destroyObject,true); }*/ SetBlockDirty(workingBlock); deleted = true; hasWorkingBlockChanged = true; if(!initialPreviewGenerated){ //there will be no other opportunity to refresh GetPreviewForGameObject(workingBlock.GetDefaultBlock(),true); initialPreviewGenerated = true; } } GUILayout.EndHorizontal(); if(!deleted){ if(preview == null){ GUILayout.Button(o.name,GUILayout.Width(100),GUILayout.Height(100)); } else{ GUILayout.Button(new GUIContent("",o.name),GUILayout.Width(100),GUILayout.Height(100)); GUI.DrawTexture(GUILayoutUtility.GetLastRect(),preview,ScaleMode.ScaleAndCrop,false); } } GUILayout.EndVertical(); }
public void SetBlockOrientation(BlockOrientation orientation, bool refresh){ if(this.orientation == (int)orientation && !refresh){ return; } Hide(); //Remove this. This is just so i can... look. O_O if(orientation != BlockOrientation.Default){ this.orientation = (int)orientation; } BlockSet chosenSet = GetSetForOrientation(orientation,false); if(chosenSet == null){ BlockSet d = GetDefaultSet(); if(d != null){ chosenSet = d; } else{ // #if UNITY_4_0 gameObject.SetActive(true); #else gameObject.active = true; #endif return; } } if(!chosenSet.HasBlocks()){ if(orientation == BlockOrientation.Default){ } else{ SetBlockOrientation(BlockOrientation.Default,true); } return; } chosenSet.Show(); #if UNITY_4_0 gameObject.SetActive(true); #else gameObject.active = true; #endif BindChildrenToBlock(); }
public Block Spawn(int x, int y, BlockOrientation orientation) { return(new Block(this, x, y, orientation)); }
public void Add(Block block, BlockOrientation orientation, BlockMaterial material, Vector2Int position) { block = block.Original; Placements.Add(new Placement(block, position, orientation, material)); SetDirtyReally(); }
public void Rotate(BlockOrientation orientation) { BlockOrientation = orientation; transform.eulerAngles = orientation.ToRotation(); }
private bool CanPlace(Block b, BlockOrientation orientation, int x, int y) { y = Height - y; return(simulator.CanPlaceBlock(b, orientation, x, y)); }
public bool CanPlaceBlock(Block block, BlockOrientation orientation, int x, int y) { block.Rotate(orientation); return(CanPlaceBlock(block, x, y)); }
public GameObject Editor_RemoveFromBlockSet(BlockOrientation orientation, GameObject blockObject){ BlockSet targetSet = GetSetForOrientation(orientation,true); if(targetSet == null){ return null; } GameObject returnObject = targetSet.Editor_RemoveFromBlockSet(blockObject); if(!targetSet.HasBlocks()){ targetSet.SetIsDefault(false); BlockSet[] bs = GetBlockSetsAsArray(); for(int i = 0; i < bs.Length; i++){ if(bs[i].HasBlocks()){ bs[i].SetIsDefault(true); break; } } } return returnObject; }
//Dictionary<string,Rect> outlineRects = new Dictionary<string, Rect>(); void DrawBlockSet(BlockSet blocks, BlockOrientation orientation){ string orientationName = orientation.ToString(); if(!scrollPositions.ContainsKey(orientationName)){ scrollPositions.Add(orientationName,Vector2.zero); } EditorGUILayout.BeginHorizontal(GUILayout.ExpandWidth(false)); EditorGUILayout.BeginVertical(GUILayout.Width(150)); EditorGUILayout.BeginHorizontal(GUILayout.ExpandWidth(false)); Texture2D icon = GetIcon(orientation.ToString()); GUILayout.Label(new GUIContent("",orientationName),GUILayout.ExpandWidth(false), GUILayout.MinWidth(100),GUILayout.MinHeight(100)); GUI.DrawTexture(GUILayoutUtility.GetLastRect(),icon,ScaleMode.ScaleAndCrop,false); bool isDefault = GUILayout.Toggle(blocks.IsDefault(),new GUIContent("",TidyMessages.BLOCK_EDITOR_BLOCKSET_IS_DEFAULT_TOOLTIP),GUILayout.Height(25)); if(isDefault && !blocks.IsDefault()){ workingBlock.ClearDefault(); blocks.SetIsDefault(true); SetBlockDirty(workingBlock); hasWorkingBlockChanged = true; if(!initialPreviewGenerated){ //there will be no other opportunity to refresh GetPreviewForGameObject(workingBlock.GetDefaultBlock(),true); initialPreviewGenerated = true; } } if(!isDefault && blocks.IsDefault()){ workingBlock.ClearDefault(); hasWorkingBlockChanged = true; SetBlockDirty(workingBlock); if(!initialPreviewGenerated){ //there will be no other opportunity to refresh GetPreviewForGameObject(workingBlock.GetDefaultBlock(),true); initialPreviewGenerated = true; } } EditorGUILayout.EndHorizontal(); if(!newObjects.ContainsKey(orientationName)){ newObjects.Add(orientationName,null); } newObjects[orientationName] = EditorGUILayout.ObjectField(newObjects[orientationName],typeof(GameObject),false,GUILayout.Width(150)) as GameObject; //Change as at 30/12/2011: No more button, automatic addition if(GUILayout.Button(new GUIContent(TidyMessages.BLOCK_EDITOR_BLOCKSET_ADD_VARIANT, TidyMessages.BLOCK_EDITOR_BLOCKSET_ADD_VARIANT_TOOLTIP)) && (newObjects[orientationName] != null && !newObjects[orientationName].Equals(workingBlock.gameObject))){ //GameObject newBlock = EditorUtility.InstantiatePrefab(newObjects[orientationName]) as GameObject; //PREFAB //GameObject newBlock = PrefabUtility.InstantiatePrefab(newObjects[orientationName]) as GameObject; //newBlock.name = newObjects[orientationName].name; //newBlock.SetActiveRecursively(false); workingBlock.Editor_AddToBlockSet(orientation,newObjects[orientationName]); if(workingBlock.GetDefaultSet() == null){ blocks.SetIsDefault(true); } hasWorkingBlockChanged = true; if(!initialPreviewGenerated){ //there will be no other opportunity to refresh GetPreviewForGameObject(workingBlock.GetDefaultBlock(),true); initialPreviewGenerated = true; } SetBlockDirty(workingBlock); newObjects[orientationName] = null; mapCreator.RefreshAllMaps(); } EditorGUILayout.EndVertical(); Vector2 scrollPos = scrollPositions[orientationName]; //scrollPos = GUILayout.BeginScrollView(scrollPos,GUILayout.MinHeight(130),GUILayout.ExpandWidth(true)); Rect r = EditorGUILayout.BeginHorizontal(GUILayout.ExpandWidth(true),GUILayout.MinHeight(130)); GUI.Box(r,""); if(blocks != null && blocks.blockSet != null){ for(int i = 0; i < blocks.blockSet.Length; i++){ DrawObjectPreview(blocks.blockSet[i],orientation); } } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); //GUILayout.EndScrollView(); //GUI.Box(GUILayoutUtility.GetLastRect(),""); scrollPositions[orientationName] = scrollPos; EditorGUILayout.EndHorizontal(); }
public Block At(int x, int y, BlockOrientation orientation = null) { return(new TestBlock(Model, x, y, orientation ?? BlockOrientation.Up)); }
private Image DrawArrow(Rectangle rect, BlockOrientation orientation, State state) { if ((rect.Width > 0) && (rect.Height > 0)) { Image resultImg = new Bitmap(rect.Width, rect.Height); if (orientation == BlockOrientation.Up) resultImg = DrawArrowUp(resultImg, new Rectangle(0, 0, rect.Width, rect.Height)); else if (orientation == BlockOrientation.Down) resultImg = DrawArrowDown(resultImg, new Rectangle(0, 0, rect.Width, rect.Height)); else if (orientation == BlockOrientation.Left) resultImg = DrawArrowLeft(resultImg, new Rectangle(0, 0, rect.Width, rect.Height)); else if (orientation == BlockOrientation.Right) resultImg = DrawArrowRight(resultImg, new Rectangle(0, 0, rect.Width, rect.Height)); if ((state & State.Pressed) != 0) return Colorize(resultImg, PressedColor); else if ((state & State.Hover) != 0) return Colorize(resultImg, HoverColor); else return Colorize(resultImg, NormalColor); } else return null; }
void DrawObjectPreview(GameObject o, BlockOrientation orientation) { if (o == null) { return; } GUILayout.BeginVertical(); Texture2D preview = GetPreviewForGameObject(o, false); GUILayout.BeginHorizontal(GUILayout.Width(100)); string name = o.name; if (name.Length >= 12) { name = name.Substring(0, 9); name += "..."; } GUILayout.Label(name); bool deleted = false; if (GUILayout.Button(new GUIContent(icons.GetTexture(TidyFileNames.ICON_DELETE_BLOCKPART), TidyMessages.BLOCK_EDITOR_BLOCKSET_REMOVE_VARIANT_TOOLTIP), GUILayout.Width(18), GUILayout.Height(18))) { workingBlock.Editor_RemoveFromBlockSet(orientation, o); //PREFAB /*if(destroyObject != null){ * Editor.DestroyImmediate(destroyObject,true); * }*/ SetBlockDirty(workingBlock); deleted = true; hasWorkingBlockChanged = true; if (!initialPreviewGenerated) { //there will be no other opportunity to refresh GetPreviewForGameObject(workingBlock.GetDefaultBlock(), true); initialPreviewGenerated = true; } } GUILayout.EndHorizontal(); if (!deleted) { if (preview == null) { GUILayout.Button(o.name, GUILayout.Width(100), GUILayout.Height(100)); } else { GUILayout.Button(new GUIContent("", o.name), GUILayout.Width(100), GUILayout.Height(100)); GUI.DrawTexture(GUILayoutUtility.GetLastRect(), preview, ScaleMode.ScaleAndCrop, false); } } GUILayout.EndVertical(); }