private void OnDisable() { foreach (GameObject hold in holds) { if (hold != null) { ClimbARHandhold.HoldLineRendererActive(hold, false); HoldText hTextScript = hold.GetComponent <HoldText>(); SoundHold script = hold.GetComponent <SoundHold>(); Destroy(hTextScript); Destroy(script); ClimbARHandhold.DestroyChildren(hold); } } }
void attachMenuHoldToHold(Dictionary <string, GameObject> menuItems) { foreach (string menuItem in menuItems.Keys) { GameObject menuHold = menuItems[menuItem]; if (menuHold == null) { Debug.Log("No hold for menu item " + menuItem); } else { // Draw custom hold sprite for menu hold if present in Resources folder if (menuSprites[menuItem] != null) { GameObject customSpriteObject = GameObject.Instantiate(customHoldSprite); customSpriteObject.transform.SetParent(menuHold.transform); customSpriteObject.transform.localPosition = new Vector3(0, 0, 0); float radius = menuHold.GetComponent <CircleCollider2D>().radius; ClimbARHandhold.DrawHoldSprite(customSpriteObject.GetComponent <SpriteRenderer>(), menuSprites[menuItem], radius / camWidth, radius / camWidth); } // Draw line renderer otherwise else { ClimbARHandhold.HoldLineRendererActive(menuHold, true); ClimbARHandhold.setHoldColor(menuHold, UnityEngine.Color.cyan); } GameObject holdText = new GameObject(); HoldText holdTextScript = holdText.AddComponent <HoldText>(); holdTextScript.setup(menuItem, holdText, menuHold); MenuHold menuHoldScript = menuHold.AddComponent <MenuHold>(); menuHoldScript.setup(menuItem); } } }
private void OnDisable() { foreach (GameObject hold in holds) { if (hold != null) { MenuHold mHoldScript = hold.GetComponent <MenuHold>(); HoldText hTextScript = hold.GetComponent <HoldText>(); // Hide the rendered sprite hold.GetComponent <SpriteRenderer>().enabled = false; ClimbARHandhold.DestroyChildren(hold); ClimbARHandhold.HoldLineRendererActive(hold, false); hold.transform.localScale = new Vector3(0.7f, 0.7f, 0.7f); // Reset line renderer to uniform color hold.GetComponent <LineRenderer>().startColor = UnityEngine.Color.cyan; hold.GetComponent <LineRenderer>().endColor = UnityEngine.Color.cyan; Destroy(mHoldScript); Destroy(hTextScript); } } }
// Use this for initialization void Start() { holds = GameObject.FindGameObjectsWithTag("Hold"); loopManager = gameObject.GetComponent <LoopManager>(); loopManager.Setup(soundItems); // If starting directly into music scene, holds will be empty if (DEBUG) { holds = ClimbARHandhold.InstantiateHandholds(prefabHold, GetComponent <Camera>(), new float[] { 1f, 1f, 0.2f, 0.2f, 2f, 2f, 0.2f, 0.2f, 1f, 1f, 0.1f, 0.1f, 0.4f, 0.4f, 0.3f, 0.2f }); holds[0].transform.localPosition = new Vector2(-1, -1); holds[1].transform.localPosition = new Vector2(1, 1); holds[2].transform.localPosition = new Vector2(-1, 1); holds[3].transform.localPosition = new Vector2(1, -1); } // If not debugging and no holds, just return else if (holds.Length <= 0) { return; } // Otherwise we actually have holds, assign it to hold HashSet <int> usedHoldIndexes = new HashSet <int>(); HashSet <int> usedSoundIndexes = new HashSet <int>(); if (holds.Length < soundItems.Length) { Debug.Log("Not enough handholds for the number of sound items"); } for (int i = 0; i < Mathf.Min(holds.Length, soundItems.Length); i++) { GameObject soundHold = holds[i]; if (soundHold == null) { Debug.Log("no valid hold found"); } else { ClimbARHandhold.HoldLineRendererActive(soundHold, true); ClimbingHold holdScript = soundHold.GetComponent <ClimbingHold>(); Destroy(holdScript); SoundHold soundHoldScript = soundHold.AddComponent <SoundHold>(); soundHoldScript.Setup(soundItems[i], i, loopManager); loopManager.RegisterHold(soundHoldScript.holdIndex, i); soundHoldScript.GetComponent <LineRenderer>() .startColor = UnityEngine.Color.cyan; soundHoldScript.GetComponent <LineRenderer>() .endColor = UnityEngine.Color.cyan; GameObject holdText = new GameObject(); HoldText holdTextScript = holdText.AddComponent <HoldText>(); holdTextScript.addText(" " + soundItems[i], holdText, soundHold); } } }