//关键对象使用前更新 public void UpdateKeyObject() { keyObject.transform.localPosition += new Vector3(0, 0, -300); //坐标前移 up = keyObject.GetComponent <UIPanel>(); newpanel = up == null ? true : false; if (up == null) { up = keyObject.AddComponent <UIPanel>(); //获取panel } UIDragPanelContents uidpc = keyObject.GetComponent <UIDragPanelContents>(); if (uidpc != null) { uidpc.enabled = false; //关闭dragpanel } UIButtonOffset ubo = keyObject.GetComponent <UIButtonOffset>(); if (ubo != null) { Destroy(ubo); } keyObject.SetActive(false); keyObject.SetActive(true); }
private void InitUIComponentReferences() { UnGainLabel = FindUIObject <UILabel>("UnGainLabel"); GainedBtnLabel = FindUIObject <UILabel>("GainedBtnLabel"); UnReachLabel = FindUIObject <UILabel>("UnReachLabel"); CountTimeLabel = FindUIObject <UILabel>("CountTimeLabel"); TimeLabel = FindUIObject <UILabel>("TimeLabel"); UnGainBackground = FindUIObject <UISprite>("UnGainBackground"); GainedBtnBackground = FindUIObject <UISprite>("GainedBtnBackground"); UnReachBackground = FindUIObject <UISprite>("UnReachBackground"); CountTimeBackground = FindUIObject <UISprite>("CountTimeBackground"); GoodsItemSprite = FindUIObject <UISprite>("GoodsItemSprite"); UnGainBtn = FindUIObject <UIButton>("UnGainBtn"); GainedBtn = FindUIObject <UIButton>("GainedBtn"); UnReachBtn = FindUIObject <UIButton>("UnReachBtn"); CountTimeBtn = FindUIObject <UIButton>("CountTimeBtn"); RewardListItemUI = FindUIObject <UIDragPanelContents>("RewardListItemUI"); GoodsList = FindUIObject <UIGrid>("GoodsList"); Disable(UnReachBtn); Disable(UnReachBtn); Disable(CountTimeBtn); Disable(GainedBtn); ActiveRedio(UnGainBtn); }
protected override void Init() { base.Init(); base.Hide(); Dictionary <string, KGiftData> giftAllData = KConfigFileManager.GetInstance().giftTabFile.getAllData(); List <KGiftData> levelAndCombatGiftDataList = new List <KGiftData>(); foreach (KGiftData giftData in giftAllData.Values) { if (giftData.eType == KGiftType.gtLevel || giftData.eType == KGiftType.gtCombat) { levelAndCombatGiftDataList.Add(giftData); } } levelAndCombatGiftDataList.Sort( delegate(KGiftData k1, KGiftData k2) { int compare = k1.nCombatLimit - k2.nCombatLimit; if (compare == 0) { return(k1.nLevelLimit - k2.nLevelLimit); } else { return(compare); } } ); foreach (KGiftData giftData in levelAndCombatGiftDataList) { UIDragPanelContents uiDragPanelContents = (UIDragPanelContents)UnityEngine.Object.Instantiate(base.GiftItem, base.GiftItem.transform.position, base.GiftItem.transform.rotation); uiDragPanelContents.transform.localScale = base.GiftItem.transform.lossyScale; GiftItem giftItem = uiDragPanelContents.gameObject.AddComponent <GiftItem>(); giftItem.Init(giftData); if (giftData.eType == KGiftType.gtLevel) { uiDragPanelContents.transform.parent = base.LevelList.gameObject.transform; LevelGiftItemList.Add(giftItem); } else if (giftData.eType == KGiftType.gtCombat) { uiDragPanelContents.transform.parent = base.CombatList.gameObject.transform; CombatGiftItemList.Add(giftItem); } } base.GiftItem.gameObject.SetActive(false); base.LevelList.sorted = false; base.LevelList.repositionNow = true; base.CombatList.sorted = false; base.CombatList.repositionNow = true; this.isListChanged = true; }
void Start() { MasterGrid = this.transform.GetComponent <UIGrid>(); AchievementDisplay display = achievePrefab.GetComponent <AchievementDisplay>(); GameObject newAchievementObj = null; for (int j = 0; j < Achievements.Length; j++) { //Fill achievements with current info Debug.Log("AAUNITY/ACHIEVEMENT Achievement " + Achievements[j].Name + " is unlocked=" + db.isUnlocked(j + 1)); if (db.isUnlocked(j + 1)) { Debug.Log("AAUNITY/ACHIEVEMENT Now set setting " + Achievements[j].Name + " to full progress of " + Achievements[j].TargetProgress); Achievements[j].SetProgress(Achievements[j].TargetProgress); } if (j >= 39 || (j >= 27 && j <= 29)) //for store and lifetime achievements show current progress { Achievements[j].SetProgress((float)db.getProgress(j + 1)); } // Get UI Label for name in child obj and set it to Achievments[j].name // Do this for description, points, and target display.nameLabel.text = Achievements[j].Name; display.descriptionLabel.text = Achievements[j].Description; display.targetLabel.text = Achievements[j].getProgress().ToString() + " / " + Achievements[j].TargetProgress.ToString(); Debug.Log("AAUNITY/ACHIEVEMENT Achievement " + Achievements[j].Name + " is Earned? " + Achievements[j].Earned); if (Achievements[j].Earned) { display.earned.SetActive(true); display.unearned.SetActive(false); } else { display.earned.SetActive(false); display.unearned.SetActive(true); } dragPanelContents = achievePrefab.GetComponent <UIDragPanelContents>(); dragPanelContents.draggablePanel = MasterDragPanel; newAchievementObj = NGUITools.AddChild(MasterGrid.gameObject, achievePrefab.gameObject); } MasterGrid.Reposition(); ValidateAchievements(); UpdateRewardPointTotals(); }
//关键对象使用后更新 public void RecoverKeyObject() { if (keyObject == null) { return; } keyObject.transform.localPosition += new Vector3(0, 0, 300); //坐标还原 if (newpanel && up != null) { Destroy(keyObject.GetComponent <UIPanel>()); //销毁panel } UIDragPanelContents uidpc = keyObject.GetComponent <UIDragPanelContents>(); if (uidpc != null) { uidpc.enabled = true; //重启dragpanel } keyObject = null; }
protected override void Init() { base.Init(); base.Hide(); Dictionary <string, KGiftData> GiftAllData = KConfigFileManager.GetInstance().giftTabFile.getAllData(); List <KGiftData> onlineGiftDataList = new List <KGiftData>(); foreach (KGiftData giftData in GiftAllData.Values) { if (giftData.eType == KGiftType.gtOnlineTime) { onlineGiftDataList.Add(giftData); } } onlineGiftDataList.Sort( delegate(KGiftData k1, KGiftData k2) { return(k1.nOnlineTime - k2.nOnlineTime); } ); foreach (KGiftData onlineGiftData in onlineGiftDataList) { UIDragPanelContents uiDragPanelContents = (UIDragPanelContents)UnityEngine.Object.Instantiate(base.GiftItem, base.GiftItem.transform.position, base.GiftItem.transform.rotation); uiDragPanelContents.transform.localScale = base.GiftItem.transform.lossyScale; uiDragPanelContents.transform.parent = base.GiftList.gameObject.transform; GiftItem giftItem = uiDragPanelContents.gameObject.AddComponent <GiftItem>(); giftItem.Init(onlineGiftData); OnlineGiftItemList.Add(giftItem); } base.GiftItem.gameObject.SetActive(false); base.GiftList.sorted = false; base.GiftList.repositionNow = true; }
// Awake private void Awake() { m_DragPanelContents = this.gameObject.GetComponent<UIDragPanelContents>(); }
//private Dictionary<ArmyType, GameObject> m_ArmyPrefabsDict; //private Dictionary<MercenaryType, GameObject> m_MercenaryPrefabsDict; //private Dictionary<PropsType, GameObject> m_PropsPrefabsDict; void Start() { Dictionary <ArmyType, List <RecordUserCommand <ArmyIdentity> > > armies = BattleRecorder.Instance.DropArmies; Dictionary <MercenaryType, List <RecordUserCommand <MercenaryIdentity> > > mercenaries = BattleRecorder.Instance.DropMercenaries; List <KeyValuePair <PropsType, int> > props = BattleRecorder.Instance.UseProps; /* * this.m_ArmyPrefabsDict = new Dictionary<ArmyType, GameObject>(){ * {ArmyType.Berserker, this.m_BerserkerPrefab}, * {ArmyType.Ranger, this.m_RangerPrefab}, * {ArmyType.Marauder, this.m_MarauderPrefab} * }; * this.m_MercenaryPrefabsDict = new Dictionary<MercenaryType, GameObject>() * { * {MercenaryType.Slinger, this.m_MercenarySlingerPrefab}, * {MercenaryType.Hercules, this.m_MercenaryHerculesPrefab}, * {MercenaryType.Kodo, this.m_MercenaryKodoPrefab}, * {MercenaryType.HerculesII, this.m_MercenaryHerculesIIPrefab}, * {MercenaryType.KodoII, this.m_MercenaryKodoIIPrefab}, * {MercenaryType.Arsonist, this.m_MercenaryArsonistPrefab}, * {MercenaryType.ArsonistII, this.m_MercenaryArsonistIIPrefab}, * {MercenaryType.PhalanxSoldier, this.m_MercenaryPhalanxSoldierPrefab}, * {MercenaryType.Catapults, this.m_MercenaryCatapultsPrefab}, * {MercenaryType.CrazyKodo, this.m_MercenaryCrazyKodoPrefab} * }; * this.m_PropsPrefabsDict = new Dictionary<PropsType, GameObject>() * { * {PropsType.DamageBottle, this.m_PropsDamageBottlePrefab}, * {PropsType.ArmyBerserkerExcellent, this.m_PropsArmyBerserkerExcellentPrefab}, * {PropsType.ArmyBerserkerSophisticated, this.m_PropsArmyBerserkerSophisticatedPrefab}, * {PropsType.ArmyBerserkerEpic, this.m_PropsArmyBerserkerEpicPrefab}, * {PropsType.ArmyBerserkerLegend, this.m_PropsArmyBerserkerLegendPrefab}, * {PropsType.ArmyRangerExcellent, this.m_PropsArmyRangerExcellentPrefab}, * {PropsType.ArmyRangerSophisticated, this.m_PropsArmyRangerSophisticatedPrefab}, * {PropsType.MercenaryArsonistExcellent, this.m_PropsMercenaryArsonistExcellentPrefab}, * {PropsType.MercenaryCrazyKodoExcellent, this.m_PropsMercenaryCrazyKodoExcellentPrefab}, * {PropsType.MercenaryCrazyKodoSophisticated, this.m_PropsMercenaryCrazyKodoSophisticatedPrefab} * }; */ foreach (ArmyType type in armies.Keys) { GameObject armyInformation = GameObject.Instantiate(this.m_ArmyPrefabs[type.ToString()]) as GameObject; armyInformation.name = type.GetUIGridSortString() + "_" + armyInformation.name; armyInformation.transform.parent = this.m_Grid.transform; DropArmyInformation info = armyInformation.GetComponent <DropArmyInformation>(); info.Level = ((ConstructArmyCommand)armies[type][0].ConstructCommand).Level; info.Quantity = armies[type].Count; UIDragPanelContents panelContent = armyInformation.GetComponentInChildren <UIDragPanelContents>(); panelContent.draggablePanel = this.m_Panel; } foreach (MercenaryType type in mercenaries.Keys) { GameObject mercenaryInformation = GameObject.Instantiate(this.m_MercenaryPrefabs[type.ToString()]) as GameObject; mercenaryInformation.name = type.GetUIGridSortString() + "_" + mercenaryInformation.name; mercenaryInformation.transform.parent = this.m_Grid.transform; DropMercenaryInformation info = mercenaryInformation.GetComponent <DropMercenaryInformation>(); info.Quantity = mercenaries[type].Count; UIDragPanelContents panelContent = mercenaryInformation.GetComponentInChildren <UIDragPanelContents>(); panelContent.draggablePanel = this.m_Panel; } foreach (KeyValuePair <PropsType, int> p in props) { GameObject propsInformation = GameObject.Instantiate(this.m_PropsPrefabs[p.Key.ToString()]) as GameObject; propsInformation.name = p.Key.GetUIGridSortString() + "_" + propsInformation.name; propsInformation.transform.parent = this.m_Grid.transform; DropPropsInformation info = propsInformation.GetComponent <DropPropsInformation>(); info.Quantity = p.Value; UIDragPanelContents panelContent = propsInformation.GetComponentInChildren <UIDragPanelContents>(); panelContent.draggablePanel = this.m_Panel; } this.m_Grid.repositionNow = true; }
private void AdjustmentAllItem(List <Tab_LevelAwardSimulate> celllist, Transform par) { if (par != null && celllist != null && GameManager.gameManager.ActivityRewardGetDic != null) { int num = celllist.Count; UIDraggablePanel udp = par.GetComponentInParent <UIDraggablePanel>(); int count = commonGo.Count; if (num > count) { for (int i = num - count; i > 0; --i) { GameObject go = GameObject.Instantiate(ItemPerObj) as GameObject; if (go != null) { go.transform.localPosition = Vector3.zero; commonGo.Add(go); Transform tf = go.transform.Find("LingquButton"); if (tf != null) { UIEventListener.Get(tf.gameObject).onClick = ItemClick; } for (int j = 1; j < 5; ++j) { tf = go.transform.Find("IconItem/Grid/Icon_" + j); if (tf != null) { UIEventListener.Get(tf.gameObject).onClick = TipClick; } } } } } clickDic.Clear(); count = commonGo.Count; for (int i = 0; i < count; ++i) { GameObject go = commonGo[i]; if (go != null) { if (i < num) { //NGUITools.SetActive(go, true); go.transform.name = i.ToString(); go.transform.parent = par; go.transform.localPosition = Vector3.zero; go.transform.localScale = Vector3.one; clickDic.Add(go, celllist[i]); SetItemInfo(go.transform, celllist[i], i); UIDragPanelContents udpc = go.GetComponentInChildren <UIDragPanelContents>(); if (udpc != null) { udpc.draggablePanel = udp; } } else { //NGUITools.SetActive(go, false); } } } UIGrid ug = par.GetComponent <UIGrid>(); if (ug != null) { ug.repositionNow = true; } } }
void Start() { MasterGrid = this.transform.GetComponent<UIGrid>(); AchievementDisplay display = achievePrefab.GetComponent<AchievementDisplay>(); GameObject newAchievementObj = null; for (int j = 0; j < Achievements.Length; j++) { //Fill achievements with current info Debug.Log ("AAUNITY/ACHIEVEMENT Achievement " + Achievements[j].Name + " is unlocked=" + db.isUnlocked(j+1)); if(db.isUnlocked(j+1)) { Debug.Log("AAUNITY/ACHIEVEMENT Now set setting " + Achievements[j].Name + " to full progress of " + Achievements[j].TargetProgress); Achievements[j].SetProgress(Achievements[j].TargetProgress); } if(j >= 39 || (j >= 27 && j <= 29)) //for store and lifetime achievements show current progress Achievements[j].SetProgress((float)db.getProgress(j+1)); // Get UI Label for name in child obj and set it to Achievments[j].name // Do this for description, points, and target display.nameLabel.text = Achievements[j].Name; display.descriptionLabel.text = Achievements[j].Description; display.targetLabel.text = Achievements[j].getProgress().ToString() + " / " + Achievements[j].TargetProgress.ToString(); Debug.Log ("AAUNITY/ACHIEVEMENT Achievement " + Achievements[j].Name + " is Earned? " + Achievements[j].Earned); if(Achievements[j].Earned) { display.earned.SetActive(true); display.unearned.SetActive(false); } else { display.earned.SetActive(false); display.unearned.SetActive(true); } dragPanelContents = achievePrefab.GetComponent<UIDragPanelContents>(); dragPanelContents.draggablePanel = MasterDragPanel; newAchievementObj = NGUITools.AddChild(MasterGrid.gameObject, achievePrefab.gameObject); } MasterGrid.Reposition(); ValidateAchievements(); UpdateRewardPointTotals(); }
// Use this for initialization void Start() { UIPanel clipPanel = this.GetComponentInChildren <UIPanel>(); this.m_MinimunButtonCount = (int)(clipPanel.clipRange.x / this.m_Grid.cellWidth); /* * this.m_ArmyPrefabDict = new Dictionary<ArmyType, GameObject>(){ * {ArmyType.Berserker, this.m_BerserkerArmyButtonPrefab}, * {ArmyType.Ranger, this.m_RangerArmyButtonPrefab}, * {ArmyType.Marauder, this.m_MarauderArmyButtonPrefab} * }; * this.m_MercenaryPrefabDict = new Dictionary<MercenaryType, GameObject>(){ * {MercenaryType.Slinger, this.m_MercenarySlingerButtonPrefab}, * {MercenaryType.Hercules, this.m_MercenaryHerculesButtonPrefab}, * {MercenaryType.Kodo, this.m_MercenaryKodoButtonPrefab}, * {MercenaryType.HerculesII, this.m_MercenaryHerculesIIButtonPrefab}, * {MercenaryType.KodoII, this.m_MercenaryKodoIIButtonPrefab}, * {MercenaryType.Arsonist, this.m_MercenaryArsonistButtonPrefab}, * {MercenaryType.ArsonistII, this.m_MercenaryArsonistIIButtonPrefab}, * {MercenaryType.PhalanxSoldier, this.m_MercenaryPhalanxSoldierButtonPrefab}, * {MercenaryType.Catapults, this.m_MercenaryCatapultsButtonPrefab}, * {MercenaryType.CrazyKodo, this.m_MercenaryCrazyKodoButtonPrefab} * }; * this.m_PropsPrefabDict = new Dictionary<PropsType, GameObject>(){ * {PropsType.DamageBottle, this.m_PropsDamageBottleButtonPrefab}, * {PropsType.ArmyBerserkerExcellent, this.m_PropsArmyBerserkerExcellentButtonPrefab}, * {PropsType.ArmyBerserkerSophisticated, this.m_PropsArmyBerserkerSophisticatedButtonPrefab}, * {PropsType.ArmyBerserkerEpic, this.m_PropsArmyBerserkerEpicButtonPrefab}, * {PropsType.ArmyBerserkerLegend, this.m_PropsArmyBerserkerLegendButtonPrefab}, * {PropsType.ArmyRangerExcellent, this.m_PropsArmyRangerExcellentButtonPrefab}, * {PropsType.ArmyRangerSophisticated, this.m_PropsArmyRangerSophisticatedButtonPrefab}, * {PropsType.MercenaryArsonistExcellent, this.m_PropsMercenaryArsonistExcellentButtonPrefab}, * {PropsType.MercenaryCrazyKodoExcellent, this.m_PropsMercenaryCrazyKodoExcellentButtonPrefab}, * {PropsType.MercenaryCrazyKodoSophisticated, this.m_PropsMercenaryCrazyKodoSophisticatedButtonPrefab} * }; */ List <KeyValuePair <ArmyType, List <ArmyIdentity> > > availableArmies = this.AvailableArmies; if (availableArmies != null) { foreach (KeyValuePair <ArmyType, List <ArmyIdentity> > armies in availableArmies) { GameObject armyButton = GameObject.Instantiate(this.m_ArmyPrefabs[armies.Key.ToString()]) as GameObject; armyButton.transform.parent = this.m_Grid.transform; armyButton.GetComponentInChildren <UICheckbox>().radioButtonRoot = this.m_Grid.transform; armyButton.name = armies.Key.GetUIGridSortString() + "_" + armyButton.name; ArmyButtonInformation info = armyButton.GetComponent <ArmyButtonInformation>(); info.Type = armies.Key; info.ArmyLevel = this.ArmyLevel[armies.Key]; info.Armies = armies.Value; this.m_TotalArmyCount += armies.Value.Count; UIDragPanelContents contents = armyButton.GetComponentInChildren <UIDragPanelContents>(); contents.draggablePanel = this.m_Panel; } } SortedDictionary <int, KeyValuePair <MercenaryType, List <MercenaryIdentity> > > availableMercenaries = new SortedDictionary <int, KeyValuePair <MercenaryType, List <MercenaryIdentity> > >(); if (this.AvailableMercenaries != null) { foreach (KeyValuePair <MercenaryType, List <MercenaryIdentity> > mercenary in this.AvailableMercenaries) { availableMercenaries.Add(ClientConfigConstants.Instance.GetMercenaryOrder(mercenary.Key), mercenary); } SortedDictionary <int, KeyValuePair <MercenaryType, List <MercenaryIdentity> > > .Enumerator en = availableMercenaries.GetEnumerator(); while (en.MoveNext()) { KeyValuePair <MercenaryType, List <MercenaryIdentity> > mercenaries = en.Current.Value; GameObject mercenaryButton = GameObject.Instantiate(this.m_MercenaryPrefabs[mercenaries.Key.ToString()]) as GameObject; mercenaryButton.transform.parent = this.m_Grid.transform; mercenaryButton.GetComponentInChildren <UICheckbox>().radioButtonRoot = this.m_Grid.transform; mercenaryButton.name = mercenaries.Key.GetUIGridSortString() + "_" + mercenaryButton.name; MercenaryButtonInformation info = mercenaryButton.GetComponent <MercenaryButtonInformation>(); info.Type = mercenaries.Key; info.Armies = mercenaries.Value; this.m_TotalMercenaryCount += mercenaries.Value.Count; UIDragPanelContents contents = mercenaryButton.GetComponentInChildren <UIDragPanelContents>(); contents.draggablePanel = this.m_Panel; } } List <KeyValuePair <PropsType, List <int> > > availableProps = this.AvailableProps; if (availableProps != null) { foreach (KeyValuePair <PropsType, List <int> > props in availableProps) { GameObject propsButton = GameObject.Instantiate(this.m_PropsPrefabs[props.Key.ToString()]) as GameObject; propsButton.transform.parent = this.m_Grid.transform; propsButton.GetComponentInChildren <UICheckbox>().radioButtonRoot = this.m_Grid.transform; propsButton.name = props.Key.GetUIGridSortString() + "_" + propsButton.name; PropsButtonInformation info = propsButton.GetComponent <PropsButtonInformation>(); info.Type = props.Key; info.Armies = props.Value; this.m_TotalPropsCount += props.Value.Count; UIDragPanelContents contents = propsButton.GetComponentInChildren <UIDragPanelContents>(); contents.draggablePanel = this.m_Panel; } } /* * foreach (int propsNo in LogicController.Instance.AvailableBattleProps) * { * PropsLogicData logicData = LogicController.Instance.GetProps(propsNo); * * GameObject propsButton = GameObject.Instantiate(this.m_PropsPrefabs[logicData.PropsType.ToString()]) as GameObject; * propsButton.transform.parent = this.m_Grid.transform; * * propsButton.GetComponentInChildren<UICheckbox>().radioButtonRoot = this.m_Grid.transform; * propsButton.name = logicData.PropsType.GetUIGridSortString() + "_" + propsButton.name; * * PropsButtonInformation info = propsButton.GetComponent<PropsButtonInformation>(); * info.Type = logicData.PropsType; * info.Armies = new List<int>(); * for(int i = 0; i < logicData.RemainingUseTime; i ++) * { * info.Armies.Add(propsNo); * } * * this.m_TotalPropsCount += logicData.RemainingUseTime; * * UIDragPanelContents contents = propsButton.GetComponentInChildren<UIDragPanelContents>(); * contents.draggablePanel = this.m_Panel; * } * * * foreach(KeyValuePair<ItemType, List<ItemIdentity>> items in LogicController.Instance.AvailableItems) * { * GameObject itemButton = GameObject.Instantiate(this.m_ItemButtonPrefab) as GameObject; * itemButton.transform.parent = this.m_Grid.transform; * * itemButton.GetComponentInChildren<UICheckbox>().radioButtonRoot = this.m_Grid.transform; * } */ int validButtonCount = this.m_Grid.transform.childCount; if (validButtonCount > this.m_MinimunButtonCount) { //this.m_Panel.dragEffect = UIDraggablePanel.DragEffect.MomentumAndSpring; } else { for (int i = 0; i < this.m_MinimunButtonCount - validButtonCount; i++) { GameObject placeHolderButton = GameObject.Instantiate(this.m_PlaceHolderPrefab) as GameObject; placeHolderButton.transform.parent = this.m_Grid.transform; placeHolderButton.transform.localPosition = Vector3.zero; } //this.m_Panel.dragEffect = UIDraggablePanel.DragEffect.Momentum; } this.m_Grid.repositionNow = true; }