Exemple #1
0
        public void RegisterItemPoolByReflection()
        {
            Type[] itemTypes = AssemblyUtility.GetDerivedTypes(typeof(ActionItem));
            if (itemTypes == null || itemTypes.Length == 0)
            {
                return;
            }

            Dictionary <Type, Type> dataToItemTypeDic = new Dictionary <Type, Type>();

            foreach (var itemType in itemTypes)
            {
                ActionItemBindDataAttribute attr = itemType.GetCustomAttribute <ActionItemBindDataAttribute>();
                if (attr == null)
                {
                    continue;
                }

                dataToItemTypeDic.Add(attr.DataType, itemType);
            }

            foreach (var kvp in dataToItemTypeDic)
            {
                ObjectPool itemPool = new ObjectPool(() =>
                {
                    return(Activator.CreateInstance(kvp.Value));
                }, null, (actionItem) =>
                {
                    ((ActionItem)actionItem).DoReset();
                }, 0);

                RegisterItemPool(kvp.Key, itemPool);
            }
        }
Exemple #2
0
        public static void CreateItemPool(string spaceName, string outputDir, string templateFilePath)
        {
            Type[] itemTypes = AssemblyUtility.GetDerivedTypes(typeof(ActionItem));
            if (itemTypes == null || itemTypes.Length == 0)
            {
                Debug.LogError($"ActionItemPoolCreator::CreateItemPool->ActionItem is not found!");
                return;
            }

            Dictionary <Type, Type> dataToItemTypeDic = new Dictionary <Type, Type>();

            foreach (var itemType in itemTypes)
            {
                ActionItemBindDataAttribute attr = itemType.GetCustomAttribute <ActionItemBindDataAttribute>();
                if (attr == null)
                {
                    Debug.LogError($"ActionItemPoolCreator::CreateItemPool->Attribute is not found.itemType = {itemType.FullName}");
                    continue;
                }

                dataToItemTypeDic.Add(attr.DataType, itemType);
            }

            StringContextContainer context = new StringContextContainer();

            context.Add("spaceName", spaceName);
            context.Add("dataToItemTypeDic", dataToItemTypeDic);

            string templateContent = File.ReadAllText(templateFilePath);

            string outputFilePath = $"{outputDir}/ActionItemPoolRegister.cs";
            string outputContent  = TemplateEngine.Execute(context, templateContent, new string[0]);

            File.WriteAllText(outputFilePath, outputContent);
        }
Exemple #3
0
 private static void LoadAttrDrawers()
 {
     attrTypeDrawerDic = new Dictionary <Type, Type>();
     Type[] types = AssemblyUtility.GetDerivedTypes(typeof(IAttrDrawer));
     foreach (var type in types)
     {
         var attrs = type.GetCustomAttributes(typeof(CustomAttrDrawerAttribute), false);
         if (attrs != null && attrs.Length > 0)
         {
             CustomAttrDrawerAttribute attr = attrs[0] as CustomAttrDrawerAttribute;
             attrTypeDrawerDic.Add(attr.AttrType, type);
         }
     }
 }
Exemple #4
0
        public static void ShowMenu(Action <ActionData> callback)
        {
            if (actionTypeDic == null)
            {
                actionTypeDic = new Dictionary <string, Type>();

                Type[] dataTypes = AssemblyUtility.GetDerivedTypes(typeof(ActionData));
                if (dataTypes != null && dataTypes.Length > 0)
                {
                    foreach (var type in dataTypes)
                    {
                        ActionMenuAttribute attr = type.GetCustomAttribute <ActionMenuAttribute>();
                        if (attr == null)
                        {
                            continue;
                        }
                        actionTypeDic.Add($"{attr.Prefix}/{attr.Name}", type);
                    }
                }
            }
            if (actionTypeDic.Count == 0)
            {
                return;
            }

            GenericMenu menu = new GenericMenu();

            if (!string.IsNullOrEmpty(LineSetting.Setting.CopiedActionData))
            {
                ActionData data = (ActionData)JsonConvert.DeserializeObject(LineSetting.Setting.CopiedActionData, new JsonSerializerSettings()
                {
                    TypeNameHandling = TypeNameHandling.All,
                });
                menu.AddItem(new GUIContent($"Paste({data.GetType().Name})"), false, () =>
                {
                    callback.Invoke(data);
                });
                menu.AddSeparator("");
            }

            foreach (var kvp in actionTypeDic)
            {
                menu.AddItem(new GUIContent(kvp.Key), false, () =>
                {
                    callback.Invoke((ActionData)Activator.CreateInstance(kvp.Value));
                });
            }
            menu.ShowAsContext();
        }
Exemple #5
0
        public static void PackAssetBundle(AssetPackerConfig packerConfig, BundleBuildConfig buildConfig)
        {
            IAssetBundlePacker bundlePacker = null;

            Type[] bundlePackerTypes = AssemblyUtility.GetDerivedTypes(typeof(IAssetBundlePacker));
            if (bundlePackerTypes != null && bundlePackerTypes.Length > 0)
            {
                bundlePacker = (IAssetBundlePacker)Activator.CreateInstance(bundlePackerTypes[0]);
            }

            if (bundlePacker == null)
            {
                Debug.LogError("AssetPackerUtil::PackAssetBundle->DoPackAssetBundle is null.");
                return;
            }

            if (string.IsNullOrEmpty(buildConfig.bundleOutputDir))
            {
                Debug.Log("AssetPackerUtil::PackAssetBundle->bundleOutputDir is null.");
                return;
            }

            string outputDir = $"{buildConfig.bundleOutputDir}/{buildConfig.buildTarget.ToString()}/assetbundles";

            if (buildConfig.cleanupBeforeBuild && Directory.Exists(outputDir))
            {
                Directory.Delete(outputDir, true);
            }
            if (!Directory.CreateDirectory(outputDir).Exists)
            {
                Debug.LogError("AssetPackUitl::PackAssetBundle->Folder is not found. dir = " + outputDir);
                return;
            }

            AssetBundleConfig bundleConfig = bundlePacker.PackAssetBundle(packerConfig, buildConfig, outputDir);
            var    json         = JsonConvert.SerializeObject(bundleConfig, Formatting.Indented);
            string jsonFilePath = $"{outputDir}/{AssetConst.ASSET_BUNDLE_CONFIG_NAME}";

            File.WriteAllText(jsonFilePath, json);
        }
Exemple #6
0
        private void CreateMenu()
        {
            Type[] types = AssemblyUtility.GetDerivedTypes(typeof(AssetPostRuler));
            genericMenu = new GenericMenu();
            foreach (var type in types)
            {
                AssetPostRulerMenuAttribute attr = type.GetCustomAttribute <AssetPostRulerMenuAttribute>();
                if (attr != null)
                {
                    genericMenu.AddItem(new GUIContent(attr.MenuName), false, (t) =>
                    {
                        var obj  = ScriptableObject.CreateInstance((Type)t);
                        obj.name = attr.FileName;
                        AssetDatabase.AddObjectToAsset(obj, target);

                        rulerProperty.AddElement(obj);

                        EditorUtility.SetDirty(target);
                        AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(target));
                    }, type);
                }
            }
        }