コード例 #1
0
ファイル: Tool.cs プロジェクト: doctorvargaz/Picker
        protected override void OnToolUpdate()
        {
            base.OnToolUpdate();

            Ray          ray   = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastInput input = new RaycastInput(ray, Camera.main.farClipPlane)
            {
                m_ignoreTerrain       = false,
                m_ignoreSegmentFlags  = NetSegment.Flags.Untouchable,
                m_ignoreNodeFlags     = NetNode.Flags.All,
                m_ignorePropFlags     = PropInstance.Flags.None,
                m_ignoreTreeFlags     = TreeInstance.Flags.None,
                m_ignoreBuildingFlags = Building.Flags.None,

                m_ignoreCitizenFlags       = CitizenInstance.Flags.All,
                m_ignoreVehicleFlags       = Vehicle.Flags.Created,
                m_ignoreDisasterFlags      = DisasterData.Flags.All,
                m_ignoreTransportFlags     = TransportLine.Flags.All,
                m_ignoreParkedVehicleFlags = VehicleParked.Flags.All,
                m_ignoreParkFlags          = DistrictPark.Flags.All
            };

            RayCast(input, out RaycastOutput output);

            // Set the world mouse position (useful for my implementation of StepOver)
            mouseCurrentPosition = output.m_hitPos;

            objectBuffer.Clear();

            if (output.m_netSegment != 0)
            {
                objectBuffer.Add(new InstanceID()
                {
                    NetSegment = output.m_netSegment
                });
            }
            if (output.m_treeInstance != 0)
            {
                objectBuffer.Add(new InstanceID()
                {
                    Tree = output.m_treeInstance
                });
            }
            if (output.m_propInstance != 0)
            {
                objectBuffer.Add(new InstanceID()
                {
                    Prop = output.m_propInstance
                });
            }
            if (output.m_building != 0)
            {
                objectBuffer.Add(new InstanceID()
                {
                    Building = output.m_building
                });
            }

            objectBuffer.Sort((a, b) => Vector3.Distance(a.Position(), mouseCurrentPosition).CompareTo(Vector3.Distance(b.Position(), mouseCurrentPosition)));
            if (objectBuffer.Count > 0)
            {
                hoveredId = objectBuffer[0];
            }
            else
            {
                hoveredId = InstanceID.Empty;
            }

            // A prefab has been selected. Find it in the UI and enable it.
            if (Input.GetKeyDown(KeyCode.Return) || Input.GetMouseButtonDown(0))
            {
                PrefabInfo info = hoveredId.Info();
                if (info == null)
                {
                    enabled = false;
                    ToolsModifierControl.SetTool <DefaultTool>();
                    return;
                }
                Activate(info);
            }

            // Escape key or RMB hit = disable the tool
            if (Input.GetKeyDown(KeyCode.Escape) || Input.GetMouseButtonDown(1))
            {
                enabled = false;
                ToolsModifierControl.SetTool <DefaultTool>();
            }
        }
コード例 #2
0
        protected override void OnToolUpdate()
        {
            base.OnToolUpdate();

            // Raycast to all currently "allowed"
            Ray          ray   = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastInput input = new RaycastInput(ray, Camera.main.farClipPlane);

            input.m_ignoreTerrain       = false;
            input.m_ignoreSegmentFlags  = np_allowSegments ? NetSegment.Flags.Untouchable : NetSegment.Flags.All;
            input.m_ignoreNodeFlags     = np_allowNodes ? NetNode.Flags.Untouchable : NetNode.Flags.All;
            input.m_ignorePropFlags     = np_allowProps ? PropInstance.Flags.None : PropInstance.Flags.All;
            input.m_ignoreTreeFlags     = np_allowTrees ? TreeInstance.Flags.None : TreeInstance.Flags.All;
            input.m_ignoreBuildingFlags = np_allowBuildings ? Building.Flags.Untouchable : Building.Flags.All;

            input.m_ignoreCitizenFlags       = CitizenInstance.Flags.All;
            input.m_ignoreVehicleFlags       = Vehicle.Flags.Created;
            input.m_ignoreDisasterFlags      = DisasterData.Flags.All;
            input.m_ignoreTransportFlags     = TransportLine.Flags.All;
            input.m_ignoreParkedVehicleFlags = VehicleParked.Flags.All;
            input.m_ignoreParkFlags          = DistrictPark.Flags.All;

            RayCast(input, out RaycastOutput output);

            // Set the world mouse position (useful for my implementation of StepOver)
            np_mouseCurrentPosition = output.m_hitPos;

            // Step Over Block.
            if (Input.GetKeyDown(KeyCode.O)) // @TODO allow user to customize this.
            {
                Debug.Log("attempted to step over");
                np_stepOverCounter++;

                if (np_stepOverCounter == 1 && np_hasSteppedOver == false) // Only will be executed the first time we reach 1.
                {
                    // @TODO populate step over buffer
                }

                np_hasSteppedOver = true;

                if (np_stepOverCounter >= np_stepOverBuffer.Count)
                {
                    np_stepOverCounter = 0;
                }
                np_hoveredObject = np_stepOverBuffer[np_stepOverCounter];
            }

            // This code is used when the step over function is not active. It will choose the closest of any given object and set it as the hovered object.
            if (!np_hasSteppedOver)
            {
                np_stepOverBuffer.Clear();

                if (output.m_netSegment != 0)
                {
                    np_stepOverBuffer.Add(new InstanceID()
                    {
                        NetSegment = output.m_netSegment
                    });
                }
                if (output.m_netNode != 0)
                {
                    np_stepOverBuffer.Add(new InstanceID()
                    {
                        NetNode = output.m_netNode
                    });
                }
                if (output.m_treeInstance != 0)
                {
                    np_stepOverBuffer.Add(new InstanceID()
                    {
                        Tree = output.m_treeInstance
                    });
                }
                if (output.m_propInstance != 0)
                {
                    np_stepOverBuffer.Add(new InstanceID()
                    {
                        NetNode = output.m_propInstance
                    });
                }
                if (output.m_building != 0)
                {
                    np_stepOverBuffer.Add(new InstanceID()
                    {
                        Building = output.m_building
                    });
                }

                np_stepOverBuffer.Sort((a, b) => Vector3.Distance(a.Position(), np_mouseCurrentPosition).CompareTo(Vector3.Distance(b.Position(), np_mouseCurrentPosition)));
                if (np_stepOverBuffer.Count > 0)
                {
                    np_hoveredObject = np_stepOverBuffer[0];
                }
                else
                {
                    np_hoveredObject = InstanceID.Empty;
                }
            }
            else
            {
                // This function resets the step over function.
                if (np_mouseCurrentPosition != np_stepOverPosition)
                {
                    np_hasSteppedOver = false;
                }
            }

            // A prefab has been selected. Find it in the UI and enable it.
            if (Input.GetKeyDown(KeyCode.Return) || Input.GetMouseButtonDown(0))
            {
                ShowInPanelResolveGrowables(Default(np_hoveredObject.Info()));
            }

            // Escape key hit = disable the tool
            if (Input.GetKeyDown(KeyCode.Escape))
            {
                enabled = false;
                ToolsModifierControl.SetTool <DefaultTool>();
            }
        }