diff --git a/AlternativePlay/AssetLoaderBehavior.cs b/AlternativePlay/AssetLoaderBehavior.cs index 474cd3c..c04c44c 100644 --- a/AlternativePlay/AssetLoaderBehavior.cs +++ b/AlternativePlay/AssetLoaderBehavior.cs @@ -7,7 +7,9 @@ public class AssetLoaderBehavior : MonoBehaviour { public GameObject TrackerPrefab { get; private set; } public GameObject SaberPrefab { get; private set; } - public GameObject FlailHandlePrefab { get; private set; } + public GameObject FlailHandleSegmentPrefab { get; private set; } + public GameObject FlailTopCapPrefab { get; private set; } + public GameObject FlailBottomCapPrefab { get; private set; } public GameObject LinkPrefab { get; private set; } private void Awake() @@ -15,7 +17,9 @@ private void Awake() AssetBundle assetBundle = AssetBundle.LoadFromStream(Assembly.GetExecutingAssembly().GetManifestResourceStream("AlternativePlay.Resources.alternativeplaymodels")); this.TrackerPrefab = assetBundle.LoadAsset("APTracker"); this.SaberPrefab = assetBundle.LoadAsset("APSaber"); - this.FlailHandlePrefab = assetBundle.LoadAsset("APFlailHandle"); + this.FlailHandleSegmentPrefab = assetBundle.LoadAsset("APFlailHandleSegment"); + this.FlailTopCapPrefab = assetBundle.LoadAsset("APFlailTopCap"); + this.FlailBottomCapPrefab = assetBundle.LoadAsset("APFlailBottomCap"); this.LinkPrefab = assetBundle.LoadAsset("APLink"); assetBundle.Unload(false); } diff --git a/AlternativePlay/BeatFlailBehavior.cs b/AlternativePlay/BeatFlailBehavior.cs index ee9aff0..c669635 100644 --- a/AlternativePlay/BeatFlailBehavior.cs +++ b/AlternativePlay/BeatFlailBehavior.cs @@ -1,4 +1,5 @@ using AlternativePlay.Models; +using System; using System.Collections; using System.Collections.Generic; using System.Linq; @@ -52,13 +53,20 @@ private void Awake() // Do nothing if we aren't playing Flail if (Configuration.Current.PlayMode != PlayMode.BeatFlail) { return; } - // Create the GameObjects used for physics calculations - this.leftPhysicsFlail = this.CreatePhysicsChain("Left", Configuration.Current.LeftFlailLength / 100.0f); - this.rightPhysicsFlail = this.CreatePhysicsChain("Right", Configuration.Current.RightFlailLength / 100.0f); - this.leftLinkMeshes = Utilities.CreateLinkMeshes(this.leftPhysicsFlail.Count, Configuration.Current.LeftFlailLength / 100.0f); - this.leftHandleMesh = GameObject.Instantiate(BehaviorCatalog.instance.AssetLoaderBehavior.FlailHandlePrefab); - this.rightLinkMeshes = Utilities.CreateLinkMeshes(this.rightPhysicsFlail.Count, Configuration.Current.RightFlailLength / 100.0f); - this.rightHandleMesh = GameObject.Instantiate(BehaviorCatalog.instance.AssetLoaderBehavior.FlailHandlePrefab); + // Create the GameObjects for the flails + if (Configuration.Current.LeftFlailMode == BeatFlailMode.Flail) + { + this.leftPhysicsFlail = this.CreatePhysicsChain("Left", Configuration.Current.LeftFlailLength / 100.0f); + this.leftLinkMeshes = Utilities.CreateLinkMeshes(this.leftPhysicsFlail.Count, Configuration.Current.LeftFlailLength / 100.0f); + this.leftHandleMesh = this.CreateFlailHandle("LeftHandle", Configuration.Current.LeftHandleLength / 100.0f); + } + + if (Configuration.Current.RightFlailMode == BeatFlailMode.Flail) + { + this.rightPhysicsFlail = this.CreatePhysicsChain("Right", Configuration.Current.RightFlailLength / 100.0f); + this.rightLinkMeshes = Utilities.CreateLinkMeshes(this.rightPhysicsFlail.Count, Configuration.Current.RightFlailLength / 100.0f); + this.rightHandleMesh = this.CreateFlailHandle("RightHandle", Configuration.Current.RightHandleLength / 100.0f); + } } private void FixedUpdate() @@ -68,7 +76,7 @@ private void FixedUpdate() float gravity = Configuration.Current.Gravity * -9.81f; - switch(Configuration.Current.LeftFlailMode) + switch (Configuration.Current.LeftFlailMode) { default: case BeatFlailMode.Flail: @@ -140,7 +148,8 @@ private void Update() Vector3 moveHandleUp = leftSaberPose.rotation * new Vector3(0.0f, 0.0f, oneChainDistance); // Move handle forward one chain length this.leftHandleMesh.transform.position = leftSaberPose.position + moveHandleUp; this.leftHandleMesh.transform.rotation = leftSaberPose.rotation; - break; + + break; case BeatFlailMode.Sword: // Do nothing @@ -244,5 +253,63 @@ private IEnumerator DisableSaberMeshes() BehaviorCatalog.instance.SaberDeviceManager.DisableRightSaberMesh(); } } + + /// + /// Create a segmented variable length flail handle + /// + /// The name for the parent handle GameObject + /// The length of the handle in meters + /// The parent GameObject for the flail handle + private GameObject CreateFlailHandle(string name, float flailTotalLength) + { + const float flailSegmentLength = 0.10f; // 10 cm or 0.1m + const float topCapLength = 0.063f; // 6.3cm + const float bottomCapLength = 0.01f; // 1 cm + + int segmentCount = (int)(flailTotalLength / flailSegmentLength); + + var assetLoader = BehaviorCatalog.instance.AssetLoaderBehavior; + + // Instantiate One-Off Game Objects + var handle = new GameObject(name); + var topCap = GameObject.Instantiate(assetLoader.FlailTopCapPrefab, Vector3.zero, Quaternion.identity, handle.transform); + var bottomCapPosition = new Vector3(0.0f, 0.0f, (flailSegmentLength * segmentCount * -1.0f) - topCapLength - bottomCapLength); + var bottomCap = GameObject.Instantiate(assetLoader.FlailBottomCapPrefab, bottomCapPosition, Quaternion.identity, handle.transform); + + // Instantiate Handle Segments + var segmentList = Enumerable.Range(0, segmentCount).Select(i => + { + float zPosition = (flailSegmentLength * i * -1.0f) - topCapLength; + var positionRelative = new Vector3(0.0f, 0.0f, zPosition); + var gameObject = GameObject.Instantiate(assetLoader.FlailHandleSegmentPrefab, positionRelative, Quaternion.identity, handle.transform); + + return new { GameObject = gameObject, Index = i }; + + }).ToList(); + segmentList.ForEach(segment => this.remapSegmentUV(segment.GameObject, segment.Index)); + + return handle; + } + + /// + /// Remaps the UV coordinates in the U direction based on the MOD 4 of the index. + /// + private void remapSegmentUV(GameObject segment, int index) + { + const int segmentsPerTexture = 4; + + Mesh mesh = segment.GetComponent().mesh; + var uvList = new List(); + mesh.GetUVs(0, uvList); + + var modifiedUV = uvList.Select(uv => + { + float correctedX = (uv.x < 0.01f && uv.x > -0.01f) ? 0.0f : 0.25f; + float multipleX = 0.25f * (index % segmentsPerTexture); + return new Vector2(correctedX + multipleX, uv.y); + }).ToList(); + + mesh.SetUVs(0, modifiedUV); + } } } \ No newline at end of file diff --git a/AlternativePlay/Models/ConfigurationData.cs b/AlternativePlay/Models/ConfigurationData.cs index e41e588..3f34601 100644 --- a/AlternativePlay/Models/ConfigurationData.cs +++ b/AlternativePlay/Models/ConfigurationData.cs @@ -81,6 +81,8 @@ public class PlayModeSettings public BeatFlailMode RightFlailMode { get; set; } = BeatFlailMode.Flail; public int LeftFlailLength { get; set; } = 80; // in centimetres public int RightFlailLength { get; set; } = 80; // in centimetres + public int LeftHandleLength { get; set; } = 40; // in centimetres + public int RightHandleLength { get; set; } = 40; // in centimetres public int MoveNotesBack { get; set; } = 0; // in centimetres // Gameplay Changes Options diff --git a/AlternativePlay/Properties/AssemblyInfo.cs b/AlternativePlay/Properties/AssemblyInfo.cs index ce37daa..f83bc94 100644 --- a/AlternativePlay/Properties/AssemblyInfo.cs +++ b/AlternativePlay/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.7.7.0")] -[assembly: AssemblyFileVersion("0.7.7.0")] +[assembly: AssemblyVersion("0.8.0.0")] +[assembly: AssemblyFileVersion("0.8.0.0")] diff --git a/AlternativePlay/Resources/alternativeplaymodels b/AlternativePlay/Resources/alternativeplaymodels index e148304..92da6dd 100644 Binary files a/AlternativePlay/Resources/alternativeplaymodels and b/AlternativePlay/Resources/alternativeplaymodels differ diff --git a/AlternativePlay/UI/BeatFlailView.bsml b/AlternativePlay/UI/BeatFlailView.bsml index 45a3b77..13101f1 100644 --- a/AlternativePlay/UI/BeatFlailView.bsml +++ b/AlternativePlay/UI/BeatFlailView.bsml @@ -11,30 +11,34 @@ - + - + - - + + + + - + - - - - + + + + + +