public void Destroy() { if (destroy) { return; } try { if (children != null) { for (PListNode n = children.next, next; n != children; n = next) { next = n.next; IRenderObject child = (IRenderObject)n; if (child != null) { child.SetParent(null); } } children = null; } if (ctrls != null) { foreach (IController c in ctrls.Values) { if (c != null) { c.Destroy(); } } ctrls.Clear(); ctrls = null; } if (timer != null) { timer.Clear(); } this.SetParent(null); this.OnDestroy(); if (this.owner != null) { this.owner.RemoveInstance(this); this.owner = null; } } catch (Exception e) { LOG.LogError(e.ToString(), this.gameObject); } destroy = true; }
public T CreateInstance <T>(string filename, IRenderObject parent, bool unload, params object[] args) where T : IRenderObject { IRenderResource resource; filename = filename.ToLower(); if (CMisc.isLegalNumber(filename)) { LOG.LogError(Localization.Format("INVALID_LOAD_PATH", filename)); } if (parent != null && parent.GetOwner() != null) { if (parent.GetOwner().unload_asset) { unload = parent.GetOwner().unload_asset; } } if (idle.TryGetValue(filename, out resource)) { idle.Remove(filename); if (resource.complete) { complete.Add(filename, resource); } else { loading.Add(filename, resource); } //LOG.Debug( "***** get resource {0} from idle, linger {1}s", filename, Time.realtimeSinceStartup - resource.idle_time ); } else if (!loading.TryGetValue(filename, out resource)) { if (!complete.TryGetValue(filename, out resource)) { resource = new IRenderResource(filename, this); resource.unload_asset = unload; loading.Add(resource.name, resource); Cookie cookie = GetCookie(filename); ++cookie.create; } } if (resource == null) { return(null); } return(resource.CreateInstance <T>(parent, args)); }
public void DestroyResource(IRenderResource resource) { loading.Remove(resource.name); complete.Remove(resource.name); if (idle.ContainsKey(resource.name)) { // 因为报了一个IRenderResource已经complete了但GetAsset()为空的错误, // 现在没时间去复现该问题,暂时这样容错!!! idle[resource.name].Destroy(); idle.Remove(resource.name); resource.Destroy(); } else { idle.Add(resource.name, resource); } }
public void SetOwner(IRenderResource owner) { this.owner = owner; }