/// <summary> /// 检测射线选择物体 /// </summary> /// <param name="origin"></param> /// <param name="direction"></param> public void UpdateSelect() { #if UNITY_EDITOR Debug.DrawLine(ray.origin, ray.origin + ray.direction * 100, Color.red); #endif if (Physics.Raycast(ray, out raycastHit, maxDistance, layerFilter)) { if (selectedObject == null) { selectedObject = raycastHit.transform.GetComponent <EBehaviour>(); } else { if (selectedObject == raycastHit.transform.GetComponent <EBehaviour>()) { ActiveSelectedEvent(SelectType.Over, selectedObject); } else { ActiveSelectedEvent(SelectType.Exit, selectedObject); selectedObject = raycastHit.transform.GetComponent <EBehaviour>(); ActiveSelectedEvent(SelectType.Enter, selectedObject); } } if (!activeEvent) { activeEvent = true; ActiveSelectedEvent(SelectType.Enter, selectedObject); } } else { if (activeEvent) { activeEvent = false; ActiveSelectedEvent(SelectType.Exit, selectedObject); selectedObject = null; } } }
//--------------------------------------------------------------------------- public void AddTarget(IEntity target, EBehaviour behaviour) { m_Target = target.GUID; m_Behaviour = behaviour; }
private void OnSelected(SelectType arg0, EBehaviour arg1) { Debug.Log(arg0 + ":" + arg1 != null ? arg1.name : "Null"); }
void ActiveSelectedEvent(SelectType selecttype, EBehaviour eobject) { SelectedEvent.Invoke(selecttype, eobject); }
//--------------------------------------------------------------------------- private List <Point> ExecuteSearch(Point startPoint, Point endPoint, EBehaviour behaviour) { foreach (PathNode node in m_Nodes) { node.Reset(); } if (StageManager.Get().IsBlocked(startPoint.X, startPoint.Y)) { return(new List <Point>()); } if (StageManager.Get().IsBlocked(endPoint.X, endPoint.Y)) { return(new List <Point>()); } if (!Bounds.Contains(startPoint.X, startPoint.Y)) { return(new List <Point>()); } if (!Bounds.Contains(endPoint.X, endPoint.Y)) { return(new List <Point>()); } SortedList <int, Point> open = new SortedList <int, Point>(new DuplicateKeyComparer <int>()); List <Point> closed = new List <Point>(); open.Add(0, startPoint); Point current = new Point(); while (open.Count > 0) { current = open.First().Value; if (current.Equals(endPoint)) { break; } else { open.RemoveAt(0); closed.Add(current); foreach (Tuple <Point, int> position in GetAdjacentNodes(current)) { if (closed.Contains(position.Item1)) { continue; } if (open.ContainsValue(position.Item1)) { continue; } m_Nodes[position.Item1.X, position.Item1.Y].Cost = m_Nodes[current.X, current.Y].Cost + position.Item2; m_Nodes[position.Item1.X, position.Item1.Y].Heuristic = Math.Abs(endPoint.X - position.Item1.X) + Math.Abs(endPoint.Y - position.Item1.Y); open.Add(m_Nodes[position.Item1.X, position.Item1.Y].Total, position.Item1); } } } bool startFound = false; List <Point> path = new List <Point>(); current = endPoint; while (!startFound) { foreach (Tuple <Point, int> position in GetAdjacentNodes(current)) { if (position.Item1.Equals(startPoint)) { startFound = true; } if (closed.Contains(position.Item1) || open.ContainsValue(position.Item1)) { if (m_Nodes[position.Item1.X, position.Item1.Y].Cost < m_Nodes[current.X, current.Y].Cost) { current = position.Item1; path.Add(position.Item1); } } } } path.Reverse(); return(path); }
//--------------------------------------------------------------------------- public List <Vector3> ExecuteSearch(Vector3 startLocation, Vector3 endLocation, EBehaviour behaviour = EBehaviour.Follow) { Area area = AreaManager.Get().GetSharedArea(startLocation.To2D(), endLocation.To2D()); if (area == null) { return(new List <Vector3>()); } else { Rectangle areaBounds = area.Collider.Rects[0]; Bounds = new Rectangle(areaBounds.X / 64, areaBounds.Y / 64, areaBounds.Width / 64, areaBounds.Height / 64); } Point startPoint = new Point(((int)startLocation.X - 32) / 64, ((int)startLocation.Y - 32) / 64); Point endPoint = new Point(((int)endLocation.X - 32) / 64, ((int)endLocation.Y - 32) / 64); List <Vector3> path = new List <Vector3>(); foreach (Point position in ExecuteSearch(startPoint, endPoint, behaviour)) { if (position.Equals(startPoint)) { continue; } Vector3 pathLocation = new Vector3(position.X * 64 + 32, position.Y * 64 + 32, startLocation.Z); path.Add(pathLocation); } return(path); }
public void SetState(EBehaviour state) { type = state; }
private bool IsState(EBehaviour state) { return(state == type); }