protected virtual void OnPlatformPlacedWithOverlapping(PlatformCutterResultModel result) { platforms.Remove(currentPlatform.gameObject); MonoBehaviour.Destroy(currentPlatform.gameObject); currentPlatform = platformsFactory.CreatePlatform( result.NewPlatformPosition, result.NewPlatformScale); cutPartsFactory.CreateCutPart( result.RemainsPartPosition, result.RemainsPartScale); platforms.Add(currentPlatform.gameObject); }
protected virtual PlatformCutterResultModel CreateByZ( Platform basePlatform, Platform targetPlatform, float difference, float depth, Transform platformAnchor, Transform cutPartAnchor) { if (depth <= 0f) { return(null); } var platformScale = new Vector3( targetPlatform.transform.localScale.x, targetPlatform.transform.localScale.y, depth); var platformPosition = new Vector3( targetPlatform.transform.position.x, targetPlatform.transform.position.y, platformAnchor.position.z + depth * 0.5f); var cutPartScale = new Vector3( targetPlatform.transform.localScale.x, targetPlatform.transform.localScale.y, difference); var cutPartPosition = new Vector3( targetPlatform.transform.position.x, targetPlatform.transform.position.y, cutPartAnchor.position.z + difference * 0.5f); var result = new PlatformCutterResultModel(); result.NewPlatformPosition = platformPosition; result.NewPlatformScale = platformScale; result.WasRemainsPart = true; result.RemainsPartPosition = cutPartPosition; result.RemainsPartScale = cutPartScale; return(result); }
protected virtual PlatformCutterResultModel DividePlatformIfOverlapped( Platform basePlatform, Platform targetPlatform) { var topDifference = targetPlatform.LeftTopPoint.position.z - basePlatform.LeftTopPoint.position.z; if (topDifference > 0f && Mathf.Abs(topDifference) > maxOffsetToSetAsNotOverlapped) { return(CreateNewTopPlatform(basePlatform, targetPlatform, topDifference)); } var bottomDifference = basePlatform.LeftBottomPoint.position.z - targetPlatform.LeftBottomPoint.position.z; if (bottomDifference > 0f && Mathf.Abs(bottomDifference) > maxOffsetToSetAsNotOverlapped) { return(CreateNewBottomPlatform(basePlatform, targetPlatform, bottomDifference)); } var leftDifference = basePlatform.LeftBottomPoint.position.x - targetPlatform.LeftBottomPoint.position.x; if (leftDifference > 0f && Mathf.Abs(leftDifference) > maxOffsetToSetAsNotOverlapped) { return(CreateNewLeftPlatform(basePlatform, targetPlatform, leftDifference)); } var rightDifference = targetPlatform.RightBottomPoint.position.x - basePlatform.RightBottomPoint.position.x; if (rightDifference > 0f && Mathf.Abs(rightDifference) > maxOffsetToSetAsNotOverlapped) { return(CreateNewRightPlatform(basePlatform, targetPlatform, rightDifference)); } var result = new PlatformCutterResultModel(); result.NewPlatformPosition = basePlatform.transform.position; result.NewPlatformScale = basePlatform.transform.localScale; result.WasRemainsPart = false; return(result); }