private void openExternalIffToolStripMenuItem_Click(object sender, EventArgs e) { var dialog = new OpenFileDialog(); dialog.Title = "Select an iff file. (iff)"; SaveFile(dialog); try { var iff = new IffFile(dialog.FileName); iff.TSBO = true; var obj = new GameObject(); obj.OBJ = iff.List <OBJD>()?.FirstOrDefault() ?? new OBJD(); obj.GUID = obj.OBJ.GUID; //var res = new GameObjectResource(iff, null, null, "what", Content.Content.Get()); var res = new GameObjectResource(iff, null, null, "what", Content.Content.Get()); var res2 = new GameGlobalResource(iff, null); obj.Resource = res; IffManager.OpenResourceWindow(res2, obj); } catch { } }
public void SetActiveObject(GameObject obj) { ActiveObj = obj; ActiveRes = obj.Resource; ActiveUpgrades = Content.Content.Get().Upgrades?.GetFile(ActiveRes.MainIff.Filename); IffSpecificBox.Text = ActiveRes.MainIff.Filename; Render(); }
private void add(GameObject gameObject) { if (fatherTransform) { gameObject.transform.parent = fatherTransform; } idCounter += 1; GameObjectResource r = new GameObjectResource(idCounter, gameObject, this); idle.Add(r.getId(), r); }
public GameObjectResource get() { if (idle.Count <= 0) { GameObject g = gameObjectFactory.CreateGameObject(); add(g); } GameObjectResource r = idle.First().Value; r.getGameObject().SetActive(true); used.Add(r.getId(), r); idle.Remove(r.getId()); return(r); }
public GameObject Get(ulong id) { return(Cache.GetOrAdd(id, (_) => { GameObjectReference reference; GameObjectResource resource = null; lock (Entries) { Entries.TryGetValue(id, out reference); if (reference == null) { Console.WriteLine("Failed to get Object ID: " + id.ToString() + " (no resource)"); return null; } /* * lock (ProcessedFiles) * { * //if a file is processed but an object in it is not in the cache, it may have changed. * //check for it again! * ProcessedFiles.TryGetValue(reference.FileName, out resource); * } */ } resource = ProcessedFiles.GetOrAdd(reference.FileName, GenerateResource(reference)); if (resource.MainIff == null) { return null; } foreach (var objd in resource.MainIff.List <OBJD>()) { if (objd.GUID == id) { var item = new GameObject { GUID = objd.GUID, OBJ = objd, Resource = resource }; return item; //found it! } } Console.WriteLine("Failed to get Object ID: " + id.ToString() + " from resource " + resource.Name); return null; })); }
public void release(GameObjectResource r) { if (r.getPool() != this) { Debug.LogError("gameObjectPool must release gameObjectResource belong to it"); return; } if (!used.ContainsKey(r.getId())) { return; } r.getGameObject().SetActive(false); used.Remove(r.getId()); idle.Add(r.getId(), r); }
public void loadObject(string assetBundle, string assetName, System.Func <IGameObjectResource, GameObject> instantiate, System.Action <GameObject> callback) { if (instantiate == null) { instantiate = _res => doInstantiate(_res, null, false); } GameObjectResource res; string resName = string.Format("{0}|{1}", assetBundle, assetName); if (resources.TryGetValue(resName, out res)) { if (res.prefab != null) { var go = instantiate.Invoke(res); if (go != null) { res.instanceList.AddLast(go); } if (callback != null) { callback.Invoke(go); } } else if (res.requests != null) { res.requests.Add(new GameObjectResource.Request(instantiate, callback)); } else { if (callback != null) { callback.Invoke(null); } } } else { res = new GameObjectResource(resName); resources.Add(resName, res); res.requests.Add(new GameObjectResource.Request(instantiate, callback)); StartCoroutine(load(res, assetBundle, assetName)); } onResourceRequest(res); }
public IEnumerator getAsync(LoaderResult result) { result.isDone = false; result.asset = null; if (idle.Count <= 0) { LoaderResult r = new LoaderResult(); yield return(gameObjectFactory.CreateGameObjectAsync(r)); add(r.asset as GameObject); } GameObjectResource res = idle.First().Value; res.getGameObject().SetActive(true); used.Add(res.getId(), res); idle.Remove(res.getId()); result.asset = res; result.isDone = true; }
/** ** Create a new unit. ** ** @param type Pointer to unit-type. ** @param player Pointer to owning player. ** ** @return Pointer to created unit. */ public Unit createUnit(UnitType type, Player player) { Unit unit; unit = AllocUnit(); if (unit == null) { return(null); } GameObjectResource g = unitDrawer.get(); unit.init(type, g.getGameObject().GetComponent <SpriteDrawer>()); // Only Assign if a Player was specified if (player != null) { unit.assignToPlayer(player); } return(unit); }
public RuntimeUpgradeLevel(UpgradeIff file, UpgradeLevel level, GameObjectResource res, Content content) { Level = level; if (Level.Price.Length == 0) { throw new Exception("Missing price."); } if (Level.Price[0] == 'R' || Level.Price[0] == '$') { if (Level.Price[0] == 'R') { Relative = true; } if (!int.TryParse(Level.Price.Substring(1), out Price)) { throw new Exception("Could parse literal upgrade level price! " + Level.Price); } } else { uint guid; if (!uint.TryParse(Level.Price, System.Globalization.NumberStyles.HexNumber, null, out guid)) { throw new Exception("Could parse guid for upgrade level price! " + Level.Price); } var item = content.WorldCatalog.GetItemByGUID(guid); if (item == null) { throw new Exception("Could not find catalog entry for price reference! This error is fatal because a 0 price upgrade would be really bad." + Level.Price); } Price = (int)item.Value.Price; } Ads = Level.Ad.Split(';'); Subs = RuntimeUpgradeFile.LoadSubs(Level.Subs, file.Groups, res); }
public static Dictionary <int, Dictionary <int, short> > LoadSubs(List <UpgradeSubstitution> subs, List <UpgradeGroup> groups, GameObjectResource res) { subs = GroupsIntoSubs(groups, subs); var result = new Dictionary <int, Dictionary <int, short> >(); foreach (var sub in subs) { //parse old var oldSplit = sub.Old.Split(':'); if (oldSplit.Length != 2) { throw new Exception("Tuning to substitute invalid: " + sub.Old); } int table; int index; if (!int.TryParse(oldSplit[0], out table)) { throw new Exception("Tuning table for sub target invalid: " + sub.Old); } if (!int.TryParse(oldSplit[1], out index)) { throw new Exception("Tuning index for sub target invalid: " + sub.Old); } //parse new if (sub.New.Length == 0) { throw new Exception("Substitution value cannot be empty."); } short value; switch (sub.New[0]) { case 'C': //lookup constant in the file. var newSplit = sub.New.Substring(1).Split(':'); if (newSplit.Length != 2) { throw new Exception("Substitution value tuning ref invalid: " + sub.New); } int ntable; int nindex; if (!int.TryParse(newSplit[0], out ntable)) { throw new Exception("Tuning table for sub value invalid: " + sub.New); } if (!int.TryParse(newSplit[1], out nindex)) { throw new Exception("Tuning index for sub value invalid: " + sub.New); } uint id = (uint)((ntable << 16) | nindex); if (ntable >= 8192 && res.SemiGlobal != null) { res.SemiGlobal.TuningCache.TryGetValue(id, out value); //ignore missing } else if (ntable >= 4096) { res.TuningCache.TryGetValue(id, out value); //ignore missing } else { Content.Get().WorldObjectGlobals.Get("global").Resource.TuningCache.TryGetValue(id, out value); //ignore missing } break; case 'V': //it's just a value. if (!short.TryParse(sub.New.Substring(1), out value)) { throw new Exception("Invalid substitution value (not a short): " + sub.New); } break; default: throw new Exception("Invalid substitution value: " + sub.New); } Dictionary <int, short> tableDict; if (!result.TryGetValue(table, out tableDict)) { tableDict = new Dictionary <int, short>(); result[table] = tableDict; } tableDict[index] = value; } return(result); }
IEnumerator load(GameObjectResource res, string assetBundle, string assetName) { do { var abreq = getAssetBundleAsync(assetBundle, null); yield return(abreq); if (abreq.assetBundle == null) { break; } var areq = abreq.assetBundle.LoadAssetAsync <GameObject>(assetName); yield return(areq); if (areq.asset == null) { break; } if ((res._prefab = areq.asset as GameObject) == null) { Resources.UnloadAsset(areq.asset); break; } if (res.requests == null) { Resources.UnloadAsset(res._prefab); res._prefab = null; } else { foreach (var req in res.requests) { var go = req.instantiate(res); if (go != null) { res.instanceList.AddLast(go); } if (req.callback != null) { req.callback.Invoke(go); } } res.requests = null; } yield break; }while (false); if (res.requests != null) { foreach (var req in res.requests) { if (req.callback != null) { req.callback.Invoke(null); } } res.requests = null; } }