IEnumerator DestroyDelay(Item item) { bool changeTypeFinished = false; if (item.NextType != ItemsTypes.NONE) { item.ChangeType(() => { changeTypeFinished = true; }); yield return(new WaitUntil(() => changeTypeFinished)); } if (LevelManager.THIS.DebugSettings.DestroyLog) { DebugLogKeeper.Log(name + " dontDestroyOnThisMove " + item.dontDestroyOnThisMove + " dontDestroyForThisCombine " + gameObject.GetComponent <Item>() .dontDestroyForThisCombine, DebugLogKeeper.LogType.Destroying); } if (item.dontDestroyOnThisMove || gameObject.GetComponent <Item>().dontDestroyForThisCombine) { GetComponent <Item>().StopDestroy(); yield break; } if (LevelManager.THIS.DebugSettings.DestroyLog) { DebugLogKeeper.Log(gameObject.GetInstanceID() + " destroyed " + item.name + " " + item.GetInstanceID(), DebugLogKeeper.LogType.Destroying); } OnDestroyItem(item); ObjectPooler.Instance.PutBack(gameObject); yield return(new WaitForSeconds(0)); }
void Show2DArray(ItemTemplate[] array, string name = "", bool showNow = false) { if (!_debugSettings.BonusCombinesShowLog && !showNow) { return; } var r = "array " + name + "\n"; var maxR = array.Max(i => Mathf.RoundToInt(i.position.y)) + 1; var maxC = array.Max(i => Mathf.RoundToInt(i.position.x)) + 1; for (var row = 0; row < maxR; row++) { for (var col = 0; col < maxC; col++) { r += GetItemBool(array, row, col) + ","; } r += "\n"; } if (!showNow) { DebugLogKeeper.Log(r, DebugLogKeeper.LogType.BonusAppearance); } else { Debug.Log(r); } }
public void DestroyItems(List <Item> items, Delays delays, Action callback) { if (LevelManager.THIS.DebugSettings.DestroyLog) { foreach (var item in items) { DebugLogKeeper.Log("Add to pipeline " + item, DebugLogKeeper.LogType.Destroying); } } var bunch = new DestroyBunch(); bunch.items = items.ToList(); bunch.callback = callback; bunch.delays = delays; pipeline.Add(bunch); }
public override void OnInspectorGUI() { if (GUILayout.Button("Print falling log")) { DebugLogKeeper.GetLog(((ItemDebugInspector)target).GetComponent <Item>().instanceID.ToString(), DebugLogKeeper.LogType.Falling); } if (GUILayout.Button("Print destroying log")) { DebugLogKeeper.GetLog(((ItemDebugInspector)target).GetComponent <Item>().instanceID.ToString(), DebugLogKeeper.LogType.Destroying); } if (GUILayout.Button("Print bonus log")) { DebugLogKeeper.GetLog(((ItemDebugInspector)target).GetComponent <Item>().instanceID.ToString(), DebugLogKeeper.LogType.BonusAppearance); } base.OnInspectorGUI(); }
public ItemsTypes GetBonusCombine(Combine combine, out ItemTemplate[] foundItems, ItemsTypes prioritiseItem = ItemsTypes.NONE) { if (bonusCombinesPatterns.Count < bonusCombineListCount) { FillPatterns(); } foundItems = null; var matrix = ConvertCombine(combine); var compare = SimplifyArray(matrix).matrix.ToArray(); Show2DArray(compare.ToArray(), "compare origin"); var baseNodePosition = GetBaseNode(compare); var types = new List <ItemsTypes>(); foreach (var typePattern in bonusCombinesPatterns) { foreach (var m in typePattern.matrices) { var pattern = m.DeepCopy().matrix; if (pattern.Any(i => i.position.x > 0 && i.position.y > 0)) { var offset = baseNodePosition - m.nodeItem; pattern = pattern.ForEachY(i => i.position += offset).ToList(); } Show2DArray(pattern.ToArray(), "pattern "); if (!IsCombineFound(compare, pattern.ToArray(), typePattern, ref types, out foundItems)) { continue; } Show2DArray(compare.ToArray(), "compare found"); Show2DArray(pattern.ToArray(), "pattern found"); ItemsTypes itemsTypes = GetCombineType(prioritiseItem, types); if (_debugSettings.BonusCombinesShowLog) { DebugLogKeeper.Log(itemsTypes + " detected", DebugLogKeeper.LogType.BonusAppearance); } return(itemsTypes); } } var type = GetCombineType(prioritiseItem, types); // Debug.Log(type + " detected"); return(type); }
public void Destroy(Item item1, Item item2) { if (GetItem.square.type == SquareTypes.WireBlock) { GetItem.square.DestroyBlock(); GetItem.StopDestroy(); return; } gameObject.AddComponent <GameBlocker>(); item1.destroying = true; if (LevelManager.THIS.DebugSettings.DestroyLog) { DebugLogKeeper.Log(" pre destroy " + " type " + GetItem.currentType + GetItem.GetInstanceID() + " " + item1?.GetInstanceID() + " : " + item2?.GetInstanceID(), DebugLogKeeper.LogType.Destroying); } GetParentItem().GetComponent <ItemDestroyAnimation>().DestroyPackage(item1); }
public void PutBack(GameObject obj) { if (LevelManager.THIS.DebugSettings.FallingLog) { DebugLogKeeper.Log(obj + " pooled", DebugLogKeeper.LogType.Falling); } obj.SetActive(false); // Destroy(obj); Item item = obj.GetComponent <Item>(); if (item != null) { if (item.transform.childCount > 0) { item.transform.GetChild(0).localScale = Vector3.one; } } }
// Use this for initialization void Awake() { Application.targetFrameRate = 60; Instance = this; RestLifeTimer = PlayerPrefs.GetFloat("RestLifeTimer"); DateOfExit = PlayerPrefs.GetString("DateOfExit", ""); if (DateOfExit == "" || DateOfExit == default(DateTime).ToString()) { DateOfExit = ServerTime.THIS.serverTime.ToString(); } DebugLogKeeper.Init(); Gems = PlayerPrefs.GetInt("Gems"); lifes = PlayerPrefs.GetInt("Lifes"); if (PlayerPrefs.GetInt("Lauched") == 0) { //First lauching lifes = CapOfLife; PlayerPrefs.SetInt("Lifes", lifes); Gems = FirstGems; PlayerPrefs.SetInt("Gems", Gems); PlayerPrefs.SetInt("Music", 1); PlayerPrefs.SetInt("Sound", 1); PlayerPrefs.SetInt("Lauched", 1); PlayerPrefs.Save(); } rate = Instantiate(Resources.Load("Prefabs/Rate")) as GameObject; rate.SetActive(false); rate.transform.SetParent(MenuReference.THIS.transform); rate.transform.localPosition = Vector3.zero; rate.GetComponent <RectTransform>().offsetMin = new Vector2(-5, -5); rate.GetComponent <RectTransform>().offsetMax = new Vector2(5, 5); // rate.GetComponent<RectTransform>().anchoredPosition = (Resources.Load("Prefabs/Rate") as GameObject).GetComponent<RectTransform>().anchoredPosition; rate.transform.localScale = Vector3.one; var g = MenuReference.THIS.Reward.gameObject; g.SetActive(true); g.SetActive(false); #if FACEBOOK FacebookManager fbManager = new GameObject("FacebookManager").AddComponent <FacebookManager>(); #endif }
/// <summary> /// destroy block (obstacle or jelly) /// </summary> public void DestroyBlock() { if (destroyIteration == 0) { destroyIteration = LevelManager.THIS.destLoopIterations; LeanTween.delayedCall(1, () => { destroyIteration = 0; }); } else { return; } if (GetSubSquare().undestroyable) { return; } if (LevelManager.THIS.DebugSettings.DestroyLog) { DebugLogKeeper.Log("DestroyBlock " + " " + type + " " + GetInstanceID(), DebugLogKeeper.LogType.Destroying); } if (GetSubSquare().CanGoInto()) { var sqList = GetAllNeghborsCross(); foreach (var sq in sqList) { if (!sq.GetSubSquare().CanGoInto() || (sq.Item?.currentType == ItemsTypes.SPIRAL && Item?.currentType != ItemsTypes.SPIRAL)) { sq.DestroyBlock(); } } } if (Item?.currentType == ItemsTypes.SPIRAL) { Item.DestroyItem(); } if (subSquares.Count > 0) { var subSquare = GetSubSquare(); if (type == SquareTypes.JellyBlock) { return; } if (subSquare.GetComponent <TargetComponent>() == null) { SoundBase.Instance.PlayOneShot(SoundBase.Instance.block_destroy); var itemAnim = new GameObject(); var animComp = itemAnim.AddComponent <AnimateItems>(); animComp.InitAnimation(subSquare.gameObject, new Vector2(transform.position.x, -5), subSquare.transform.localScale, null); } LevelManager.THIS.levelData.GetTargetObject().CheckSquare(new[] { this }); LevelManager.THIS.ShowPopupScore(subSquare.score, transform.position, 0); subSquares.Remove(subSquare); Destroy(subSquare.gameObject); subSquare = GetSubSquare(); if (subSquares.Count > 0) { type = subSquare.type; } if (subSquares.Count == 0) { type = SquareTypes.EmptySquare; } } if (IsFree() && Item == null) { Item = null; } }
/// <summary> /// Generate new item /// </summary> /// <returns>The item.</returns> /// <param name="falling">If set to <c>true</c> prepare for falling animation.</param> public Item GenItem(bool falling = true, ItemsTypes itemType = ItemsTypes.NONE, int color = -1) { if (IsNone() && !CanGoInto()) { return(null); } GameObject item = null; if (itemType == ItemsTypes.NONE) { if (LevelManager.THIS.collectIngredients && !IsObstacle()) { item = GetIngredientItem(); } if (!item) { item = ObjectPooler.Instance.GetPooledObject("Item"); } } else { item = ObjectPooler.Instance.GetPooledObject(itemType.ToString()); item?.GetComponent <Item>().anim?.SetTrigger("bonus_appear"); } if (item == null) { Debug.LogError("there is no " + itemType + " in pool "); } item.transform.localScale = Vector2.one * 0.42f; Item itemComponent = item.GetComponent <Item>(); itemComponent.square = this; // item.GetComponent<IColorableComponent>().RandomizeColor(); IColorableComponent colorableComponent = item.GetComponent <IColorableComponent>(); if (color == -1) { itemComponent.GenColor(); } else if (colorableComponent != null) { colorableComponent.SetColor(color); } itemComponent.field = field; itemComponent.needFall = falling; if (!falling) { item.transform.position = (Vector3)((Vector2)transform.position) + Vector3.back * 0.2f; } if (LevelManager.THIS.gameStatus != GameState.Playing && LevelManager.THIS.gameStatus != GameState.Tutorial) { Item = itemComponent; } else if (!IsHaveFallingItemsAbove()) { Item = itemComponent; } // this.item.falling = falling; if (falling) { Vector3 startPos = GetReverseDirection(); item.transform.position = transform.position + startPos * field.squareHeight + Vector3.back * 0.2f; itemComponent.JustCreatedItem = true; } if (LevelManager.THIS.DebugSettings.DestroyLog) { DebugLogKeeper.Log(name + " gen item " + item.name + " pos " + item.transform.position, DebugLogKeeper.LogType.Destroying); } itemComponent.needFall = falling; // if ((!nextSquare?.IsFree() ?? false) || Item == itemComponent) itemComponent.StartFallingTo(itemComponent.GenerateWaypoints(this)); // itemComponent.StartFalling(); return(itemComponent); }
public GameObject GetPooledObject(string tag, bool active = true, bool canBeActive = false) { ClearNullElements(); PoolBehaviour obj = null; for (int i = 0; i < pooledObjects.Count; i++) { if (pooledObjects[i] == null) { continue; } if ((!pooledObjects[i].gameObject.activeSelf || canBeActive) && pooledObjects[i].name == tag) { Item item = pooledObjects[i].GetComponent <Item>(); if (item && item.canBePooled) { obj = pooledObjects[i]; } else if (!item) { obj = pooledObjects[i]; } if (obj) { break; } } } if (itemsToPool == null) { LoadFromScriptable(); } if (!obj) { foreach (var item in itemsToPool) { if (item != null && item.objectToPool == null) { continue; } if (item.objectToPool.name == tag) { if (item.shouldExpand) { obj = CreatePooledObject(item); break; } } } } if (LevelManager.THIS.DebugSettings.FallingLog) { DebugLogKeeper.Log(obj + " unpooled", DebugLogKeeper.LogType.Falling); } if (obj != null) { obj.gameObject.SetActive(active); return(obj.gameObject); } return(null); }