// Use this for initialization void Awake() { for (int i = 0; i < binders.Length; i++) { EventToTrigger ett = binders[i]; SuperFunction.SuperFunctionCallBack0 del = delegate(int _index) { Reset(); animator.SetTrigger(ett.trigger); }; SuperFunction.Instance.AddEventListener(target, ett.eventName, del); } }
public void Init(TurrentCreater _parent) { parent = _parent; float fieldWidth = (transform as RectTransform).rect.width; float width = fieldWidth / (BattleConst.MAP_WIDTH * 2 - 1); float scale = width / (cellRes.transform as RectTransform).sizeDelta.x; for (int i = 0; i < BattleConst.MAP_HEIGHT; i++) { for (int m = 0; m < BattleConst.MAP_WIDTH * 2 - 1; m++) { TurrentCreaterCell cell = Instantiate(cellRes); cell.x = m - (BattleConst.MAP_WIDTH - 1); cell.y = i; cell.gameObject.SetActive(true); cell.transform.SetParent(transform, false); cell.transform.localScale = new Vector3(scale, scale, 1); (cell.transform as RectTransform).anchoredPosition = new Vector2(0.5f * fieldWidth - width * 0.5f - m * width, 0.5f * width + i * width + yFix); cellDic.Add(new KeyValuePair <int, int>(cell.x, cell.y), cell); SuperFunction.SuperFunctionCallBack0 dele = delegate(int _index) { ClickCell(cell); }; SuperFunction.Instance.AddEventListener(cell.gameObject, BattleClickGo.EVENT_NAME, dele); } } }
private void InitCards() { List <int> handCards = battle.GetHandCards(); if (handCards.Count > 0) { float screenWidth = (transform.root as RectTransform).sizeDelta.x; float screenHeight = (transform.root as RectTransform).sizeDelta.y; Vector2 size = (cardRes.transform as RectTransform).sizeDelta; float x = (screenWidth - handCards.Count * size.x - (handCards.Count - 1) * cardGap) * 0.5f + size.x * 0.5f - 0.5f * screenWidth; float y = -0.5f * screenHeight + size.y * 0.5f; bool getSelectedCard = false; for (int i = 0; i < handCards.Count; i++) { int uid = handCards[i]; int id = battle.GetCard(battle.clientIsMine, uid); BattleCard card; if (cards.Count == i) { card = Instantiate(cardRes); card.gameObject.SetActive(true); card.transform.SetParent(battleContainer, false); SuperFunction.SuperFunctionCallBack0 dele = delegate(int _index) { ClickCard(card); }; SuperFunction.Instance.AddEventListener(card.gameObject, BattleClickGo.EVENT_NAME, dele); cards.Add(card); } else { card = cards[i]; } (card.transform as RectTransform).anchoredPosition = new Vector2(x + i * (size.x + cardGap), y); card.Init(uid, id); if (card.uid == nowSelectedCardUid) { getSelectedCard = true; } } if (!getSelectedCard) { nowSelectedCardUid = -1; } else { RefreshSelectedCard(); } } else { nowSelectedCardUid = -1; } while (cards.Count > handCards.Count) { Destroy(cards[cards.Count - 1].gameObject); cards.RemoveAt(cards.Count - 1); } }
private void InitPos() { float screenWidth = (transform.root as RectTransform).sizeDelta.x; float screenHeight = (transform.root as RectTransform).sizeDelta.y; float width = screenWidth / BattleConst.MAP_WIDTH; for (int i = 0; i < BattleConst.MAP_HEIGHT; i++) { for (int m = 0; m < BattleConst.MAP_WIDTH; m++) { int id = i * BattleConst.MAP_WIDTH + m; BattleCell go = Instantiate(mPosRes); go.gameObject.SetActive(true); go.SetHintVisible(false); float scale = width / (go.transform as RectTransform).sizeDelta.x; go.transform.localScale = new Vector3(scale, scale, 1); go.transform.SetParent(battleContainer, false); mPosArr[id] = go; (go.transform as RectTransform).anchoredPosition = new Vector2(-0.5f * screenWidth + width * 0.5f + m * width, -0.5f * turrentGap - 0.5f * width - i * width + yFix); SuperFunction.SuperFunctionCallBack0 dele = delegate(int _index) { ClickMyPos(id); }; SuperFunction.Instance.AddEventListener(go.gameObject, BattleClickGo.EVENT_NAME, dele); } } mBase = Instantiate(baseRes); mBase.transform.SetParent(battleContainer, false); mBase.gameObject.SetActive(true); (mBase.transform as RectTransform).anchoredPosition = new Vector2(-0.5f * screenWidth + width * 0.5f + (float)(BattleConst.MAP_WIDTH - 1) / 2 * width, -0.5f * turrentGap - 0.5f * width - BattleConst.MAP_HEIGHT * width + yFix); for (int i = 0; i < BattleConst.MAP_HEIGHT; i++) { for (int m = 0; m < BattleConst.MAP_WIDTH; m++) { int id = i * BattleConst.MAP_WIDTH + m; BattleClickGo go = Instantiate(oPosRes); go.gameObject.SetActive(true); float scale = width / (go.transform as RectTransform).sizeDelta.x; go.transform.localScale = new Vector3(scale, scale, 1); go.transform.SetParent(battleContainer, false); oPosArr[id] = go; (go.transform as RectTransform).anchoredPosition = new Vector2(0.5f * screenWidth - width * 0.5f - m * width, 0.5f * turrentGap + 0.5f * width + i * width + yFix); SuperFunction.SuperFunctionCallBack0 dele = delegate(int _index) { ClickOppPos(id); }; SuperFunction.Instance.AddEventListener(go.gameObject, BattleClickGo.EVENT_NAME, dele); } } oBase = Instantiate(baseRes); oBase.transform.SetParent(battleContainer, false); oBase.gameObject.SetActive(true); (oBase.transform as RectTransform).anchoredPosition = new Vector2(0.5f * screenWidth - width * 0.5f - (float)(BattleConst.MAP_WIDTH - 1) / 2 * width, 0.5f * turrentGap + 0.5f * width + BattleConst.MAP_HEIGHT * width + yFix); }