Example #1
0
    public void AddHexToLevel(HexTypeEnum hexType, Vector2 location, ElementAttribute attribute)
    {
        throw new System.NotImplementedException("TODO: use hex location to modify the hex tile at that location(?)");


        //levelBeingEdited.hexs[1] = new MapElement(HexTypeEnum.HexTile_MenuOptionEdit, new Vector2Int(1, 0), new MenuButtonElementAttribute(Command.Edit));
    }
Example #2
0
    public static string[] GetCompatibleAttrributes(this HexTypeEnum hexType)
    {
        switch (hexType)
        {
        case HexTypeEnum.HexTile_Digit0:
        case HexTypeEnum.HexTile_Digit1:
        case HexTypeEnum.HexTile_Digit2:
        case HexTypeEnum.HexTile_Digit3:
        case HexTypeEnum.HexTile_Digit4:
        case HexTypeEnum.HexTile_Digit5:
        case HexTypeEnum.HexTile_Digit6:
        case HexTypeEnum.HexTile_Digit7:
        case HexTypeEnum.HexTile_Digit8:
            return(new string[]  {
                typeof(DigitElementAttribute).ToString(),
            });

        case HexTypeEnum.HexTile_MenuOptionEdit:
            return(new string[]  {
                typeof(MenuButtonElementAttribute).ToString()
            });

        default:
            return(allhexAttributes);
        }
    }
Example #3
0
    void OnEnable()
    {
        LastTool      = Tools.current;
        Tools.current = Tool.None;

        hexType = HexTypeEnum.HexTile_ClickDestroy; // Sets the initially chosen hex type
    }
Example #4
0
    private bool ReplaceDigit(int index, HexTypeEnum typeToDisplay)
    {
        Hex newHex = MapSpawner.Instance.SpawnHexAtLocation(MapSpawner.Instance.grid.WorldToCell(digitHexes[index].transform.position), typeToDisplay, true, MapSpawner.MAP_LAYER_DIGIT);

        //TODO: Move Component to new hex
        DigitComponent component = this;

        digitHexes[index].DigHex(false);
        digitHexes[index] = newHex;
        return(true);
    }
Example #5
0
    public void NewHexPicked(HexTypeEnum hexType)
    {
        isCurrent = hexType == this.hexType;

        if (isCurrent)
        {
            transform.localScale = defaultScale * 1.2f;
        }
        else
        {
            transform.localScale = defaultScale;
        }
    }
Example #6
0
    //Spawns a new leading digit
    private bool SpawnNewDigit(HexTypeEnum digitToAdd = HexTypeEnum.HexTile_Digit0)
    {
        Vector2Int nextHexCoord = MapSpawner.Instance.grid.WorldToCell(this.gameObject.transform.position) - new Vector2Int(digitHexes.Count, 0);

        Hex spawnedHex = MapSpawner.Instance.SpawnHexAtLocation(
            nextHexCoord,
            digitToAdd,
            true,
            MapSpawner.MAP_LAYER_DIGIT
            );

        if (spawnedHex)
        {
            digitHexes.Add(spawnedHex);
            //digitValues.Add(0);


            //Hex[] extendedDigitArray = new Hex[digitHexes.Count + 1];

            //for (int i = 0; i < digitHexes.Length - 1; ++i)
            //{
            //    extendedDigitArray[i] = digitHexes[i];
            //}

            //extendedDigitArray[digitHexes.Length - 1] = spawnedHex;

            //Debug.Log("spawnedHex.gameObject = " + spawnedHex.gameObject);
            //Debug.Log("digit hexes length pre extend = " + digitHexes.Length);

            //digitHexes = extendedDigitArray;

            //Debug.Log("digit hexes length post extend = " + digitHexes.Length);



            //digitHexes.Add(spawnedHex);
            //Debug.Log("SpawnNewDigit = " + spawnedHex + ". Count = " + digitHexes.Count);
            return(true);
        }
        else
        {
            Debug.Log("SpawnNewDigit failed");
            return(false);
        }
    }
Example #7
0
    public Hex SpawnHexAtLocation(Vector2Int hexLoc, HexTypeEnum typeToSpawn, bool replaceExisting, int layer = MAP_LAYER_0)
    {
        bool positionOccupied = mapLayers[layer].ContainsKey(hexLoc);

        // Position blocked
        if (positionOccupied && !replaceExisting)
        {
            Debug.LogWarning("Failed To Spawn Hex at " + hexLoc + ". Position Occupied.");
            return(null);
        }
        else
        {
            if (positionOccupied) // Remove occupying tile
            {
                mapLayers[layer][hexLoc].DigHex(false);
                mapLayers[layer].Remove(hexLoc);
            }

            grid.transform.rotation = Quaternion.Euler(Vector3.zero);

            Vector3?gridPos = grid.CellToWorld(new Vector2Int(hexLoc.x, hexLoc.y));

            if (gridPos == null)
            {
                Debug.LogWarning("Failed To Spawn Hex at " + hexLoc + ". Out of Grid Bounds");
                return(null);
            }
            else
            {
                //gridPos -= grid.gameObject.transform.position;
                Hex hexInstance = HexBank.Instance.GetDisabledHex(typeToSpawn, gridPos.Value, grid.transform).GetComponent <Hex>();

                // Sets the local position of the Hex to match the level holder
                hexInstance.gameObject.transform.localPosition = new Vector3(hexInstance.gameObject.transform.position.x, 0, hexInstance.gameObject.transform.position.z);

                SetGameobjectWidth(hexInstance.gameObject);

                // adds the hex to the dictonary for the grid finder
                mapLayers[layer].Add(hexLoc, hexInstance);
                return(hexInstance);
            }
        }
    }
Example #8
0
    public GameObject GetDisabledHex(HexTypeEnum hexType, Vector3 position, Transform parent, int recursionAccumulator = 0)
    {
        Quaternion rotation = Quaternion.Euler(-0, 0, 0);


        GameObject target;

        if (disableHexTypes.Exists(x => x.hexType == hexType) && disableHexTypes.Find(x => x.hexType == hexType).disabledHexObjects.Count != 0)
        {
            target = disableHexTypes.Find(x => x.hexType == hexType).PullFirstHexObject();
        }
        else
        {
            GameObject newPrefab = hexPrefabs.ToList().Find(x => x.GetComponent <Hex>().typeOfHex == hexType);
            target = Instantiate(newPrefab);
            target.SetActive(false); // Set to false before the position is set in order to prevent OnEnable initiating visual effects prematurely
        }

        if (target != null)
        {
            target.transform.parent = parent;
            target.transform.SetPositionAndRotation(position, rotation);

            target.SetActive(true);

            return(target);
        }


        // In case a new hex fails to spawn; the method is called recursively until a target is found or recursion depth is too great.
        // This was initially added as while using this method in the unity editor - the returned 'target' would sometimes be null.
        else if (recursionAccumulator < 4)
        {
            Debug.Log("RecursionAcc = " + recursionAccumulator);
            return(GetDisabledHex(hexType, position, parent, ++recursionAccumulator));
        }
        else
        {
            return(null);
        }
    }
Example #9
0
    public void SetUp(HexTypeEnum hexType)
    {
        Hex hex = HexBank.Instance.GetHexFromType(hexType);

        MeshRenderer newMeshRend = hex.GetComponent <MeshRenderer>();
        MeshRenderer oldMeshRend = GetComponent <MeshRenderer>();

        MeshFilter newMesh = hex.GetComponent <MeshFilter>();
        MeshFilter oldMesh = GetComponent <MeshFilter>();

        oldMesh.sharedMesh          = newMesh.sharedMesh;
        oldMeshRend.sharedMaterials = newMeshRend.sharedMaterials;


        this.hexType = hexType;

        gameObject.name = "HEX UI: " + hexType;

        defaultScale = transform.localScale;

        GameManager.instance.editHexPicked += NewHexPicked;
    }
Example #10
0
 public void EditUIHexClick(HexTypeEnum hexType)
 {
     currentGameState.currentEditHexType = hexType;
     editHexPicked(hexType);
 }
Example #11
0
 public void AddHexToLevel(HexTypeEnum hexType, Vector2 location)
 {
     throw new System.NotImplementedException();
 }
Example #12
0
    private void OnGUI()
    {
        GUIStyle buttonStyle = new GUIStyle(GUI.skin.button);

        buttonStyle.onHover.textColor = Color.green;


        GUILayoutOption[] buttonLayoutOptions = new GUILayoutOption[]
        {
            GUILayout.MinWidth(150),
            GUILayout.MaxWidth(150),
        };


        GUILayout.Height(100);


        HexTypeEnum prevHexType = hexType;

        GUILayout.Label("Select the type of hex and attibute you wish to add to the level.", EditorStyles.boldLabel);
        GUILayout.Space(20);

        hexType = (HexTypeEnum)EditorGUILayout.EnumPopup("Type of Hex", hexType);

        location = EditorGUILayout.Vector2Field("Hex Location", location);

        #region attribute
        GUILayout.BeginHorizontal();
        GUILayout.Label("Attribute");
        choiceIndex = EditorGUILayout.Popup(choiceIndex, attributeChoices);
        GUILayout.EndHorizontal();
        GUILayout.Space(40);
        #endregion

        switch (attributeChoices[choiceIndex])
        {
        case "None":
            break;

        case "DigitElementAttribute":
            if (attribute == null || attribute.GetType() != typeof(DigitElementAttribute))
            {
                attribute = new DigitElementAttribute(0);
            }
            ShowLayout_DigitAttribute();
            break;

        case "MenuButtonElementAttribute":
            if (attribute == null || attribute.GetType() != typeof(MenuButtonElementAttribute))
            {
                attribute = new MenuButtonElementAttribute(Command.NextMenu);
            }
            ShowLayout_MenuButtonAttribute();
            break;

        default:
            break;
        }

        GUILayout.FlexibleSpace();
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("CloseWindow", buttonStyle, buttonLayoutOptions))
        {
            this.Close();
        }
        GUILayout.Space(this.position.width - 310);
        if (GUILayout.Button("Add Hex", buttonStyle, buttonLayoutOptions))
        {
            AddHexToLevel();
        }
        GUILayout.EndHorizontal();

        GUILayout.Space(40);


        UpdateAttributeChoices();


        // Refreshes the popup window in order to update options
        if (EditorApplication.isPlaying)
        {
            if (prevHexType != hexType)
            {
                UpdateAttributeChoices();
                Repaint();
            }
        }
    }
Example #13
0
 public void AddHexTypeUI(HexTypeEnum hexType)
 {
     Instantiate(hexUIPrefab, panel).SetUp(hexType);
 }
Example #14
0
 public MapElement(HexTypeEnum hexType, Vector2Int gridPos, ElementAttribute hexAttributes = null)
 {
     this.hexType      = hexType;
     this.gridPos      = gridPos;
     this.hexAttribute = hexAttributes;
 }
Example #15
0
 public HexTypeHolder(HexTypeEnum newHexType)
 {
     this.hexType = newHexType;
 }
Example #16
0
 public Hex GetHexFromType(HexTypeEnum hexType)
 {
     return(hexPrefabs.ToList().Find(x => x.GetComponent <Hex>().typeOfHex == hexType).GetComponent <Hex>());
 }
Example #17
0
    void DisplayHexAttributeOptions()
    {
        GUIStyle buttonStyle = new GUIStyle(GUI.skin.button);

        buttonStyle.onHover.textColor = Color.green;


        GUILayoutOption[] buttonLayoutOptions = new GUILayoutOption[]
        {
            GUILayout.MinWidth(150),
            GUILayout.MaxWidth(150),
        };


        GUILayout.Height(100);


        HexTypeEnum prevHexType = hexType;

        GUILayout.Label("Select the type of hex and attibute you wish to add to the level.", EditorStyles.boldLabel);
        GUILayout.Space(20);

        hexType = (HexTypeEnum)EditorGUILayout.EnumPopup("Type of Hex", hexType);

        //location = EditorGUILayout.Vector2Field("Hex Location", location);
        EditorGUILayout.Vector2Field("Hex Location", gridLoc);

        #region attribute
        GUILayout.BeginHorizontal();
        GUILayout.Label("Attribute");
        choiceIndex = EditorGUILayout.Popup(choiceIndex, attributeChoices);
        GUILayout.EndHorizontal();
        GUILayout.Space(40);
        #endregion


        switch (attributeChoices[choiceIndex])
        {
        case "None":
            break;

        case "DigitElementAttribute":
            if (attribute == null || attribute.GetType() != typeof(DigitElementAttribute))
            {
                attribute = new DigitElementAttribute(0);
            }
            ShowLayout_DigitAttribute();
            break;

        case "MenuButtonElementAttribute":
            if (attribute == null || attribute.GetType() != typeof(MenuButtonElementAttribute))
            {
                attribute = new MenuButtonElementAttribute(Command.NextMenu);
            }
            ShowLayout_MenuButtonAttribute();
            break;

        default:
            break;
        }

        GUILayout.FlexibleSpace();
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Save Level", buttonStyle, buttonLayoutOptions))
        {
            SaveLevel();
        }
        if (GUILayout.Button("Load Level", buttonStyle, buttonLayoutOptions))
        {
            LoadLevel();
        }
        if (GUILayout.Button("New Level", buttonStyle, buttonLayoutOptions))
        {
            NewLevel();
        }

        //GUILayout.Space(this.position.width - 310);


        GUILayout.EndHorizontal();

        GUILayout.Space(40);


        UpdateAttributeChoices();
        if (prevHexType != hexType)
        {
            UpdateHexCursorObject();
        }
        Repaint();
    }