क्या यह कुछ मदद चाहिए?
public static Dictionary<String, T> LoadContent<T>(this ContentManager contentManager, string contentFolder)
{
//Load directory info, abort if none
DirectoryInfo dir = new DirectoryInfo(contentManager.RootDirectory + "\\" + contentFolder);
if (!dir.Exists)
throw new DirectoryNotFoundException();
//Init the resulting list
Dictionary<String, T> result = new Dictionary<String, T>();
//Load all files that matches the file filter
FileInfo[] files = dir.GetFiles("*.*");
foreach (FileInfo file in files)
{
string key = Path.GetFileNameWithoutExtension(file.Name);
result[key] = contentManager.Load<T>(contentManager.RootDirectory + "/" + contentFolder + "/" + key);
}
//Return the result
return result;
}
स्रोत
2010-10-29 14:14:50
मुझे सामग्री फ़ोल्डर स्कैन करने के बारे में क्यों नहीं लगता था:/ –
ग्रेट सामान! इसका उपयोग करने के लिए संघर्ष करने वाले किसी भी व्यक्ति के लिए मैंने पाया कि मेरे प्रोजेक्ट के लिए मुझे लोड कॉल से "contentManager.RootDirectory +" को हटाने की आवश्यकता है क्योंकि मैंने Content.RootDirectory = सामग्री पहले ही सेट की है। इसके अलावा इस विधि को इस्तेमाल करने के लिए एक स्थिर वर्ग में होना चाहिए। – Mafro34
ध्यान दें कि यह सभी सामग्री (इस प्रकार विधि का नाम) लोड करने लगता है। यदि आप वस्तुओं को गिनना चाहते हैं लेकिन * उन्हें लोड नहीं करना चाहते हैं, तो यह थोड़ा भारी हो सकता है। साथ ही, मुझे नहीं लगता कि सामग्री लोड किए बिना किसी निश्चित प्रकार की सामग्री को गिनने का कोई तरीका है। भावहीन। मुझे लगता है कि इस परिदृश्य में एक ऑफ़लाइन कदम अच्छी तरह से काम करेगा। –
cod3monk3y