public void updateListItem(GameObject destroyObject) { if (destroyObject.GetComponent <UIAnchor>().side == UIAnchor.Side.TopLeft) // item dau { GameObject deleteItem = tempListDragonItem.transform.GetChild(0).gameObject; UIAnchor uiAnchorDeleteItem = deleteItem.GetComponent <UIAnchor>(); UIStretch uiStretchDeleteItem = deleteItem.GetComponent <UIStretch>(); if (tempListDragonItem.transform.childCount > 1) { GameObject secondItem = tempListDragonItem.transform.GetChild(1).gameObject; UIAnchor uiAnchorSecondItem = secondItem.GetComponent <UIAnchor>(); UIStretch uiStretchSecondItem = secondItem.GetComponent <UIStretch>(); uiAnchorSecondItem.container = uiAnchorDeleteItem.container; uiAnchorSecondItem.side = uiAnchorDeleteItem.side; uiAnchorSecondItem.relativeOffset = uiAnchorDeleteItem.relativeOffset; uiStretchSecondItem.container = uiStretchDeleteItem.container; secondItem.transform.localPosition = deleteItem.transform.localPosition; secondItem.GetComponent <UIWidget>().pivot = UIWidget.Pivot.TopLeft; } AutoDestroy.Destroy(destroyObject); } else { } }
//这个调用clear无效!子弹是走对象池的! public override void clear() { this.bulletEntity = null; this.clientRunTime.removeClientView(this); AutoDestroy auto = this.GetComponent <AutoDestroy>(); if (!this._isEnabled) { return; } if (this.gameObject.activeSelf) { if (null != auto) { auto.enabled = true; this.changeView(false); } else { this.gameObject.SetActive(false); } } else { //就为了触发那个OnDisable 有可能因为追时间或者子弹瞬间消失 this.gameObject.SetActive(true); this.gameObject.SetActive(false); } }
private void ObjToMax() { //特效达到最大值 GameObject obj = GameObject.Instantiate(InsoulUpEffect); obj.transform.SetParent(Ins_content.transform); obj.transform.localPosition = new Vector3(0, 0, 0); obj.transform.localScale = new Vector3(1, 1, 1); obj.gameObject.SetActive(true); AutoDestroy destory = obj.GetComponent <AutoDestroy>(); destory.delay = 1000; destory.enabled = true; Queue <GameObject> Inseffobjlist = new Queue <GameObject>(); foreach (Transform child in Ins_content.transform) { Inseffobjlist.Enqueue(child.gameObject); } int count = Inseffobjlist.Count; int max = GeneralConfigInfo.defaultConfig.InsoulMax; for (int i = 0; i < count - max; i++) { Inseffobjlist.Dequeue().SetActive(false); } }
public override void StartSkill(float speed) { if (this.lightning == null) { UnityEngine.Object.Destroy(this); return; } Skill component = base.gameObject.GetComponent <Skill>(); if (!component || !component.startGo || component.targetGos.Count == 0) { UnityEngine.Object.Destroy(this); return; } GameObject gameObject = component.startGo; for (int i = 0; i < component.targetGos.Count; i++) { GameObject gameObject2 = UnityEngine.Object.Instantiate <GameObject>(this.lightning); AutoDestroy autoDestroy = gameObject2.AddComponent <AutoDestroy>(); autoDestroy.lifetime = this.deleteDelay; LineRenderer[] componentsInChildren = gameObject2.GetComponentsInChildren <LineRenderer>(); for (int j = 0; j < componentsInChildren.Length; j++) { componentsInChildren[j].SetVertexCount(2); componentsInChildren[j].SetPosition(0, gameObject.transform.position); componentsInChildren[j].SetPosition(1, component.targetGos[i].transform.position); } gameObject = component.targetGos[i]; } UnityEngine.Object.Destroy(this); }
void reset() { AutoDestroy.destroyChildren(PlayPanel.Instance.Tutorial); PlayPanel.Instance.Tutorial.SetActive(false); Time.timeScale = PlayerInfo.Instance.userInfo.timeScale; isEnable = false; }
void OnEnable() { AutoDestroy auto = this.gameObject.GetComponent <AutoDestroy>(); if (null != auto) { auto.enabled = false; } }
private void WO_Loot_OnDestroy() { _destroy?.Destroy(); _view.ClearSubscriptions(); _server.Room.Destroy(_view); _view = null; _onwer = null; _destroy = null; }
/// <summary> /// 播放过场。 /// </summary> /// <param name="path">过场动画路径。</param> public void TryPlayerCutScene(LuaTable cfg) { //上一个动画还未结束 if (Time.realtimeSinceStartup < m_LastPlayStopTime) { return; } //首次播放检查 int id = cfg.Get <int>("id"); if (cfg.Get <int>("time") == TRIGGER_TIME_ONCE) { if (IsHavePlay(id)) { return; } else { SetHavePlay(id); } } //播放动画 GameObject prefab = (GameObject)CoreEntry.gResLoader.Load(cfg.Get <string>("animation"), typeof(GameObject)); if (prefab == null) { LogMgr.LogError("加载过场动画失败 path:{0}", cfg.Get <string>("animation")); return; } GameObject obj = GameObject.Instantiate(prefab) as GameObject; USSequencer us = obj.GetComponent <USSequencer>(); if (us == null) { LogMgr.LogError("播放场动画失败,未找到USSequencer组建 path:{0}", cfg.Get <string>("animation")); return; } us.PlaybackFinished += OnAniEnd; m_CurID = id; OnAniStart(us); //保存结束时间,在次期间不再播动画 float duration = 0; AutoDestroy ad = obj.GetComponent <AutoDestroy>(); if (ad != null) { duration = ad.Delay; } m_LastPlayStopTime = Time.realtimeSinceStartup + duration; #if UNITY_EDITOR LogMgr.Log("播放过场动画 duration:{0} path:{1}", duration, cfg.Get <string>("animation")); #endif }
//获取实例化资源的地方(同步方式加载预设) public GameObject RGet(string bundleName, string assetName, ELoadType loadType, GameObject parent = null) { if (string.IsNullOrEmpty(bundleName)) { return(null); } string strFullBundleName = BundleLoaderManager.GetBundleName(bundleName, loadType); string strFullAssetName = BundleLoaderManager.GetAssertName(bundleName, assetName, ABPathHelper.PrefabSuffix, loadType); //Debug.Log("<color=yellow>资源:bundleName: " + strFullBundleName + " assetName: " + strFullAssetName + "</color>"); Object source = null; #if UNITY_EDITOR if (GameUtils.ScriptLoad && loadType == ELoadType.UI) { source = UnityEditor.AssetDatabase.LoadAssetAtPath(strFullAssetName, typeof(UnityEngine.Object)); } else #endif { source = BundleLoaderManager.Instance.Load(strFullBundleName, strFullAssetName, loadType); } if (source is GameObject) { GameObject go = GameObject.Instantiate(source) as GameObject; MaterialUtils.ResetGameObjectMaterials(go); if (loadType == ELoadType.UI) { AutoDestroy autoDestroyCom = go.GetComponent <AutoDestroy>(); if (autoDestroyCom == null) { autoDestroyCom = go.AddComponent <AutoDestroy>(); } } go.name = go.name.Replace("(Clone)", ""); int nBundleId = strFullBundleName.GetHashCode(); m_AllGameObjects.Add(go, nBundleId); if (parent != null) { go.transform.parent = parent.transform; go.transform.localPosition = Vector3.zero; go.transform.localScale = Vector3.one; go.transform.localRotation = Quaternion.identity; } return(go); } else { Debug.Log("<color=red> object is null: " + strFullAssetName + "\n" + "</color>"); } return(null); }
// Use this for initialization void Awake() { this.rb = this.GetComponent <Rigidbody2D> (); tween = null; particlesCharge = this.GetComponentInChildren <ParticleSystem> (); particlesCharge.gameObject.SetActive(false); anim = this.GetComponent <Animator>(); autoDestroy = this.GetComponent <AutoDestroy> (); autoDestroy.enabled = false; }
public void loadEnemy() { AutoDestroy.destroyChildren(selectedRegionPanel); infoTower.gameObject.SetActive(false); infoEnemy.gameObject.SetActive(true); guideType = UIGuideButton.ENEMY; target = null; //set grid UIGrid grid = selectedRegionPanel.GetComponent <UIGrid>(); grid.maxPerLine = PlayConfig.GridGuideEnemy.MaxPerLine; grid.cellWidth = PlayConfig.GridGuideEnemy.CellWidth; grid.cellHeight = PlayConfig.GridGuideEnemy.CellHeight; grid.enabled = true; grid.repositionNow = true; EnemyController enemyController = Resources.Load <GameObject>("Prefab/Enemy/Enemy").GetComponent <EnemyController>(); int length = enemies.Length; foreach (System.Collections.Generic.KeyValuePair <string, EnemyData> iterator in ReadDatabase.Instance.EnemyInfo) { GameSupportor.transferEnemyData(enemyController, iterator.Value); GameObject enemyGuide = Instantiate(PlayManager.Instance.modelPlay.EnemyGuide) as GameObject; enemyGuide.transform.parent = selectedRegionPanel.transform; enemyGuide.name = enemyController.name; enemyGuide.GetComponent <UIStretch>().container = selectedRegionPanel; EnemyGuideController controller = enemyGuide.GetComponent <EnemyGuideController>(); controller.ID = enemyController.ID; controller.visible = PlayerInfo.Instance.listEnemy[enemyController.ID]; //set icon if (controller.visible) { controller.Icon.mainTexture = Resources.Load <Texture>("Image/Enemy/00 Guide Icon/" + enemyController.ID.ToLower()); } if (target == null && controller.visible) { target = enemyGuide; } } if (target != null) { target.GetComponent <EnemyGuideController>().setColor(true); } loadEnemyInfo(); }
public override void OnInspectorGUI() { DrawDefaultInspector(); EditorGUILayout.Separator(); AutoDestroy autoDestroy = target as AutoDestroy; if (GUILayout.Button("Auto Destroy")) { autoDestroy.AutoDestroyObject(); } }
// Use this for initialization public override void Awake() { base.Awake(); if (bodyComponent == null) { bodyComponent = GetComponent <Rigidbody2D>(); } if (destructionComponent == null) { destructionComponent = GetComponent <AutoDestroy>(); } }
private void WO_Loot_OnSpawn() { if (_resource == null) { return; } _view = _server.Room.Instantiate(_resource, _position, _rotation); _view.SubscribeToRpc(50, 52, RPC_50_52); _view.GettingPosition += View_GettingPosition; _view.GettingRotation += View_GettingRotation; _view.CheckVisibility += View_CheckVisibility; _view.RebuildVisibility(); _destroy = new AutoDestroy(this, TimeSpan.FromSeconds(Constants.LootDespawnTime)); }
static int get_lifetime(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); AutoDestroy obj = (AutoDestroy)o; float ret = obj.lifetime; LuaDLL.lua_pushnumber(L, ret); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o, "attempt to index lifetime on a nil value")); } }
static int get_onDestroyCallback(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); AutoDestroy obj = (AutoDestroy)o; System.Action ret = obj.onDestroyCallback; ToLua.Push(L, ret); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o, "attempt to index onDestroyCallback on a nil value")); } }
static int set_lifetime(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); AutoDestroy obj = (AutoDestroy)o; float arg0 = (float)LuaDLL.luaL_checknumber(L, 2); obj.lifetime = arg0; return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o, "attempt to index lifetime on a nil value")); } }
protected override void preInit() { base.preInit(); this.mainBody = this.gameObject.transform; if (this.isNullBullet) { AutoDestroy auto = this.gameObject.GetComponent <AutoDestroy>(); if (null != auto) { ResFactory.Destroy(auto); } } else { this._particles = new List <ParticleSystem>(this.GetComponentsInChildren <ParticleSystem>()).ConvertAll <ParticleReset>((p) => { return(new ParticleReset(p)); }); } }
static int set_onDestroyCallback(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); AutoDestroy obj = (AutoDestroy)o; System.Action arg0 = (System.Action)ToLua.CheckDelegate <System.Action>(L, 2); obj.onDestroyCallback = arg0; return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o, "attempt to index onDestroyCallback on a nil value")); } }
public void OnShowMessageOver() { // m_isPlaying = false; m_quiltGO.SetActive(true); m_bed.SetActive(false); CursorManager.SetCursor(CursorManager.CursorState.DEFAULT); NotifyActionOverEvent(); if (m_ghost == null) { return; } m_ghost.SetActive(true); AudioManager.Instance.PlayAudio(m_ghostAudio, false); AutoDestroy adCtr = m_ghost.AddComponent <AutoDestroy>(); adCtr.AutoDestroyAfterSeconds(m_ghostAudio.length); }
public IEnumerator SpawnGhost_C(GameObject visualsToDuplicate, Material ghostMaterial, float effectDuration, float ghostLifetime, float ghostSpawnInterval, float time) { if (time <= effectDuration || effectDuration < 0) { GameObject dup = Instantiate(visualsToDuplicate); dup.transform.position = visualsToDuplicate.transform.position; dup.transform.rotation = visualsToDuplicate.transform.rotation; //Freezes the animator of the ghost Animator potentialAnimator = dup.GetComponentInChildren <Animator>(); if (potentialAnimator != null) { potentialAnimator.speed = 0; } //Removes useless components Component[] componentList = dup.GetComponentsInChildren(typeof(Component)); foreach (Component c in componentList) { if (c.GetType() != typeof(MeshRenderer) && c.GetType() != typeof(Animator) && c.GetType() != typeof(MeshFilter) && c.GetType() != typeof(Transform) && c.GetType() != typeof(Light)) { Destroy(c); } } //Apply ghost material MeshRenderer[] meshRenderers = dup.GetComponentsInChildren <MeshRenderer>(); foreach (MeshRenderer mr in meshRenderers) { mr.material = ghostMaterial; } AutoDestroy autoDestroyer = dup.AddComponent <AutoDestroy>(); autoDestroyer.InitAutoDestruction(ghostLifetime); yield return(new WaitForSeconds(ghostSpawnInterval)); time += ghostSpawnInterval; yield return(StartCoroutine(SpawnGhost_C(visualsToDuplicate, ghostMaterial, effectDuration, ghostLifetime, ghostSpawnInterval, time))); } }
public static GameObject getCacheEffect(string name, ClientRunTime clientRunTime, bool visible = true) { GameObject result = null; if (!effectMap.ContainsKey(name)) { effectMap[name] = new List <GameObject>(); } List <GameObject> gameObjects = effectMap[name]; if (gameObjects.Count > 0) { int len = gameObjects.Count - 1; result = gameObjects[len]; gameObjects.RemoveAt(len); } else { result = ResFactory.getEffect(name); if (null == result) { Debug.Log("没有资源" + name); } result = ResFactory.createObject <GameObject>(result); result.AddComponent <CacheEffect>().clientRunTime = clientRunTime; result.name = name; AutoDestroy auto = result.GetComponent <AutoDestroy>(); if (auto != null) { auto.onlyDeactivate = true; } } if (visible) { result.gameObject.SetActive(true); //有些要延迟生效 就不给他visible等于true。 } return(result); }
void initAchievement() { AutoDestroy.destroyChildren(tempAchievement, "Collider Drag", "Scroll Bar"); int i = 0; foreach (System.Collections.Generic.KeyValuePair <int, AchievementData> iterator in ReadDatabase.Instance.AchievementInfo) { GameObject achievement = Instantiate(LevelManager.Instance.Model.Achievement) as GameObject; achievement.transform.parent = tempAchievement.transform; achievement.transform.localScale = Vector3.one; //Anchor UIAnchor uiAnchor = achievement.GetComponent <UIAnchor>(); uiAnchor.container = tempAchievement; uiAnchor.relativeOffset = new Vector2(LevelConfig.AnchorAchievementX, LevelConfig.AnchorAchievementY - i * LevelConfig.AnchorAchievementDistanceY); //Stretch achievement.GetComponent <UIStretch>().container = tempAchievement; //Drag object achievement.GetComponent <UIDragScrollView>().scrollView = tempAchievement.GetComponent <UIScrollView>(); AchievementController controller = achievement.GetComponent <AchievementController>(); controller.spriteIcon.spriteName = iterator.Value.Icon; controller.labelName.text = iterator.Value.Name; controller.labelSub.text = LevelConfig.getAchievementTextValue(iterator.Key, iterator.Value, PlayerInfo.Instance.listAchievement[iterator.Key]); controller.labelReward.text = iterator.Value.RewardAmount.ToString(); controller.completeIcon.SetActive(false); checkAchievement(controller, iterator.Key, iterator.Value, PlayerInfo.Instance.listAchievement[iterator.Key]); i++; } }
// Use this for initialization public override void Awake() { if (alreadyAwaked) { return; } base.Awake(); CircleCollider2D planetCollider = GetComponent <CircleCollider2D>(); if (planetCollider) { GetComponent <CircleCollider2D>().radius = GetRadius; } if (gravitationalField == null) { GetComponentInChildren <CircleCollider2D>(); } if (gravitationalField != null) { gravFieldRadius = gravitationalField.radius; } if (signal == null) { signal = GetComponent <SignalEmitter>(); } if (autoDestroyComponent == null) { autoDestroyComponent = GetComponent <AutoDestroy>(); } }
private void OnCollisionEnter(Collision collision) { if (!bCanExplode) { return; } bCanExplode = false; Vector3 explosionPos = transform.position; if (GameManager.instance.enableParticleEffect) { GameObject explosionFX = Instantiate(explosionFXPrefab, explosionPos, Quaternion.identity); explosionFX.transform.localScale = new Vector3(explosionRadius, explosionRadius, explosionRadius); explosionFX.transform.localScale /= 4.0f; if (!GameManager.instance.enableSoundEffect) { explosionFX.GetComponent <AudioSource>().enabled = false; } } if (GameManager.instance.enableCameraShake) { EZCameraShake.CameraShaker.Instance.ShakeOnce(3, 4, 0.1f, 1); } Collider[] colliders = Physics.OverlapSphere(explosionPos, explosionRadius); foreach (Collider hit in colliders) { if (hit.gameObject.layer == GameManager.instance.enemyLayer) { Enemy enemy = hit.GetComponent <Enemy>(); if (enemy != null) { Rigidbody[] partRBs = enemy.OnDamage(1); if (partRBs != null) { foreach (Rigidbody partRB in partRBs) { if (partRB != null) { partRB.AddExplosionForce(explosionPower, explosionPos, explosionRadius, 3.0F); } } } } } AutoDestroy AD = hit.GetComponent <AutoDestroy>(); if (AD != null) { AD.OnHit(); } Rigidbody rb = hit.GetComponent <Rigidbody>(); if (rb != null) { rb.AddExplosionForce(explosionPower, explosionPos, explosionRadius, 3.0F); } } }
void initalize() { #region DRAGON ITEM AutoDestroy.destroyChildren(tempListDragonItem, null); //Debug.Log(ReadDatabase.Instance.DragonItemInfo.Count); int i = 0; GameObject DragonItemBefore = null; float rowItemBefore = 0f; #region Code cũ foreach (System.Collections.Generic.KeyValuePair <string, DragonItemData> iterator in ReadDatabase.Instance.DragonInfo.Item) { GameObject dragonItem = Instantiate(Resources.Load <GameObject>("Prefab/Level/Dragon Item")) as GameObject; dragonItem.transform.parent = tempListDragonItem.transform; dragonItem.transform.localScale = Vector3.one; //set ID dragonItem.GetComponent <DragonItemsController>().ID = iterator.Key; //lay du lieu bonus tu item string bonusText = ""; //int OptionInRow = 0; // 2 se xuong dong float row = 0f; for (int j = 0; j < iterator.Value.Options.Length; j++) { if (iterator.Value.Options[j] > 0) { bonusText += DragonItemData.nameOptions[j] + "+" + iterator.Value.Options[j].ToString(); bonusText += "\n"; row++; } } bonusText = bonusText.Substring(0, bonusText.Length - 1); // bo /n cuoi cung, do hon xet if trong vong lap //Anchor UIAnchor uiAnchor = dragonItem.GetComponent <UIAnchor>(); //Stretch UIStretch uiStretch = dragonItem.GetComponent <UIStretch>(); if (i == 0) // Phan tu dau neo theo cha { uiAnchor.container = tempListDragonItem; uiStretch.container = tempListDragonItem; uiStretch.relativeSize = new Vector2(uiStretch.relativeSize.x, row / 10); dragonItem.GetComponent <UIDragScrollView>().scrollView = tempListDragonItem.GetComponent <UIScrollView>(); } else // cac phan tu sau noi duoi voi nhau { uiAnchor.container = DragonItemBefore; uiAnchor.relativeOffset.y = -0.52f; uiAnchor.side = UIAnchor.Side.Center; // dragonItem.GetComponent<UIWidget>().pivot = UIWidget.Pivot.Top; uiStretch.container = DragonItemBefore; uiStretch.relativeSize = new Vector2(uiStretch.relativeSize.x, row / rowItemBefore); dragonItem.GetComponent <UIDragScrollView>().scrollView = DragonItemBefore.GetComponent <UIScrollView>(); } #endregion #region code thu nghiem //foreach (System.Collections.Generic.KeyValuePair<int, DragonItemData> iterator in ReadDatabase.Instance.DragonItemInfo) //{ // GameObject dragonItem = Instantiate(LevelManager.Instance.Model.DragonItem) as GameObject; // dragonItem.transform.parent = tempListDragonItem.transform; // dragonItem.transform.localScale = Vector3.one; // //lay du lieu bonus tu item // string bonusText = ""; // //int OptionInRow = 0; // 2 se xuong dong // float row = 0f; // for (int j = 0; j < iterator.Value.Options.Length; j++) // { // if (iterator.Value.Options[j] > 0) // { // bonusText += DragonItemData.nameOptions[j] + "+" + iterator.Value.Options[j].ToString(); // bonusText += "\n"; // row++; // } // } // bonusText = bonusText.Substring(0,bonusText.Length - 2); // bo /n cuoi cung, do hon xet if trong vong lap // //Stretch // UIStretch uiStretch = dragonItem.GetComponent<UIStretch>(); // uiStretch.container = tempListDragonItem; // uiStretch.relativeSize = new Vector2(uiStretch.relativeSize.x, row / 10); // dragonItem.GetComponent<UIDragScrollView>().scrollView = tempListDragonItem.GetComponent<UIScrollView>(); // float currentPosY = 0f; // if (i == 0) // currentPosY = dragonItem.GetComponentInParent<UIPanel>().height / 2 - dragonItem.GetComponent<UIWidget>().height / 2; // else // currentPosY = beforePositionY - dragonItem.GetComponent<UIWidget>().height / 2; // dragonItem.transform.localPosition = new Vector3(0, currentPosY, 0); // Debug.Log(dragonItem.transform.localPosition); #endregion switch (iterator.Value.Name.Substring(iterator.Value.Name.LastIndexOf(' ') + 1)) { case "Head": dragonItem.GetComponent <UIDragonItems>().dragonItemType = DragonItemType.Head; break; case "Body": dragonItem.GetComponent <UIDragonItems>().dragonItemType = DragonItemType.Body; break; case "Ring": dragonItem.GetComponent <UIDragonItems>().dragonItemType = DragonItemType.Ring; break; case "Amulet": dragonItem.GetComponent <UIDragonItems>().dragonItemType = DragonItemType.Amulet; break; case "Wing": dragonItem.GetComponent <UIDragonItems>().dragonItemType = DragonItemType.Wing; break; case "Rune": dragonItem.GetComponent <UIDragonItems>().dragonItemType = DragonItemType.Rune; break; } dragonItem.transform.GetChild(0).gameObject.GetComponent <UILabel>().text = iterator.Value.Name; dragonItem.transform.GetChild(1).gameObject.GetComponent <UILabel>().text = bonusText; dragonItem.transform.GetChild(2).gameObject.GetComponent <UISprite>().spriteName = iterator.Value.Icon; dragonItem.SetActive(true); DragonItemBefore = dragonItem; rowItemBefore = row; listItems.Add(iterator.Key, dragonItem); i++; } #endregion #region LOAD DATABASE string dataHead = PlayerInfo.Instance.dragonInfo.itemHead; string dataWing = PlayerInfo.Instance.dragonInfo.itemWing; string dataRing = PlayerInfo.Instance.dragonInfo.itemRing; string dataAmulet = PlayerInfo.Instance.dragonInfo.itemAmulet; string dataBody = PlayerInfo.Instance.dragonInfo.itemBody; string dataRune = PlayerInfo.Instance.dragonInfo.itemRune; if (!dataHead.Equals("")) { GameObject item = listItems[dataHead]; item.GetComponent <UIDragonItems>().EquipItem(); } if (!dataWing.Equals("")) { GameObject item = listItems[dataWing]; item.GetComponent <UIDragonItems>().EquipItem(); } if (!dataRing.Equals("")) { GameObject item = listItems[dataRing]; item.GetComponent <UIDragonItems>().EquipItem(); } if (!dataAmulet.Equals("")) { GameObject item = listItems[dataAmulet]; item.GetComponent <UIDragonItems>().EquipItem(); } if (!dataBody.Equals("")) { GameObject item = listItems[dataBody]; item.GetComponent <UIDragonItems>().EquipItem(); } if (!dataRune.Equals("")) { GameObject item = listItems[dataRune]; item.GetComponent <UIDragonItems>().EquipItem(); } #endregion }
public void loadInfoTower() { if (target != null) { AutoDestroy.destroyChildren(infoPanel, PlayNameHashIDs.Collider); //active tower name if (!labelTowerName.gameObject.activeSelf) { labelTowerName.gameObject.SetActive(true); } TowerShopController targetController = target.GetComponent <TowerShopController>(); labelTowerName.text = targetController.Name.text.ToUpper() + " TOWER"; //Set towe name color Color[] nameColor = PlayConfig.getColorTowerName(targetController.ID); labelTowerName.color = nameColor[0]; labelTowerName.effectColor = nameColor[1]; STowerID towerID = targetController.ID; GameObject[] towers = ObjectManager.Instance.Towers; int length = towers.Length; int count = 0; for (int i = 0; i < length; i++) { TowerController towerController = towers[i].GetComponent <TowerController>(); if (towerController.ID.Type == towerID.Type && towerController.ID.Level == towerID.Level) { while (true) { GameObject info = Instantiate(towerInfoModel) as GameObject; info.transform.parent = infoPanel.transform; info.transform.localScale = Vector3.one; info.name = towerController.name; UIAnchor anchor = info.GetComponent <UIAnchor>(); anchor.container = infoPanel.gameObject; anchor.relativeOffset = new Vector2(0, PlayConfig.InfoShopAnchor.PanelAnchorStart - count * PlayConfig.InfoShopAnchor.PanelAnchorDistance); #region TOWER TowerShopInfoController infoController = info.GetComponent <TowerShopInfoController>(); infoController.icon.mainTexture = Resources.Load <Texture>(PlayConfig.getTowerIcon(towerID)); infoController.level.text = "Level " + ((int)towerID.Level).ToString(); infoController.atk.text = towerController.attribute.MinATK.ToString() + " - " + towerController.attribute.MaxATK.ToString(); infoController.spawnShoot.text = towerController.attribute.SpawnShoot.ToString(); infoController.timeBuild.text = towerController.attribute.TimeBuild.ToString(); //Bullet label string[] str = PlayConfig.getBulletType(towerController.attackType.ToString()); infoController.bulletAbility.text = str[0] + " TARGET"; infoController.bulletRegion.text = str[1]; //set icon fix size infoController.icon.keepAspectRatio = UIWidget.AspectRatioSource.Free; Vector2 localSize = new Vector2(infoController.icon.mainTexture.width, infoController.icon.mainTexture.height); infoController.icon.SetDimensions((int)localSize.x, (int)localSize.y); infoController.icon.keepAspectRatio = UIWidget.AspectRatioSource.BasedOnHeight; UIStretch uiStretch = infoController.icon.GetComponent <UIStretch>(); uiStretch.enabled = true; #endregion #region BULLET object[] bulletData = PlayConfig.getBulletShop(towerID); infoController.bulletIcon.mainTexture = Resources.Load <Texture>("Image/Bullet/Bullet Icon/" + bulletData[0].ToString()); infoController.bulletIcon.keepAspectRatio = UIWidget.AspectRatioSource.Free; infoController.bulletIcon.SetDimensions(infoController.bulletIcon.mainTexture.width, infoController.bulletIcon.mainTexture.height); infoController.bulletIcon.keepAspectRatio = UIWidget.AspectRatioSource.BasedOnHeight; UIStretch stretch = infoController.bulletIcon.GetComponent <UIStretch>(); stretch.relativeSize.y = (float)bulletData[1]; stretch.enabled = true; //Add effect infoController.bullet = towerController.bullet; #endregion count++; //get Next Tower if (towerController.nextLevel != null) { towerID = towerController.nextLevel.GetComponent <TowerController>().ID; towerController = towerController.nextLevel; } else { break; } } break; } } } }
public void loadItem() { if (shopType == EShopType.ITEM) { return; } shopType = EShopType.ITEM; target = null; AutoDestroy.destroyChildren(towerPanel, PlayNameHashIDs.Collider); towerPanel.transform.localPosition = Vector3.zero; towerPanel.GetComponent <UIPanel> ().clipOffset = Vector2.zero; setSpriteButton(EShopType.ITEM); int i = 0; foreach (System.Collections.Generic.KeyValuePair <string, ItemData> item in ReadDatabase.Instance.ItemInfo) { GameObject _itemShop = Instantiate(itemShopModel) as GameObject; _itemShop.transform.parent = towerPanel.transform; _itemShop.transform.localScale = Vector3.one; UIAnchor anchor = _itemShop.GetComponent <UIAnchor>(); anchor.container = towerPanel.gameObject; anchor.relativeOffset = new Vector2(PlayConfig.TowerShopAnchor.PanelAnchorStart + i * PlayConfig.TowerShopAnchor.PanelAnchorDistance, 0); ItemShopController itemShopController = _itemShop.GetComponent <ItemShopController>(); itemShopController.ID = item.Key; itemShopController.ItemState = ItemManager.getItemState(item.Key); //set name string[] arr = item.Value.Name.Split('-'); string text = ""; string mainName = ""; for (int k = 0; k < arr.Length; k++) { text += arr[k]; mainName += arr[k] + " "; if (k + 1 < arr.Length) { text += "\n"; } } text = text.Trim(); mainName = mainName.Trim(); itemShopController.Name.text = text; itemShopController.MainName = mainName; //set text value itemShopController.Value.text = item.Value.ValueText; //set background stretch foreach (Transform child in _itemShop.transform) { if (child.name == "Background") { child.GetComponent <UIStretch>().container = towerPanel; break; } } //set icon itemShopController.icon.spriteName = "item-" + item.Key.ToLower(); itemShopController.setColor(false); itemShopController.icon.keepAspectRatio = UIWidget.AspectRatioSource.Free; itemShopController.icon.SetDimensions(itemShopController.icon.mainTexture.width, itemShopController.icon.mainTexture.height); itemShopController.icon.keepAspectRatio = UIWidget.AspectRatioSource.BasedOnHeight; UIStretch uiStretch = itemShopController.icon.GetComponent <UIStretch>(); uiStretch.enabled = true; if (target == null) { target = _itemShop; } i++; } if (target != null) { target.GetComponentInChildren <ItemShopController>().setColor(true); } loadInfoItem(); }
public void loadInfoItem() { if (target != null) { AutoDestroy.destroyChildren(infoPanel, PlayNameHashIDs.Collider); //active tower name if (!labelTowerName.gameObject.activeSelf) { labelTowerName.gameObject.SetActive(true); } ItemShopController targetController = target.GetComponent <ItemShopController>(); labelTowerName.text = targetController.MainName; //Set name color labelTowerName.color = PlayConfig.ColorShopItemName; labelTowerName.effectColor = PlayConfig.ColorShopItemNameOutline; GameObject info = Instantiate(itemShopInfoModel) as GameObject; info.transform.parent = infoPanel.transform; info.transform.localScale = Vector3.one; info.GetComponent <UIAnchor>().container = infoPanel.gameObject; info.GetComponent <UIStretch>().container = infoPanel.gameObject; //Set value ItemShopInfoController infoController = info.GetComponent <ItemShopInfoController>(); infoController.icon.spriteName = targetController.icon.spriteName; infoController.value.text = targetController.Value.text; //set icon fix size infoController.icon.keepAspectRatio = UIWidget.AspectRatioSource.Free; infoController.icon.SetDimensions(infoController.icon.mainTexture.width, infoController.icon.mainTexture.height); infoController.icon.keepAspectRatio = UIWidget.AspectRatioSource.BasedOnHeight; //set package ItemData itemData = ReadDatabase.Instance.ItemInfo[targetController.ID]; int length = itemData.Packages.Count; for (int i = 0; i < length; i++) { ItemPackage itemPackage = (ItemPackage)itemData.Packages[i]; ItemShopPackageController packageController = infoController.packages[i].GetComponent <ItemShopPackageController>(); packageController.labelDiamond.text = itemPackage.Diamond.ToString(); packageController.labelGold.text = itemPackage.Gold.ToString(); int result = -1; if (int.TryParse(itemPackage.Wave, out result)) { if (result <= 1) { packageController.labelDuration.text = "Duration: " + result + " wave"; } else { packageController.labelDuration.text = "Duration: " + result + " waves"; } } else { if (itemPackage.Wave.Equals("Half")) { packageController.labelDuration.text = "Duration: " + WaveController.Instance.infoMap.WaveLength / 2 + " waves"; } else if (itemPackage.Wave.Equals("Full")) { packageController.labelDuration.text = "Duration: all waves"; } } } } }
private static GameObject generateTriangularPiece(GameObject source, List <Vector2> tri, Vector2 origVelocity, Vector3 origScale, Quaternion origRotation, Material mat) { //Create Game Object and set transform settings properly GameObject piece = new GameObject(source.name + " piece"); piece.transform.position = source.transform.position; piece.transform.rotation = source.transform.rotation; piece.transform.localScale = source.transform.localScale; //Create and Add Mesh Components MeshFilter meshFilter = (MeshFilter)piece.AddComponent(typeof(MeshFilter)); piece.AddComponent(typeof(MeshRenderer)); Mesh uMesh = piece.GetComponent <MeshFilter>().sharedMesh; if (uMesh == null) { meshFilter.mesh = new Mesh(); uMesh = meshFilter.sharedMesh; } Vector3[] vertices = new Vector3[3]; int[] triangles = new int[3]; vertices[0] = new Vector3(tri[0].x, tri[0].y, 0); vertices[1] = new Vector3(tri[1].x, tri[1].y, 0); vertices[2] = new Vector3(tri[2].x, tri[2].y, 0); triangles[0] = 0; triangles[1] = 1; triangles[2] = 2; uMesh.vertices = vertices; uMesh.triangles = triangles; if (source.GetComponent <SpriteRenderer>() != null) { uMesh.uv = calcUV(vertices, source.GetComponent <SpriteRenderer>(), source.transform); } else { uMesh.uv = calcUV(vertices, source.GetComponent <MeshRenderer>(), source.transform); } //set transform properties before fixing the pivot for easier rotation piece.transform.localScale = origScale; piece.transform.localRotation = origRotation; Vector3 diff = calcPivotCenterDiff(piece); centerMeshPivot(piece, diff); uMesh.RecalculateBounds(); //setFragmentMaterial(piece, source); piece.GetComponent <MeshRenderer>().sharedMaterial = mat; //assign mesh meshFilter.mesh = uMesh; //Create and Add Polygon Collider PolygonCollider2D collider = piece.AddComponent <PolygonCollider2D>(); collider.SetPath(0, new Vector2[] { uMesh.vertices[0], uMesh.vertices[1], uMesh.vertices[2] }); //Create and Add Rigidbody Rigidbody2D rigidbody = piece.AddComponent <Rigidbody2D>(); rigidbody.velocity = origVelocity; rigidbody.mass = 0.1f; AutoDestroy autoDestroy = piece.AddComponent <AutoDestroy>(); autoDestroy.time = 4f; return(piece); }