Exemple #1
0
    public void OnSceneGUI()
    {
        if (prefabCreator.hideFlags != HideFlags.NotEditable)
        {
            Event guiEvent = Event.current;

            Ray ray = HandleUtility.GUIPointToWorldRay(guiEvent.mousePosition);

            RaycastHit raycastHit;
            if (Physics.Raycast(ray, out raycastHit, 100f, ~(1 << prefabCreator.settings.FindProperty("ignoreMouseRayLayer").intValue | 1 << prefabCreator.settings.FindProperty("roadLayer").intValue)))
            {
                Vector3 hitPosition = raycastHit.point;

                if (guiEvent.control == true)
                {
                    Vector3 nearestGuideline = Misc.GetNearestGuidelinePoint(hitPosition);
                    if (nearestGuideline != Misc.MaxVector3)
                    {
                        hitPosition = new Vector3(nearestGuideline.x, hitPosition.y, nearestGuideline.z);
                    }
                    else
                    {
                        hitPosition = new Vector3(Mathf.Round(hitPosition.x), hitPosition.y, Mathf.Round(hitPosition.z));
                    }
                }

                if (guiEvent.type == EventType.MouseDown)
                {
                    if (guiEvent.button == 0)
                    {
                        if (guiEvent.shift == true)
                        {
                            prefabCreator.CreatePoints(hitPosition);
                        }
                    }
                    else if (guiEvent.button == 1 && guiEvent.shift == true)
                    {
                        prefabCreator.RemovePoints();
                    }
                }

                if (prefabCreator.transform.childCount > 0 && prefabCreator.transform.GetChild(0).childCount > 1 && (guiEvent.type == EventType.MouseDrag || guiEvent.type == EventType.MouseMove || guiEvent.type == EventType.MouseDown))
                {
                    points = CalculateTemporaryPoints(guiEvent, hitPosition);
                }

                Draw(guiEvent, hitPosition);
            }

            if (Physics.Raycast(ray, out raycastHit, 100f, ~(1 << prefabCreator.settings.FindProperty("roadLayer").intValue)))
            {
                Vector3 hitPosition = raycastHit.point;

                if (guiEvent.control == true)
                {
                    Vector3 nearestGuideline = Misc.GetNearestGuidelinePoint(hitPosition);
                    if (nearestGuideline != Misc.MaxVector3)
                    {
                        hitPosition = new Vector3(nearestGuideline.x, hitPosition.y, nearestGuideline.z);
                    }
                    else
                    {
                        hitPosition = new Vector3(Mathf.Round(hitPosition.x), hitPosition.y, Mathf.Round(hitPosition.z));
                    }
                }

                if (guiEvent.shift == false)
                {
                    prefabCreator.MovePoints(hitPosition, guiEvent, raycastHit);
                }
                else
                {
                    prefabCreator.MovePoints(Misc.MaxVector3, guiEvent, raycastHit);
                }
            }

            GameObject.FindObjectOfType <RoadSystem>().ShowCreationButtons();
            SceneView.currentDrawingSceneView.Repaint();
        }
    }
    public void OnSceneGUI()
    {
        if (prefabCreator.isFollowObject == false)
        {
            HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive));
            Event guiEvent = Event.current;

            Ray ray = HandleUtility.GUIPointToWorldRay(guiEvent.mousePosition);

            RaycastHit raycastHit;
            if (Physics.Raycast(ray, out raycastHit, 100f, ~(1 << prefabCreator.globalSettings.ignoreMouseRayLayer | 1 << prefabCreator.globalSettings.roadLayer)))
            {
                Vector3 hitPosition = raycastHit.point;

                if (guiEvent.control == true)
                {
                    Vector3 nearestGuideline = Misc.GetNearestGuidelinePoint(hitPosition);
                    if (nearestGuideline != Misc.MaxVector3)
                    {
                        hitPosition = nearestGuideline;
                    }
                    else
                    {
                        hitPosition = Misc.Round(hitPosition);
                    }
                }

                if (guiEvent.type == EventType.MouseDown)
                {
                    if (guiEvent.button == 0)
                    {
                        if (guiEvent.shift == true)
                        {
                            prefabCreator.CreatePoints(hitPosition);
                        }
                    }
                    else if (guiEvent.button == 1 && guiEvent.shift == true)
                    {
                        prefabCreator.RemovePoints();
                    }
                }

                if (prefabCreator.transform.childCount > 0 && prefabCreator.transform.GetChild(0).childCount > 1 && (guiEvent.type == EventType.MouseDrag || guiEvent.type == EventType.MouseMove || guiEvent.type == EventType.MouseDown))
                {
                    points = CalculatePoints(guiEvent, hitPosition);
                }

                Draw(guiEvent, hitPosition);
            }

            if (Physics.Raycast(ray, out raycastHit, 100f, ~(1 << prefabCreator.globalSettings.roadLayer)))
            {
                Vector3 hitPosition = raycastHit.point;

                if (guiEvent.control == true)
                {
                    hitPosition = Misc.Round(hitPosition);
                }

                if (guiEvent.shift == false)
                {
                    prefabCreator.MovePoints(hitPosition, guiEvent, raycastHit);
                }
            }

            GameObject.Find("Road System").GetComponent <RoadSystem>().ShowCreationButtons();
        }
    }
Exemple #3
0
    public void OnSceneGUI()
    {
        if (prefabCreator.transform.hasChanged == true)
        {
            prefabCreator.transform.rotation   = Quaternion.identity;
            prefabCreator.transform.localScale = Vector3.one;
            prefabCreator.PlacePrefabs();
            prefabCreator.transform.hasChanged = false;
        }

        Event guiEvent = Event.current;
        Ray   ray      = HandleUtility.GUIPointToWorldRay(guiEvent.mousePosition);

        RaycastHit raycastHit;

        if (Physics.Raycast(ray, out raycastHit, 100f, ~(1 << LayerMask.NameToLayer("Ignore Mouse Ray") | 1 << LayerMask.NameToLayer("Prefab Line"))))
        {
            Vector3 hitPosition = raycastHit.point;

            if (guiEvent.control == true)
            {
                Vector3 nearestGuideline = Misc.GetNearestGuidelinePoint(hitPosition);
                if (nearestGuideline != Misc.MaxVector3)
                {
                    hitPosition = new Vector3(nearestGuideline.x, hitPosition.y, nearestGuideline.z);
                }
                else
                {
                    hitPosition = new Vector3(Mathf.Round(hitPosition.x), hitPosition.y, Mathf.Round(hitPosition.z));
                }
            }

            if (guiEvent.type == EventType.MouseDown)
            {
                if (guiEvent.button == 0)
                {
                    if (guiEvent.shift == true)
                    {
                        prefabCreator.CreatePoints(hitPosition);
                    }
                }
                else if (guiEvent.button == 1 && guiEvent.shift == true)
                {
                    prefabCreator.RemovePoints();
                }
            }

            if (prefabCreator.transform.childCount > 0 && prefabCreator.transform.GetChild(0).childCount > 1 && (guiEvent.type == EventType.MouseDrag || guiEvent.type == EventType.MouseMove || guiEvent.type == EventType.MouseDown))
            {
                points = CalculateTemporaryPoints(guiEvent, hitPosition);
            }

            Draw(guiEvent, hitPosition);
        }

        if (Physics.Raycast(ray, out raycastHit, 100f, ~(1 << LayerMask.NameToLayer("Prefab Line"))))
        {
            Vector3 hitPosition = raycastHit.point;

            if (guiEvent.control == true)
            {
                Vector3 nearestGuideline = Misc.GetNearestGuidelinePoint(hitPosition);
                if (nearestGuideline != Misc.MaxVector3)
                {
                    hitPosition = new Vector3(nearestGuideline.x, hitPosition.y, nearestGuideline.z);
                }
                else
                {
                    hitPosition = new Vector3(Mathf.Round(hitPosition.x), hitPosition.y, Mathf.Round(hitPosition.z));
                }
            }

            if (guiEvent.shift == false)
            {
                prefabCreator.MovePoints(hitPosition, guiEvent, raycastHit);
            }
            else
            {
                prefabCreator.MovePoints(Misc.MaxVector3, guiEvent, raycastHit);
            }
        }

        if (guiEvent.type == EventType.MouseDown && guiEvent.button == 2)
        {
            if (Physics.Raycast(ray, out raycastHit, 100f, 1 << LayerMask.NameToLayer("Prefab Line")))
            {
                if (raycastHit.transform.parent.parent.GetComponent <PrefabLineCreator>() != null)
                {
                    prefabCreator.CopyPrefabLine(raycastHit.transform.parent.parent.GetComponent <PrefabLineCreator>());
                }
            }
        }

        prefabCreator.transform.parent.GetComponent <RoadSystem>().ShowCreationButtons();
        SceneView.currentDrawingSceneView.Repaint();
    }