コード例 #1
0
        public override void DeleteFile(string path)
        {
            path = AssetPath.CorrectSlashes(path);
            var desc = GetDescriptor(path);

            index.Remove(path);
            trash.Add(desc);
        }
コード例 #2
0
ファイル: PackedAssetBundle.cs プロジェクト: x5f3759df/Citrus
        public override void SetAttributes(string path, AssetAttributes attributes)
        {
            OnModifying?.Invoke();
            var desc = GetDescriptor(path);

            index[AssetPath.CorrectSlashes(path)] = desc;
            wasModified = true;
        }
コード例 #3
0
ファイル: PackedAssetBundle.cs プロジェクト: x5f3759df/Citrus
        private AssetDescriptor GetDescriptor(string path)
        {
            AssetDescriptor desc;

            if (index.TryGetValue(AssetPath.CorrectSlashes(path), out desc))
            {
                return(desc);
            }
            throw new Exception("Asset '{0}' doesn't exist", path);
        }
コード例 #4
0
ファイル: PackedAssetBundle.cs プロジェクト: x5f3759df/Citrus
        public override void DeleteFile(string path)
        {
            OnModifying?.Invoke();
            path = AssetPath.CorrectSlashes(path);
            var desc = GetDescriptor(path);

            index.Remove(path);
            trash.Add(desc);
            wasModified = true;
        }
コード例 #5
0
ファイル: PackedAssetBundle.cs プロジェクト: x5f3759df/Citrus
 public AssetStream(PackedAssetBundle bundle, string path)
 {
     this.bundle = bundle;
     if (!bundle.index.TryGetValue(AssetPath.CorrectSlashes(path), out descriptor))
     {
         throw new Exception("Can't open asset: {0}", path);
     }
     stream = bundle.AllocStream();
     Seek(0, SeekOrigin.Begin);
 }
コード例 #6
0
        private string GetCurrentSerializationDirectory()
        {
            var path = Path.GetDirectoryName(pathStack.Peek());

            if (!string.IsNullOrEmpty(path))
            {
                path = AssetPath.CorrectSlashes(path);
            }
            return(path);
        }
コード例 #7
0
ファイル: PackedAssetBundle.cs プロジェクト: x5f3759df/Citrus
        public override void ImportFile(string path, Stream stream, int reserve, string sourceExtension, DateTime time, AssetAttributes attributes, byte[] cookingRulesSHA1)
        {
            OnModifying?.Invoke();
            AssetDescriptor d;

            if ((attributes & AssetAttributes.Zipped) != 0)
            {
                stream = CompressAssetStream(stream, attributes);
            }
            bool reuseExistingDescriptor = index.TryGetValue(AssetPath.CorrectSlashes(path), out d) &&
                                           (d.AllocatedSize >= stream.Length) &&
                                           (d.AllocatedSize <= stream.Length + reserve);

            if (reuseExistingDescriptor)
            {
                d.Length           = (int)stream.Length;
                d.ModificationTime = time;
                d.CookingRulesSHA1 = cookingRulesSHA1;
                d.Attributes       = attributes;
                d.SourceExtension  = sourceExtension;
                index[AssetPath.CorrectSlashes(path)] = d;
                this.stream.Seek(d.Offset, SeekOrigin.Begin);
                stream.CopyTo(this.stream);
                reserve = d.AllocatedSize - (int)stream.Length;
                if (reserve > 0)
                {
                    byte[] zeroBytes = new byte[reserve];
                    this.stream.Write(zeroBytes, 0, zeroBytes.Length);
                }
            }
            else
            {
                if (FileExists(path))
                {
                    DeleteFile(path);
                }
                d = new AssetDescriptor();
                d.ModificationTime = time;
                d.CookingRulesSHA1 = cookingRulesSHA1;
                d.Length           = (int)stream.Length;
                d.Offset           = indexOffset;
                d.AllocatedSize    = d.Length + reserve;
                d.Attributes       = attributes;
                d.SourceExtension  = sourceExtension;
                index[AssetPath.CorrectSlashes(path)] = d;
                indexOffset += d.AllocatedSize;
                this.stream.Seek(d.Offset, SeekOrigin.Begin);
                stream.CopyTo(this.stream);
                byte[] zeroBytes = new byte[reserve];
                this.stream.Write(zeroBytes, 0, zeroBytes.Length);
                this.stream.Flush();
            }
            wasModified = true;
        }
コード例 #8
0
ファイル: PackedAssetBundle.cs プロジェクト: x5f3759df/Citrus
 public override bool FileExists(string path)
 {
     return(index.ContainsKey(AssetPath.CorrectSlashes(path)));
 }
コード例 #9
0
        public override void SetAttributes(string path, AssetAttributes attributes)
        {
            var desc = GetDescriptor(path);

            index[AssetPath.CorrectSlashes(path)] = desc;
        }
コード例 #10
0
ファイル: Model3DAttachment.cs プロジェクト: klenin/Citrus
        private static string FixPath(string modelPath, string path)
        {
            var baseDir = Path.GetDirectoryName(modelPath);

            return(AssetPath.CorrectSlashes(Path.Combine(AssetPath.CorrectSlashes(baseDir), AssetPath.CorrectSlashes(path))));
        }
コード例 #11
0
ファイル: Model3DAttachment.cs プロジェクト: klenin/Citrus
        public Model3DAttachment Parse(string modelPath, bool useBundle = true)
        {
            modelPath = AssetPath.CorrectSlashes(
                Path.Combine(Path.GetDirectoryName(modelPath) ?? "",
                             Path.GetFileNameWithoutExtension(AssetPath.CorrectSlashes(modelPath) ?? "")
                             ));
            var attachmentPath = modelPath + Model3DAttachment.FileExtension;

            try {
                ModelAttachmentFormat modelAttachmentFormat;
                if (useBundle)
                {
                    if (!AssetBundle.Current.FileExists(attachmentPath))
                    {
                        return(null);
                    }
                    modelAttachmentFormat = Serialization.ReadObject <ModelAttachmentFormat>(attachmentPath);
                }
                else
                {
                    if (!File.Exists(attachmentPath))
                    {
                        return(null);
                    }
                    modelAttachmentFormat = Serialization.ReadObjectFromFile <ModelAttachmentFormat>(attachmentPath);
                }

                var attachment = new Model3DAttachment {
                    ScaleFactor = modelAttachmentFormat.ScaleFactor
                };
                if (modelAttachmentFormat.MeshOptions != null)
                {
                    foreach (var meshOptionFormat in modelAttachmentFormat.MeshOptions)
                    {
                        var meshOption = new Model3DAttachment.MeshOption()
                        {
                            Id            = meshOptionFormat.Key,
                            HitTestTarget = meshOptionFormat.Value.HitTestTarget
                        };
                        if (!string.IsNullOrEmpty(meshOptionFormat.Value.CullMode))
                        {
                            switch (meshOptionFormat.Value.CullMode)
                            {
                            case "None":
                                meshOption.CullMode = CullMode.None;
                                break;

                            case "CullClockwise":
                                meshOption.CullMode = CullMode.CullClockwise;
                                break;

                            case "CullCounterClockwise":
                                meshOption.CullMode = CullMode.CullCounterClockwise;
                                break;
                            }
                        }
                        attachment.MeshOptions.Add(meshOption);
                    }
                }

                if (modelAttachmentFormat.Animations != null)
                {
                    foreach (var animationFormat in modelAttachmentFormat.Animations)
                    {
                        var animation = new Model3DAttachment.Animation {
                            Name = animationFormat.Key,
                        };

                        if (animationFormat.Value.Markers != null)
                        {
                            foreach (var markerFormat in animationFormat.Value.Markers)
                            {
                                var markerData = new Model3DAttachment.MarkerData {
                                    Marker = new Marker {
                                        Id    = markerFormat.Key,
                                        Frame = FixFrame(markerFormat.Value.Frame)
                                    }
                                };
                                if (!string.IsNullOrEmpty(markerFormat.Value.Action))
                                {
                                    switch (markerFormat.Value.Action)
                                    {
                                    case "Start":
                                        markerData.Marker.Action = MarkerAction.Play;
                                        break;

                                    case "Stop":
                                        markerData.Marker.Action = MarkerAction.Stop;
                                        break;

                                    case "Jump":
                                        markerData.Marker.Action = MarkerAction.Jump;
                                        markerData.Marker.JumpTo = markerFormat.Value.JumpTarget;
                                        break;
                                    }
                                }
                                if (markerFormat.Value.Blending != null)
                                {
                                    markerData.Blending = new BlendingOption((int)markerFormat.Value.Blending);
                                }
                                if (markerFormat.Value.SourceMarkersBlending != null)
                                {
                                    foreach (var elem in markerFormat.Value.SourceMarkersBlending)
                                    {
                                        animation.MarkersBlendings.Add(new Model3DAttachment.MarkerBlendingData {
                                            DestMarkerId   = markerFormat.Key,
                                            SourceMarkerId = elem.Key,
                                            Blending       = new BlendingOption(elem.Value),
                                        });
                                    }
                                }

                                animation.Markers.Add(markerData);
                            }
                        }

                        if (animationFormat.Value.Blending != null)
                        {
                            animation.Blending = new BlendingOption((int)animationFormat.Value.Blending);
                        }

                        if (animationFormat.Value.Nodes != null)
                        {
                            animation.Nodes = new ObservableCollection <Model3DAttachment.NodeData>(
                                animationFormat.Value.Nodes.Select(n => new Model3DAttachment.NodeData {
                                Id = n
                            }));
                        }

                        if (animationFormat.Value.IgnoredNodes != null && animationFormat.Value.IgnoredNodes.Count > 0)
                        {
                            if (animation.Nodes.Count > 0)
                            {
                                throw new Exception("Conflict between 'Nodes' and 'IgnoredNodes' in animation '{0}", animation.Name);
                            }
                            animation.IgnoredNodes = new ObservableCollection <Model3DAttachment.NodeData>(
                                animationFormat.Value.IgnoredNodes.Select(n => new Model3DAttachment.NodeData {
                                Id = n
                            }));
                        }

                        attachment.Animations.Add(animation);
                    }
                }

                if (modelAttachmentFormat.MaterialEffects != null)
                {
                    foreach (var materialEffectFormat in modelAttachmentFormat.MaterialEffects)
                    {
                        var materialEffect = new Model3DAttachment.MaterialEffect()
                        {
                            Name         = materialEffectFormat.Key,
                            MaterialName = materialEffectFormat.Value.MaterialName,
                            Path         = FixPath(modelPath, materialEffectFormat.Value.Path)
                        };
                        if (materialEffectFormat.Value.Blending != null)
                        {
                            materialEffect.Blending = new BlendingOption((int)materialEffectFormat.Value.Blending);
                        }
                        attachment.MaterialEffects.Add(materialEffect);
                    }
                }

                return(attachment);
            } catch (System.Exception e) {
                throw new System.Exception(modelPath + ": " + e.Message, e);
            }
        }