public void SetOwner(IOwner owner) { this.owner = owner; ai.owner = owner; owner.GetUnitsCommanding().Add(this); if (owner as AirCarrier || owner as GroundCarrier) { // GET THE DRONES TO MOVE ai.setMode(AirCraftAI.AIMode.Path); var path = ScriptableObject.CreateInstance <Path>(); path.waypoints = new List <Path.Node>(); var vec = Vector2.zero; if (owner as AirCarrier) { foreach (var ent in BattleZoneManager.getTargets()) { if (ent && ent is ICarrier && !FactionManager.IsAllied(ent.faction, owner.GetFaction()) && ent.transform) { vec = ent.transform.position; } } } // otherwise this is a ground carrier, drones are defensive for them so set a path to the drone position currently else { var angle = Random.Range(0F, 360); vec = owner.GetTransform().position + new Vector3(5 * Mathf.Sin(angle), 5 * Mathf.Cos(angle)); } // TODO: jank, fix this eventually var node = new Path.Node(); node.position = vec; node.ID = 0; node.children = new List <int>(); if (vec != Vector2.zero) { path.waypoints.Add(node); } if (owner as AirCarrier) { ai.setPath(path); } else { NodeEditorFramework.Standard.PathData data = new NodeEditorFramework.Standard.PathData(); data.waypoints = new List <NodeEditorFramework.Standard.PathData.Node>(); // TODO: LOL THESE TWO ARE DIFFERENT, unify them foreach (var point in path.waypoints) { var node2 = new NodeEditorFramework.Standard.PathData.Node(); node2.ID = point.ID; node2.children = point.children; node2.position = point.position; data.waypoints.Add(node2); } ai.setPath(data, null, true); } } }
public void SetPath(NodeEditorFramework.Standard.PathData data) { pathNodes.Clear(); if (data != null && data.waypoints != null) { for (int i = 0; i < data.waypoints.Count; i++) { if (IDCount < data.waypoints[i].ID) { IDCount = data.waypoints[i].ID + 1; } pathNodes.Add(new Path.Node() { ID = data.waypoints[i].ID, position = data.waypoints[i].position, children = data.waypoints[i].children }); } } CleanPath(); UpdateMesh(); }
public void pathDrawing(WorldCreatorCursor.WCCursorMode originalMode, NodeEditorFramework.Standard.PathData path = null) { pathCreator.Clear(); pathCreator.SetPath(path); taskInterface.CloseUI(); originalCursorMode = originalMode; SetMode(WCCursorMode.DrawPath); }
public void SetPath(NodeEditorFramework.Standard.PathData path) { rectTransform.gameObject.SetActive(true); if (currentItem != null) { currentItem.patrolPath = path; } if (WorldCreatorCursor.finishPath != null) { WorldCreatorCursor.finishPath -= SetPath; } }
public void setPath(NodeEditorFramework.Standard.PathData data, UnityAction OnPathEnd = null, bool patrolling = false) { craft.isPathing = true; Path path = ScriptableObject.CreateInstance <Path>(); path.waypoints = new List <Path.Node>(); if (data != null && data.waypoints != null) { for (int i = 0; i < data.waypoints.Count; i++) { path.waypoints.Add(new Path.Node() { ID = data.waypoints[i].ID, position = data.waypoints[i].position, children = data.waypoints[i].children }); } } setMode(AIMode.Path); (module as PathAI).setPath(path, patrolling); if (OnPathEnd == null) { OnPathEnd = new UnityAction(() => craft.isPathing = false); } else { var OldOnPathEnd = OnPathEnd; OnPathEnd = new UnityAction(() => { OldOnPathEnd.Invoke(); craft.isPathing = false; }); } (module as PathAI).OnPathEnd = OnPathEnd; }
public void PollPathDrawing() { Vector2 pos = WorldCreatorCursor.GetMousePos(); if (pathNodes == null) { pathNodes = new List <Path.Node>(); } if (Input.GetMouseButton(0)) { if (dragging) { selectedNode.position = pos; UpdateMesh(); } } if (Input.GetMouseButtonDown(0)) { int closest = GetClosestNodeIndex(pos); bool grabbed = false; if (closest >= 0) { float d = (pathNodes[closest].position - pos).sqrMagnitude; if (d < maxClickDistance * maxClickDistance) { Debug.Log("grabbed"); grabbed = true; dragging = true; selectedNode = pathNodes[closest]; selectedNode.position = pos; UpdateMesh(); } } if (!grabbed) { AddPoint(pos); } } else if (Input.GetMouseButtonUp(0)) { int closest = GetClosestNodeIndex(pos, selectedNode != null ? selectedNode.ID : -1); if (closest >= 0) { float d = (pathNodes[closest].position - pos).sqrMagnitude; if (d < maxClickDistance * maxClickDistance && dragging) { Path.Node from = selectedNode; Path.Node to = pathNodes[closest]; for (int i = 0; i < pathNodes.Count; i++) { for (int j = 0; j < pathNodes[i].children.Count; j++) { if (pathNodes[i].children[j] == from.ID) { pathNodes[i].children[j] = to.ID; } } } to.children.AddRange(from.children); for (int i = 0; i < to.children.Count; i++) { if (to.children[i] == to.ID) { to.children.RemoveAt(i--); continue; } for (int j = 0; j < to.children.Count; j++) { if (i != j && to.children[i] == to.children[j]) { to.children.RemoveAt(j--); } } } pathNodes.Remove(from); Debug.Log($"Combined {from.ID} to {to.ID}"); CleanPath(); UpdateMesh(); } } dragging = false; selectedNode = null; } if (Input.GetMouseButtonUp(1)) { int closest = GetClosestNodeID(pos); if (closest >= 0) { RemoveNode(closest); UpdateMesh(); Debug.Log($"Node {closest} removed!"); } } if (Input.GetKeyDown(KeyCode.Return)) { var pathData = new NodeEditorFramework.Standard.PathData(); pathData.waypoints = new List <NodeEditorFramework.Standard.PathData.Node>(); for (int i = 0; i < pathNodes.Count; i++) { pathData.waypoints.Add(new NodeEditorFramework.Standard.PathData.Node() { ID = pathNodes[i].ID, position = pathNodes[i].position, children = pathNodes[i].children }); } WorldCreatorCursor.finishPath.Invoke(pathData); WorldCreatorCursor.instance.SetMode(WorldCreatorCursor.originalCursorMode); Clear(); } }