public override void Initial(ModelElement model) { base.Initial(model); ScrollView = model.Context; eventCall = EventCallBack.RegEvent <EventCallBack>(ScrollView); eventCall.Drag = Draging; eventCall.DragEnd = (o, e, s) => { Scrolling(o, s); if (ItemDockCenter) { CenterScroll(this); } if (ScrollStart != null) { ScrollStart(this); } if (eventCall.VelocityY == 0) { OnScrollEnd(o); } }; model.SizeChanged = (o) => { Refresh(0, m_point); }; eventCall.Scrolling = Scrolling; eventCall.ScrollEndY = OnScrollEnd; eventCall.ForceEvent = true; eventCall.AutoColor = false; Size = ScrollView.sizeDelta; ScrollView.anchorMin = ScrollView.anchorMax = ScrollView.pivot = Center; eventCall.CutRect = true; mModel = model; }
public override void Initial(ModelElement mod) { Model = mod; callBack = EventCallBack.RegEvent <EventCallBack>(Model); callBack.Drag = callBack.DragEnd = Draging; callBack.PointerDown = PointDown; callBack.AutoColor = false; var child = mod.child; FillImage = mod.Find("FillImage"); if (FillImage != null) { image = FillImage.GetComponent <ImageElement>(); } Nob = mod.Find("Nob"); var fake = mod.GetExtand() as FakeStruct; if (fake != null) { unsafe { info = *(SliderInfo *)fake.ip; } } }
public delegate void EventCallBack(ConfigVo configVo); //声明回调事件委托 public static void InitConfig(EventCallBack callBack = null) { //PS:如果是打包成WebGL,由于浏览器的同源策略,会存在跨域问题,这一点需要注意 HTTPRequest httpRequest = new HTTPRequest( new Uri(Application.streamingAssetsPath + "/Config.txt"), (req, resp, responseheader) => { //Json字符串转对象 // ConfigVo configVo = JsonUtility.FromJson<ConfigVo>(resp.DataAsText); ConfigVo configVo = JsonMapper.ToObject <ConfigVo>(resp.DataAsText); Config.serviceUrl = configVo.serviceUrl; Debug.Log("初始化配置成功!"); callBack(configVo); } ); httpRequest.MethodType = HTTPMethods.Get; //post请求,如需设置请求参数 // httpRequest.MethodType=HTTPMethods.Post; // httpRequest.AddField("key","value"); httpRequest.Send(); }
public void AddListener(int sender, int evtType, EventCallBack cb, int id) { if (cb == null) { return; } Dictionary <int, Dictionary <int, List <EventCallBack> > > senderDic = null; if (!_listeners.TryGetValue(sender, out senderDic)) { senderDic = new Dictionary <int, Dictionary <int, List <EventCallBack> > >(); _listeners[sender] = senderDic; } Dictionary <int, List <EventCallBack> > eventDic = null; if (!senderDic.TryGetValue(evtType, out eventDic)) { eventDic = new Dictionary <int, List <EventCallBack> >(); senderDic[evtType] = eventDic; } List <EventCallBack> eventCBList = null; if (!eventDic.TryGetValue(id, out eventCBList)) { eventCBList = new List <EventCallBack>(); eventDic[id] = eventCBList; } eventCBList.Add(cb); }
void PointDown(EventCallBack back, UserAction action) { float x = action.CanPosition.x - back.GlobalPosition.x; float y = action.CanPosition.y - back.GlobalPosition.y; x /= back.GlobalScale.x; y /= back.GlobalScale.y; float al = MathH.atan(x, y); _angle = al; al += 22.5f; if (al > 360f) { al -= 360f; } al /= 45f; int index = (Int32)al; index++; _dir = (Direction)index; if (Nob != null) { Nob.data.localPosition.x = x; Nob.data.localPosition.y = y; Nob.IsChanged = true; } vector.x = x; vector.y = y; if (Rocking != null) { Rocking(this); } }
void InitialLabel() { Head = new ModelElement(); Head.Load(auxiliary.Item.ModData); Head.SetParent(auxiliary.head); label = Head.Find("Label"); var eve = EventCallBack.RegEvent <EventCallBack>(label); eve.PointerDown = HeadPointDown; eve.Click = HeadClick; eve.Drag = HeadDrag; eve.DragEnd = HeadDragEnd; eve.DataContext = this; var txt = label.GetComponent <TextElement>(); txt.text = name; txt.UseTextSize = true; close = Head.Find("Close"); if (close != null) { clo = EventCallBack.RegEvent <EventCallBack>(close); clo.DataContext = this; clo.Click = CloseClick; } }
void Draging(EventCallBack back, UserAction action, Vector2 v) { pos += v; ApplyValue(); if (OnValueChanged != null) OnValueChanged(this); }
void PointDownR(EventCallBack back, UserAction action) { float x = action.CanPosition.x - back.GlobalPosition.x; float y = action.CanPosition.y - back.GlobalPosition.y; x /= back.GlobalScale.x; y /= back.GlobalScale.y; float sx = x * x + y * y; float r = Mathf.Sqrt(220 * 220 / sx); x *= r; y *= r; if (NobA != null) { NobA.data.localPosition = new Vector3(x, y, 0); NobA.IsChanged = true; } float al = MathH.atan(-x, -y); palette.LoadHSVTAsync(al / 360); Color col = palette.buffer[Index]; SelectColor.r = col.r; SelectColor.g = col.g; SelectColor.b = col.b; if (TemplateChanged != null) { TemplateChanged(this); } }
void Scrolling(EventCallBack back, Vector2 v) { if (view == null) { return; } if (Content == null) { return; } v.x /= eventCall.Target.localScale.x; v.y /= eventCall.Target.localScale.y; var p = Content.localPosition; var s = Content.sizeDelta; p.x += v.x; p.y += v.y; v = Correction(view.sizeDelta, p, s); if (v.x == 0) { back.VelocityX = 0; } if (v.y == 0) { back.VelocityY = 0; } Content.localPosition = v; if (Scroll != null) { Scroll(this, v); } }
/// <summary> /// 对象反射 /// </summary> /// <param name="t"></param> /// <param name="reflections"></param> /// <param name="mod"></param> public static void GetObject(TempReflection reflections, ModelElement mod) { for (int i = 0; i < reflections.Top; i++) { var m = reflections.All[i]; if (m.name == mod.name) { if (m.FieldType == typeof(ModelElement)) { m.Value = mod; } else if (typeof(EventCallBack).IsAssignableFrom(m.FieldType)) { m.Value = EventCallBack.RegEvent(mod, m.FieldType); } else if (typeof(ModelInital).IsAssignableFrom(m.FieldType)) { var obj = Activator.CreateInstance(m.FieldType) as ModelInital; obj.Initial(mod); m.Value = obj; } else if (typeof(DataConversion).IsAssignableFrom(m.FieldType)) { m.Value = mod.GetComponent(m.FieldType.Name); } reflections.Top--; var j = reflections.Top; var a = reflections.All[j]; reflections.All[i] = a; reflections.All[j] = m; break; } } }
public override void Initial(ModelElement mod) { palette = new Palette(); callBackR = EventCallBack.RegEvent <EventCallBack>(mod); callBackR.IsCircular = true; callBackR.Drag = callBackR.DragEnd = DragingR; callBackR.PointerDown = PointDownR; NobA = mod.Find("NobA"); NobB = mod.Find("NobB"); hc = mod.Find("HTemplate"); template = hc.GetComponent <RawImageElement>(); callBackC = EventCallBack.RegEvent <EventCallBack>(hc); callBackC.Drag = callBackC.DragEnd = DragingC; callBackC.PointerDown = PointDownC; htemp = mod.GetComponent <RawImageElement>(); ThreadMission.InvokeToMain((o) => { htemp.Context.texture = Palette.LoadCTemplateAsync(); template.Context.texture = palette.texture; slider.Context.texture = Palette.AlphaTemplate(); }, null); palette.LoadHSVTAsync(1); SelectColor.a = 1; var son = mod.Find("Slider"); slider = son.GetComponent <RawImageElement>(); uISlider = new UISlider(); uISlider.Initial(son); uISlider.OnValueChanged = AlphaChanged; uISlider.Percentage = 1; }
protected TreeViewItem CreateItem() { TreeViewItem it = queue.Dequeue(); if (it != null) { it.target.activeSelf = true; return(it); } ModelElement mod = new ModelElement(); mod.Load(ItemMod.ModData); mod.SetParent(View); mod.data.localPosition = new Vector3(10000, 10000); mod.data.localScale = Vector3.one; mod.IsChanged = true; TreeViewItem a = new TreeViewItem(); a.target = mod; a.text = mod.GetComponent <TextElement>(); a.callBack = EventCallBack.RegEvent <EventCallBack>(mod); a.callBack.Click = (o, e) => { var item = o.DataContext as TreeViewItem; if (item.node != null) { item.node.extand = !item.node.extand; Refresh(); } }; a.callBack.DataContext = a; return(a); }
public LayoutLine(Layout lay, ModelElement mod, Direction dir, bool real = true) { realLine = real; layout = lay; layout.lines.Add(this); model = mod; mod.SetParent(layout.LineLevel); if (real) { mod.Instantiate(); callBack = EventCallBack.RegEvent <EventCallBack>(model.Context); callBack.Drag = Drag; direction = dir; #if UNITY_EDITOR || UNITY_STANDALONE_WIN //callBack.PointerEntry = (o, e) => { // ThreadMission.InvokeToMain((y) => { // Cursor.SetCursor(UnityEngine.Resources.Load<Texture2D>("emoji"),Vector2.zero,CursorMode.Auto); // },null); //}; //callBack.DragEnd = (o, e, v) => { // ThreadMission.InvokeToMain((y) => // { // Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto); // }, null); //}; #endif } }
/// <summary> /// 获取战场上的玩家监听 /// </summary> /// <param name="data"></param> private void GetPlayersListener(EventData data) { //data中分装的是一个回调方法 EventCallBack ecb = data.Param as EventCallBack; ecb?.Invoke(new EventData(null, gameObject)); }
void OnScrollEndY(EventCallBack back) { if (scrollType == ScrollType.BounceBack) { if (Position.y < 0) { back.DecayRateY = 0.988f; float d = 0.25f - Position.y; back.ScrollDistanceY = d * eventCall.Target.localScale.y; } else if (Position.y + Size.y > ActualSize.y) { back.DecayRateY = 0.988f; float d = ActualSize.y - Position.y - Size.y - 0.25f; back.ScrollDistanceY = d * eventCall.Target.localScale.y; } else { if (ScrollEnd != null) { ScrollEnd(this); } } } else if (ScrollEnd != null) { ScrollEnd(this); } }
void OnScrollEndX(EventCallBack back) { if (scrollType == ScrollType.BounceBack) { if (Position.x < 0) { back.DecayRateX = 0.988f; float d = 0.25f - Position.x; back.ScrollDistanceX = -d * eventCall.Target.localScale.x; } else if (Position.x + Size.x > ActualSize.x) { back.DecayRateX = 0.988f; float d = ActualSize.x - Position.x - Size.x - 0.25f; back.ScrollDistanceX = -d * eventCall.Target.localScale.x; } else { if (ScrollEnd != null) { ScrollEnd(this); } } } else if (ScrollEnd != null) { ScrollEnd(this); } }
public override void Initial(ModelElement mod) { var fill = mod.Find("FillImage"); if (fill != null) { fill.Instantiate(); FillImage = fill.Context; image = FillImage.GetComponent<Image>(); } var nob = mod.Find("Nob"); if (nob != null) { nob.Instantiate(); Nob = nob.Context; } model = mod.Context; callBack = EventCallBack.RegEvent<EventCallBack>(model); callBack.Drag = callBack.DragEnd = Draging; callBack.PointerDown = PointDown; callBack.AutoColor = false; var fake = mod.GetExtand(); if(fake!=null) { unsafe { info = *(SliderInfo*)fake.ip; } } }
public override void Initial(ModelElement mod) { items = new List <Item>(); View = mod; eventCall = EventCallBack.RegEvent <EventCallBack>(mod); eventCall.AutoColor = false; eventCall.ForceEvent = true; eventCall.Drag = (o, e, s) => { Scrolling(o, s); }; eventCall.DragEnd = (o, e, s) => { if (o.VelocityY == 0) { OnScrollEnd(o); } else { Scrolling(o, s); } }; eventCall.Scrolling = Scrolling; eventCall.ScrollEndY = OnScrollEnd; eventCall.PointerUp = (o, e) => { if (o.VelocityY == 0) { OnScrollEnd(o); } }; model = mod; for (int i = 0; i < model.child.Count; i++) { model.child[i].activeSelf = false; } }
void Scrolling(EventCallBack back, Vector2 v) { if (View == null) { return; } var size = Size; float y = Point + v.y; if (y < 0) { y = 0; back.VelocityY = 0; } if (y + size.y > ActualSize.y) { y = ActualSize.y - size.y; back.VelocityY = 0; } if (back.VelocityX != 0) { back.VelocityX = 0; } Order(y); if (Scroll != null) { Scroll(this, v); } }
void OnScrollEndY(EventCallBack back) { if (scrollType == ScrollType.BounceBack) { if (Position.y < -ScrollContent.Tolerance) { back.DecayRateY = 0.988f; float d = -Position.y; back.ScrollDistanceY = d * eventCall.Context.data.localScale.y; } else { float max = ContentSize.y + ScrollContent.Tolerance; if (max < Size.y) { max = Size.y + ScrollContent.Tolerance; } if (Position.y + Size.y > max) { back.DecayRateY = 0.988f; float d = ContentSize.y - Position.y - Size.y; back.ScrollDistanceY = d * eventCall.Context.data.localScale.y; } else { //if (ScrollEnd != null) // ScrollEnd(this); } } } //else if (ScrollEnd != null) // ScrollEnd(this); }
public void RemoveCommand(string cmd, EventCallBack cb) { if (eventLib != null) { eventLib.RemoveEvent(cmd, cb); } }
public override void Initial(ModelElement element) { view = element; Size = element.data.sizeDelta; element.RegEvent <EventCallBack>(); eventCall = element.baseEvent; eventCall.Drag = (o, e, s) => { Scrolling(o, s); }; eventCall.DragEnd = (o, e, s) => { Scrolling(o, s); o.DecayRateX = 0.998f; o.DecayRateY = 0.998f; }; eventCall.ScrollEndX = OnScrollEndX; eventCall.ScrollEndY = OnScrollEndY; eventCall.Scrolling = Scrolling; eventCall.ForceEvent = true; view.data.anchorMin = view.data.anchorMax = view.data.pivot = new Vector2(0.5f, 0.5f); eventCall.CutRect = true; Content = element.Find("Content"); if (Content != null) { ContentSize = Content.data.sizeDelta; } }
protected TreeViewItem CreateItem() { TreeViewItem it = queue.Dequeue(); if (it != null) { it.target.SetActive(true); return(it); } GameObject g = ModelManagerUI.LoadToGame(ItemMod, null); var t = g.transform; t.SetParent(View); t.localPosition = new Vector3(10000, 10000); t.localScale = Vector3.one; t.localEulerAngles = Vector3.zero; TreeViewItem a = new TreeViewItem(); a.target = g; a.text = g.GetComponent <Text>(); a.callBack = EventCallBack.RegEvent <EventCallBack>(g.transform as RectTransform); a.callBack.Click = (o, e) => { var item = o.DataContext as TreeViewItem; if (item.node != null) { item.node.extand = !item.node.extand; Refresh(); } }; a.callBack.DataContext = a; return(a); }
protected void Limit(EventCallBack callBack, float y) { var size = Size; if (size.y > aSize.y) { m_point = 0; return; } if (y == 0) { return; } float vy = m_point + y; if (vy < 0) { m_point = 0; eventCall.VelocityY = 0; return; } else if (vy + size.y > aSize.y) { m_point = aSize.y - size.y; eventCall.VelocityY = 0; return; } m_point += y; }
public override void Initial(ModelElement mod) { main = mod.Context; ShowLabel = main.GetComponentInChildren <Text>(); callBack = EventCallBack.RegEvent <EventCallBack>(main); callBack.Click = Show; }
public static void LoadPage(Type type, object dat = null) { if (typeof(UIPage).IsAssignableFrom(type)) { if (CurrentPage != null) { if (CurrentPage.GetType() == type) { CurrentPage.Show(dat); return; } } EventCallBack.ClearEvent(); AnimationManage.Manage.ReleaseAll(); if (CurrentPage != null) { CurrentPage.Dispose(); } var t = Activator.CreateInstance(type) as UIPage; CurrentPage = t; t.Initial(Root, dat); t.ReSize(); t.Recovery(); t.ChangeLanguage(); } }
void ItemClick(EventCallBack eventCall, UserAction action) { if (Checked != null) { Checked.SetActive(false); } PopItemMod mod = eventCall.DataContext as PopItemMod; if (mod == null) { return; } if (mod.Checked != null) { mod.Checked.SetActive(true); } SelectIndex = mod.Index; if (ShowLabel != null) { if (mod.data is string) { ShowLabel.text = mod.data as string; } else { ShowLabel.text = mod.data.ToString(); } } if (OnSelectChanged != null) { OnSelectChanged(this, mod.data); } scrollY.ScrollView.gameObject.SetActive(false); }
public DropdownEx(ScrollY scroll, EventCallBack parent) { main = parent.Target; parent.Click = Show; ShowLabel = main.GetComponentInChildren <Text>(); scrollY = scroll; }
public void TriggerEvent(string eventType, object arg1, object arg2) { Delegate d; if (!m_theRouter.TryGetValue(eventType, out d)) { return; } var callBacks = d.GetInvocationList(); for (int i = 0; i < callBacks.Length; i++) { EventCallBack <object, object> callBack = callBacks[i] as EventCallBack <object, object>; if (null == callBack.Target) { continue; } if (callBack == null) { throw new Exception(string.Format("TriggerEvent {0} error:types of parameters not match", eventType)); } try { callBack(arg1, arg2); } catch (Exception ex) { ZLogger.Except(ex); } } }
void OnScrollEnd(EventCallBack back) { if (datas.Count == 0) { return; } if (OutDown()) { back.DecayRateY = 0.988f; float d = -datas[pointIndex].high * pointOffsetRatio; back.ScrollDistanceY = d * eventCall.Context.data.localScale.y; } else { if (OutTop()) { back.DecayRateY = 0.988f; var item = datas[maxIndex]; float f = View.data.sizeDelta.y * 0.5f; float d = f + item.offset - item.high; d = GetDownLenth(d); if (d > 0.01f) { back.ScrollDistanceY = -d * eventCall.Context.data.localScale.y; } else { back.VelocityY = 0; } } } }
public void AddEvent(GameEventType type,EventCallBack callBack) { if (EventGroup.ContainsKey (type)) { EventGroup [type] += callBack; } else { EventGroup[type] = callBack; } }
public void DeleteEvent(GameEventType type,EventCallBack callBack) { if (EventGroup.ContainsKey (type)) { EventGroup[type]-=callBack; } }