void Start() { Application.targetFrameRate = 60; GRoot.inst.SetContentScaleFactor(1136, 640); Stage.inst.onKeyDown.Add(OnKeyDown); UIPackage.AddPackage("UI/Basics"); #if UNITY_5 //Use the font names directly UIConfig.defaultFont = "Droid Sans,Droid Sans Fallback,Microsoft YaHei"; #else //Need to put a ttf file into Resources folder. Here is the file name of the ttf file. UIConfig.defaultFont = "afont"; #endif UIConfig.verticalScrollBar = UIPackage.GetItemURL("Basics", "ScrollBar_VT"); UIConfig.horizontalScrollBar = UIPackage.GetItemURL("Basics", "ScrollBar_HZ"); UIConfig.popupMenu = UIPackage.GetItemURL("Basics", "PopupMenu"); UIConfig.buttonSound = (AudioClip)UIPackage.GetItemAsset("Basics", "click"); _mainView = UIPackage.CreateObject("Basics", "Main").asCom; _mainView.fairyBatching = true; _mainView.SetSize(GRoot.inst.width, GRoot.inst.height); _mainView.AddRelation(GRoot.inst, RelationType.Size); GRoot.inst.AddChild(_mainView); _backBtn = _mainView.GetChild("btn_Back"); _backBtn.visible = false; _backBtn.onClick.Add(onClickBack); _demoContainer = _mainView.GetChild("container").asCom; _viewController = _mainView.GetController("c1"); _demoObjects = new Dictionary <string, GComponent>(); int cnt = _mainView.numChildren; for (int i = 0; i < cnt; i++) { GObject obj = _mainView.GetChildAt(i); if (obj.group != null && obj.group.name == "btns") { obj.onClick.Add(runDemo); } } }
void HideMouse(GComponent obj) { if (obj == null) { return; } obj.touchable = false; for (int i = 0; i < obj.numChildren; i++) { GObject item = obj.GetChildAt(i); item.touchable = false; if (item is GComponent) { HideMouse((GComponent)item); } } }
void __playProgress(object param) { GComponent obj = _demoObjects["ProgressBar"]; int cnt = obj.numChildren; for (int i = 0; i < cnt; i++) { GProgressBar child = obj.GetChildAt(i) as GProgressBar; if (child != null) { child.value += 1; if (child.value > child.max) { child.value = 0; } } } }
void __sliderChanged(EventContext context) { int cnt = _mainView.numChildren; for (int i = 0; i < cnt; i++) { GObject obj = _mainView.GetChildAt(i); if (obj.filter is ColorFilter) { ColorFilter filter = (ColorFilter)obj.filter; filter.Reset(); filter.AdjustBrightness((_s0.value - 100) / 100f); filter.AdjustContrast((_s1.value - 100) / 100f); filter.AdjustSaturation((_s2.value - 100) / 100f); filter.AdjustHue((_s3.value - 100) / 100f); } } }
private void PlayDepth() { GComponent obj = _demoObjects["Depth"]; GComponent testContainer = obj.GetChild("n22").asCom; GObject fixedObj = testContainer.GetChild("n0"); fixedObj.sortingOrder = 100; fixedObj.draggable = true; int numChildren = testContainer.numChildren; int i = 0; while (i < numChildren) { GObject child = testContainer.GetChildAt(i); if (child != fixedObj) { testContainer.RemoveChildAt(i); numChildren--; } else i++; } startPos = new Vector2(fixedObj.x, fixedObj.y); obj.GetChild("btn0").onClick.Add(() => { GGraph graph = new GGraph(); startPos.x += 10; startPos.y += 10; graph.xy = startPos; graph.DrawRect(150, 150, 1, Color.black, Color.red); obj.GetChild("n22").asCom.AddChild(graph); }); obj.GetChild("btn1").onClick.Add(() => { GGraph graph = new GGraph(); startPos.x += 10; startPos.y += 10; graph.xy = startPos; graph.DrawRect(150, 150, 1, Color.black, Color.green); graph.sortingOrder = 200; obj.GetChild("n22").asCom.AddChild(graph); }); }
public static void SetWidthHeight(GObject g) { if (g is GComponent) { GComponent ggg = g.asCom; GObject gg; for (int i = 0; i < ggg.numChildren; i++) { gg = ggg.GetChildAt(i); gg.height = GRoot.inst.height; gg.width = bgOffsetW; gg.x = bgOffsetX; } } else { g.height = GRoot.inst.height; g.width = bgOffsetW; g.x = bgOffsetX; } }
void Start() { Application.targetFrameRate = 60; Stage.inst.onKeyDown.Add(OnKeyDown); _mainView = this.GetComponent<UIPanel>().ui; _backBtn = _mainView.GetChild("btn_Back"); _backBtn.visible = false; _backBtn.onClick.Add(onClickBack); _demoContainer = _mainView.GetChild("container").asCom; _viewController = _mainView.GetController("c1"); _demoObjects = new Dictionary<string, GComponent>(); int cnt = _mainView.numChildren; for (int i = 0; i < cnt; i++) { GObject obj = _mainView.GetChildAt(i); if (obj.group != null && obj.group.name == "btns") obj.onClick.Add(runDemo); } }
/// <summary> /// 获取组件包围盒 /// </summary> /// <returns>x:最小值 y:最小值 w:宽 h:高</returns> public static Rect GetRect(GComponent gcom) { if (gcom == null) { return(Rect.zero); } float ax = 0f; float ay = 0f; float aw = 0f; float ah = 0f; GObject[] childs = new GObject[4]; GObject maxDisschild = null; float diss = 0f; int cnt = gcom.numChildren; if (gcom.numChildren > 0) { ax = int.MaxValue; ay = int.MaxValue; float ar = int.MinValue; float ab = int.MinValue; float tmp; for (int i = 0; i < cnt; ++i) { GObject child = gcom.GetChildAt(i); tmp = child.xMin; if (tmp < ax) { ax = tmp; childs[0] = child; } tmp = child.yMin; if (tmp < ay) { ay = tmp; childs[1] = child; } tmp = child.xMin + child.actualWidth; if (tmp > ar) { ar = tmp; childs[2] = child; } tmp = child.yMin + child.actualWidth; if (tmp > ab) { ab = tmp; childs[3] = child; } } for (int i = 0; i < childs.Length; ++i) { if (diss <= childRadiusDiss(childs[i])) { diss = childRadiusDiss(childs[i]); maxDisschild = childs[i]; } } var ratio = Mathf.Max(maxDisschild.actualWidth, maxDisschild.height) / Mathf.Min(maxDisschild.actualWidth, maxDisschild.actualHeight); diss = diss * ratio; aw = ar - ax + diss; ah = ab - ay + diss; ax = ax - diss * 0.5f; ay = ay - diss * 0.5f; return(new Rect(ax, ay, aw, ah)); } return(new Rect(gcom.x, gcom.y, gcom.actualWidth, gcom.actualHeight)); }
/// <summary> /// 实现音效和BGM的音量设置 /// </summary> private void VolumeAlert() { list.touchable = false; list_sub.touchable = false; Transition t = Alert.GetTransition("t0"); t.Play(); mainUI.AddChild(Alert); Alert.GetChildAt(1).visible = false; Alert.GetChildAt(2).asLoader.url = "ui://se5xss9vi9wvvd"; CloseAlter(); Alert.GetChildAt(3).onClick.Set(() => { Setting.Sound = Convert.ToSingle(Alert.GetChild("n2").asLoader.component.GetChildAt(0).asCom.GetChild("title").text) / 100; Setting.BGM = Convert.ToSingle(Alert.GetChild("n2").asLoader.component.GetChildAt(1).asCom.GetChild("title").text) / 100; SoundSetup(); AlertClose(); }); }