Пример #1
0
        private Plant SpawnPlant(Vector3 p, Quaternion r, Characteristics c, Characteristics cMin, Characteristics cMax)
        {
            if (Animals.Count + Plants.Count > maxHostsUntilPause)
            {
                Gm.instance.Pause();
                NiwradMenu.instance.ShowNotification($"Reached maximum hosts {maxHostsUntilPause}, pausing.");
            }

            var veg = Pool.Spawn(c.Carnivorous ? lowPolyCarnivorousPlantPrefab : lowPolyHerbivorousPlantPrefab, p, r)
                      .GetComponent <Plant>();

            _nextId++;
            Plants[_nextId] = veg;
            Plants[_nextId].characteristics    = c.Clone();
            Plants[_nextId].characteristicsMin = cMin;
            Plants[_nextId].characteristicsMax = cMax;
            Plants[_nextId].id = _nextId;
            // _plants[_nextId].isCarnivorous = c.Carnivorous; // TODO:

            if (!Gm.instance.online || Sm.instance.isServer)
            {
                Plants[_nextId].EnableBehaviour(true);
            }
            return(Plants[_nextId]);
        }
Пример #2
0
        private CommonAnimal SpawnAnimal(Vector3 p, Quaternion r, Characteristics c, Characteristics cMin, Characteristics cMax)
        {
            // Just a little hack to avoid crashing the PC ! :)
            if (Animals.Count + Plants.Count > maxHostsUntilPause)
            {
                Gm.instance.Pause();
                NiwradMenu.instance.ShowNotification($"Reached maximum hosts {maxHostsUntilPause}, pausing.");
            }
            _nextId++;
            var a = Pool.Spawn(c.Carnivorous ? lowPolyCarnivorousAnimalPrefab : lowPolyHerbivorousAnimalPrefab, p, r);

            // a.GetComponent<MeshRenderer>().material.mainTexture = MaterialHelper.RandomTexture(a.transform, frequency: 10);
            // a.GetComponent<MeshRenderer>().material = new Material(Shader.Find("Standard")) { color = Random.ColorHSV()};
            a.transform.localScale              = Vector3.one * Random.Range(0.5f, 1.5f);
            Animals[_nextId]                    = a.GetComponent <SimpleAnimal>();
            Animals[_nextId].characteristics    = c.Clone(); // TODO: prob quite expensive gotta pool later or something maybe
            Animals[_nextId].characteristicsMin = cMin;
            Animals[_nextId].characteristicsMax = cMax;
            Animals[_nextId].id                 = _nextId;
            Animals[_nextId].isCarnivorous      = c.Carnivorous;
            // TODO: should prob have 2 prefab
            // Only server handle animal behaviours
            if (!Gm.instance.online || Sm.instance.isServer)
            {
                Animals[_nextId].EnableBehaviour(true);
                // var tSync = m_Animals[obj.Id].gameObject.AddComponent<TransformSync>();
                // tSync.id = obj.Id;
            }

            return(Animals[_nextId]);
        }