/// <summary> /// Creates an <see cref="InstanceTrailData" /> object /// with the correct trail transforms /// </summary> /// <param name="saberObject">The saber gameobject that the <see cref="CustomTrail" /> component is on</param> /// <param name="trailModel">The <see cref="TrailModel" /> to use</param> public void InitializeTrailData(GameObject saberObject, TrailModel trailModel) { if (saberObject is null || trailModel is null) { return; } var trails = SaberHelpers.GetTrails(saberObject).ToArray(); // Add new CustomTrail component with given data (creating position transforms for given position) CustomTrail SetupTrail(int length, float startPos, float endPos, Material material) { var newTrail = saberObject.AddComponent <CustomTrail>(); newTrail.Length = length; newTrail.PointStart = saberObject.CreateGameObject("PointStart").transform; newTrail.PointEnd = saberObject.CreateGameObject("PointEnd").transform; newTrail.PointEnd.localPosition = new Vector3(0, 0, endPos); newTrail.PointStart.localPosition = new Vector3(0, 0, startPos); newTrail.TrailMaterial = material; return(newTrail); } // if saber has no trial set up a generic one if (trails is null || trails.Length < 1) { trails = new[] { SetupTrail(12, 0, 1, null) }; } var saberTrail = trails[0]; List <CustomTrail> secondaryTrails = null; // set up secondary trails from other saber if (trailModel.TrailOriginTrails is { } && trailModel.TrailOriginTrails.Count > 1)
private async Task LoadFromTrailOrigin(Serializer serializer, JToken trailOrigin) { var comp = await serializer.LoadPiece(trailOrigin); if (!(comp?.GetLeft() is CustomSaberModel cs)) { return; } var originTrailModel = cs.GrabTrail(true); if (originTrailModel == null) { return; } Material ??= new MaterialDescriptor(null); Material.Material = originTrailModel.Material.Material; TrailOriginTrails = SaberHelpers.GetTrails(cs.Prefab); }