/// Add a new resource prefab instance to the current scene and return it /// @param factory The factory type. /// @return A new world instance of factory. public static Option <GameObject> Spawn(GameObject factory) { try { var instance = Object.Instantiate(factory); return(Option.Some(instance)); } catch (Exception e) { Console.Error("Failed to load prefab: " + factory + ": " + e); } return(Option.None <GameObject>()); }
public static void Run(string restrictPath) { try { // Expand to specific target, if restricted var target = ".*Resources.*"; if (restrictPath != null) { target += restrictPath + ".*"; } // Find all the folders and generate a manifest var resources = Project.AllDirs(target); foreach (var path in resources) { if (!path.EndsWith("Resources")) { var files = Project.Files(path, ".*"); for (var i = 0; i < files.Length; ++i) { files[i] = Path.GetFileNameWithoutExtension(files[i]); } var dirs = Project.Dirs(path, ".*"); for (var i = 0; i < dirs.Length; ++i) { var value = dirs[i].Replace(path, ""); value = value.Replace("/", ""); value = value.Replace("\\", ""); dirs[i] = value; } var manifest = new Manifest() { files = files, folders = dirs }; var output = Json.Serialize(manifest); System.IO.File.WriteAllText(Path.Combine(path, "manifest.json"), output); Console.Log("Generated manifest for: {0}", path); } } } catch (Exception err) { Console.Log("Failed to run manifest builder"); Console.Error(err); } }
/// Fetch a game object factory from a resource url /// @param resource The resource path to the instance /// @return A factory instance, for a prefab. public static Option <GameObject> Prefab(string resource) { try { var rtn = Resources.Load(resource, typeof(GameObject)) as GameObject; if (rtn != null) { return(Option.Some(rtn)); } else { Console.Error("Failed to load prefab path: " + resource + ": not found"); } } catch (Exception e) { Console.Error("Failed to load prefab path: " + resource + ": " + e); } return(Option.None <GameObject>()); }
/// Populate a dictionary of objects from a heirarchy public static Option <Dictionary <string, GameObject> > Find(string[] tags, GameObject heirarchy) { var rtn = new Dictionary <string, GameObject>(); var count = 0; foreach (var tag in tags) { var instance = Find(tag, heirarchy); if (instance) { rtn[tag] = instance.Unwrap(); count += 1; } else { Console.Error("Some UI tags were missing: {0}", tag); } } return(count == tags.Length ? Option.Some(rtn) : Option.None <Dictionary <string, GameObject> >()); }