コード例 #1
0
 public IFont this[string name]
 {
     get
     {
         if (FontNameChanger != null)
         {
             name = FontNameChanger(name);
         }
         if (string.IsNullOrEmpty(name))
         {
             name = DefaultFontName;
         }
         IFont font;
         if (fonts.TryGetValue(name, out font))
         {
             return(font);
         }
         string[] fontExtensions = { ".tft", ".fnt" };
         foreach (var e in fontExtensions)
         {
             string path = DefaultFontDirectory + name + e;
             if (!AssetBundle.Initialized || !AssetBundle.Current.FileExists(path))
             {
                 continue;
             }
             font        = Serialization.ReadObject <Font>(path);
             fonts[name] = font;
             return(font);
         }
         return(Null);
     }
 }
コード例 #2
0
ファイル: Texture2D.cs プロジェクト: aologos/Citrus
        private void LoadTextureParams(string path)
        {
            var textureParamsPath = path + ".texture";

            if (AssetBundle.Current.FileExists(textureParamsPath))
            {
                using (var stream = AssetBundle.Current.OpenFile(textureParamsPath)) {
                    TextureParams = Serialization.ReadObject <TextureParams>(textureParamsPath, stream);
                }
            }
            else
            {
                TextureParams = TextureParams.Default;
            }
        }
コード例 #3
0
        public void LoadTextureParams(string path)
        {
            var textureParamsPath = Path.ChangeExtension(path, ".texture");

            if (AssetBundle.Current.FileExists(textureParamsPath))
            {
                using (var stream = AssetBundle.Current.OpenFile(textureParamsPath)) {
                    TextureParams = Serialization.ReadObject <TextureParams>(textureParamsPath, stream);
                }
            }
            else
            {
                TextureParams = TextureParams.Default;
            }
        }
コード例 #4
0
ファイル: Node.cs プロジェクト: klenin/Citrus
        public static Node CreateFromAssetBundle(string path, Node instance = null)
        {
            if (scenesBeingLoaded == null)
            {
                scenesBeingLoaded = new HashSet <string>();
            }
            var fullPath = ResolveScenePath(path);

            if (fullPath == null)
            {
                throw new Exception($"Scene '{path}' not found in current asset bundle");
            }
            if (scenesBeingLoaded.Contains(fullPath))
            {
                throw new Exception($"Cyclic scenes dependency was detected: {fullPath}");
            }
            scenesBeingLoaded.Add(fullPath);
            try {
                using (Stream stream = AssetBundle.Current.OpenFileLocalized(fullPath)) {
                    instance = Serialization.ReadObject <Node>(fullPath, stream, instance);
                }
                instance.LoadExternalScenes();
                if (!Application.IsTangerine)
                {
                    instance.Tag = fullPath;
                }
            } finally {
                scenesBeingLoaded.Remove(fullPath);
            }
            if (instance is Model3D)
            {
                var attachment = new Model3DAttachmentParser().Parse(path);
                attachment?.Apply((Model3D)instance);
            }
            return(instance);
        }
コード例 #5
0
ファイル: TextureAtlasElement.cs プロジェクト: aologos/Citrus
 public static Params ReadFromBundle(string path)
 {
     return(Serialization.ReadObject <Params>(path));
 }
コード例 #6
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);
            }
        }