当前位置: 首页>>代码示例>>C#>>正文


C# NamedObjectSave.GetCustomVariable方法代码示例

本文整理汇总了C#中FlatRedBall.Glue.SaveClasses.NamedObjectSave.GetCustomVariable方法的典型用法代码示例。如果您正苦于以下问题:C# NamedObjectSave.GetCustomVariable方法的具体用法?C# NamedObjectSave.GetCustomVariable怎么用?C# NamedObjectSave.GetCustomVariable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FlatRedBall.Glue.SaveClasses.NamedObjectSave的用法示例。


在下文中一共展示了NamedObjectSave.GetCustomVariable方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ReactToTextureAddressMode

        private void ReactToTextureAddressMode(NamedObjectSave namedObjectSave, object oldValue)
        {
            bool isSprite = namedObjectSave.SourceType == SourceType.FlatRedBallType && namedObjectSave.SourceClassType == "Sprite";
            if(isSprite)
            {
                var addressModeVariable = namedObjectSave.GetCustomVariable("TextureAddressMode");

                if (addressModeVariable != null && addressModeVariable.Value != null && 
                    ((TextureAddressMode)(addressModeVariable.Value) == TextureAddressMode.Wrap || (TextureAddressMode)(addressModeVariable.Value) == TextureAddressMode.Mirror))
                {
                    // How big is the texture?
                    var textureVariable = namedObjectSave.GetCustomVariable("Texture");

                    if (textureVariable != null && textureVariable.Value != null)
                    {
                        string value = textureVariable.Value as string;

                        var rfs = namedObjectSave.GetContainer().GetReferencedFileSaveByInstanceName(value);

                        if (rfs != null)
                        {

                            var width = ImageHeader.GetDimensions(
                                    ProjectManager.MakeAbsolute(rfs.Name)).Width;
                            var height = ImageHeader.GetDimensions(
                                    ProjectManager.MakeAbsolute(rfs.Name)).Height;

                            string whatIsWrong = null;

                            if (FlatRedBall.Math.MathFunctions.IsPowerOfTwo(width) == false)
                            {
                                whatIsWrong = "This Sprite's texture (" + textureVariable.Value + ") has a width of " + 
                                    width + " but it should be a power of two to use " + addressModeVariable.Value + " TextureAddressMode";
                            }


                            if (FlatRedBall.Math.MathFunctions.IsPowerOfTwo(height) == false)
                            {
                                whatIsWrong = "This Sprite's texture (" + textureVariable.Value + ") has a height of " +
                                    height + " but it should be a power of two to use " + addressModeVariable.Value + " TextureAddressMode";
                            }

                            if(!string.IsNullOrEmpty(whatIsWrong))
                            {
                                whatIsWrong += "\nWhat would you like to do?";

                                MultiButtonMessageBox mbmb = new MultiButtonMessageBox();
                                mbmb.MessageText = whatIsWrong;
                                mbmb.AddButton("Undo the change", DialogResult.Cancel);
                                mbmb.AddButton("Keep the change (May cause runtime crashes)", DialogResult.Yes);

                                var result = mbmb.ShowDialog();

                                if(result == DialogResult.Cancel)
                                {
                                    addressModeVariable.Value = oldValue;
                                }

                            }
                        }
                    }
                }
            }
        }
开发者ID:vchelaru,项目名称:FlatRedBall,代码行数:64,代码来源:NamedObjectSetVariableLogic.cs

示例2: ReactToAnimationChainSet

        private void ReactToAnimationChainSet(NamedObjectSave namedObjectSave, object oldValue)
        {
            AvailableAnimationChainsStringConverter aacsc = new AvailableAnimationChainsStringConverter(
                GlueState.Self.CurrentElement, namedObjectSave);

            var customVariable = namedObjectSave.GetCustomVariable("CurrentChainName");

            string currentChain = null;

            if (customVariable != null)
            {
                currentChain = customVariable.Value as string;
            }

            if (!aacsc.AvailableChains.Contains(currentChain))
            {
                if (aacsc.AvailableChains.Length == 0)
                {
                    namedObjectSave.SetPropertyValue("CurrentChainName", null);

                }
                else
                {
                    namedObjectSave.SetPropertyValue("CurrentChainName", aacsc.AvailableChains[0]);
                }
            }
        }
开发者ID:gitter-badger,项目名称:FlatRedBall,代码行数:27,代码来源:NamedObjectSetVariableLogic.cs

示例3: ReactToFontSet

        private void ReactToFontSet(NamedObjectSave namedObjectSave, object oldValue)
        {
            string value = namedObjectSave.GetCustomVariable("Font").Value as string;

            if (!string.IsNullOrEmpty(value))
            {
                IElement element = EditorLogic.CurrentElement;

                ReferencedFileSave referencedFileSave = element.GetReferencedFileSaveByInstanceNameRecursively(value);


                if (referencedFileSave != null)
                {
                    string file = referencedFileSave.GetRelativePath();
                    file = ProjectManager.MakeAbsolute(file, true);

                    string contents = FileManager.FromFileText(file);

                    int size =
                        StringFunctions.GetIntAfter(
                        "size=", contents);

                    float lineHeightInPixels =
                        StringFunctions.GetIntAfter(
                        "lineHeight=", contents);

                    lineHeightInPixels /= 2.0f;

                    namedObjectSave.SetPropertyValue("Scale", (float)lineHeightInPixels);
                    namedObjectSave.SetPropertyValue("Spacing", (float)lineHeightInPixels);
                    namedObjectSave.SetPropertyValue("NewLineDistance", (float)(lineHeightInPixels * 1.5f));

                }
            }
        }
开发者ID:vchelaru,项目名称:FlatRedBall,代码行数:35,代码来源:NamedObjectSetVariableLogic.cs

示例4: SetVariableToDefault

        public static void SetVariableToDefault(NamedObjectSave currentNamedObject, string variableToSet)
        {
            // July 13, 2014
            // This used to simply set the value to null, but why don't we remove it if it exists?
            // This way if an error is introduced by some plugin that sets the type to something invalid
            // the user can still remove it through this option and recover the type later.
            //currentNamedObject.SetPropertyValue(variableToSet, null);
            currentNamedObject.InstructionSaves.RemoveAll(item => item.Member == variableToSet);

            if (currentNamedObject.GetCustomVariable(variableToSet) != null)
            {
                // See if this variable is tunneled into in this element.
                // If so, set that value too.
                CustomVariableInNamedObject cvino = currentNamedObject.GetCustomVariable(variableToSet);
                object value = cvino.Value;

                foreach (CustomVariable customVariable in EditorLogic.CurrentElement.CustomVariables)
                {
                    if (customVariable.SourceObject == currentNamedObject.InstanceName &&
                        customVariable.SourceObjectProperty == variableToSet)
                    {
                        customVariable.DefaultValue = value;
                        break;
                    }
                }

                GlueCommands.Self.RefreshCommands.RefreshPropertyGrid();
            }
        }
开发者ID:vchelaru,项目名称:FlatRedBall,代码行数:29,代码来源:PropertyGridRightClickHelper.cs


注:本文中的FlatRedBall.Glue.SaveClasses.NamedObjectSave.GetCustomVariable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。