コード例 #1
0
            void AssetCreator()
            {
                selectedCreatorTool = GUILayout.Toolbar(selectedCreatorTool, creatorTools);
                switch (selectedCreatorTool)
                {
                case 0:
                    GUILayout.Label("Creation system for new ammunition types", EditorStyles.boldLabel);
                    ammoName       = EditorGUILayout.TextField("Ammunition name", ammoName);
                    projectileType = (ProjectileType)EditorGUILayout.EnumPopup("Projectile type", projectileType);

                    if (GUILayout.Button("Add"))
                    {
                        db.AddAmmoType(ammoName, projectileType);
                        Undo.RecordObject(db, "Add ammo");
                        EditorUtility.SetDirty(db);
                    }
                    break;

                case 1:
                    GUILayout.Label("Creation system for new weapons", EditorStyles.boldLabel);
                    newWeapon = (GameObject)EditorGUILayout.ObjectField(new GUIContent("Weapon", "Weapon prefab that you want to add to the database"), newWeapon, typeof(GameObject), true);
                    if (GUILayout.Button("Add"))
                    {
                        if (newWeapon != null)
                        {
                            if (newWeapon.GetComponent <Weapon>() != null)
                            {
                                db.AddWeapon(newWeapon);
                                newWeapon = null;
                                Undo.RecordObject(db, "Add weapon");
                                EditorUtility.SetDirty(db);
                            }
                            else
                            {
                                EditorUtility.DisplayDialog("Wrong prefab!", "Selected prefab does not contain Weapon script!", "Ok");
                            }
                        }
                    }
                    break;
                }
            }