public void AddAsset() { var dict = Asset.GatherAssetTypes() .Select(type => new KeyValuePair <string, Type>(type.GetCustomAttribute <AssetAttribute>().Category + ": " + type.GetCustomAttribute <AssetAttribute>().NiceName, type)); if (!dict.Any()) { MessageBox.Show("There are not asset classes. Make sure that your classes are inherited from Asset class and has attribute AssetAttribute", "Add Asset", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } Type result; if (ObjectSelector.Show(developerConsole, "Select asset type", "Add Asset", dict, out result)) { string suggestion = result.GetCustomAttribute <AssetAttribute>().Category + @"\"; var path = NameDialog.Show(developerConsole, "Enter asset name", "Add Asset", suggestion); if (path == null) { return; } var desc = (Asset)Activator.CreateInstance(result); desc.AssetPath = path; try { contentBuilder.AddAsset(desc); } catch (ContentException e) { MessageBox.Show(e.Message, "Add Asset", MessageBoxButtons.OK, MessageBoxIcon.Error); } Modified = true; developerConsole.RefreshConsole(false); //game.Reload(); } }
public void CreateAssetFromAsset() { var dict = Asset.GatherAssetTypes() .Select(type => new KeyValuePair <string, Type>(type.GetCustomAttribute <AssetAttribute>().Category + ": " + type.GetCustomAttribute <AssetAttribute>().NiceName, type)); if (!dict.Any()) { MessageBox.Show("There are not asset classes. Make sure that your classes are inherited from Asset class and has attribute AssetAttribute", "Add Asset", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } Type result; if (ObjectSelector.Show(developerConsole, "Select asset type", "Add Asset", dict, out result)) { try { var objs = developerConsole.GetSelectedObjects().Where(o => o is Asset); foreach (var obj in objs) { var asset = Activator.CreateInstance(result); if (asset is IAssetDerivable) { ((IAssetDerivable)asset).InitFromAsset((Asset)obj); } } } catch (Exception e) { MessageBox.Show(e.Message, "Create Asset From Asset", MessageBoxButtons.OK, MessageBoxIcon.Error); } Modified = true; } }