/******************************* MOUSE CLICK MANAGER *******************************/ public void OnPointerClick(PointerEventData data) { if (!thisSlotHasACombinationPending) { if (data.button == PointerEventData.InputButton.Left) { if (Input.GetKey(KeyCode.LeftShift) && currentlyAssigned != null) { ItemCombinationHandler(); } else { MouseItemMovementAndStackHandler(); } } else if (data.button == PointerEventData.InputButton.Right) { if (mainSlotManager.GetItemInControlByMouse() == null) { if (currentlyAssigned != null) { int amountOfItemToAssign = (currentlyAssigned.stack - currentlyAssigned.stack % 2) / 2; if (amountOfItemToAssign != 0) { mainSlotManager.AssignItemToMouseControl(new ResourceReferenceWithStack(currentlyAssigned.uiSlotContent, amountOfItemToAssign)); } currentlyAssigned.stack -= amountOfItemToAssign; UpdateStackIndicator(); Debug.Log("Assigned " + amountOfItemToAssign + " of " + currentlyAssigned.uiSlotContent.itemScreenName + " to mouse control."); } } else if (mainSlotManager.GetItemInControlByMouse() != null) { if (currentlyAssigned == null) { if (mainSlotManager.GetItemInControlByMouse().stack == 1) { AssignNewItem(mainSlotManager.DeAssignItemFromMouseControl()); } else { AssignNewItem(new ResourceReferenceWithStack(mainSlotManager.GetItemInControlByMouse().uiSlotContent, 1)); mainSlotManager.ChangeStackOfItemInControlByMouse(mainSlotManager.GetItemInControlByMouse().stack - 1); } } else if (currentlyAssigned != null) { if (ScriptingUtilities.CheckUIResourceReferencesForEquality(currentlyAssigned, mainSlotManager.GetItemInControlByMouse())) { currentlyAssigned.stack += 1; UpdateStackIndicator(); mainSlotManager.ChangeStackOfItemInControlByMouse(mainSlotManager.GetItemInControlByMouse().stack - 1); } } } } } }
protected override void OnDeath() { playerHealthPanelReference.Clear(); //Note: Application.Quit() does not work for the Web Player or the Unity Editor. //Application.Quit (); //The following does work for the editor. Debug.Log("Quitting the game"); ScriptingUtilities.QuitGame(); Destroy(this.gameObject); }
/// <inheritdoc/> public override void Initialize() { base.Initialize(); #if UNITY_EDITOR // When in the editor, check for the DotNetWinRT dll and define the appropriate // preprocessor sybmol ScriptingUtilities.AppendScriptingDefinitions( "Microsoft.Windows.MixedReality.DotNetWinRT.dll", UnityEditor.BuildTargetGroup.WSA, new string[] { "DOTNETWINRT_PRESENT" }); #endif // UNITY_EDITOR }
//Should be called by PurchasePanelManager. public void DefinePanelItem(ResourceReferenceWithStack item, int requiredCost) { if (item != null && item.stack != 0) { heldItem = item; //Get sprite without pivot point. currentItemIcon.sprite = ScriptingUtilities.GetSpriteWithoutPivotPoint(item.uiSlotContent.itemIcon); cost.text = requiredCost.ToString(); } else { Debug.LogError("Cannot define panel item to be null or have a stack of 0!!"); } }
/******************************* ASSIGNING *******************************/ public virtual void AssignNewItem(ResourceReferenceWithStack itemToAssign) { if (itemToAssign.stack != 0) { Sprite itemWithoutPivotPoint = ScriptingUtilities.GetSpriteWithoutPivotPoint(itemToAssign.uiSlotContent.itemIcon); childIcon.enabled = true; currentlyAssigned = itemToAssign; childIcon.sprite = itemWithoutPivotPoint; UpdateStackIndicator(); } else { Debug.LogError("Could not assign item with 0 stack!"); } }
public void InitializeProjectileWithThresholdAndDeviation(Vector3 positionToFireToward, float velocity, float currentHeading, float headingThreshold, float maxRandomDeviation, float ctorArrowPower) { playerObject = CurrentLevelVariableManagement.GetPlayerReference(); //Set physics of the projectile. rb2d = GetComponent <Rigidbody2D> (); //Returned in radians. float radianAngleToTarget = Mathf.Atan2((positionToFireToward.y - transform.position.y), (positionToFireToward.x - transform.position.x)); float degreeAngleToTarget = ScriptingUtilities.RadiansToDegrees(radianAngleToTarget); //Used to set the threshold angles that the arrow can be shot at. if (currentHeading == 0) { if (180 >= degreeAngleToTarget && degreeAngleToTarget >= headingThreshold) { degreeAngleToTarget = headingThreshold; } else if (-180 <= degreeAngleToTarget && degreeAngleToTarget <= -headingThreshold) { degreeAngleToTarget = -headingThreshold; } } else if (currentHeading == 180) { if (0 <= degreeAngleToTarget && degreeAngleToTarget <= 180 - headingThreshold) { degreeAngleToTarget = 180 - headingThreshold; } else if (0 >= degreeAngleToTarget && degreeAngleToTarget >= -180 + headingThreshold) { degreeAngleToTarget = -180 + headingThreshold; } } degreeAngleToTarget += Random.Range(0, maxRandomDeviation) - maxRandomDeviation / 2; transform.localRotation = Quaternion.Euler(new Vector3(0, 0, degreeAngleToTarget)); rb2d.velocity = new Vector2(velocity * Mathf.Cos(ScriptingUtilities.DegreesToRadians(degreeAngleToTarget)), velocity * Mathf.Sin(ScriptingUtilities.DegreesToRadians(degreeAngleToTarget))); arrowPower = ctorArrowPower; //Start the coroutine that checks when the arrow should be destroyed (takes up memory space) StartCoroutine(DestroyIfDistanceFromPlayer()); }
public virtual void Initialize(Vector2 positionToFireToward, float velocity, float power) { playerObject = InstanceDatabase.GetPlayerReference(); //Get the Rigidbody component so that physics can be used. rb2d = GetComponent <Rigidbody2D> (); //Calculate the heading to the fire location. float radianAngleToTarget = Mathf.Atan2((positionToFireToward.y - transform.position.y), (positionToFireToward.x - transform.position.x)); float degreeAngleToTarget = radianAngleToTarget * Mathf.Rad2Deg; //Turn to the heading and move in that direction. transform.localRotation = Quaternion.Euler(new Vector3(0, 0, degreeAngleToTarget)); rb2d.velocity = new Vector2(velocity * Mathf.Cos(ScriptingUtilities.DegreesToRadians(degreeAngleToTarget)), velocity * Mathf.Sin(ScriptingUtilities.DegreesToRadians(degreeAngleToTarget))); //Set the strength of the arrow. this.power = power; //Start the coroutine that checks when the arrow should be destroyed (takes up memory space) StartCoroutine(DestroyIfDistanceFromPlayer()); }
//Called from the public AddIngredient function. void ManageCombination() { // Check the createdIngredientArray to see whether the ResourceReference components match. ResourceReference[] createdIngredientResourceReferenceArray = { pendingCombinationIngredient1.uiSlotContent, pendingCombinationIngredient2.uiSlotContent }; //For every combination in the database. for (int i = 0; i < ResourceDatabase.masterItemCombinationList.Count; i++) { //Convert the two database ingredients in use into an array. ResourceReference[] combinationDatabaseItemRequirements = { ResourceDatabase.masterItemCombinationList[i].ingredients[0].uiSlotContent, ResourceDatabase.masterItemCombinationList[i].ingredients[1].uiSlotContent }; //Check whether the local and database arrays are equal. if (ScriptingUtilities.CheckArraysForEquality(createdIngredientResourceReferenceArray, combinationDatabaseItemRequirements)) { //Create an integer array that defines the stack of each local item. int[] createdIngredientStackArray = { pendingCombinationIngredient1.stack, pendingCombinationIngredient2.stack }; //Create an integer array that defines the stack of each database ingredient. int[] combinationDatabaseStackRequirements = { ResourceDatabase.masterItemCombinationList[i].ingredients[0].stack, ResourceDatabase.masterItemCombinationList[i].ingredients[1].stack }; //Determine whether the stacks satisfy the minimum requirement. if ( createdIngredientStackArray[0] >= combinationDatabaseStackRequirements[0] && createdIngredientStackArray[1] >= combinationDatabaseStackRequirements[1] ) { int maxPossibleItemStack = DetermineMaxPossibleStackOfItem(combinationDatabaseStackRequirements, createdIngredientStackArray); if (maxPossibleItemStack != 0) { assigner1.ModifyCurrentItemStack(-1 * maxPossibleItemStack * combinationDatabaseStackRequirements[0]); Debug.Log("Deducted " + maxPossibleItemStack * combinationDatabaseStackRequirements[0] + " from assigner 1."); assigner2.ModifyCurrentItemStack(-1 * maxPossibleItemStack * combinationDatabaseStackRequirements[1]); Debug.Log("Deducted " + maxPossibleItemStack * combinationDatabaseStackRequirements[1] + " from assigner 2, stack is now."); ResourceReferenceWithStack finalProduct = new ResourceReferenceWithStack(ResourceDatabase.masterItemCombinationList[i].product.uiSlotContent, ResourceDatabase.masterItemCombinationList[i].product.stack * maxPossibleItemStack); AssignItemToMouseControl(finalProduct); ResetPendingCombinationSequence(); } else { Debug.Log("Max possible item stack was 0"); } return; } else { Debug.LogError("Stack did not satisfy the minimum number required."); return; } } if (i == ResourceDatabase.masterItemCombinationList.Count - 1) { Debug.LogError("Combination ingredients not found"); ResetPendingCombinationSequence(); } } }
//Takes the transfer segments defined earlier and instantiates them based on sprite size. TerrainReferenceClass InitializeTerrain() { //Make sure that the level length is not less than what has to be instantiated. if (levelLength < transferSegments.endVariations.Length + transferSegments.introductoryVariations.Length) { Debug.Log("The level length is not large enough to hold all of the required variations, changing to " + (transferSegments.endVariations.Length + transferSegments.introductoryVariations.Length)); levelLength = transferSegments.endVariations.Length + transferSegments.introductoryVariations.Length; } //This is recorded and changed as more terrain is added. float currentXPosition = 0; //This will be returned once filled in. TerrainReferenceClass createdMaze = new TerrainReferenceClass(levelLength + transferSegments.introductoryVariations.Length + transferSegments.introductoryVariations.Length); //This holds the main maze part. Transform parentMaze = new GameObject("Maze").transform; parentMaze.localPosition = new Vector3(0, 0, -8); //Instantiate the starting point. GameObject instantiatedStartPoint = LayTerrainAsset(transferSegments.startSegment, Vector3.zero, Quaternion.identity, parentMaze); instantiatedStartPoint.transform.localPosition = Vector3.zero; currentXPosition += GetSpriteSizeFromGameObject(instantiatedStartPoint).x / 2f; //Apparently this can be null (weird error) for (int i = 0; i < transferSegments.introductoryVariations.Length; i++) { //Instantiate the next introductory variation. float halfWidth = GetSpriteSizeFromGameObject(transferSegments.introductoryVariations [i].variationReference.gameObject).x / 2f; currentXPosition += halfWidth; GameObject createdAsset = LayTerrainAsset(transferSegments.introductoryVariations [i].variationReference.gameObject, new Vector3(currentXPosition, 0, 0), Quaternion.identity, parentMaze); createdMaze.layer1[i] = createdAsset.transform; currentXPosition += halfWidth; } //For all levelLength values. Start at the length of introductory variations and move on from there to the level length minus the number of . for (int i = transferSegments.introductoryVariations.Length; i < levelLength - transferSegments.endVariations.Length; i++) { //Half-Width and currentX position are used for all variations. VariationReference chosenVariationLayer1 = ScriptingUtilities.GetRandomObjectFromArray(transferSegments.l1Variations); GameObject chosenObjectLayer1 = chosenVariationLayer1.variationReference; float halfWidth = GetSpriteSizeFromGameObject(chosenObjectLayer1).x / 2f; currentXPosition += halfWidth; //Layer 1 Vector3 pointToInstantiateLayer1Object = new Vector3(currentXPosition, 0, 0); GameObject instantiatedObjectLayer1 = LayTerrainAsset(chosenObjectLayer1, pointToInstantiateLayer1Object, Quaternion.identity, parentMaze); if (Random.Range(0, 2) == 1 && chosenVariationLayer1.canBeFlipped) { instantiatedObjectLayer1.transform.localScale = new Vector3(-1, 1, 1); } createdMaze.layer1[i + transferSegments.introductoryVariations.Length] = instantiatedObjectLayer1.transform; //Layer 2 //Make sure that layer 2 objects do exist. if (transferSegments.l2Variations.Length != 0) { VariationReference chosenVariationLayer2 = ScriptingUtilities.GetRandomObjectFromArray(transferSegments.l2Variations); GameObject chosenObjectLayer2 = chosenVariationLayer2.variationReference; Vector3 pointToInstantiateLayer2Object = new Vector3(currentXPosition, -(GetSpriteSizeFromGameObject(chosenObjectLayer1).y / 2f + GetSpriteSizeFromGameObject(chosenObjectLayer2).y / 2f), 0); GameObject instantiatedObjectLayer2 = LayTerrainAsset(chosenObjectLayer2, pointToInstantiateLayer2Object, Quaternion.identity, parentMaze); if (Random.Range(0, 2) == 1 && chosenVariationLayer2.canBeFlipped) { instantiatedObjectLayer2.transform.localScale = new Vector3(-1, 1, 1); } createdMaze.layer2[i] = instantiatedObjectLayer2.transform; //Layer 3 //Make sure that layer 3 objects do exist (dependent on whether layer 2 objects exist as well). if (transferSegments.l3Variations.Length != 0) { VariationReference chosenVariationLayer3 = ScriptingUtilities.GetRandomObjectFromArray(transferSegments.l3Variations); GameObject chosenObjectLayer3 = chosenVariationLayer3.variationReference; Vector3 pointToInstantiateLayer3Object = new Vector3(currentXPosition, instantiatedObjectLayer2.transform.position.y - (GetSpriteSizeFromGameObject(chosenObjectLayer2).y / 2f + GetSpriteSizeFromGameObject(chosenObjectLayer3).y / 2f), 0); GameObject instantiatedObjectLayer3 = LayTerrainAsset(chosenObjectLayer3, pointToInstantiateLayer3Object, Quaternion.identity, parentMaze); if (Random.Range(0, 2) == 1 && chosenVariationLayer3.canBeFlipped) { instantiatedObjectLayer3.transform.localScale = new Vector3(-1, 1, 1); } createdMaze.layer3[i] = instantiatedObjectLayer3.transform; } } //Add current X position currentXPosition += halfWidth; } //Apparently this can be null (weird error) for (int i = 0; i < transferSegments.endVariations.Length; i++) { //Instantiate the next introductory variation. float halfWidth = GetSpriteSizeFromGameObject(transferSegments.endVariations [i].variationReference.gameObject).x / 2f; currentXPosition += halfWidth; GameObject createdAsset = LayTerrainAsset(transferSegments.endVariations [i].variationReference.gameObject, new Vector3(currentXPosition, 0, 0), Quaternion.identity, parentMaze); createdMaze.layer1[i + levelLength + transferSegments.introductoryVariations.Length] = createdAsset.transform; currentXPosition += halfWidth; } //Instantiate the end segment. currentXPosition += GetSpriteSizeFromGameObject(transferSegments.startSegment).x / 2f; GameObject instantiatedEndPoint = LayTerrainAsset(transferSegments.startSegment, new Vector3(currentXPosition, 0, 0), Quaternion.identity, parentMaze); instantiatedEndPoint.transform.localScale = new Vector3(-1, 1, 1); instantiatedEndPoint.transform.localPosition = new Vector3(instantiatedEndPoint.transform.position.x, instantiatedEndPoint.transform.position.y, 0); //Calculate the float level length, then send it over to CurrentLevelVariableManagement. float levelLengthX = instantiatedEndPoint.transform.position.x - instantiatedStartPoint.transform.position.x; //Set the level length (will be used for things like the particle effect). CurrentLevelVariableManagement.SetLevelLengthX(levelLengthX); return(createdMaze); }
//Parse through all enemy item points. void CreateTerrainItems(TerrainReferenceClass mazeSegments) { //This list will hold the positions of all of the enemy item positions. List <Transform> allEnemyItemPoints = new List <Transform> (); //This prevents a ton of future errors and if-checking. if (initialGameElements.Length != 0) { //Instantiate all items for (int i = 0; i < mazeSegments.layer1.Length; i++) { //Preventing future errors. if (mazeSegments.layer1[i] != null) { if (mazeSegments.layer1[i].Find("Points") != null) { Transform enemyItemsTransform = mazeSegments.layer1[i].Find("Points").Find("EnemyItems"); //Check to make sure enemy item points exist. if (enemyItemsTransform != null) { //Find the points Transform[] enemyItemPoints = ScriptingUtilities.ParseChildrenFromTransform(enemyItemsTransform); for (int j = 0; j < enemyItemPoints.Length; j++) { //Add all transforms to the master list. allEnemyItemPoints.Add(enemyItemPoints[j]); } } } else { Debug.Log("Did not find points upon which to instantiate enemies on increment " + i + " with variation name " + mazeSegments.layer1[i].gameObject.name); } } else { Debug.LogError("MazeSegments.layer1[" + i + "] is null!!!!"); } } } else { Debug.LogError("No initial game elements are set!"); } //Make sure that the previous step added transforms to the list. if (allEnemyItemPoints.Count > 0) { //Sort the object references SortObjectArray(); //Make sure that the variations have the capacity to fill all required items. if (requiredItems.Length <= allEnemyItemPoints.Count) { //List of empty points List <int> emptyPoints = new List <int> (); //Populate the list of points. for (int j = 0; j < allEnemyItemPoints.Count; j++) { emptyPoints.Add(j); } //All required items. for (int j = 0; j < requiredItems.Length; j++) { int chosenLoc = Random.Range(0, emptyPoints.Count); //Choose a point out of the existing points. int pointToInstantiateRequiredItem = emptyPoints [chosenLoc]; //Instantiate the object GameObject createdElement = InstantiateElementOnPoint(requiredItems [j].elementReference, allEnemyItemPoints [pointToInstantiateRequiredItem].position ); createdElement.transform.SetParent(allEnemyItemPoints [pointToInstantiateRequiredItem]); //Remove the point that was just used from the list. emptyPoints.RemoveAt(chosenLoc); } //For the rest of the points. while (emptyPoints.Count > 0) { int chosenLoc = Random.Range(0, emptyPoints.Count); int pointToInstantiateRequiredItem = emptyPoints [chosenLoc]; //Instantiate the object InstantiatableObjectReference chosenElement = ChooseElement(); //Check to make sure that it is not supposed to instantiate anything. if (chosenElement != null) { //Instantiate element GameObject createdElement = InstantiateElementOnPoint(chosenElement.elementReference, allEnemyItemPoints [pointToInstantiateRequiredItem].position ); createdElement.transform.SetParent(allEnemyItemPoints [pointToInstantiateRequiredItem]); } //Remove the point that was just used from the list. emptyPoints.RemoveAt(chosenLoc); } } } }