コード例 #1
0
 private void RemoveElementFromList(ElementObject elementObject)
 {
     if (!elementObject.CanDelete)
     {
         return;
     }
     if (elementObject.GetComponent <ObjObstacle>() != null)
     {
         ObstacleList.Remove((ObjObstacle)elementObject);
     }
     else if (elementObject.GetComponent <ObjCheckPoint>() != null)
     {
         CheckPointList.Remove((ObjCheckPoint)elementObject);
     }
     else if (elementObject.GetComponent <ObjHuman>() != null)
     {
         HumanList.Remove((ObjHuman)elementObject);
     }
     else if (elementObject.GetComponent <ObjAICar>() != null)
     {
         CarList.Remove(elementObject);
     }
     else if (elementObject.GetComponent <ObjTrafficLight>() != null)
     {
         TrafficLightList.Remove((ObjTrafficLight)elementObject);
     }
     if (ElementList.Contains(elementObject))
     {
         ElementList.Remove(elementObject);
     }
     Destroy(elementObject);
     SelectedElement = null;
 }
コード例 #2
0
        public Transform AddLogic(GameObject obj, ElementObject elementObject)
        {
            Transform logicTransform = Instantiate(obj, Logics).transform;

            logicTransform.GetComponent <LogicObj>().elementObject = elementObject;
            return(logicTransform);
        }
コード例 #3
0
ファイル: ObjAICar.cs プロジェクト: strongdeer/autocore_sim
 bool RayCheckCar(Vector3 posOrigin, Vector3 direction, out ElementObject element)
 {
     rayElement = new Ray(posOrigin, direction);
     if (Physics.Raycast(rayElement, out RaycastHit hitInfo, distanceBrake + 2, maskElement))
     {
         element = hitInfo.transform.GetComponentInParent <ElementObject>();
         if (element != null && element != this)
         {
             return(true);
         }
     }
     element = null;
     return(false);
 }
コード例 #4
0
 public void RemoveAllElements()
 {
     for (int i = ElementList.Count - 1; i >= 0; i--)
     {
         ElementObject Element = ElementList[i];
         if (!Element.CanDelete)
         {
             continue;
         }
         Destroy(Element.gameObject);
     }
     ObstacleList.Clear();
     HumanList.Clear();
     CarList.Clear();
     CheckPointList.Clear();
     CarList.Add(ObjTestCar.TestCar);
     SelectedElement = null;
 }
コード例 #5
0
 public void AddCheckPointElement(ElementObject obj)
 {
     CheckPointList.Add((ObjCheckPoint)obj);
 }
コード例 #6
0
 public void AddObstacleElement(ElementObject obj)
 {
     ObstacleList.Add((ObjObstacle)obj);
 }
コード例 #7
0
 public void AddHumanElement(ElementObject obj)
 {
     HumanList.Add((ObjHuman)obj);
 }
コード例 #8
0
 public void AddTrafficLightElement(ElementObject obj)
 {
     TrafficLightList.Add((ObjTrafficLight)obj);
 }
コード例 #9
0
 public void AddCarElement(ElementObject obj)
 {
     CarList.Add(obj);
 }
コード例 #10
0
        private void Update()
        {
            mousePos = OverLookCamera.Instance.MouseWorldPos;
            //if (editMode != EditMode.Null)
            //{
            //    if (!isCursorSeted)
            //    {
            //        Cursor.SetCursor(textureTarget, new Vector2(61.5f, 61.5f), cm);
            //        isCursorSeted = true;
            //    }
            //}
            //else
            //{
            //    if (isCursorSeted)
            //    {
            //        Cursor.SetCursor(null, Vector2.zero, cm);
            //        isCursorSeted = false;
            //    }

            //}
            switch (editMode)
            {
            case EditMode.Null:
                indexMode = 0;
                break;

            case EditMode.SetCarPose:
                switch (indexMode)
                {
                case 0:
                    MainUI.Instance.SetTipText("Click to set vehicle position,right click to cancel");
                    PanelSettings.Instance.SetCameraFollowCarPos(false);
                    PanelSettings.Instance.SetCameraFollowCarRot(false);
                    indexMode = 1;
                    break;

                case 1:
                    if (Input.GetMouseButtonDown(0))
                    {
                        MainUI.Instance.SetTipText("Click to set vehicle orientation");
                        ObjTestCar.TestCar.transform.position = mousePos + Vector3.up * 0.5f;
                        TestDataManager.Instance.WriteTestData("Set ego vehicle position:" + mousePos);
                        indexMode = 2;
                    }
                    else if (MouseInputBase.Button1Down)
                    {
                        editMode = EditMode.Null;
                    }
                    break;

                case 2:
                    if (Vector3.Distance(ObjTestCar.TestCar.transform.position, mousePos) > 1)
                    {
                        ObjTestCar.TestCar.transform.LookAt(mousePos, Vector3.up);
                    }
                    if (Input.GetMouseButtonDown(0))
                    {
                        editMode = EditMode.Null;
                    }
                    break;

                default:
                    break;
                }
                break;

            case EditMode.SetStatic:
                switch (indexMode)
                {
                case 0:
                    MainUI.Instance.SetTipText("Click to set obstacle position,left ctrl+ mouse wheel to set obstacle size,right click to cancel");
                    objTemp         = Instantiate(Static, statics);
                    SelectedElement = objTemp.GetComponent <ElementObject>();
                    indexMode       = 1;
                    break;

                case 1:
                    if (MouseInputBase.Button0Down)
                    {
                        objTemp.tag  = "Obstacle";
                        objTemp.name = "Obstacle" + ObstacleList.Count.ToString();
                        objTemp.transform.SetParent(statics);
                        TestDataManager.Instance.WriteTestData("Set Static Obstacle,Position:" + mousePos + "Scale:" + objTemp.transform.localScale.x);
                        editMode = EditMode.Null;
                    }
                    else if (MouseInputBase.Button1Down)
                    {
                        RemoveElement(objTemp);
                        editMode = EditMode.Null;
                    }
                    objTemp.transform.rotation = Quaternion.identity;
                    objTemp.GetComponent <ObjObstacle>().FollowMouse();
                    break;

                default:
                    break;
                }
                break;

            case EditMode.SetHuman:
                switch (indexMode)
                {
                case 0:
                    MainUI.Instance.SetTipText("Click to set pedestrian starting position");
                    indexMode = 1;
                    break;

                case 1:
                    if (MouseInputBase.Button0Down)
                    {
                        MainUI.Instance.SetTipText("Click to add target position for pedestrian, right click to cancel");
                        SelectedElement = AddHuman(mousePos + Vector3.up * 0.1f);
                        ObjHuman.PosList.Add(mousePos);
                        TestDataManager.Instance.WriteTestData("Set Human,Position:" + mousePos.ToString());
                        indexMode = 2;
                    }
                    else if (MouseInputBase.Button1Down)
                    {
                        editMode = EditMode.Null;
                    }
                    break;

                case 2:
                    isShowLine = true;
                    LinePoses  = ObjHuman.PosList.ToArray();
                    LinePoses  = new Vector3[ObjHuman.PosList.Count + 1];
                    ObjHuman.PosList.CopyTo(LinePoses);
                    LinePoses[LinePoses.Length - 1] = mousePos;
                    if (MouseInputBase.Button0Down)
                    {
                        if (ObjHuman.PosList.Count > 10)
                        {
                            MainUI.Instance.SetTipText("Can't set target positon more than 10");
                        }
                        else
                        {
                            ObjHuman.PosList.Add(mousePos);
                            MainUI.Instance.SetTipText("Click to add target position for pedestrian, right click to cancel");
                        }
                    }
                    else if (MouseInputBase.Button1Down)
                    {
                        editMode   = EditMode.Null;
                        isShowLine = false;
                        MainUI.Instance.SetTipText("cancelled");
                    }
                    break;

                default:
                    break;
                }
                break;

            case EditMode.SetCarAI:
                switch (indexMode)
                {
                case 0:
                    MainUI.Instance.SetTipText("Click to set AI vehicle init position");
                    indexMode = 1;
                    break;

                case 1:
                    if (Input.GetMouseButtonDown(0))
                    {
                        SelectedElement  = AddCarAI(mousePos);
                        ObjAiCar.posInit = mousePos;
                        MainUI.Instance.SetTipText("Click to set AI vehicle starting position");
                        indexMode = 2;
                    }
                    else if (Input.GetMouseButtonDown(1))
                    {
                        editMode = EditMode.Null;
                    }
                    break;

                case 2:
                    isShowLine = true;
                    LinePoses  = new Vector3[2] {
                        ObjAiCar.transform.position, mousePos
                    };
                    Lane    laneTemp = MapManager.Instance.SearchNearestPos2Lane(out int index, mousePos);
                    Vector3 posStart = laneTemp.list_Pos[index];
                    ObjAiCar.transform.LookAt(posStart);
                    if (Input.GetMouseButtonDown(0))
                    {
                        isShowLine        = false;
                        ObjAiCar.posStart = posStart;
                        TestDataManager.Instance.WriteTestData("Set AI vehicle Init Position:" + ObjAiCar.posInit + "Start Position:" + posStart);
                        ObjAiCar.CarInit();
                        editMode = EditMode.Null;
                    }
                    else if (Input.GetMouseButtonDown(1))
                    {
                        isShowLine = false;
                        Destroy(ObjAiCar.gameObject);
                        editMode = EditMode.Null;
                    }
                    break;

                case 3:
                    MainUI.Instance.SetTipText("Click to set AI vehicle target position");
                    indexMode = 4;
                    break;

                case 4:
                    if (Input.GetMouseButtonDown(0))
                    {
                        MainUI.Instance.SetTipText("AI vehicle settled");
                        SelectedElement.GetComponent <ObjAICar>().SetTarget(mousePos);
                        editMode = EditMode.Null;
                    }
                    break;

                default:
                    break;
                }
                break;

            case EditMode.SetCheckPoint:
                switch (indexMode)
                {
                case 0:
                    MainUI.Instance.SetTipText("Click to set checkpoint position,left ctrl+ mouse wheel to set checkpoint size,right click to cancel");
                    objTemp = Instantiate(CheckPoint, CheckPoints);
                    objTemp.transform.SetParent(CheckPoints);
                    SelectedElement = objTemp.GetComponent <ElementObject>();
                    indexMode       = 1;
                    break;

                case 1:
                    if (MouseInputBase.Button0Down)
                    {
                        if (CheckPointList.Count == 1)
                        {
                            SwitchCheckPoint();
                        }
                        TestDataManager.Instance.WriteTestData("Set CheckPoint,Position:" + mousePos + "Scale:" + objTemp.transform.localScale.x);
                        editMode = EditMode.Null;
                    }
                    else if (MouseInputBase.Button1Down)
                    {
                        RemoveElement(objTemp);
                        editMode = EditMode.Null;
                    }
                    objTemp.transform.rotation = Quaternion.identity;
                    objTemp.GetComponent <ObjCheckPoint>().FollowMouse();
                    break;

                default:
                    break;
                }
                break;

            default:
                break;
            }
            if (isShowLine)
            {
                SetLineRenderer(LinePoses);
            }
            else if (lineRenderer.enabled)
            {
                lineRenderer.enabled = false;
            }
        }