public virtual T AttachRenderTarget <T>(ResourceRenderTarget obj, Resource.ResourceGroup rg) where T : UnityEngine.UI.Graphic { var target = obj.GetComponent <ResourceRenderTarget>(); target.renderer = this; target.resourceGroup = rg; return(null); }
public override T AttachRenderTarget <T>(ResourceRenderTarget target, Resource.ResourceGroup rg) { base.AttachRenderTarget <T>(target, rg); System.Type type = Content.GetType(); var dst = target.GetComponent(type) as T; if (!dst) { dst = target.gameObject.AddComponent(type) as T; } var fields = type.GetFields(); foreach (var field in fields) { if (field.IsStatic) { continue; } field.SetValue(dst, field.GetValue(Content)); } var props = type.GetProperties(); foreach (var prop in props) { if (!prop.CanWrite || !prop.CanWrite || prop.Name == "name") { continue; } prop.SetValue(dst, prop.GetValue(Content, null), null); } target.transform.localPosition = Vector3.zero; RectTransform rect = target.GetComponent <RectTransform>(); rect.anchoredPosition = rectTranfrom.anchoredPosition; var cont = target.gameObject.AddComponent <ContentSizeFitter> (); cont.verticalFit = ContentSizeFitter.FitMode.PreferredSize; cont.horizontalFit = ContentSizeFitter.FitMode.PreferredSize; target.SetTarget(rg); return(dst); }