/// <summary> /// Callback triggered when the player clicks on something. /// </summary> void OnClick(int button) { if (button == 0) { if (mIsValid) { if (mTargetTown != null) { if (mRoute.Connect(mTargetTown)) { // See if there is a duplicate route foreach (TradeRoute tr in TradeRoute.list) { if (tr != mRoute && tr.GetConnectedTown(mRoute.town0) == mRoute.town1) { // Copy the trade path tr.CopyPath(mRoute.path); // Ensure that no towns are still referencing this trade route foreach (Town t in Town.list) { t.DisconnectTradeRoute(tr); } Object.Destroy(mGO); break; } } // This route has now been created mIsValid = false; mTargetTown = null; mRoute = null; mGO = null; } } else { mRoute.Add(mTargetPos); } } } else if (!mRoute.UndoAdd()) { foreach (Town t in Town.list) { t.DisconnectTradeRoute(mRoute); } Object.Destroy(mGO); mIsValid = false; mTargetTown = null; mRoute = null; mGO = null; } }