public void AddLink(PowerManager iTarget, bool longLink) { Vector3 sourcePosition = transform.position; Vector3 targetPosition = iTarget.transform.position; // Isn't self // Has Room // Target Has Room // Link doesn't already exist. // Asserts? Something like it anyway. If x, continue, else break and throw exception. if (this != iTarget) { // Can't link to yoruself if ((CanLinkOutLong() && longLink) || CanLinkOutShort()) { // Gotta have room for output link. if (iTarget.CanLinkIn()) { // And input link on the target if (_powerLinksOut.Find(x => x._target == iTarget) == null && _powerLinksIn.Find(x => x._source == iTarget) == null) { // Make sure it doesn't exist already. No duplicates. // Check range. if (PowerLink.isInRange(this, iTarget, longLink)) { // Always break long links out if you have a link out already. // Only one allowed. if (longLink) { // Long links remove all other links out, and long links in on the target. RemoveLinksOut(); iTarget.RemoveLongLinksIn(); EntityManager.CreatePowerLink(this, iTarget); } else { // short links cannot exist with long links, in or out. RemoveLongLinksOut(); iTarget.RemoveLongLinksIn(); EntityManager.CreatePowerLink(this, iTarget); } } else { EntityManager.CreateFloatingText(targetPosition, "Out of Range", 1.0f, Color.red); } } else { EntityManager.CreateFloatingText(targetPosition, "Already Linked", 1.0f, Color.red); } } else { EntityManager.CreateFloatingText(targetPosition, "Link Limit Reached", 1.0f, Color.red); } } else { EntityManager.CreateFloatingText(sourcePosition, "Link Limit Reached", 1.0f, Color.red); } } else { EntityManager.CreateFloatingText(sourcePosition, "Cannot Link to Self", 1.0f, Color.red); } }