private SerializableSaber GetSerializableSaber(SaberModel saberModel)
        {
            var serializableSaber = new SerializableSaber();

            serializableSaber.SaberWidth = saberModel.SaberWidth;

            var pieceList = new List <SerializablePiece>();

            foreach (BasePieceModel pieceModel in saberModel.PieceCollection)
            {
                pieceList.Add(new SerializablePiece {
                    Path = pieceModel.StoreAsset.RelativePath
                });
            }

            serializableSaber.Pieces = pieceList;

            var trailModel = saberModel.GetTrailModel();

            if (trailModel != null)
            {
                var trail = new SerializableTrail();
                trail.Length            = trailModel.Length;
                trail.Width             = trailModel.Width;
                trail.Whitestep         = trailModel.Whitestep;
                trail.TrailOrigin       = trailModel.TrailOrigin;
                trail.ClampTexture      = trailModel.ClampTexture;
                trail.Material          = SerializableMaterial.FromMaterial(trailModel.Material.Material);
                serializableSaber.Trail = trail;
            }

            return(serializableSaber);
        }
Esempio n. 2
0
        private async Task LoadSaberModel(SaberModel saberModel, SerializableSaber serializableSaber)
        {
            saberModel.SaberWidth = serializableSaber.SaberWidth;

            if (_mainAssetStore.IsLoading)
            {
                await _mainAssetStore.CurrentTask;
            }

            foreach (var piece in serializableSaber.Pieces)
            {
                var comp = await _mainAssetStore[piece.Path];
                saberModel.PieceCollection.AddPiece(comp.AssetTypeDefinition, comp.GetPiece(saberModel.SaberSlot));
            }

            var trail = serializableSaber.Trail;

            if (trail != null)
            {
                var trailModel = new TrailModel(Vector3.zero, trail.Width, trail.Length, null, trail.Whitestep, trail.TrailOrigin);
                if (!string.IsNullOrEmpty(trail.TrailOrigin))
                {
                    await LoadFromTrailOrigin(trailModel, trail.TrailOrigin);
                }

                if (saberModel.GetCustomSaber(out var customsaber))
                {
                    customsaber.TrailModel = trailModel;
                }
                else
                {
                    saberModel.TrailModel = trailModel;
                }
            }
        }
        private async Task LoadSaberModel(SaberModel saberModel, SerializableSaber serializableSaber)
        {
            saberModel.SaberWidth = serializableSaber.SaberWidth;

            if (_mainAssetStore.IsLoading)
            {
                await _mainAssetStore.CurrentTask;
            }

            foreach (var piece in serializableSaber.Pieces)
            {
                var comp = await _mainAssetStore[piece.Path];
                if (comp != null)
                {
                    saberModel.PieceCollection.AddPiece(comp.AssetTypeDefinition, comp.GetPiece(saberModel.SaberSlot));
                }
            }

            TrailModel trailModel = null;

            if (saberModel.GetCustomSaber(out var customsaber))
            {
                trailModel = customsaber.TrailModel;
            }
            else
            {
                trailModel = new TrailModel();
            }

            var trail = serializableSaber.Trail;

            if (trail != null)
            {
                trailModel.TrailPosOffset = Vector3.zero;
                trailModel.Width          = trail.Width;
                trailModel.Length         = trail.Length;
                trailModel.Whitestep      = trail.Whitestep;
                trailModel.ClampTexture   = trail.ClampTexture;

                // if trail comes from another saber
                if (!string.IsNullOrEmpty(trail.TrailOrigin))
                {
                    await LoadFromTrailOrigin(trailModel, trail.TrailOrigin);
                }

                // assign trailmodel to custom saber or saber factory saber
                // depending on which trail type is being used
                if (customsaber is null)
                {
                    saberModel.TrailModel = trailModel;
                }

                trail.Material?.ApplyToMaterial(trailModel.Material?.Material, ResolveTexture);
            }
        }