public DeleteBlockCommand(GameObject block, StageEditorState stageState) { EditorBlockData data = block.GetComponent <EditorBlockData_SceneInstance>().Data; OrthoAngle angle = block.transform.eulerAngles.y.ToOrthoAngle(); rect = data.GetGridRect( new Vector2(block.transform.position.x, block.transform.position.z), angle == OrthoAngle.Ninety || angle == OrthoAngle.TwoSeventy); blockObject = block; blockMesh = block.GetComponent <MeshFilter>().mesh; this.stageState = stageState; }
/// <summary> /// Converts an ortho angle to its corresponding value in degrees. /// </summary> /// <param name="orthoAngle">The angle to convert.</param> /// <returns>The angle in degrees.</returns> public static float ToDegrees(this OrthoAngle orthoAngle) { switch (orthoAngle) { case OrthoAngle.Zero: return(0f); case OrthoAngle.Ninety: return(90f); case OrthoAngle.OneEighty: return(180f); case OrthoAngle.TwoSeventy: return(270f); default: return(default); } }
private void Awake() { interactionLogic.NewBlockSelected += OnNewPieceSelected; interactionLogic.EditModeChanged += OnEditModeChanged; colliderClickBroadcaster.ColliderHovered += OnColliderHovered; colliderClickBroadcaster.ColliderClicked += OnColliderClicked; RangeX = tileRangeX.Value; RangeZ = tileRangeZ.Value; newBlockRenderer.material = placeableBlockMaterial; blockRotation = OrthoAngle.Zero; blockIsPlaceable = true; selectionSize = Vector3Int.one; stageState = new StageEditorState(RangeX, RangeZ); }
/// <summary> /// Creates a command to place a block at the given location and rotation. /// </summary> /// <param name="blockData">Describes the block being placed.</param> /// <param name="atLocation">The location to place the block at.</param> /// <param name="rotation">The rotation of this block.</param> /// <param name="stageState">The persistent stage state object.</param> public PlaceBlockCommand(EditorBlockData blockData, Vector3 atLocation, OrthoAngle rotation, StageEditorState stageState) { this.blockData = blockData; this.atLocation = atLocation; this.rotation = rotation; this.stageState = stageState; // Calculate the rect that this block will effect. rect = blockData.GetGridRect( new Vector2(atLocation.x, atLocation.z), rotation == OrthoAngle.Ninety || rotation == OrthoAngle.TwoSeventy); // Create a new instance for this command. spawnedInstance = new GameObject { layer = LayerMask.NameToLayer("Block") }; // Allow future commands to access this block data. spawnedInstance.AddComponent <EditorBlockData_SceneInstance>().Data = blockData; }