int RebuildSegment(int segmentIndex, NetInfo newPrefab, Vector3 directionPoint, Vector3 direction, ref ToolError error)
        {
            //  ModDebug.LogClassAndMethodName(this.GetType().Name, System.Reflection.MethodBase.GetCurrentMethod().Name);

            NetManager net    = Singleton <NetManager> .instance;
            NetInfo    prefab = net.m_segments.m_buffer[segmentIndex].Info;

            NetTool.ControlPoint startPoint;
            NetTool.ControlPoint middlePoint;
            NetTool.ControlPoint endPoint;

            MethodInfo dynMethod = netTool.GetType().GetMethod("ChangeElevation", BindingFlags.NonPublic | BindingFlags.Instance);

            if (toolMode == ToolMode.RoadHeightUp)
            {
                Singleton <SimulationManager> .instance.AddAction <bool>((IEnumerator <bool>) dynMethod.Invoke(new NetTool(), new object[] { 1 }));
            }
            else if (toolMode == ToolMode.RoadHeightDown)
            {
                Singleton <SimulationManager> .instance.AddAction <bool>((IEnumerator <bool>) dynMethod.Invoke(new NetTool(), new object[] { -1 }));
            }

            GetSegmentControlPoints(segmentIndex, out startPoint, out middlePoint, out endPoint);

            if (direction.magnitude > 0.0f)
            {
                float dot       = Vector3.Dot(direction.normalized, (endPoint.m_position - startPoint.m_position).normalized);
                float threshold = Mathf.Cos(Mathf.PI / 4);

                if (dot > -threshold && dot < threshold)
                {
                    return(0);
                }
            }

            ushort node           = 0;
            ushort segment        = 0;
            int    cost           = 0;
            int    productionRate = 0;

            //  CreateNode(NetInfo info, NetTool.ControlPoint startPoint, NetTool.ControlPoint middlePoint, NetTool.ControlPoint endPoint, FastList<NetTool.NodePosition> nodeBuffer, int maxSegments, bool test, bool visualize, bool autoFix, bool needMoney, bool invert, bool switchDir, ushort relocateBuildingID, out ushort firstNode, out ushort lastNode, out ushort segment, out int cost, out int productionRate)
            if (mouseDown && ((currentTime - prevRebuildTime) > 0.4f))
            {
                newPrefab.m_minHeight = 12.0f;
                NetTool.CreateNode(newPrefab, startPoint, middlePoint, endPoint, NetTool.m_nodePositionsSimulation, 1000, false, false, true, false, false, false, (ushort)0, out node, out segment, out cost, out productionRate);
            }
            if (segment != 0)
            {
                if (newPrefab.m_class.m_service == ItemClass.Service.Road)
                {
                    Singleton <CoverageManager> .instance.CoverageUpdated(ItemClass.Service.None, ItemClass.SubService.None, ItemClass.Level.None);
                }

                error = ToolError.None;
                return(segment);
            }

            return(0);
        }
Example #2
0
        public void Initialize(MeasureTool measureTool, NetTool netTool)
        {
            try
            {
                _terrainManager = Singleton <TerrainManager> .instance;

                _measureTool = measureTool;
                _netTool     = netTool;

                _controlPointCountField = netTool.GetType().GetField("m_controlPointCount", BindingFlags.NonPublic | BindingFlags.Instance);
                _controlPointsField     = netTool.GetType().GetField("m_controlPoints", BindingFlags.NonPublic | BindingFlags.Instance);
            }
            catch (Exception e)
            {
                Debug.Log("[Measure It!] MeasureInfo:Initialize -> Exception: " + e.Message);
            }
        }
Example #3
0
        public void Start()
        {
            NetSkins_Support.Init();

            // Getting NetTool
            m_netTool = GameObject.FindObjectOfType <NetTool>();
            if (m_netTool == null)
            {
                DebugUtils.Warning("NetTool not found.");
                enabled = false;
                return;
            }

            // Getting BulldozeTool
            m_bulldozeTool = GameObject.FindObjectOfType <BulldozeTool>();
            if (m_bulldozeTool == null)
            {
                DebugUtils.Warning("BulldozeTool not found.");
                enabled = false;
                return;
            }

            // Getting BuildingTool
            m_buildingTool = GameObject.FindObjectOfType <BuildingTool>();
            if (m_buildingTool == null)
            {
                DebugUtils.Warning("BuildingTool not found.");
                enabled = false;
                return;
            }

            // Getting NetTool private fields
            m_elevationField         = m_netTool.GetType().GetField("m_elevation", BindingFlags.NonPublic | BindingFlags.Instance);
            m_elevationUpField       = m_netTool.GetType().GetField("m_buildElevationUp", BindingFlags.NonPublic | BindingFlags.Instance);
            m_elevationDownField     = m_netTool.GetType().GetField("m_buildElevationDown", BindingFlags.NonPublic | BindingFlags.Instance);
            m_buildingElevationField = m_buildingTool.GetType().GetField("m_elevation", BindingFlags.NonPublic | BindingFlags.Instance);
            m_controlPointCountField = m_netTool.GetType().GetField("m_controlPointCount", BindingFlags.NonPublic | BindingFlags.Instance);
            m_upgradingField         = m_netTool.GetType().GetField("m_upgrading", BindingFlags.NonPublic | BindingFlags.Instance);
            m_placementErrorsField   = m_buildingTool.GetType().GetField("m_placementErrors", BindingFlags.NonPublic | BindingFlags.Instance);

            if (m_elevationField == null || m_elevationUpField == null || m_elevationDownField == null || m_buildingElevationField == null || m_controlPointCountField == null || m_upgradingField == null || m_placementErrorsField == null)
            {
                DebugUtils.Warning("NetTool fields not found");
                m_netTool = null;
                enabled   = false;
                return;
            }

            // Getting Upgrade button template
            try
            {
                m_upgradeButtonTemplate = GameObject.Find("RoadsSmallPanel").GetComponent <GeneratedScrollPanel>().m_OptionsBar.Find <UIButton>("Upgrade");
            }
            catch
            {
                DebugUtils.Warning("Upgrade button template not found");
            }

            // Creating UI
            CreateToolOptionsButton();

            // Store segment count
            m_segmentCount = NetManager.instance.m_segmentCount;

            // Getting control points
            try
            {
                m_controlPoints       = m_netTool.GetType().GetField("m_controlPoints", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(m_netTool) as NetTool.ControlPoint[];
                m_cachedControlPoints = m_netTool.GetType().GetField("m_cachedControlPoints", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(m_netTool) as NetTool.ControlPoint[];
            }
            catch
            {
                DebugUtils.Warning("ControlPoints not found");
            }

            // Init dictionary
            RoadPrefab.Initialize();

            m_inEditor            = (ToolManager.instance.m_properties.m_mode & ItemClass.Availability.AssetEditor) != ItemClass.Availability.None;
            RoadPrefab.singleMode = m_inEditor;

            if (changeMaxTurnAngle.value)
            {
                RoadPrefab.SetMaxTurnAngle(maxTurnAngle.value);
            }

            // Update Catenary
            UpdateCatenary();

            // Fix nodes
            FixNodes();

            DebugUtils.Log("Initialized");
        }