protected DisplayObject[] ConstructFromResource() { var count = _timeLine.instances.Length; var instances = new DisplayObject[count]; for (int i = 0; i < count; i++) { var instName = _timeLine.instances[i].name; var resourcePath = _timeLine.GetResourcePath(i); var resource = FlashResources.GetResource <IDisplayResource>(resourcePath); DisplayObject instance; if (resource != null) { instance = resource.CreateInstance(); } else if (resourcePath == "flash/text/TextField") { instance = new TextLabel() { text = ":-)" }; } else { var className = resourcePath .Replace("Placeholders/", "") .Replace("/", "."); var type = Type.GetType(className); if (type != null) { instance = (DisplayObject)Activator.CreateInstance(type); } else { throw new Exception("Resource not found: " + resourcePath); } } instance.name = instName; instances[i] = instance; var field = GetType().GetField(instName); if (field != null && field.FieldType.IsInstanceOfType(instance)) { field.SetValue(this, instance); } } return(instances); }
void UpdateContent() { root.RemoveChildren(); if (resourcePath.IsNullOrEmpty()) { return; } var bundleName = resourcePath.Split("/")[0]; var bundle = FlashResources.GetBundleInstance(bundleName); if (bundle == null) { Debug.Log("Bundle not found: " + bundleName); return; } if (!bundle.isLoaded) { FlashResources.LoadBundle(bundle); } var resource = FlashResources.GetResource <IDisplayResource>(resourcePath); if (resource == null) { Debug.Log("Resource not found: " + resourcePath); return; } var instance = resource.CreateInstance(); root.AddChild(instance); if (isPlaying) { if (instance.totalFrames > 1) { instance.Play(); } else { var displayContainer = instance as DisplayContainer; if (displayContainer != null) { displayContainer.PlayAllChildren(); } } } }