예제 #1
0
        /// <summary>
        /// The set up default keys function.
        /// Sets up the default keys.
        /// </summary>
        private void SetUpDefaultKeys()
        {
            // The default keys and values
            this.thekeybinddictionary.Add("Settings", KeyCode.Escape);
            this.thekeybinddictionary.Add("Objectives", KeyCode.O);
            this.thekeybinddictionary.Add("Crafting", KeyCode.C);
            this.thekeybinddictionary.Add("Actions", KeyCode.Tab);
            this.thekeybinddictionary.Add("Units", KeyCode.U);
            this.thekeybinddictionary.Add("Workshop", KeyCode.M);
            this.thekeybinddictionary.Add("Ability", KeyCode.Space);
            this.thekeybinddictionary.Add("Home", KeyCode.H);
            this.thekeybinddictionary.Add("Cancel", KeyCode.X);
            this.thekeybinddictionary.Add("SAExtractors", KeyCode.F1);
            this.thekeybinddictionary.Add("SAMiners", KeyCode.F2);
            this.thekeybinddictionary.Add("SAHarvesters", KeyCode.F3);
            this.thekeybinddictionary.Add("SAUnits", KeyCode.F4);
            this.thekeybinddictionary.Add("BuyExtractor", KeyCode.Alpha1);
            this.thekeybinddictionary.Add("BuyMiner", KeyCode.Alpha2);
            this.thekeybinddictionary.Add("BuyHarvester", KeyCode.Alpha3);
            this.thekeybinddictionary.Add("Controls", KeyCode.Slash);
            this.thekeybinddictionary.Add("Instructions", KeyCode.F5);

            this.keybindmapping.Add("Settings", delegate { EventManager.Publish("Settings"); });
            this.keybindmapping.Add("Objectives", delegate { EventManager.Publish("ObjectiveClick"); });
            this.keybindmapping.Add("Crafting", delegate { EventManager.Publish("Crafting"); });
            this.keybindmapping.Add("Actions", delegate { EventManager.Publish("Actions"); });
            this.keybindmapping.Add("Units", delegate { EventManager.Publish("UnitTab"); });
            this.keybindmapping.Add("Workshop", delegate { EventManager.Publish("Workshop"); });
            this.keybindmapping.Add("Ability", delegate { EventManager.Publish("ActivateAbility"); });
            this.keybindmapping.Add("Home", delegate { EventManager.Publish("Recall"); });
            this.keybindmapping.Add("Cancel", delegate { EventManager.Publish("CancelAction"); });
            this.keybindmapping.Add("SAExtractors", delegate { EventManager.Publish("SAExtract"); });
            this.keybindmapping.Add("SAMiners", delegate { EventManager.Publish("SAMiner"); });
            this.keybindmapping.Add("SAHarvesters", delegate { EventManager.Publish("SAHarvest"); });
            this.keybindmapping.Add("SAUnits", delegate { EventManager.Publish("SAUnit"); });
            this.keybindmapping.Add("BuyExtractor", delegate { EventManager.Publish("OnEChoice"); });
            this.keybindmapping.Add("BuyMiner", delegate { EventManager.Publish("OnMChoice"); });
            this.keybindmapping.Add("BuyHarvester", delegate { EventManager.Publish("OnHChoice"); });
            this.keybindmapping.Add("Controls", delegate { EventManager.Publish("Customize"); });
            this.keybindmapping.Add("Instructions", delegate { EventManager.Publish("Instructions"); });

            // Load the hotkeys - If they can't be loaded then make the keys
            if (!this.LoadHotkeys())
            {
                foreach (var val in this.thekeybinddictionary)
                {
                    this.MakeHotKey(val.Key, val.Value.ToString());
                }
            }
        }
예제 #2
0
        /// <summary>
        /// The update function.
        /// </summary>
        private void Update()
        {
            // Get the right mouse button
            if (Input.GetMouseButtonDown(0))
            {
                RaycastHit hit;

                // Perform ray cast
                Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

                // If ray cast hit something
                if (Physics.Raycast(ray, out hit, 100.0f))
                {
                    // Check if it was a tile
                    TileBehavior tile = hit.collider.GetComponent <TileBehavior>();

                    // If the start node is null
                    if (this.startNode == null)
                    {
                        // If the tile is not null and the node is walkable
                        if (tile != null && tile.Node.IsWalkable)
                        {
                            // Set the start node to that node
                            this.startNode = tile.Node;

                            // Change sprite renderer to green
                            hit.collider.gameObject.GetComponent <SpriteRenderer>().material.color = Color.green;

                            // Add the tile to the list to be reset
                            this.tilesForReset.Add(tile);
                        }
                    } // Else if the goal node is null
                    else if (this.goalNode == null)
                    {
                        // If the tile is not null and the node is walkable and the node is not the start node
                        if (tile != null && tile.Node.IsWalkable && tile.Node != this.startNode)
                        {
                            // Set the node to the goal node
                            this.goalNode = tile.Node;

                            // Change sprite renderer to red
                            hit.collider.gameObject.GetComponent <SpriteRenderer>().material.color = Color.red;

                            // Add the tile to the list to be reset
                            this.tilesForReset.Add(tile);
                        }
                    }
                }
            }

            // Get the right mouse button
            if (Input.GetMouseButtonDown(1))
            {
                RaycastHit hit;

                // Perform ray cast
                Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

                // If ray cast hit something
                if (Physics.Raycast(ray, out hit, 100.0f))
                {
                    // If clicked on an enemy then just return
                    if (hit.collider.GetComponent <Enemy>())
                    {
                        return;
                    }

                    // Check if it was a tile
                    TileBehavior tile = hit.collider.GetComponent <TileBehavior>();

                    // If the tile clicked on is the start node or goal node then just return
                    if (tile.Node == this.startNode || tile.Node == this.goalNode)
                    {
                        return;
                    }

                    // Set the node to not walkable
                    tile.Node.IsWalkable = false;

                    // Change sprite renderer to blue
                    hit.collider.gameObject.GetComponent <SpriteRenderer>().material.color = Color.blue;

                    // Run the algorithm again because the moving objects path might need to be changed
                    EventManager.Publish("Run");

                    // Add the tile to the list to be reset
                    this.tilesForReset.Add(tile);
                }
            }
        }