예제 #1
0
파일: Main.cs 프로젝트: pipe01/WireEdit
        private void RunWireHighlight()
        {
            if (Input.GetMouseButtonDown(0) && Input.GetKey(KeyCode.LeftControl) && State.CurrentState == States.None)
            {
                foreach (var item in Highlighted)
                {
                    Highlighter.StopHighlight(item);
                }
                Highlighted.Clear();

                if (Physics.Raycast(FirstPersonInteraction.Ray(), out var hit, Settings.ReachDistance) &&
                    hit.collider.tag != "CircuitBoard")
                {
                    var wire = hit.collider.GetComponent <Wire>();

                    if (wire != null) //Clicked on wire, highlight it and both ends
                    {
                        HighlightWire(wire);
                    }
                    else
                    {
                        var input  = hit.collider.GetComponent <CircuitInput>();
                        var output = hit.collider.GetComponent <CircuitOutput>();

                        if (input != null) //Clicked on input peg, highlight it and all wires connected to it
                        {
                            foreach (var item in input.IIConnections.Cast <Wire>().Concat(input.IOConnections.Cast <Wire>()))
                            {
                                HighlightWire(item);
                            }
                        }
                        else if (output != null) //Clicked on output peg, highlight it and all wires connected to it
                        {
                            foreach (var item in output.GetIOConnections())
                            {
                                HighlightWire(item);
                            }
                        }
                        else //Clicked on component, highlight inputs and outputs and all wires connected to it
                        {
                            var component = ComponentPlacer.FullComponent(hit.collider);

                            foreach (var item in Mover.GetWires(component))
                            {
                                HighlightWire(item);
                            }
                        }
                    }
                }
            }

            void HighlightWire(Wire wire)
            {
                Highlight(wire.gameObject, 0);

                HighlightComponent(wire.Point1);
                HighlightComponent(wire.Point2);
            }

            void HighlightComponent(Transform wireReference)
            {
                Highlight(wireReference.parent.gameObject, 3);

                if (wireReference.parent.parent?.tag != "CircuitBoard" && wireReference.parent.parent != null)
                {
                    Highlight(wireReference.parent.parent.gameObject, 2);
                }
            }

            void Highlight(GameObject obj, int clr)
            {
                Highlighted.Add(obj);
                Highlighter.Highlight(obj, clr);
            }
        }
예제 #2
0
 public static void CancelPlacement() => Mover.CancelMove();