// obsolete public UIPreferenceMenu GetPreference(LevelObject.ObjectType type) { UIPreferenceMenu menu = null; switch (type) { case LevelObject.ObjectType.turret: return(turretMenu); case LevelObject.ObjectType.portal: return(portalMenu); case LevelObject.ObjectType.attractor: return(attractorMenu); case LevelObject.ObjectType.speedStrip: return(speedStripMenu); case LevelObject.ObjectType.finish: return(finishMenu); case LevelObject.ObjectType.spawn: return(spawnMenu); } return(menu); }
public bool Contains(LevelObject.ObjectType type) { if (unlockedLevelObjects.Contains(type)) { return(true); } return(false); }
// removes an entry from the inventory public void Remove(LevelObject.ObjectType type) { if (unlockedLevelObjects.Contains(type)) { unlockedLevelObjects.Remove(type); } onInventoryChange.Invoke(); }
// adds a value to the given entry in the inventory, if it doesnt exist, it gets created. Can be used to substract. public void Add(LevelObject.ObjectType type, int value) { // add the value to the existing value if (!unlockedLevelObjects.Contains(type)) { unlockedLevelObjects.Add(type); } onInventoryChange.Invoke(); }
// checks for double clicks and selectes/deselects objects accordingly private void ClickHandler(Vector3 position) { bool objectSelected = false; if (LevelEditor.editorMode == LevelEditor.EditorMode.select) { // double click if (Time.time - doubleClickTime < doubleClickDelay && doubleClickTime > 0) { LevelObject levelObject = GetLevelObjectAt(position); if (levelObject != null) { Debug.Log("SELECTED OBJ " + levelObject.name); LevelEditor.SetSelectedObject(levelObject); objectSelected = true; } // the raycast didn't select any levelobjects if (!objectSelected) { Vector3 localPos = LevelPlacer.generatedLevel.moveArea.transform.InverseTransformPoint(position); bool clickInsideMesh = VertHelper.IsInsideMesh(LevelPlacer.generatedLevel.moveArea.meshFilter.mesh, Vector3.zero, localPos); // we double clicked inside the mesh => select the mesh if (clickInsideMesh) { LevelEditor.SetSelectedObject(LevelPlacer.generatedLevel.moveArea); objectSelected = true; } } } } else if (LevelEditor.editorMode == LevelEditor.EditorMode.edit) { if (Time.time - doubleClickTime < doubleClickDelay && doubleClickTime > 0) { LevelObject levelObject = GetLevelObjectAt(position); if (levelObject != null) { // same object got selected again, deselect it if (levelObject == LevelEditor.selectedObject) { LevelEditor.SetSelectedObject(null); objectSelected = true; } // a new object gets selected, replace the old selection with the new one. else if (levelObject != LevelEditor.selectedObject) { LevelEditor.SetSelectedObject(levelObject); objectSelected = true; } } // the raycast didn't select any levelobjects if (!objectSelected) { Vector3 localPos = LevelPlacer.generatedLevel.moveArea.transform.InverseTransformPoint(position); bool clickInsideMesh = VertHelper.IsInsideMesh(LevelPlacer.generatedLevel.moveArea.meshFilter.mesh, Vector3.zero, localPos); // we double clicked inside the mesh => select the mesh if (clickInsideMesh) { if (LevelEditor.selectedObject.objectType != LevelObject.ObjectType.moveArea) LevelEditor.SetSelectedObject(LevelPlacer.generatedLevel.moveArea); else LevelEditor.SetSelectedObject(null); objectSelected = true; } } } Debug.Log(LevelEditor.selectedObject); // there was no double click detected, if a movearea is selected, try to add vertices if (LevelEditor.selectedObject != null && LevelEditor.selectedObject.objectType == LevelObject.ObjectType.moveArea && !Handle.vertGettingSelected) { Vector3 screenPosition = Camera.main.WorldToScreenPoint(position); bool isInIgnoreArea = screenPosition.y < Camera.main.pixelHeight * ignoreBottomScreenPercent; if (!isInIgnoreArea) if (VertHandler._instance.VertexAdd(position)) { SoundManager.ButtonClicked(); } } } else if (LevelEditor.editorMode == LevelEditor.EditorMode.place) { // snapping Vector3 snapPos = VertHelper.Snap(position, false); LevelObject.ObjectType objectType = UILevelObject.currentSelectedObject.objectType; Vector3 screenPosition = Camera.main.WorldToScreenPoint(snapPos); bool isInIgnoreArea = screenPosition.y < Camera.main.pixelHeight * ignoreBottomScreenPercent; // the snapping found a valid snap position around the given position if (snapPos != Vector3.zero && !isInIgnoreArea) { Debug.Log("Buttom screen percent " + ignoreBottomScreenPercent + " screenPos.y " + screenPosition.y); // return to selection mode and deselect the inventory item LevelEditor.SetSelectedObject(LevelPlacer.generatedLevel.AddObject(objectType, snapPos)); UILevelObject.onItemSelect.Invoke(null); } } else if (LevelEditor.editorMode == LevelEditor.EditorMode.portalLink) { if (Time.time - doubleClickTime < doubleClickDelay && doubleClickTime > 0) { LevelObject levelObject = GetLevelObjectAt(position); if (levelObject != null) { if (levelObject.objectType == LevelObject.ObjectType.portal) { Portal p = levelObject.GetComponent<Portal>(); UIPortalMenu.SelectLinkPortal(p); } } } } doubleClickTime = Time.time; }
// add an object to the level. this step of reference is needed for later deconstruction of the level and serialization public LevelObject AddObject(LevelObject.ObjectType type, Vector3 position) { if (LevelPlacer._instance != null) { switch (type) { case LevelObject.ObjectType.turret: Turret turret = (Turret)Instantiate(LevelPlacer._instance.turretPrefab, Vector3.zero, Quaternion.identity); turret.transform.parent = LevelPlacer.generatedLevel.transform; Vector2 turretPos = new Vector3(position.x, position.y, LevelPlacer.levelObjectZ); turret.transform.position = turretPos; turrets.Add(turret); // ProgressManager.GetProgress().unlocks.inventory.Add(type, -1); UndoManager.AddUndoPoint(); return(turret); case LevelObject.ObjectType.attractor: Attractor a = (Attractor)Instantiate(LevelPlacer._instance.attractorPrefab, Vector3.zero, Quaternion.identity); a.transform.parent = LevelPlacer.generatedLevel.transform; Vector2 aPos = new Vector3(position.x, position.y, LevelPlacer.levelObjectZ); a.transform.position = aPos; attractors.Add(a); //ProgressManager.GetProgress().unlocks.inventory.Add(type, -1); UndoManager.AddUndoPoint(); return(a); case LevelObject.ObjectType.portal: Portal p = (Portal)Instantiate(LevelPlacer._instance.portalPrefab, Vector3.zero, Quaternion.identity); p.transform.parent = LevelPlacer.generatedLevel.transform; Vector2 pPos = new Vector3(position.x, position.y, LevelPlacer.levelObjectZ); p.transform.position = pPos; p.portalID = GetFreePortalID(0); p.linkedPortalID = -1; portals.Add(p); // ProgressManager.GetProgress().unlocks.inventory.Add(type, -1); UndoManager.AddUndoPoint(); return(p); case LevelObject.ObjectType.speedStrip: SpeedStrip s = (SpeedStrip)Instantiate(LevelPlacer._instance.speedStripPrefab, Vector3.zero, Quaternion.identity); s.transform.parent = LevelPlacer.generatedLevel.transform; Vector2 sPos = new Vector3(position.x, position.y, LevelPlacer.levelObjectZ); s.transform.position = sPos; s.transform.rotation = Quaternion.Euler(0, 0, 180); speedStrips.Add(s); // ProgressManager.GetProgress().unlocks.inventory.Add(type, -1); UndoManager.AddUndoPoint(); return(s); case LevelObject.ObjectType.bouncer: Bouncer b = (Bouncer)Instantiate(LevelPlacer._instance.bouncerPrefab, Vector3.zero, Quaternion.identity); b.transform.parent = LevelPlacer.generatedLevel.transform; Vector2 bPos = new Vector3(position.x, position.y, LevelPlacer.levelObjectZ); b.transform.position = bPos; b.transform.rotation = Quaternion.Euler(0, 0, 0); bouncers.Add(b); // ProgressManager.GetProgress().unlocks.inventory.Add(type, -1); UndoManager.AddUndoPoint(); return(b); default: //Debug.Log("Wasnt able to add the levelobject to the LevelDataMono of type " + lo.objectType); break; } } else { Debug.LogError("LevelPlacer needed to add an object to the level."); } return(null); }
// activates the properties menu that corresponds to the current selected object public static UIPreferenceMenu ShowMenu() { LevelObject.ObjectType type = LevelEditor.selectedObject.objectType; Debug.Log("type " + type + " - " + _instance); if (_instance != null) { UndoManager.AddUndoPoint(); switch (type) { case LevelObject.ObjectType.turret: UITurretMenu.Activate(LevelEditor.CreateLevelData()); UIPreferenceMenu.onPreferenceChange.Invoke(_instance.turretMenu); animator.ResetTrigger("showTurret"); animator.ResetTrigger("hideTurret"); animator.SetTrigger("showTurret"); Debug.Log("treeehehee " + _instance.turretMenu); menuOpen = true; openedMenuType = LevelObject.ObjectType.turret; return(_instance.turretMenu); case LevelObject.ObjectType.portal: UIPortalMenu.Activate(LevelEditor.CreateLevelData()); UIPreferenceMenu.onPreferenceChange.Invoke(_instance.portalMenu); animator.ResetTrigger("showPortal"); animator.SetTrigger("showPortal"); menuOpen = true; openedMenuType = LevelObject.ObjectType.portal; return(_instance.portalMenu); case LevelObject.ObjectType.attractor: UIAttractorMenu.Activate(LevelEditor.CreateLevelData()); UIPreferenceMenu.onPreferenceChange.Invoke(_instance.attractorMenu); animator.ResetTrigger("showAttractor"); animator.SetTrigger("showAttractor"); menuOpen = true; openedMenuType = LevelObject.ObjectType.attractor; return(_instance.attractorMenu); case LevelObject.ObjectType.speedStrip: UISpeedStripMenu.Activate(LevelEditor.CreateLevelData()); UIPreferenceMenu.onPreferenceChange.Invoke(_instance.speedStripMenu); animator.ResetTrigger("showSpeedStrip"); animator.ResetTrigger("hideSpeedStrip"); animator.SetTrigger("showSpeedStrip"); menuOpen = true; openedMenuType = LevelObject.ObjectType.speedStrip; return(_instance.speedStripMenu); case LevelObject.ObjectType.bouncer: UIBouncerMenu.Activate(LevelEditor.CreateLevelData()); UIPreferenceMenu.onPreferenceChange.Invoke(_instance.bouncerMenu); animator.ResetTrigger("showBouncer"); animator.SetTrigger("showBouncer"); menuOpen = true; openedMenuType = LevelObject.ObjectType.bouncer; return(_instance.bouncerMenu); case LevelObject.ObjectType.finish: return(_instance.finishMenu); case LevelObject.ObjectType.spawn: return(_instance.spawnMenu); } Debug.Log("HERE"); } return(null); }