Esempio n. 1
0
    public void Init(CarAIData data)
    {
        Data = data;

        if (Data.Keys.Count > 0)
        {
            SimpleCarController prefab = LevelManager.Instance.GetCarsList()[Data.CarIndex];
            CarController = Instantiate(prefab);
            CarController.transform.SetParent(transform);
            CarController.Init(CarOwner.kAI);
            if (Data.Keys.Count > 1)
            {
                Vector3 spawnLocation = Data.GetKey(0);
                Vector3 targetVector  = Data.GetKey(1) - Data.GetKey(0);
                CarController.SetTransform(spawnLocation, Mathf.Atan2(targetVector.x, targetVector.z) * Mathf.Rad2Deg);
                CanMove        = true;
                TargetKeyIndex = 1;
            }
        }
    }
Esempio n. 2
0
    private void DrawCarAiEdit()
    {
        GUILayout.Space(35f);
        GUILayout.Label("--- CAR AI EDIT SECTION ---");
        GUILayout.Space(5f);

        GUILayout.BeginHorizontal();
        if (GUILayout.Button("NEW CAR"))
        {
            if (CurrentCarAiIndex < CarAiGameObjets.Count && CurrentCarAiIndex >= 0)
            {
                for (int i = 0; i < CarAiGameObjets[CurrentCarAiIndex].Count; i++)
                {
                    CarAiGameObjets[CurrentCarAiIndex][i].SetActive(false);
                }
            }
            WorldEditor.WorldData.CarAIDatas.Add(new CarAIData());
            CarAiGameObjets.Add(new List <GameObject>());
            CurrentCarAiIndex = CarAiGameObjets.Count - 1;
            Repaint();
        }

        EditorGUI.BeginDisabledGroup(CurrentCarAiIndex < 0 || CurrentCarAiIndex >= CarAiGameObjets.Count);
        if (GUILayout.Button("DELETE CAR"))
        {
            for (int i = 0; i < CarAiGameObjets[CurrentCarAiIndex].Count; i++)
            {
                DestroyImmediate(CarAiGameObjets[CurrentCarAiIndex][i]);
            }
            CarAiGameObjets.Remove(CarAiGameObjets[CurrentCarAiIndex]);
            WorldEditor.WorldData.CarAIDatas.RemoveAt(CurrentCarAiIndex);
            Repaint();
        }
        EditorGUI.EndDisabledGroup();
        GUILayout.EndHorizontal();

        if (WorldEditor.WorldData.CarAIDatas.Count == 0)
        {
            return;
        }

        if (CurrentCarAiIndex >= CarAiGameObjets.Count || CurrentCarAiIndex < 0)
        {
            CurrentCarAiIndex = 0;
        }

        GUILayout.BeginHorizontal();
        GUILayout.Label("Car ai: " + (CurrentCarAiIndex + 1) + "/" + WorldEditor.WorldData.CarAIDatas.Count);
        if (GUILayout.Button("<"))
        {
            for (int i = 0; i < CarAiGameObjets[CurrentCarAiIndex].Count; i++)
            {
                CarAiGameObjets[CurrentCarAiIndex][i].SetActive(false);
            }
            CurrentCarAiIndex -= 1;
            if (CurrentCarAiIndex < 0)
            {
                CurrentCarAiIndex = WorldEditor.WorldData.CarAIDatas.Count - 1;
            }
            for (int i = 0; i < CarAiGameObjets[CurrentCarAiIndex].Count; i++)
            {
                CarAiGameObjets[CurrentCarAiIndex][i].SetActive(true);
            }
            Repaint();
        }
        if (GUILayout.Button(">"))
        {
            for (int i = 0; i < CarAiGameObjets[CurrentCarAiIndex].Count; i++)
            {
                CarAiGameObjets[CurrentCarAiIndex][i].SetActive(false);
            }
            CurrentCarAiIndex = (CurrentCarAiIndex + 1) % WorldEditor.WorldData.CarAIDatas.Count;
            for (int i = 0; i < CarAiGameObjets[CurrentCarAiIndex].Count; i++)
            {
                CarAiGameObjets[CurrentCarAiIndex][i].SetActive(true);
            }
            Repaint();
        }
        GUILayout.EndHorizontal();


        GUILayout.Space(10);
        GUILayout.Label("Current number of keys: " + CarAiGameObjets[CurrentCarAiIndex].Count);
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("ADD KEY"))
        {
            GameObject locator = GameObject.CreatePrimitive(PrimitiveType.Cube);
            locator.transform.SetParent(WorldEditor.transform);
            locator.transform.localScale = Vector3.one * 0.5f;
            if (CarAiGameObjets[CurrentCarAiIndex].Count == 0)
            {
                locator.transform.position = Vector3.up;
            }
            else
            {
                locator.transform.position = CarAiGameObjets[CurrentCarAiIndex][CarAiGameObjets[CurrentCarAiIndex].Count - 1].transform.position + Vector3.left + Vector3.forward;
            }
            Selection.activeObject = locator;
            CarAiGameObjets[CurrentCarAiIndex].Add(locator);
            WorldEditor.WorldData.CarAIDatas[CurrentCarAiIndex].Keys.Add(locator.transform.position);
        }

        if (GUILayout.Button("DELETE ALL KEYS"))
        {
            foreach (GameObject locator in CarAiGameObjets[CurrentCarAiIndex])
            {
                DestroyImmediate(locator);
            }
            CarAiGameObjets[CurrentCarAiIndex].Clear();
            WorldEditor.WorldData.CarAIDatas[CurrentCarAiIndex].Keys.Clear();
        }
        GUILayout.EndHorizontal();


        CarAIData data = WorldEditor.WorldData.CarAIDatas[CurrentCarAiIndex];

        data.CarIndex        = EditorGUILayout.IntField("Car index:", data.CarIndex);
        data.MotorMultiplier = EditorGUILayout.FloatField("Motor multiplier:", data.MotorMultiplier);
        data.WheelMultiplier = EditorGUILayout.FloatField("Steering multiplier:", data.WheelMultiplier);
    }