コード例 #1
0
 void DestroyBuildTool()
 {
     if (buildTool != null)
     {
         ModDebug.Log("Tool destroyed");
         BuildTool118.Destroy(buildTool);
         buildTool = null;
     }
 }
コード例 #2
0
 void CreateBuildTool()
 {
     if (buildTool == null)
     {
         buildTool = ToolsModifierControl.toolController.gameObject.GetComponent <BuildTool118>();
         if (buildTool == null)
         {
             buildTool = ToolsModifierControl.toolController.gameObject.AddComponent <BuildTool118>();
             ModDebug.Log("Tool created: " + buildTool);
         }
         else
         {
             ModDebug.Log("Found existing tool: " + buildTool);
         }
     }
 }
コード例 #3
0
        void _OnBeforeSimulationTick()
        {
            if (toolMode == ToolMode.None)
            {
                return;
            }

            if (!mouseDown)
            {
                dragging = false;
                prevBuiltSegmentIndex = 0;
            }

            if (buildTool != null)
            {
                buildTool.isHoveringSegment = false;
                buildTool.toolMode          = toolMode;
                buildTool.ToolCursor        = netTool.m_upgradeCursor;
            }

            if (!mouseRayValid)
            {
                return;
            }

            ToolBase.RaycastInput raycastInput = new ToolBase.RaycastInput(mouseRay, mouseRayLength);
            raycastInput.m_netService         = raycastService;
            raycastInput.m_ignoreTerrain      = true;
            raycastInput.m_ignoreNodeFlags    = NetNode.Flags.All;
            raycastInput.m_ignoreSegmentFlags = NetSegment.Flags.Untouchable;

            ToolBase.RaycastOutput raycastOutput;
            if (BuildTool118.RayCast(raycastInput, out raycastOutput))
            {
                int segmentIndex = raycastOutput.m_netSegment;
                if (segmentIndex != 0)
                {
                    NetManager net           = Singleton <NetManager> .instance;
                    NetInfo    newRoadPrefab = null;

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

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

                    ushort node;
                    ushort outSegment;
                    int    cost;
                    int    productionRate;
                    // Check for out-of-area error and initialized collide arrays for visualization
                    ToolBase.ToolErrors errors = NetTool.CreateNode(net.m_segments.m_buffer[segmentIndex].Info,
                                                                    startPoint, middlePoint, endPoint, NetTool.m_nodePositionsSimulation, 1000,
                                                                    true, false, true, false, false, false, (ushort)0, out node, out outSegment, out cost, out productionRate);

                    if ((errors & ToolBase.ToolErrors.OutOfArea) != 0)
                    {
                        toolError = ToolError.OutOfArea;
                    }
                    else
                    {
                        if (mouseDown)
                        {
                            HandleMouseDrag(ref raycastOutput, ref toolError, false, ref newRoadPrefab, ref segmentIndex);

                            if (segmentIndex == prevBuiltSegmentIndex)
                            {
                                toolError = ToolError.AlreadyBuilt;
                            }
                        }
                        else
                        {
                            HandleMouseDrag(ref raycastOutput, ref toolError, true, ref newRoadPrefab, ref segmentIndex);
                        }
                    }

                    if (buildTool != null)
                    {
                        buildTool.segment           = net.m_segments.m_buffer[segmentIndex];
                        buildTool.segmentIndex      = segmentIndex;
                        buildTool.isHoveringSegment = toolError != ToolError.Unknown;
                        if (newRoadPrefab != null)
                        {
                            buildTool.newPrefab = newRoadPrefab;
                        }
                        GetSegmentControlPoints(segmentIndex, out buildTool.startPoint, out buildTool.middlePoint, out buildTool.endPoint);
                    }
                }
            }

            if (buildTool != null)
            {
                buildTool.toolError = toolError;
            }
        }
コード例 #4
0
 void DestroyBuildTool() {
     if (buildTool != null) {
         ModDebug.Log("Tool destroyed");
         BuildTool118.Destroy(buildTool);
         buildTool = null;
     }
 }
コード例 #5
0
 void CreateBuildTool() {
     if (buildTool == null) {
         buildTool = ToolsModifierControl.toolController.gameObject.GetComponent<BuildTool118>();
         if (buildTool == null) {  
             buildTool = ToolsModifierControl.toolController.gameObject.AddComponent<BuildTool118>();
             ModDebug.Log("Tool created: " + buildTool);
         }
         else {
             ModDebug.Log("Found existing tool: " + buildTool);
         }
     } 
 }