예제 #1
0
파일: Core.cs 프로젝트: ooame0825/Effekseer
        /// <summary>
        /// New
        /// </summary>
        public static void New()
        {
            if (OnBeforeNew != null)
            {
                OnBeforeNew(null, null);
            }

            StartFrame = 0;
            EndFrame   = 120;
            IsLoop     = true;

            SelectedNode = null;
            Command.CommandManager.Clear();
            Root           = new Data.NodeRoot();
            effectBehavior = new Data.EffectBehaviorValues();
            culling        = new Data.EffectCullingValues();
            globalValues   = new Data.GlobalValues();

            // Add a root node
            Root.AddChild();
            Command.CommandManager.Clear();
            FullPath  = string.Empty;
            IsChanged = false;

            if (OnAfterNew != null)
            {
                OnAfterNew(null, null);
            }
        }
예제 #2
0
파일: Core.cs 프로젝트: yczxf/Effekseer
        /// <summary>
        /// New
        /// </summary>
        public static void New()
        {
            if (OnBeforeNew != null)
            {
                OnBeforeNew(null, null);
            }

            StartFrame = 0;
            EndFrame   = 120;
            IsLoop     = true;

            SelectedNode = null;
            Command.CommandManager.Clear();
            Root = new Data.NodeRoot();

            // Adhoc code
            effectBehavior.Reset();
            culling      = new Data.EffectCullingValues();
            globalValues = new Data.GlobalValues();

            if (recording.RecordingStorageTarget.Value == Data.RecordingStorageTargetTyoe.Local)
            {
                recording = new Data.RecordingValues();
            }

            dynamic_ = new Data.DynamicValues();

            // Add a root node
            Root.AddChild();
            Command.CommandManager.Clear();
            FullPath  = string.Empty;
            IsChanged = false;

            // Select child
            //SelectedNode = Root.Children[0];

            if (OnAfterNew != null)
            {
                OnAfterNew(null, null);
            }
        }
예제 #3
0
파일: Core.cs 프로젝트: ooame0825/Effekseer
        public static bool LoadFrom(string path)
        {
            path = System.IO.Path.GetFullPath(path);

            if (!System.IO.File.Exists(path))
            {
                return(false);
            }
            SelectedNode = null;

            FullPath = path;

            var doc = new System.Xml.XmlDocument();

            doc.Load(path);

            if (doc.ChildNodes.Count != 2)
            {
                return(false);
            }
            if (doc.ChildNodes[1].Name != "EffekseerProject")
            {
                return(false);
            }

            if (OnBeforeLoad != null)
            {
                OnBeforeLoad(null, null);
            }

            uint toolVersion = 0;

            if (doc["EffekseerProject"]["ToolVersion"] != null)
            {
                var fileVersion    = doc["EffekseerProject"]["ToolVersion"].GetText();
                var currentVersion = Core.Version;

                toolVersion = ParseVersion(fileVersion);

                if (toolVersion > ParseVersion(currentVersion))
                {
                    switch (Language)
                    {
                    case Effekseer.Language.English:
                        throw new Exception("Version Error : \nThe file is created with a newer version of the tool.\nPlease use the latest version of the tool.");
                        break;

                    case Effekseer.Language.Japanese:
                        throw new Exception("Version Error : \nファイルがより新しいバージョンのツールで作成されています。\n最新バージョンのツールを使用してください。");
                        break;
                    }
                }
            }

            // For compatibility
            {
                // Stripe→Ribbon
                var innerText = doc.InnerXml;
                innerText = innerText.Replace("<Stripe>", "<Ribbon>").Replace("</Stripe>", "</Ribbon>");
                doc       = new System.Xml.XmlDocument();
                doc.LoadXml(innerText);
            }

            // For compatibility
            {
                // GenerationTime
                // GenerationTimeOffset

                Action <System.Xml.XmlNode> replace = null;
                replace = (node) =>
                {
                    if ((node.Name == "GenerationTime" || node.Name == "GenerationTimeOffset") &&
                        node.ChildNodes.Count > 0 &&
                        node.ChildNodes[0] is System.Xml.XmlText)
                    {
                        var name  = node.Name;
                        var value = node.ChildNodes[0].Value;

                        node.RemoveAll();

                        var center = doc.CreateElement("Center");
                        var max    = doc.CreateElement("Max");
                        var min    = doc.CreateElement("Min");

                        center.AppendChild(doc.CreateTextNode(value));
                        max.AppendChild(doc.CreateTextNode(value));
                        min.AppendChild(doc.CreateTextNode(value));

                        node.AppendChild(center);
                        node.AppendChild(max);
                        node.AppendChild(min);
                    }
                    else
                    {
                        for (int i = 0; i < node.ChildNodes.Count; i++)
                        {
                            replace(node.ChildNodes[i]);
                        }
                    }
                };

                replace(doc);
            }

            var root = doc["EffekseerProject"]["Root"];

            if (root == null)
            {
                return(false);
            }

            var behaviorElement = doc["EffekseerProject"]["Behavior"];

            if (behaviorElement != null)
            {
                var o = effectBehavior as object;
                Data.IO.LoadObjectFromElement(behaviorElement as System.Xml.XmlElement, ref o, false);
            }
            else
            {
                effectBehavior = new Data.EffectBehaviorValues();
            }

            var cullingElement = doc["EffekseerProject"]["Culling"];

            if (cullingElement != null)
            {
                var o = culling as object;
                Data.IO.LoadObjectFromElement(cullingElement as System.Xml.XmlElement, ref o, false);
            }
            else
            {
                culling = new Data.EffectCullingValues();
            }

            var globalElement = doc["EffekseerProject"]["Global"];

            if (globalElement != null)
            {
                var o = globalValues as object;
                Data.IO.LoadObjectFromElement(globalElement as System.Xml.XmlElement, ref o, false);
            }
            else
            {
                globalValues = new Data.GlobalValues();
            }

            StartFrame = 0;
            EndFrame   = doc["EffekseerProject"]["EndFrame"].GetTextAsInt();
            StartFrame = doc["EffekseerProject"]["StartFrame"].GetTextAsInt();
            IsLoop     = bool.Parse(doc["EffekseerProject"]["IsLoop"].GetText());
            IsLoop     = true;

            int version = 0;

            if (doc["EffekseerProject"]["Version"] != null)
            {
                version = doc["EffekseerProject"]["Version"].GetTextAsInt();
            }

            var root_node = new Data.NodeRoot() as object;

            Data.IO.LoadObjectFromElement(root as System.Xml.XmlElement, ref root_node, false);

            // For compatibility
            if (version < 3)
            {
                Action <Data.NodeBase> convert = null;
                convert = (n) =>
                {
                    var n_ = n as Data.Node;

                    if (n_ != null)
                    {
                        if (n_.DrawingValues.Type.Value == Data.RendererValues.ParamaterType.Sprite)
                        {
                            n_.RendererCommonValues.ColorTexture.SetAbsolutePathDirectly(n_.DrawingValues.Sprite.ColorTexture.AbsolutePath);
                            n_.RendererCommonValues.AlphaBlend.SetValueDirectly(n_.DrawingValues.Sprite.AlphaBlend.Value);
                        }
                        else if (n_.DrawingValues.Type.Value == Data.RendererValues.ParamaterType.Ring)
                        {
                            n_.RendererCommonValues.ColorTexture.SetAbsolutePathDirectly(n_.DrawingValues.Ring.ColorTexture.AbsolutePath);
                            n_.RendererCommonValues.AlphaBlend.SetValueDirectly(n_.DrawingValues.Ring.AlphaBlend.Value);
                        }
                        else if (n_.DrawingValues.Type.Value == Data.RendererValues.ParamaterType.Ribbon)
                        {
                            n_.RendererCommonValues.ColorTexture.SetAbsolutePathDirectly(n_.DrawingValues.Ribbon.ColorTexture.AbsolutePath);
                            n_.RendererCommonValues.AlphaBlend.SetValueDirectly(n_.DrawingValues.Ribbon.AlphaBlend.Value);
                        }
                    }

                    for (int i = 0; i < n.Children.Count; i++)
                    {
                        convert(n.Children[i]);
                    }
                };

                convert(root_node as Data.NodeBase);
            }

            Root = root_node as Data.NodeRoot;
            Command.CommandManager.Clear();
            IsChanged = false;

            if (OnAfterLoad != null)
            {
                OnAfterLoad(null, null);
            }

            return(true);
        }