コード例 #1
0
        // Use this for initialization
        void Start()
        {
            EffectConfig config = new EffectConfig();

            config.Id        = EnumUtils.EnumToInt(EffectConfigName.THIRD_PERSON);
            config.Directory = "CameraFollowDemo/ThirdPersonCharacter/Prefabs";
            config.Names     = new List <string>()
            {
                "ThirdPersonController.prefab"
            };
            config.Delay         = false;
            config.StrategyType  = StrategyType.FixedForce;
            config.MaxSize       = 4;
            config.MinSize       = 1;
            config.LifeTime      = 2000;
            config.GoName        = "Test";
            config.Reset         = true;
            config.BehaviourName = typeof(EffectBehaviour).FullName;
            config.Mask          = EnumUtils.EnumToInt(ResourceCacheMask.Testing);
            config.Level         = DeviceLevel.High;
            config.IsTimerOn     = true;

            bool   test = LuaTable.PackLuaTable(config, out Lua);
            string v1   = Lua.ToString();

            DebugUtils.Info("LuaTableTest", v1);

            //Lua.Clear();
            //LuaTable.ParseLuaTable(v1, out Lua);
            //string v2 = Lua.ToString();
            //DebugUtils.Info("LuaTableTest", v2);
        }
コード例 #2
0
        private void Save()
        {
            int id = 0;
            List <EffectConfig> configs = new List <EffectConfig>();

            EffectConfig config = new EffectConfig();

            config.Id        = EnumUtils.EnumToInt(EffectConfigName.THIRD_PERSON);
            config.Directory = "CameraFollowDemo/ThirdPersonCharacter/Prefabs";
            config.Names     = new List <string>()
            {
                "ThirdPersonController.prefab"
            };
            config.Delay         = false;
            config.StrategyType  = StrategyType.FixedForce;
            config.MaxSize       = 4;
            config.MinSize       = 1;
            config.LifeTime      = 2000;
            config.GoName        = "Test";
            config.Reset         = true;
            config.BehaviourName = typeof(EffectBehaviour).FullName;
            config.Mask          = EnumUtils.EnumToInt(ResourceCacheMask.Testing);
            config.Level         = DeviceLevel.High;
            config.IsTimerOn     = true;
            configs.Add(config);

            EffectConfig.CheckDuplicatedDatas("ResourceConfig", configs);
            SortById <EffectConfig> inst = new SortById <EffectConfig>();

            configs.Sort(inst);
            XmlFileUtils.SaveXML(string.Format("{0}/{1}/{2}{3}", Application.dataPath, XmlFileNameDefine.Directory, XmlFileNameDefine.ResourceCache, XmlFileNameDefine.SuffixFlag), configs);
        }
コード例 #3
0
 private void OnGUI()
 {
     if (GUILayout.Button("Save"))
     {
         Save();
     }
     if (!IsInitialized && GUILayout.Button("Initialize"))
     {
         XmlDataLoader.Instance.InitAndLoad(XmlFileNameDefine.Namespace, XmlFileNameDefine.SuffixFlag);
         DebugUtils.Info("EffectConfig", "DataPath " + Application.dataPath + " Count: " + EffectConfig.DataMap.Count);
         EffectPools.Initialize(ResourceCacheMask.Testing, EffectConfig.DataMap);
         IsInitialized = true;
     }
     if (IsInitialized)
     {
         if (GUILayout.Button("Play"))
         {
             int poolId = EnumUtils.EnumToInt(EffectConfigName.THIRD_PERSON);
             ResourceCacheBehaviourParam param = new ResourceCacheBehaviourParam();
             EffectPools.Play(poolId, 5000, ResourceCacheBindParent.WorldEffectBind, param);
         }
     }
 }
コード例 #4
0
        // 可以扩展成递归模式,多个类型嵌套的
        public static void SaveXML <T>(string path, List <T> data)
        {
            string attrName = typeof(T).Name;
            var    root     = new SecurityElement(attrName + "s");

            var props   = typeof(T).GetProperties();
            var keyProp = props[0];

            foreach (var prop in props)
            {
                if (XmlData.mKeyFieldName == prop.Name)
                {
                    keyProp = prop;
                    break;
                }
            }
            foreach (var item in data)
            {
                // 下面在LoadXML时,key id必须先加载,所以这里第一个创建 id
                var    xml = new SecurityElement(attrName);
                object obj = keyProp.GetGetMethod().Invoke(item, null);
                xml.AddChild(new SecurityElement(keyProp.Name, obj.ToString()));
                foreach (var prop in props)
                {
                    if (prop == keyProp)
                    {
                        continue;
                    }
                    var    type   = prop.PropertyType;
                    string result = string.Empty;
                    obj = prop.GetGetMethod().Invoke(item, null);
                    if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Dictionary <,>))
                    {
                        object ret = typeof(XmlFileUtils).GetMethod("PackMap")
                                     .MakeGenericMethod(type.GetGenericArguments())
                                     .Invoke(null, new object[] { obj, KEY_VALUE_SPRITER, MAP_SPRITER });
                        result = ret != null?ret.ToString() : null;
                    }
                    else if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List <>))
                    {
                        object ret = typeof(XmlFileUtils).GetMethod("PackList")
                                     .MakeGenericMethod(type.GetGenericArguments())
                                     .Invoke(null, new object[] { obj, LIST_SPRITER });
                        result = ret != null?ret.ToString() : null;
                    }
                    else if (type.BaseType == typeof(Enum))
                    {
                        Type underType = Enum.GetUnderlyingType(type);
                        if (underType == typeof(int))
                        {
                            obj = EnumUtils.EnumToInt(obj) + "";
                        }
                        result = obj.ToString();
                    }
                    else
                    {
                        result = obj != null?obj.ToString() : null;
                    }
                    if (result != null)
                    {
                        xml.AddChild(new SecurityElement(prop.Name, result));
                    }
                }
                root.AddChild(xml);
            }
            // 格式化
            XElement element = XElement.Parse(root.ToString());
            string   output  = path;

            if (!output.EndsWith(".xml"))
            {
                output = output + ".xml";
            }
            SaveText(output, element.ToString());
        }