/// <summary> /// 删除 /// </summary> virtual public void Destroy() { UFlux.Destroy(this.Transform.gameObject); this.Transform = null; UFlux.Unload(this.resPath); IsDestroy = true; }
/// <summary> /// 构造 /// </summary> /// <param name="trans"></param> public ATComponent(Transform trans) { this.Transform = trans; //创建State this.Props = new T(); UFlux.InitComponent(this); }
/// <summary> /// 构造 /// </summary> /// <param name="trans"></param> public Component(Transform trans) { this.Transform = trans; //创建State this.Props = new T(); UFlux.SetTransformPath(this); }
/// <summary> /// 提交状态 /// </summary> protected void SetProps() { if (this.Props.IsChanged()) { UFlux.SetComponentValue(this.Transform, this.Props); } }
/// <summary> /// 设置数据,全局只能通过这个接口设置数据 /// </summary> /// <param name="props"></param> public void SetProps(T props) { if (props.IsChanged()) { this.Props = props; UFlux.SetComponentValue(this.Transform, props); } }
/// <summary> /// 设置属性 /// </summary> /// <param name="transform"></param> /// <param name="value"></param> private void SetChildValue(Transform transform, object value) { var props = value as PropsBase; if (props == null) { Debug.LogError("类型不是props:" + value.GetType().Name); return; } UFlux.SetComponentValue(transform, props); }
/// <summary> /// 提交状态 /// </summary> protected void CommitProps(bool isAllPrpertyChanged = false) { if (isAllPrpertyChanged) { this.Props.SetAllPropertyChanged(); } if (this.Props.IsChanged()) { UFlux.SetComponentValue(this.Transform, this.Props); } }
/// <summary> /// 设置图片 /// </summary> /// <param name="value"></param> private void SetProp_Sprite(UIBehaviour uiBehaviour, object value) { var img = uiBehaviour as Image; if (value is string) { img.sprite = UFlux.Load <Sprite>((string)value); } else if (value is Sprite) { img.sprite = (Sprite)value; } }
/// <summary> /// 加载接口 /// </summary> public void Load() { if (resPath == null) { return; } var o = UFlux.Load <GameObject>(resPath); this.Transform = GameObject.Instantiate(o).transform; this.IsLoad = true; UFlux.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) { UFlux.SetComponentProps(transform.GetChild(idx), props); } }); }
/// <summary> /// 将List中的数据设置给子节点 /// </summary> /// <param name="transform"></param> /// <param name="value">Value必须为集合类型</param> private void ForeahSetChildValueFormArray(Transform transform, object value) { ICollection Collection = value as ICollection; if (Collection == null) { return; } int count = 0; foreach (var item in Collection) { var props = item as PropsBase; if (props != null) { transform.gameObject.SetActive(true); var child = transform.GetChild(count); if (child) { UFlux.SetComponentValue(child, props); } } else { BDebug.LogError("list数据错误:" + value.GetType()); return; } count++; } for (int i = 0; i < transform.childCount; i++) { if (i > count - 1) { transform.GetChild(i).gameObject.SetActive(false); } else { transform.GetChild(i).gameObject.SetActive(true); } } }
/// <summary> /// 异步加载 /// </summary> /// <param name="callback"></param> public void AsyncLoad(Action callback = null) { if (resPath == null) { return; } UFlux.AsyncLoad <GameObject>(resPath, obj => { this.Transform = GameObject.Instantiate(obj).transform; this.IsLoad = true; UFlux.InitComponent(this); //初始化 Init(); if (callback != null) { callback(); } }); }
/// <summary> /// 提交状态 /// </summary> protected void CommitProps() { UFlux.SetComponentProps(this.Transform, this.Props); }