private void Start() { //we multiply by 2 since we want the bottom of the background to hit the screenTop //for such, the top of the background has to hit two the size of the screen top. screenTop = ScreenPositionService.GetTopEdge(Camera.main).y * 2; currentBackgroundContext = BackgroundContextEnum.Surface_1; currentBackground = BackgroundService.GetBackground(backgroundsPool, currentBackgroundContext); BackgroundService.SetPropsForBackgroundContext(backgroundPropsPool, ref currentBackground); StartCoroutine(SlideBackground()); }
void Start() { currentContextProps = BackgroundService.SetPropsForBackgroundContext(propsPool, currentBackgroundContext, maxPropsAmount, backgroundDisplay); for (int i = 0; i < currentContextProps.Count; i++) { currentContextProps[i].gameObject.SetActive(true); } ChangeBackgroundColor(); lastBackground = BackgroundService.GetLastBackground(); }
public static Transform GetBackground(Transform backgroundsPool, BackgroundContextEnum context) { foreach (Transform bckg in backgroundsPool) { if (bckg.name == context.ToString()) { return(bckg); } } return(null); }
public static BackgroundContextEnum GetNextContext(BackgroundContextEnum currentContext, int maxBackgroundVal, ref int maxAmount) { int ctxVal = currentContext.GetHashCode(); //has reached last level if (ctxVal == maxBackgroundVal) { return(currentContext); } int nextVal = ctxVal + 1; if (nextVal == maxBackgroundVal) { //Abyss can have only 1 abyssal monster maxAmount = 1; } return((BackgroundContextEnum)nextVal); }
void Update() { //Has loaded next context and still has props from previous background //Wait until all props have been unloaded. if (HasPropsFromPreviousBackground() && hasNextContextLoaded) { return; } else if (!HasPropsFromPreviousBackground() && hasNextContextLoaded) { SwapPropsToCurrentContext(); } if (currentBackgroundContext == lastBackground) { return; } //Randomize props for this context if (!HasPropsFromPreviousBackground() && !hasNextContextLoaded) { currentContextProps = BackgroundService.SetPropsForBackgroundContext(propsPool, currentBackgroundContext, maxPropsAmount, backgroundDisplay); for (int i = 0; i < currentContextProps.Count; i++) { currentContextProps[i].SetActive(true); } } backgroundTickTime += Time.deltaTime; if (backgroundTickTime >= timeToChangeBackground) { currentBackgroundContext = BackgroundService.GetNextContext(currentBackgroundContext, lastBackground.GetHashCode(), ref maxPropsAmount); LoadNextBackground(); } }
public static List <GameObject> SetPropsForBackgroundContext(Transform backgroundPropsPool, BackgroundContextEnum currentContext, int maxProps, Transform backgroundDisplay) { List <GameObject> props = new List <GameObject>(); var possiblePropsContexts = BackgroundPropsLevel.GetBackgroundPropLevel()[currentContext]; List <Transform> contextsPools = new List <Transform>(); //Find context in pool foreach (Transform item in backgroundPropsPool) { if (possiblePropsContexts.minLevel == item.name || possiblePropsContexts.maxLevel == item.name) { contextsPools.Add(item); } } for (int i = 0; i < maxProps; i++) { int ctxVal = RandomValueTool.GetRandomValue(0, contextsPools.Count - 1); var child = GetChild(contextsPools[ctxVal], backgroundDisplay); if (child != null) { props.Add(child.gameObject); } } return(props); }