示例#1
0
        static void Main(string[] args)
        {
            var         lol         = new AssemblyCreator("testAssembly");
            EnumCreator enumCreator = lol.CreateEnum("lol");

            enumCreator.AddEntry("lol", 1);
            enumCreator.Compile();
            TypeCreator             typeCreator      = lol.CreateClass("lol2");
            GenericParameterCreator genericParameter = typeCreator.SetGenericParameter("bon")[0];

            typeCreator.AddConstructor(MethodAttributes.Public, new List <Metadata>()
            {
                genericParameter
            });
            typeCreator.AddField("lol", genericParameter, FieldAttributes.Public);
            MethodCreator methodCreator = typeCreator.AddMethod("hey", MethodAttributes.Public, CallingConventions.HasThis);

            methodCreator.SetParameters(genericParameter);
            methodCreator.SetReturnType(genericParameter);
            methodCreator.ConfigureParameter(1, ParameterAttributes.None, "salut");
            typeCreator.AddProperty("salut", genericParameter, PropertyAttributes.HasDefault);
            Type   type1 = typeCreator.Compile();
            object test  = Activator.CreateInstance(type1.MakeGenericType(typeof(int)), Enum.ToObject(enumCreator, 1));

            return;
        }
示例#2
0
    public static void CreateEffectType(EffectsTable effectTable)
    {
        List <string> names = new List <string>();

        foreach (var effect in effectTable.gameEffectList)
        {
            names.Add(effect.name);
        }

        //Enum作成
        EnumCreator.Create(
            enumName: effectEnumName,          //enumの名前
            itemNameList: names,               //enumの項目
                                               //作成したファイルのパスをAssetsから拡張子まで指定
            exportPath: "Assets/GameEffectManager/Scripts/" + effectEnumName + ".cs"
            );
    }
    private void OnGUI()
    {
        using (new EditorGUILayout.VerticalScope())
        {
            using (new EditorGUILayout.HorizontalScope())
            {
                if (GUILayout.Button("サウンドデータを読み込み"))
                {
                    audios = Resources.LoadAll <AudioClip>("");
                }
            }

            if (audios == null)
            {
                return;
            }
            using (new EditorGUILayout.VerticalScope(GUI.skin.box))
            {
                using (new EditorGUILayout.HorizontalScope())
                {
                    GUILayout.Label("Enum名");
                    GUILayout.FlexibleSpace();
                    GUILayout.Label("サウンドデータ");
                }

                foreach (var audio in audios)
                {
                    using (new EditorGUILayout.HorizontalScope())
                    {
                        if (audio != null)
                        {
                            GUILayout.Label(audio.name);
                        }
                        else
                        {
                            GUI.color = Color.red; GUILayout.Label("Missing");
                        }
                        GUILayout.FlexibleSpace();
                        using (new EditorGUI.DisabledGroupScope(true))
                        {
                            EditorGUILayout.ObjectField(audio, typeof(AudioClip));
                        }
                    }
                }
            }

            GUI.color = Color.white;

            using (new EditorGUILayout.VerticalScope(GUI.skin.box))
            {
                GUILayout.Label("Enumクラスの出力先");
                using (new EditorGUILayout.HorizontalScope())
                {
                    GUILayout.Label(enumFileSavePath);
                    if (GUILayout.Button("変更", GUILayout.Width(50)))
                    {
                        string path = EditorUtility.SaveFilePanel("Enumクラスの出力先", "Assets", "SoundEnum", "cs");
                        if (path.Length != 0)
                        {
                            enumFileSavePath = ToRelativePath(path);
                        }
                    }
                }
            }

            using (new EditorGUILayout.VerticalScope(GUI.skin.box))
            {
                GUILayout.Label("アセットデータの出力先");
                using (new EditorGUILayout.HorizontalScope())
                {
                    GUILayout.Label(assetDataSavePath);
                    if (GUILayout.Button("変更", GUILayout.Width(50)))
                    {
                        string path = EditorUtility.SaveFilePanel("アセットデータの出力先", "Assets", "SoundData", "asset");
                        if (path.Length != 0)
                        {
                            assetDataSavePath = ToRelativePath(path);
                        }
                    }
                }
            }

            if (enumFileSavePath.Length != 0 && assetDataSavePath.Length != 0)
            {
                if (GUILayout.Button("データ作成"))
                {
                    enumElements.Clear();

                    foreach (var audio in audios)
                    {
                        enumElements.Add(audio.name);
                    }

                    string[] split    = enumFileSavePath.Split('/');
                    string   enumName = split[split.Length - 1].Substring(0, split[split.Length - 1].IndexOf(".cs"));
                    EnumCreator.Create(enumElements.ToArray(), enumFileSavePath, enumName);

                    AssetDatabase.CreateAsset(new SoundAssetsScript(audios), assetDataSavePath);

                    AssetDatabase.Refresh(ImportAssetOptions.ImportRecursive);
                }
            }
        }
    }