/// <summary> /// 构造 /// </summary> /// <param name="trans"></param> public ATComponent(Transform trans) { this.Transform = trans; //创建State this.Props = new T(); UFluxUtils.InitComponent(this); }
/// <summary> /// 删除 /// </summary> virtual public void Destroy() { UFluxUtils.Destroy(this.Transform.gameObject); this.Transform = null; UFluxUtils.Unload(this.resPath); IsDestroy = true; }
/// <summary> /// 提交状态 刷新 /// </summary> /// <param name="transform">不为null,则指定一个Transform刷新.不然则刷新当前Window.Transform</param> protected void CommitProps(Transform transform = null) { if (transform) { UFluxUtils.SetComponentProps(transform, this.Props); } else { UFluxUtils.SetComponentProps(this.Transform, this.Props); } }
/// <summary> /// 绑定单个节点 /// </summary> /// <param name="transform"></param> /// <param name="value"></param> private void BindChild(Transform transform, object value) { var props = value as APropsBase; if (props == null) { Debug.LogError("类型不是props:" + value.GetType().Name); return; } UFluxUtils.SetComponentProps(transform, props); }
/// <summary> /// 加载接口 /// </summary> public void Load() { if (resPath == null) { return; } var o = UFluxUtils.Load <GameObject>(resPath); this.Transform = GameObject.Instantiate(o).transform; this.IsLoad = true; UFluxUtils.InitComponent(this); //初始化 this.Init(); }
/// <summary> /// 绑定多个节点 /// </summary> /// <param name="transform"></param> /// <param name="value">Value必须为集合类型</param> private void BindChildren(Transform transform, object value) { IPropsList propsList = value as IPropsList; if (!propsList.IsChanged) { return; } //绑定子节点 propsList.Foreach((idx, props) => { if (idx < transform.childCount) { UFluxUtils.SetComponentProps(transform.GetChild(idx), props); } }); }
/// <summary> /// 异步加载 /// </summary> /// <param name="callback"></param> public void AsyncLoad(Action callback = null) { if (resPath == null) { return; } UFluxUtils.AsyncLoad <GameObject>(resPath, obj => { this.Transform = GameObject.Instantiate(obj).transform; this.IsLoad = true; UFluxUtils.InitComponent(this); //初始化 Init(); if (callback != null) { callback(); } }); }
/// <summary> /// 提交状态 /// </summary> protected void CommitProps() { UFluxUtils.SetComponentProps(this.Transform, this.Props); }