Пример #1
0
        private void SpawnAll(JPLElementsData[] inputData)
        {
            // Spawn all bodies in multiple passes to resolve parent-child connections.
            // All spawned bodies are instantiated from signle template, which has no visual components attached,
            // because this example is designed only for simplest orbits loading process demonstration.

            if (inputData == null || inputData.Length == 0)
            {
                return;
            }
            List <JPLElementsData> spawnOrder = new List <JPLElementsData>(inputData);

            ClearAllInstances();
            bool isAnySpawned = true;

            while (spawnOrder.Count > 0 && isAnySpawned)
            {
                isAnySpawned = false;
                for (int i = 0; i < spawnOrder.Count; i++)
                {
                    var spawnItem     = spawnOrder[0];
                    var attractorName = spawnItem.AttractorName != null?spawnItem.AttractorName.Trim() : "";

                    bool Predicate(KeplerOrbitMover s)
                    {
                        return(s.name == attractorName);
                    }

                    bool isAttractorSpawned = string.IsNullOrEmpty(attractorName) || _spawnedInstances.Any(Predicate);
                    if (isAttractorSpawned)
                    {
                        KeplerOrbitMover body = SpawnBody(spawnItem, attractorName);
                        spawnOrder.RemoveAt(0);
                        i--;
                        _spawnedInstances.Add(body);
                        _spawnNotifier.NotifyBodySpawned(body);
                        isAnySpawned = true;
                    }
                    else
                    {
                        // If attractor not spawned yet, then wait for next spawn cycle pass.
                    }
                }
            }

            if (!isAnySpawned && spawnOrder.Count > 0)
            {
                Debug.LogError("Couldn't spawn " + spawnOrder.Count + " because assigned attractor was not found");
            }
        }