/// <summary> /// Draws the zone graph data in the inspector /// </summary> /// <param name="target">The ZoneGraph.</param> public override void OnInspectorGUI(NavGraph target) { ZoneGraph graph = target as ZoneGraph; graph.WaypointTag = EditorGUILayout.TagField("Waypoint Tag", graph.WaypointTag); graph.ZonesTag = EditorGUILayout.TagField("Zones Tag", graph.ZonesTag); graph.TransitionZonesTag = EditorGUILayout.TagField("Transition Zones Tag", graph.TransitionZonesTag); graph.CollisionMask = EditorGUILayoutx.LayerMaskField("Collision Mask", graph.CollisionMask); graph.WaypointSubdivisionSize = EditorGUILayout.FloatField("Waypoint Subdivison", graph.WaypointSubdivisionSize); }
// Helper method to find a new random location for the enemy to go to protected virtual void GetRandomSearchPoint(Bounds constraints) { // Don't do anything if we're already searching for a path if (IsSearchingForPath) { return; } // Make sure we have a worthwhile graph ZoneGraph graph = GameManager.AI.Graph; if (graph.Nodes.Length <= 0 || graph.ZonesWithWaypoints == null || graph.ZonesWithWaypoints.Count <= 0) { //Debug.LogWarning("ZoneGraph not initialized while searching for a random search point!"); return; } // Find the zone to narrow our search List <Bounds> zones = new List <Bounds>(graph.ZonesWithWaypoints.Keys); Bounds zone = zones [0]; if (constraints.extents != Vector3.zero) { foreach (Bounds bounds in zones) { if (bounds.Equals(constraints)) { zone = bounds; } } } // Make sure our zone has some nodes to search if (graph.ZonesWithWaypoints [zone].Count <= 0) { //Debug.LogWarning("ZoneGraph not initialized while searching for a random search point!"); return; } // Find a random node within that zone List <ZoneNode> nodes = graph.ZonesWithWaypoints [zone]; ZoneNode randomNode = nodes [(int)Random.Range(0, nodes.Count)]; bool isNodeGround = (randomNode.Tag & (1 << 0)) != 0; bool isAcceptable = randomNode.Walkable && isNodeGround; while (!isAcceptable) { randomNode = nodes [(int)Random.Range(0, nodes.Count)]; isNodeGround = (randomNode.Tag & (1 << 0)) != 0; isAcceptable = randomNode.Walkable && isNodeGround; } // And update our target position to the position of that random node UpdateAStarTarget((Vector3)randomNode.position); }
void Start() { // Make sure astar is set up in the scene AstarPath astar = AstarPath.active; foreach (NavGraph graph in astar.data.graphs) { if (graph is ZoneGraph) { _graph = (ZoneGraph)graph; } } // If we couldn't find a graph, create one if (_graph == null) { astar.data.AddGraph(typeof(ZoneGraph)); _graph = (ZoneGraph)astar.graphs [0]; } // All managers need to report to the main GameManager when they are ready _ready = true; }
void Start() { // Set up motion variables _moveID = -1; _moveStartPos = Vector2.zero; _moveMin = Screen.width / 32.0f; // TODO: MAKE SURE THIS VALUE NEVER BECOMES TOO LARGE _lastMovePos = Vector2.zero; float dpi = Screen.dpi; if (dpi <= 0) { Debug.LogWarning("Failed to find Screen DPI!"); dpi = 160; // Default value for Android mdpi devices } _distanceForMaxSpeed = InchesForMaxSpeed * dpi; // Set up action variables _actionID = -1; _actionStartPos = Vector2.zero; _actionMin = Screen.width / 32.0f; // TODO: MAKE SURE THIS VALUE NEVER BECOMES TOO LARGE _lastActionPos = Vector2.zero; _speedForInstantAction = _distanceForMaxSpeed * 100.0f; // TODO: DETERMINE A GOOD VALUE FOR THIS // Gonna store the input here _input = GameManager.Player.GetComponent <CharacterInput> (); // Left-hand side GUI _horizontalSlider = (Transform)Instantiate(SliderPrefab, SliderPrefab.position, Quaternion.identity); _verticalSlider = (Transform)Instantiate(SliderPrefab, SliderPrefab.position, Quaternion.Euler(Vector3.forward * 90)); _moveButton = (Transform)Instantiate(MoveButtonPrefab, MoveButtonPrefab.position, MoveButtonPrefab.rotation); _radioWaves = (Transform)Instantiate(RadioPrefab, RadioPrefab.position, RadioPrefab.rotation); // Organize it away _horizontalSlider.parent = transform; _verticalSlider.parent = transform; _moveButton.parent = transform; _radioWaves.parent = transform; // And hide them _horizontalSlider.GetComponent <Renderer>().enabled = false; _verticalSlider.GetComponent <Renderer>().enabled = false; _moveButton.GetComponent <Renderer>().enabled = false; _radioWaves.GetComponent <Renderer>().enabled = false; // Right-hand side GUI _blueCircle = (Transform)Instantiate(BlueCirclePrefab, BlueCirclePrefab.position, BlueCirclePrefab.rotation); Color blueAlpha = _blueCircle.GetComponent <Renderer>().material.color; blueAlpha.a = blueAlpha.a * 0.5f; _blueCircle.GetComponent <Renderer>().material.color = blueAlpha; _selections = (Transform)Instantiate(SelectionsPrefab, SelectionsPrefab.position, SelectionsPrefab.rotation); _jumpSign = (Transform)Instantiate(JumpSignPrefab, JumpSignPrefab.position, JumpSignPrefab.rotation); _attack1Sign = (Transform)Instantiate(AttackSignPrefab, AttackSignPrefab.position, AttackSignPrefab.rotation); _attack2Sign = (Transform)Instantiate(AttackSignPrefab, -AttackSignPrefab.position, AttackSignPrefab.rotation); _pickupSign = (Transform)Instantiate(ItemPickupSignPrefab, ItemPickupSignPrefab.position, ItemPickupSignPrefab.rotation); _glowOff = (Transform)Instantiate(GlowOffPrefab, GlowOffPrefab.position, GlowOffPrefab.rotation); Transform particles = (Transform)Instantiate(ParticlePrefab, ParticlePrefab.position, ParticlePrefab.rotation); _particles = particles.GetComponent <ParticleSystem> (); // Organize them away _blueCircle.parent = transform; _selections.parent = transform; _jumpSign.parent = transform; _attack1Sign.parent = transform; _attack2Sign.parent = transform; _pickupSign.parent = transform; _glowOff.parent = transform; // And hide them _blueCircle.GetComponent <Renderer>().enabled = false; _selections.GetComponent <Renderer>().enabled = false; _jumpSign.GetComponent <Renderer>().enabled = false; _attack1Sign.GetComponent <Renderer>().enabled = false; _attack2Sign.GetComponent <Renderer>().enabled = false; _pickupSign.GetComponent <Renderer>().enabled = false; _glowOff.GetComponent <Renderer>().enabled = false; // The dots indicating the action to the player _uiDots = new List <Transform> (9); for (int i = 0; i < 9; i++) { Transform dot = (Transform)Instantiate(DotPrefab, DotPrefab.position, DotPrefab.rotation); dot.GetComponent <Renderer>().enabled = false; dot.parent = transform; _uiDots.Add(dot); } // The relative positions at which those dots are located _dotPositions = new List <Vector3> (9); Vector3 originPoint = new Vector3(0f, 0f, -0.3f); Vector3 zeroRotation = originPoint + Vector3.right * 9.7f; _dotPositions.Add(originPoint); _dotPositions.Add(zeroRotation); _dotPositions.Add(ZoneGraph.RotatePointAroundPivot(zeroRotation, originPoint, Vector3.forward * 15.0f)); _dotPositions.Add(ZoneGraph.RotatePointAroundPivot(zeroRotation, originPoint, Vector3.forward * 90.0f)); _dotPositions.Add(ZoneGraph.RotatePointAroundPivot(zeroRotation, originPoint, Vector3.forward * 165.0f)); _dotPositions.Add(ZoneGraph.RotatePointAroundPivot(zeroRotation, originPoint, Vector3.forward * 180.0f)); _dotPositions.Add(ZoneGraph.RotatePointAroundPivot(zeroRotation, originPoint, Vector3.forward * 235.0f)); _dotPositions.Add(ZoneGraph.RotatePointAroundPivot(zeroRotation, originPoint, Vector3.forward * 270.0f)); _dotPositions.Add(ZoneGraph.RotatePointAroundPivot(zeroRotation, originPoint, Vector3.forward * 305.0f)); // Set up new update methods to show the GUI elements StartCoroutine(DisplayLeftHandSide()); StartCoroutine(DisplayRightHandSide()); }
// Draw code IEnumerator DisplayRightHandSide() { // We're essentially replicating another update loop for rendering the right hand side while (true) { yield return(null); // Make the images visible as appropriate bool actTouched = _actionID != -1; _blueCircle.GetComponent <Renderer>().enabled = actTouched; _selections.GetComponent <Renderer>().enabled = actTouched; _jumpSign.GetComponent <Renderer>().enabled = actTouched && GameManager.Player.CanInputJump; _attack1Sign.GetComponent <Renderer>().enabled = actTouched && GameManager.Player.CanInputAttack; _attack2Sign.GetComponent <Renderer>().enabled = actTouched && GameManager.Player.CanInputAttack; _pickupSign.GetComponent <Renderer>().enabled = actTouched && GameManager.Player.CanInputPickup; _glowOff.GetComponent <Renderer>().enabled = actTouched; // Make the dots visible as appropriate _uiDots [0].GetComponent <Renderer>().enabled = actTouched; _uiDots [1].GetComponent <Renderer>().enabled = actTouched && GameManager.Player.CanInputAttack; _uiDots [2].GetComponent <Renderer>().enabled = actTouched && (GameManager.Player.CanInputAttack || GameManager.Player.CanInputJump); _uiDots [3].GetComponent <Renderer>().enabled = actTouched && GameManager.Player.CanInputJump; _uiDots [4].GetComponent <Renderer>().enabled = actTouched && (GameManager.Player.CanInputJump || GameManager.Player.CanInputAttack); _uiDots [5].GetComponent <Renderer>().enabled = actTouched && GameManager.Player.CanInputAttack; _uiDots [6].GetComponent <Renderer>().enabled = actTouched && (GameManager.Player.CanInputAttack || GameManager.Player.CanInputPickup); _uiDots [7].GetComponent <Renderer>().enabled = actTouched && GameManager.Player.CanInputPickup; _uiDots [8].GetComponent <Renderer>().enabled = actTouched && (GameManager.Player.CanInputPickup || GameManager.Player.CanInputAttack); // We don't need to move + color things if they're not visible if (!actTouched) { continue; } // Put the images at the correct spot Vector3 pos = ConvertTouchPosToWorldPoint(_actionStartPos); _blueCircle.position = pos; _selections.position = pos + SelectionsPrefab.position; _selections.GetComponent <Renderer>().material.color = Color.white; _jumpSign.position = pos + JumpSignPrefab.position; _jumpSign.GetComponent <Renderer>().material.color = Color.white; _attack1Sign.position = pos + AttackSignPrefab.position; _attack1Sign.GetComponent <Renderer>().material.color = Color.white; _attack2Sign.position = pos + AttackSignPrefab.position + Vector3.left * 2 * AttackSignPrefab.position.x; _attack2Sign.GetComponent <Renderer>().material.color = Color.white; _pickupSign.position = pos + ItemPickupSignPrefab.position; _pickupSign.GetComponent <Renderer>().material.color = Color.white; // Put the dots at the correct position for (int dot = 0; dot < _uiDots.Count; dot++) { _uiDots [dot].transform.position = pos + _dotPositions [dot]; _uiDots [dot].GetComponent <Renderer>().material.color = Color.white; } // Put the glow-off at the correct location float deg = CalculateActionDegree(); Vector3 originPoint = pos + GlowOffPrefab.position; Vector3 zeroRotation = originPoint + Vector3.right * 9.0f; _glowOff.position = ZoneGraph.RotatePointAroundPivot(zeroRotation, originPoint, Vector3.forward * deg); _glowOff.rotation = Quaternion.Euler(Vector3.forward * deg); _glowOff.GetComponent <Renderer>().material.color = Color.white; // Color as appropriate if (IsInteraction(deg)) { _selections.GetComponent <Renderer>().material.color = Color.black; _glowOff.GetComponent <Renderer>().enabled = false; _uiDots [0].GetComponent <Renderer>().material.color = Color.black; } else if (GameManager.Player.CanInputJump && (IsJumpLeft(deg) || IsJumpUp(deg) || IsJumpRight(deg))) { _selections.GetComponent <Renderer>().material.color = Color.blue; _jumpSign.GetComponent <Renderer>().material.color = Color.blue; _glowOff.GetComponent <Renderer>().material.color = Color.blue; if (IsJumpRight(deg)) { _uiDots [2].GetComponent <Renderer>().material.color = Color.blue; } else if (IsJumpUp(deg)) { _uiDots [3].GetComponent <Renderer>().material.color = Color.blue; } if (IsJumpLeft(deg)) { _uiDots [4].GetComponent <Renderer>().material.color = Color.blue; } } else if (GameManager.Player.CanInputAttack && (IsAttackLeft(deg) || IsAttackRight(deg))) { _selections.GetComponent <Renderer>().material.color = Color.red; _glowOff.GetComponent <Renderer>().material.color = Color.red; if (IsAttackRight(deg)) { _attack1Sign.GetComponent <Renderer>().material.color = Color.red; _uiDots [1].GetComponent <Renderer>().material.color = Color.red; _uiDots [2].GetComponent <Renderer>().material.color = Color.red; _uiDots [7].GetComponent <Renderer>().material.color = Color.red; } else if (IsAttackLeft(deg)) { _attack2Sign.GetComponent <Renderer>().material.color = Color.red; _uiDots [4].GetComponent <Renderer>().material.color = Color.red; _uiDots [5].GetComponent <Renderer>().material.color = Color.red; _uiDots [6].GetComponent <Renderer>().material.color = Color.red; } } else if (GameManager.Player.CanInputPickup && IsPickup(deg)) { _selections.GetComponent <Renderer>().material.color = Color.green; _pickupSign.GetComponent <Renderer>().material.color = Color.green; _glowOff.GetComponent <Renderer>().material.color = Color.green; _uiDots [6].GetComponent <Renderer>().material.color = Color.green; _uiDots [7].GetComponent <Renderer>().material.color = Color.green; _uiDots [8].GetComponent <Renderer>().material.color = Color.green; } } }