public void Spawn() { if (position == null) { position = transform; } foreach (SpawnParameters sp in spawnList) { NodeBehaviour startingNode; if (sp.startingNode != null) { startingNode = sp.startingNode; } else { startingNode = NodeBehaviour.GetClosestFreeSpawnNode(position.position); } GameObject enemyPawn = GameObject.Instantiate(sp.enemyPrefab, startingNode.offsetPosition, Quaternion.identity) as GameObject; startingNode.currentObject = enemyPawn.GetComponent <Targetable>(); player.AddPawn(enemyPawn.GetComponent <Pawn>()); } }
// Start is called before the first frame update void Start() { _nodes = new NodeBehaviour[_baseIndustryNumber.Length - 1]; _natRes = new NaturalResource[_naturalResources.Length]; for (int i = 0; i < _baseIndustryNumber.Length - 1; ++i) { int var = _baseIndustryNumber[i] + (Random.Range(-_industryNumberVariations[i], _industryNumberVariations[i])); _totalIndusty += var; _nodes[i] = new NodeBehaviour(); _nodes[i].ammount = var; _nodes[i].acceptancePerc = _baseIndustryNumber[5] + (Random.Range((float)-_industryNumberVariations[5], (float)_industryNumberVariations[5])); _nodes[i].industry = new Industry(); _nodes[i].industry.industryName = _baseWorld.baseIndustries[i].industryName; _nodes[i].industry.baseGenerationPerDay = _baseWorld.baseIndustries[i].baseGenerationPerDay; _nodes[i].industry.baseMultiplierPerDay = _baseWorld.baseIndustries[i].baseMultiplierPerDay; WorldBehaviour.onDayUpdate += _nodes[i].OnDateUpdate; } for (int i = 0; i < _naturalResources.Length; ++i) { int var = _naturalResources[i] + (Random.Range(-_naturalResourcesVariation[i], _naturalResourcesVariation[i])); _totalNaturalResources += var; _natRes[i] = new NaturalResource(); _natRes[i].ammount = var; _natRes[i].resourceName = _baseWorld.naturalResources[i].resourceName; _natRes[i].baseReductionPerDay = _baseWorld.naturalResources[i].baseReductionPerDay; WorldBehaviour.onDayUpdate += _natRes[i].OnDateUpdate; } }
public override bool Execute() { if (!CheckTarget() || !CheckCost(actionCost)) { return(false); } Pawn tPawn = target.GetComponent <Pawn>(); if (owner.weapon.range == 1) { AttackCommand.Attack(owner, target); } LinkPositions pushDirection; pushDirection = owner.currentNode.GetRelativePositionInLinks(tPawn.currentNode); for (int i = 0; i < distance; i++) { NodeBehaviour tmpNode = tPawn.currentNode.GetLinkInDirection(pushDirection); if (!tmpNode.isOccupied) { tPawn.GetComponent <GridNavMeshWrapper>().currentNode = tmpNode; } } return(true); }
private NodeBehaviour ConnectToOtherNode(NodeBehaviour currentNode) { float closestDistance = float.MaxValue; NodeBehaviour candidate = null; foreach (NodeBehaviour otherNode in DataTools.allNodes) { if (otherNode.connected) { continue; } if (currentNode != otherNode) { float distance = Vector3.Distance(currentNode.transform.position, otherNode.transform.position); if (distance < closestDistance) { candidate = otherNode; closestDistance = distance; } } } currentNode.nextNode = candidate; candidate.prevNode = currentNode; candidate.connected = true; return(candidate); }
bool Move(Pawn p, NodeBehaviour target) { if (pawns.Contains(p)) { p.move = new MoveCommand(p); if (debug) { Debug.Log(p.move); } bool result = p.move.Execute(); if (result) { if (debug) { Debug.Log("Pathfinder Successful"); } } else if (debug) { Debug.Log("Pathfinder Failed"); } return(result); } return(false); }
void NextDestination() { if (path == null) { return; } if (debug) { Debug.Log(path.Count); } currentDestination = path[0]; path.RemoveAt(0); if (debug) { Debug.Log(path.Count); } if (path.Count == 0) { if (debug) { Debug.Log("Nulling Path"); } path = null; } velocity = currentDestination.offsetPosition - position; velocity.Normalize(); velocity *= Speed; if (debug) { Debug.Log(velocity); } }
private static void onNodeCreation(NodeBehaviour node) { var go = node.gameObject; go.layer = LayerMask.NameToLayer("AutoGen"); go.tag = "EditorAutoGen"; }
private void Launch() { _launched = false; // Use object already set in UpdateRaycast if (RaycastSelectObject != null) { NodeBehaviour newNode = RaycastSelectObject.GetComponent <NodeBehaviour>(); if (newNode != null) { if (newNode.IsCursorSelected && newNode.IsOpen) { // Update this NodeBehaviour NodeBehaviour currentNode = GetComponentInParent <NodeBehaviour>(); currentNode.OnTravelFrom(); SetToNode(RaycastSelectObject); newNode.OnTravelTo(); _launched = true; GameLoop.Instance.CurrentLevel.PushLightLine(currentNode.transform, newNode.transform); } else { newNode.FlashWarningColor(); } } } }
void Start() { position = StartingNode.offsetPosition; currentNode = StartingNode; currentDestination = StartingNode; DestinationReached += TurnManager.instance.SetFree; }
public override void OnInspectorGUI() { NodeBehaviour node = target as NodeBehaviour; EditorGUI.BeginChangeCheck(); GUILayout.BeginVertical(GUIStyleManager.style.basicStyle); GUILayout.Label("References (non adjustable)", GUIStyleManager.style.titleStyle); GUIStyleManager.style.DrawObjectField("Next node", ref node.nextNode, false); GUIStyleManager.style.DrawObjectField("Previous node", ref node.prevNode, false); GUILayout.Space(10); GUILayout.Label("Node options", GUIStyleManager.style.titleStyle); GUIStyleManager.style.DrawToggle("End node", ref node.endNode); GUIStyleManager.style.DrawToggle("Reset curve", ref node.resetCurves); if (node.resetCurves) { GUIStyleManager.style.DrawWarning("Curve of this node will be reset when the next reconnect will be made"); } GUILayout.EndVertical(); }
void Hit(NodeBehaviour targetNode, Targetable pTarget) { Debug.Log("Target Node " + targetNode); Debug.Log("Targetable " + pTarget); if (pTarget.GetComponent <Pawn>() != null) { double hitChance = 1 - (1 - 0.5) * (Vector3.Distance(owner.transform.position, targetNode.transform.position) - 1) / (range - 1); if (RNG.NextDouble() < hitChance) { double accuracy = Vector3.Distance(targetNode.transform.position, pTarget.GetComponent <Pawn>().transform.position) / 200d; double tmpDamageMod = (1 - accuracy) * RNG.NextDouble() + accuracy; if (tmpDamageMod > 1d) { tmpDamageMod = 1d; } int tmpDamage = (int)System.Math.Round((double)damage * tmpDamageMod); if (tmpDamage < 1) { tmpDamage = 1; } Debug.Log(owner + " hit " + (pTarget.GetComponent <Pawn>()) + " and dealt " + tmpDamage + " damage."); pTarget.GetComponent <Health>().Damage(owner, tmpDamage); } } else if (pTarget.GetComponent <DestroyableProp>() != null) { pTarget.GetComponent <Health>().Damage(owner, 1); } }
public static void CopyFrom(this NodeBehaviour to, NodeBehaviour from) { if (from == null || to == null || from.bindNodes == null || from.bindNodes.Length == 0) { return; } to.FindBoneNodes(); to.FindSMRendererNodes(); NodeData[] fromBindNodes = from.bindNodes; List <NodeData> toBindNodes = new List <NodeData>(); Transform toTran = to.gameObject.transform; foreach (var node in fromBindNodes) { if (node == null || node.transform == null) { continue; } string tranName = node.transform.name; Transform targetTran = toTran.GetChildByName(tranName); if (targetTran != null) { NodeData data = new NodeData(); data.name = node.name; data.nodeType = NodeType.BindNode; data.transform = targetTran; toBindNodes.Add(data); } } to.bindNodes = toBindNodes.ToArray(); }
public static List <NodeBehaviour> NodesWithinSteps(NodeBehaviour node, int steps, bool ignoreOccupied = true) { List <NodeBehaviour> list = new List <NodeBehaviour>(); list.Add(node); if (steps == 0) { return(list); } List <NodeBehaviour> parser = new List <NodeBehaviour>(); parser.AddRange(node.links); List <NodeBehaviour> temp = new List <NodeBehaviour>(); while (parser.Count != 0 && steps > 0) { foreach (NodeBehaviour neighbour in parser) { if (!list.Contains(neighbour)) { if (!ignoreOccupied || !neighbour.isOccupied) { list.Add(neighbour); temp.AddRange(neighbour.links); } } } parser.AddRange(temp.FindAll(x => !list.Contains(x))); steps--; } return(list); }
public void UpdateScene(GameObject nodeObj) { NodeBehaviour node = nodeObj.GetComponent <NodeBehaviour>(); // update scene string scenePath = "Images/" + node.info.sceneName; Sprite sceneSprite = Resources.Load <Sprite>(scenePath); sceneSpriteRenderer.sprite = sceneSprite; // update soundtrack if (audioSource.clip == null || audioSource.clip.name != node.info.soundTrackName) { string audioPath = "Sound/" + node.info.soundTrackName; AudioClip audioClip = Resources.Load <AudioClip>(audioPath); audioSource.clip = audioClip; audioSource.Play(); } // update dialogue StartCoroutine(DisplayText(node.info.dialogues, 1f)); // update graph camera Vector3 nodePos = nodeObj.transform.position; Vector3 cameraPos = graphCamera.transform.position; graphCamera.transform.position = new Vector3(nodePos.x, nodePos.y, cameraPos.z); }
void OnEnable() { nodeBehaviour = (NodeBehaviour)target; bindNodes = new List <NodeData>(nodeBehaviour.bindNodes); boneNodes = new List <NodeData>(nodeBehaviour.boneNodes); smRendererNodes = new List <NodeData>(nodeBehaviour.smRendererNodes); }
public static CoverState GetCoverAtNode(NodeBehaviour node, Pawn other) { Vector3 direction = other.currentNode.position - node.position; direction.Normalize(); RaycastHit hit; if (Physics.Raycast(node.offsetPosition + (Vector3.up * 1.5f), direction, out hit, 1f)) { if (hit.collider.gameObject != other.gameObject) { return(CoverState.Full); } } if (Physics.Raycast(node.offsetPosition + (Vector3.up * 0.5f), direction, out hit, 1f)) { if (hit.collider.gameObject != other.gameObject) { return(CoverState.Half); } } return(CoverState.None); }
private void UpdateRaycast() { var launchDirection = CursorControl.instance.CursorPosition - transform.position; //var launchDistance = launchDirection.magnitude; var ray = new Ray(transform.position, launchDirection); RaycastHit hit; if (Physics.Raycast(ray, out hit, maxDistance: 1000f, layerMask: 1 << 9)) { NodeBehaviour nodeObj = hit.transform.GetComponent <NodeBehaviour>(); if (nodeObj != null && nodeObj.gameObject != RaycastSelectObject) { if (RaycastSelectObject != null) { RaycastSelectObject.GetComponent <NodeBehaviour>().SetAsRaycastHit(false); } RaycastSelectObject = nodeObj.gameObject; RaycastSelectObject.GetComponent <NodeBehaviour>().SetAsRaycastHit(true); } } else { // Reset reference so linerenderer defers to CursorPosition if (RaycastSelectObject != null) { RaycastSelectObject.GetComponent <NodeBehaviour>().SetAsRaycastHit(false); } RaycastSelectObject = null; } }
public override bool Execute() { Debug.Log(target); if (!CheckTarget()) { return(false); } NodeBehaviour tNode = target.GetComponent <NodeBehaviour>(); List <NodeBehaviour> path = Pathfinder.GetPath(owner.currentNode, tNode); if (path.Count == 0) { return(false); } int cost = Mathf.CeilToInt(((float)path.Count - 1f) / (float)Pawn.STEPSPERPOINT); if (!CheckCost(cost)) { return(false); } owner.GetComponent <GridNavMeshWrapper> ().SetPath(path); Debug.Log(owner + " Executes " + name); //also send UI feedback at some point return(true); }
void Update() { if (!stopped) { if (ReachedCurrentDestination()) { currentNode = currentDestination; position = currentNode.offsetPosition; if (path == null) { stopped = true; if (DestinationReached != null) { DestinationReached(); } } else { NextDestination(); } } else { position += velocity; } } modelRoot.LookAt(currentDestination.offsetPosition); }
private void PopThroughHistory() { while (m_history.Count > 0) { NodeBehaviour node = m_history.Pop(); switch (node.m_Operator) { case EBoolOperator.Union: m_YourSymbol.UnionWith(node.m_Symbol); break; case EBoolOperator.Intersection: m_YourSymbol.IntersectionWith(node.m_Symbol); break; case EBoolOperator.Complement: break; case EBoolOperator.EndComparison: default: Debug.Log("YOu shouldnt be here..."); break; } } }
public LinkPositions GetRelativePosition(NodeBehaviour node) { Vector3 offset = node.position - position; offset = new Vector3(offset.x, 0, offset.z); offset.Normalize(); if (Vector3.Dot(offset, Vector3.forward) == 1) { return(LinkPositions.Forward); } else if (Vector3.Dot(offset, Vector3.right) == 1) { return(LinkPositions.Right); } else if (Vector3.Dot(offset, Vector3.back) == 1) { return(LinkPositions.Back); } else if (Vector3.Dot(offset, Vector3.left) == 1) { return(LinkPositions.Left); } throw new UnityException("Nodes not aligned"); }
public void AddNode(NodeBehaviour node) { _nodeList.Add(new GridList(node, node.GridLocation)); if (_totalEntries == _nodeList.Count) { ConvertListToArray(); } }
void Start() { if (SetStartPosition && m_pathController != null && m_pathController.points.Count > 0) { //bodyPhysics.position = m_pathController.points [m_currentNode].position; Mover.SetPosition(m_pathController.points [m_currentNode].position); } if (m_pathController != null) { if (!m_pathController.berzierPath) { foreach (Transform vec in m_pathController.points) { m_list.Add(vec.position); } } else { m_list = m_pathController.GetBerzierPoints(m_pathController.segmentsForCurve); } // m_pathSegments = m_list.Count; m_rotate = m_pathController.loop; m_return = m_pathController.pathReturn; m_time = 0; m_lastStartPoint = this.transform.position; m_lastStartRotation = this.transform.rotation; m_currentDistance = Vector3.Distance(m_lastStartPoint, m_list [m_currentNode]); if (!m_usePhysics) { startTime = Time.time; } else { startTime = Time.time; } this.waitTime = startdelay; NodeBehaviour n = m_pathController.GetNodeBehaviour(m_currentNode); if (n != null) { this.m_speed = n.speed; this.waitTime = n.waitTime; } } if (m_usePhysics) { bodyPhysics = this.GetComponent <Rigidbody2D> (); } rendererSprite = this.GetComponent <Renderer> (); }
public void SetNodeToNull() { if (_selectedNode == null || _selectionSize == 4) { return; } ChangeColorsToOld(); _selectedNode = null; }
// Update is called once per frame void Update() { if (attachedNode.currentObject != null && attachedNode.currentObject.GetComponent <Pawn>()) { attachedNode.currentObject.GetComponent <Pawn>().LevelUp(); attachedNode = null; Destroy(this.gameObject); } }
public void Unbind(NodeBehaviour other) { if (debug) { Debug.Log("Unbinding"); } links.Remove(other); other.links.Remove(this); }
public void Bind(NodeBehaviour other) { OneWayBind(other); if (other.links != null) { other.OneWayBind(this); } }
public void OneWayBind(NodeBehaviour other) { if (other != this) { if (!links.Contains(other)) { links.Add(other); } } }
private void UnloadSkeleton() { nodeBehaviour = null; partInstanceDic.Clear(); if (avatarInstance != null) { GameObject.DestroyImmediate(avatarInstance); avatarInstance = null; } }
public bool IsPlayerOnSideTo(NodeBehaviour lookAtNode) { if (player.CurrentNode.transform.position == lookAtNode.transform.position) { return(true); } else { return(false); } }