Example #1
0
    public void Init(HumanSpawnerData data)
    {
        Data = data;

        transform.position = data.Position;
        Timer = Data.SpawnCooldown;

        for (int i = 0; i < data.MaxNumberOfHumans; i++)
        {
            SpawnHuman();
        }
    }
Example #2
0
    private void DrawHumanAIEdit()
    {
        GUILayout.Space(35f);
        GUILayout.Label("--- HUMAN SPAWNER EDIT SECTION ---");
        GUILayout.Space(5f);

        GUILayout.BeginHorizontal();
        if (GUILayout.Button("NEW"))
        {
            if (CurrentHumanSpawnerIndex < HumanSpanerGameObjects.Count && CurrentHumanSpawnerIndex >= 0)
            {
                HumanSpanerGameObjects[CurrentHumanSpawnerIndex].SetActive(false);
            }
            GameObject locator = GameObject.CreatePrimitive(PrimitiveType.Sphere);
            locator.transform.SetParent(WorldEditor.transform);
            locator.transform.localScale = Vector3.one * 0.5f;
            locator.transform.position   = Vector3.up;
            HumanSpanerGameObjects.Add(locator);
            WorldEditor.WorldData.HumanSpawnerDatas.Add(new HumanSpawnerData());
            CurrentHumanSpawnerIndex = HumanSpanerGameObjects.Count - 1;
            Repaint();
        }

        EditorGUI.BeginDisabledGroup(CurrentHumanSpawnerIndex < 0 || CurrentHumanSpawnerIndex >= HumanSpanerGameObjects.Count);
        if (GUILayout.Button("DELETE"))
        {
            HumanSpanerGameObjects.Remove(HumanSpanerGameObjects[CurrentHumanSpawnerIndex]);
            WorldEditor.WorldData.HumanSpawnerDatas.RemoveAt(CurrentHumanSpawnerIndex);
            DestroyImmediate(HumanSpanerGameObjects[CurrentHumanSpawnerIndex]);
            Repaint();
        }
        EditorGUI.EndDisabledGroup();
        GUILayout.EndHorizontal();

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

        if (CurrentHumanSpawnerIndex >= HumanSpanerGameObjects.Count || CurrentHumanSpawnerIndex < 0)
        {
            CurrentHumanSpawnerIndex = 0;
        }

        GUILayout.BeginHorizontal();
        GUILayout.Label("Spawners " + (CurrentHumanSpawnerIndex + 1) + "/" + WorldEditor.WorldData.HumanSpawnerDatas.Count);
        if (GUILayout.Button("<"))
        {
            HumanSpanerGameObjects[CurrentHumanSpawnerIndex].SetActive(false);
            CurrentHumanSpawnerIndex -= 1;
            if (CurrentHumanSpawnerIndex < 0)
            {
                CurrentHumanSpawnerIndex = WorldEditor.WorldData.HumanSpawnerDatas.Count - 1;
            }
            HumanSpanerGameObjects[CurrentHumanSpawnerIndex].SetActive(true);
            Repaint();
        }
        if (GUILayout.Button(">"))
        {
            HumanSpanerGameObjects[CurrentHumanSpawnerIndex].SetActive(false);
            CurrentHumanSpawnerIndex = (CurrentHumanSpawnerIndex + 1) % WorldEditor.WorldData.HumanSpawnerDatas.Count;
            HumanSpanerGameObjects[CurrentHumanSpawnerIndex].SetActive(true);
            Repaint();
        }
        GUILayout.EndHorizontal();

        HumanSpawnerData data = WorldEditor.WorldData.HumanSpawnerDatas[CurrentHumanSpawnerIndex];

        EditorGUI.BeginDisabledGroup(true);
        data.Position = EditorGUILayout.Vector3Field("Position:", data.Position);
        EditorGUI.EndDisabledGroup();
        data.SpawnRadius          = EditorGUILayout.FloatField("Radius:", data.SpawnRadius);
        data.SpawnCooldown        = EditorGUILayout.FloatField("Cooldown:", data.SpawnCooldown);
        data.MaxNumberOfHumans    = EditorGUILayout.IntField("MaxNumberOfHumans:", data.MaxNumberOfHumans);
        data.MaxDistanceFromSpawn = EditorGUILayout.FloatField("MaxDistanceFromSpawn:", data.MaxDistanceFromSpawn);
    }