void OnSceneGUI() { for (int i = 0; i < followScript.levelAreas.Count; i++) { EditorGUI.BeginChangeCheck(); followScript.levelAreas[i].Set(HandlesUtil.ResizeRect(followScript.levelAreas[i].levelRect, Handles.DotCap, 1f)); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(target, "Changed levelBounds"); EditorUtility.SetDirty(followScript); } } }
public void OnSceneGUI() { var script = (EnemyMoveFlyingController)target; Vector2 startPosition = (Vector2)script.transform.position; Vector2 endPosition = startPosition + script.MoveDirection; HandlesUtil.DrawArrow2D(startPosition, endPosition, Color.white); using (var check = new EditorGUI.ChangeCheckScope()) { HandlesUtil.DrawFreeMoveHandle(ref endPosition, Color.blue, capFunction: HandlesUtil.CrossedCircleHandleCap, screenSizeScale: 2f); // moving direction handle if (check.changed) { // Don't normalize direction to make it easier to edit using snapping // with values like (-2, 1) // Move direction will be normalized before moving script.MoveDirection = endPosition - startPosition; } } }
private void OnSceneGUI() { var script = (EnemyWave)target; // Scale offset with handle size so it remains constant on screen float handleSize = HandlesUtil.Get2DPixelSize(); // In order to draw the global handle (that moves all spawn points at the same time), we must determine // the minimum bounding box containing all the spawn points Rect boundingBox = new Rect { min = Vector2.positiveInfinity, max = Vector2.negativeInfinity }; // we're modifying indirect (deep) members of the script, and besides applying custom rounding, // so changes are not trivial and need Undo Record Object Undo.RecordObject(script, "Changed Enemy Wave Data"); foreach (EnemySpawnData enemySpawnData in script.EnemySpawnDataArray) { using (var check = new EditorGUI.ChangeCheckScope()) { HandlesUtil.DrawFreeMoveHandle(ref enemySpawnData.spawnPosition, spawnPointColor, manualSnapValue * Vector2.one, HandlesUtil.CrossedCircleHandleCap, 2f); if (check.changed) { enemySpawnData.spawnPosition = RoundPosition(enemySpawnData.spawnPosition); } } // Expand bounding box to contain any (rounded) spawn point not inside it already // Note that we are following 2D psace convention, not UI convention, so +Y is up boundingBox.min = Vector2.Min(boundingBox.min, enemySpawnData.spawnPosition); boundingBox.max = Vector2.Max(boundingBox.max, enemySpawnData.spawnPosition); string enemyName = enemySpawnData.enemyData ? enemySpawnData.enemyData.enemyName : "NONE"; HandlesUtil.Label2D(new Vector3(enemySpawnData.spawnPosition.x - 24f * handleSize, enemySpawnData.spawnPosition.y - 32f * handleSize, 0f), enemyName, 2f, true, spawnPointColor); Texture previewTexture = enemySpawnData.enemyData.editorSpawnPreviewTexture; if (previewTexture != null) { Vector3 labelPosition = new Vector3(enemySpawnData.spawnPosition.x - (previewTexture.width / 2f) * handleSize, enemySpawnData.spawnPosition.y - (15f + previewTexture.height / 2f) * handleSize, 0f); Handles.Label(labelPosition, previewTexture); } } // Ignore infinite bounding box (only happens when EnemySpawnDataArray is empty) if (!float.IsInfinity(boundingBox.width) && !float.IsInfinity(boundingBox.height)) { // Place batch move handle above the bounding box (remember 2D convention is +Y up) // Since we are using 2D space coordinates, we don't need fixed screen scaling, so no need to * handleSize Vector2 batchMoveHandleStartPosition = new Vector2(boundingBox.center.x, boundingBox.yMax + 1f); Vector2 batchMoveHandleCurrentPosition = batchMoveHandleStartPosition; using (var check = new EditorGUI.ChangeCheckScope()) { HandlesUtil.DrawFreeMoveHandle(ref batchMoveHandleCurrentPosition, batchHandleColor, manualSnapValue * Vector2.one, Handles.RectangleHandleCap, 2f); if (check.changed) { // Calculate handle move Vector2 handleDelta = batchMoveHandleCurrentPosition - batchMoveHandleStartPosition; // Move all spawn points the same way we moved the batch handle foreach (EnemySpawnData enemySpawnData in script.EnemySpawnDataArray) { enemySpawnData.spawnPosition = RoundPosition(enemySpawnData.spawnPosition + handleDelta); } } } HandlesUtil.Label2D(new Vector3(batchMoveHandleCurrentPosition.x - 63f * handleSize, batchMoveHandleCurrentPosition.y + 52f * handleSize, 0f), "Batch move", 2f, true, batchHandleColor); } }
public void OnSceneGUI() { var script = (EnemyMoveGroundedController)target; HandlesUtil.Label2D(script.transform.position + 1f * Vector3.up, script.DebugLastAIBehaviourResult, color: Color.black); }