private void GenerateRandomBlock() { MapModel mapModel = MapModel.Inst; GComponent mapBlock = mapModel.GetCurrentBlockCom(); AddChildAt(mapBlock, 1); //要在TopFrame下面 //根据数据初始化不同的地图块 foreach (var child in mapBlock.GetChildren()) { MapNodeCom childNode = child as MapNodeCom; if (childNode == null) { continue; } string strIndex = childNode.name.Replace("node", ""); MapNodeBase nodeData = mapModel.GetCurrentLayerMapNodeData(strIndex); if (nodeData == null) { Debug.LogError("no node data:" + strIndex); continue; } childNode.SetNodeData(nodeData); childNode.onClick.Add(OnNodeClick); _dicNodeCom.Add(strIndex, childNode); } }
//public List<MonsterCardComponent> monsters = new List<MonsterCardComponent>(); public void clearAllEnemy() { foreach (GObject o in monsterContianer.GetChildren()) { o.Dispose(); } monsterContianer.RemoveChildren(); PlayerData.getInstance().chasingEnemies.Clear(); }
//设置所有节点为不可进入状态 private void SetAllNodeNotEnter() { GComponent mapBlock = MapModel.Inst.GetCurrentBlockCom(); foreach (var child in mapBlock.GetChildren()) { MapNodeCom childNode = child as MapNodeCom; if (childNode != null) { childNode.SetCanEnter(false); } } }
public static void SetAllChildrenRelation(GComponent comp, RelationType relationType = RelationType.Size) { if (comp == null) { return; } if (comp.numChildren > 0) { GObject[] childrenArr = comp.GetChildren(); for (int i = 0, len = childrenArr.Length; i < len; i++) { GObject child = childrenArr[i]; child.AddRelation(comp, relationType); SetAllChildrenRelation(child.asCom, relationType); } } }
public void FanHand() { // -(x/(0.5 *len - 1) -1)^2 + 1 Func <float, int, float> yPosFn = (x, len) => Mathf.Pow(1 - x / (0.5f * (len - 1)), 2f); // (x/0.5 - 1)^3 Func <float, int, float> rotationFn = (x, len) => ((2 * x) / (len - 1)) - 1; float ySpacing = 20; float maxTilt = 10f; float handWidth = 600; float cardWidth = 380 * 0.7f; float xOffset = (g_handComp.width - handWidth - cardWidth) / 2; var hands = g_handComp.GetChildren(); Vector3 pos; Vector3 rotation; if (hands.Length == 1) { pos = Vector3.zero; rotation = Vector3.zero; hands[0].SetXY(pos.x + xOffset, pos.y); hands[0].rotation = rotation.z; } else { for (int i = 0; i < hands.Length; i++) { pos = new Vector3( ((float)i / (hands.Length)) * handWidth, yPosFn(i, hands.Length) * ySpacing, -i); rotation = new Vector3(0, 0, rotationFn(i, hands.Length) * maxTilt); hands[i].SetXY(pos.x + xOffset, pos.y); hands[i].rotation = rotation.z; } } }
static void CollectUIElements(string dlg, GComponent comp, Info info) { GObject[] children = comp.GetChildren(); for (int i = 0; i < children.Length; i++) { GObject child = children[i]; string name = child.name; int pos = name.IndexOf('_'); bool isGroup = false; if (pos > 1) { string prefix = name.Substring(0, pos); if (prefixs.ContainsKey(prefix)) { int typev = prefixs[prefix]; isGroup = typev == 2; Type type = child.GetType(); var property = type.GetProperty(prefix); FieldInfo field = new FieldInfo(); field.Name = name; string cType = child.GetType().ToString(); field.Type = cType; string nType = "FairyGUI.G" + prefix; if (cType != nType) { Debug.LogErrorFormat("[{0}]{1}的类型({2})与实际需求({3})不匹配", dlg, name, cType, nType); } info.Fields.Add(field); } } if (!isGroup && child.asCom != null && child.asCom.numChildren > 0) { CollectUIElements(dlg + 1, child.asCom, info); } child.Dispose(); } comp.Dispose(); }
void FreshMap(THClimbTower.EventType type, params object[] Param) { Map map = Param[0] as Map; foreach (GComponent g in GTile.GetChildren()) { Tile t = g.data as Tile; if (map.NowTile.tileStatus == Tile.TileStatusEnum.OnTile) { g.GetTransition("t1").Stop(); } else if (map.CanMove(t)) { g.GetTransition("t1").Play(); } else { g.GetTransition("t1").Play(); g.GetTransition("t1").Stop(); } } }
/// <summary> /// 遍历获得子节点 /// </summary> /// <param name="parent"></param> /// <param name="childName"></param> /// <returns></returns> public static GComponent GetChild(GComponent parent, string childName) { GComponent comp = parent.GetChild(childName) as GComponent; if (comp != null) { return(comp); } GComponent obj = null; foreach (GObject child in parent.GetChildren()) { if (child is GComponent) { obj = GetChild(child as GComponent, childName); if (obj != null) { break; } } } return(obj); }