Ejemplo n.º 1
0
        private ICollection <AsteroidData> AsteroidEphemeris(AstroEventsContext context)
        {
            List <AsteroidData> results = new List <AsteroidData>();

            SkyContext ctx = new SkyContext(context.From, context.GeoLocation, true);

            var brightestAsteroids = asteroidsCalc.Asteroids.Where(a => a.MaxBrightness <= 10);

            for (double jd = context.From - 2; jd < context.To + 2; jd++)
            {
                if (context.CancelToken?.IsCancellationRequested == true)
                {
                    return(new AsteroidData[0]);
                }

                ctx.JulianDay = jd;
                foreach (Asteroid a in brightestAsteroids)
                {
                    var data = new AsteroidData();
                    data.Asteroid            = a;
                    data.JulianDay           = jd;
                    data.LongitudeDifference = ctx.Get(asteroidsCalc.LongitudeDifference, a);
                    results.Add(data);
                }
            }

            return(results);
        }
Ejemplo n.º 2
0
        public Dictionary <string, int> DropMaterials(AsteroidData asteroidData)
        {
            Dictionary <string, int> result = new Dictionary <string, int>();

            if (asteroidData != null)
            {
                foreach (var dropData in asteroidData.ContentData)
                {
                    for (int i = 0; i < dropData.MaxCount; i++)
                    {
                        if (Rand.Float01() <= dropData.Prob)
                        {
                            if (result.ContainsKey(dropData.Id))
                            {
                                result[dropData.Id]++;
                            }
                            else
                            {
                                result.Add(dropData.Id, 1);
                            }
                        }
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 3
0
        private float GetDataProb(AsteroidData data, int zoneLevel)
        {
            float res = 0.5f / (float)(Math.Pow(Math.Abs(data.Quality - zoneLevel), 2) + 1.0f);

            //Console.WriteLine("prob of asteroid: " + res);
            return(res);
        }
Ejemplo n.º 4
0
    void SpawnAsteroid()
    {
        //Should be a better way to do this
        int  randomSelection = Random.Range(0, PotentialRocks.Count - 1);
        Data selectedData    = PotentialRocks[randomSelection];
//        print(selectedData.Name);

        GameObject newRock = Instantiate(Asteroid, GetSpawnPos(), new Quaternion());

        activeAsteroids.Add(newRock);
        var outlineData = newRock.GetComponent <OutlineDistanceFinder>();

        outlineData.endPoint = earth;

        AsteroidData rockData = newRock.GetComponent <AsteroidData>();
        float        randX    = Random.Range(0f, 1000f);
        float        randY    = Random.Range(0f, 1000f);
        float        randZ    = Random.Range(0f, 1000f);

        rockData.scientificName    = selectedData.Name;
        rockData.distanceFromEarth = selectedData.NominalDistance;
        rockData.estimatedDiameter = selectedData.EstimatedDiameter;
        rockData.velocity          = selectedData.RelativeVel;

        Vector3 forceDir = earth.transform.position - transform.position;

        forceDir = Quaternion.Euler(Random.Range(-45, 45), Random.Range(-45, 45), Random.Range(-45, 45)) * forceDir;
        newRock.GetComponent <Asteroid>().forceDir = forceDir;
        newRock.GetComponent <Rigidbody>().AddForce(forceDir * Random.Range(4.0f, 10.0f));
        newRock.AddComponent <Asteroid>();
        PotentialRocks.Remove(selectedData);

        Locator.Instance.GameEvents.asteroidSpawnMsg?.Invoke(activeAsteroids.Count);
    }
 // Use this for initialization
 void Start()
 {
     asteroidText = this.GetComponent <TextMesh>();
     asteroid     = this.transform.parent.GetComponent <AsteroidData>();
     this.GetComponent <Renderer>().sortingLayerID = this.transform.parent.GetComponent <Renderer>().sortingLayerID;
     this.GetComponent <Renderer>().sortingOrder   = 10;
 }
Ejemplo n.º 6
0
    public void SpawnFragments(Vector3 spawnPosition, AsteroidData asteroidData)
    {
        int fragmentCount = asteroidData.GetNumberOfFragments();

        if (fragmentCount > 0)
        {
            AsteroidData fragmentData = asteroidData.GetFragmentToSpawn();
            for (int i = 0; i < fragmentCount; i++)
            {
                SpawnAsteroid(spawnPosition, fragmentData);
            }
        }
        else
        {
            int activeAsteroids = 0;
            for (int i = 0; i < transform.childCount; i++)
            {
                GameObject child = transform.GetChild(i).gameObject;
                if (child.tag == GameManager.Instance.GetAsteroidTag() && child.activeInHierarchy)
                {
                    activeAsteroids++;
                    if (activeAsteroids > 1)
                    {
                        break;
                    }
                }
            }

            // only the asteroid being destroyed is active
            if (activeAsteroids == 1)
            {
                StartCoroutine(WaitToRespawn());
            }
        }
    }
Ejemplo n.º 7
0
 private void OnAsteroidDestroyed(AsteroidData data)
 {
     if (astDataCheck == data.scientificName)
     {
         uiFrame.CloseWindow("AstDataWindow");
     }
 }
    public void SaveAsteroid(GameObject asteroid)
    {
        // 1: Create asteroid data for this asteroid.
        AsteroidData ad = new AsteroidData(asteroid.transform.position, asteroid.transform.localScale);

        // 2: Add asteroid data to asteroidArray as JSONClass
        asteroidArray.Add(ad.ToJSON());
    }
Ejemplo n.º 9
0
    // 3D ASTEROID GENERATION
    public GameObject GenerateAsteroid(AsteroidBillboard billboard, BeltChunk chunk)
    {
        AsteroidData asteroidData = asteroidDatas[billboard.atlasIndex];
        GameObject   ret          = Instantiate(asteroidData.prefab, billboard.position, Quaternion.identity, chunk.transform);

        ret.transform.localScale = Vector3.one * billboard.size;
        return(ret);
    }
Ejemplo n.º 10
0
        /// <summary>
        /// Create or not asteroid in zone, with prob of data
        /// </summary>
        public bool DropOccured(int zoneLevel, AsteroidData data, bool forceCreation)
        {
            if (forceCreation)
            {
                return(true);
            }

            return(Rand.Float01() < this.GetDataProb(data, zoneLevel));
        }
Ejemplo n.º 11
0
    public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    {
        AsteroidData data = new AsteroidData
        {
            position = Position,
            velocity = Velocity
        };

        dstManager.AddComponentData(entity, data);
    }
Ejemplo n.º 12
0
 public void Setup(AsteroidData data, Size size, UnityAction <Size, Vector2> onAsteroidDied)
 {
     spriteRenderer.sprite = data.sprites[Random.Range(0, data.sprites.Length)];
     this.data             = data;
     recalculateCollider();
     rb.mass             = data.mass;
     this.life           = data.life;
     this.size           = size;
     this.onAsteroidDied = onAsteroidDied;
 }
Ejemplo n.º 13
0
    // Use this for initialization
    void Start()
    {
        GameObject[] asteroids = GameObject.FindGameObjectsWithTag("Asteroid");

        Vector3 pos   = asteroids[0].transform.position;
        Vector3 scale = asteroids[0].transform.localScale;

        AsteroidData ad = new AsteroidData(pos, scale);

        ad.Save("Asteroid.txt");
    }
Ejemplo n.º 14
0
    void SpawnAsteroidFromData(AsteroidData ad)
    {
        gen.transform.position = new Vector3(ad.posx, ad.posy, gen.transform.position.z);
        Asteroid clone = gen.GenerateAsteroid(ad.mineral, ad.size, chunkSeed + ad.index);

        clone.gen     = gen;
        clone.chunk   = this;
        clone.id      = ad.index;
        clone.flagged = true;

        asteroids.Add(clone.id, clone);
    }
Ejemplo n.º 15
0
    // Use this for initialization
    void Start()
    {
        AsteroidData[] asteroids    = new AsteroidData[numAsteroids];
        Vector2[]      outAsteroids = new Vector2[numAsteroids];
        for (int i = 0; i < numAsteroids; i++)
        {
            asteroids[i] = new AsteroidData(new Vector2(Random.Range(-100f, 100f), Random.Range(-100f, 100f)), new Vector2(0, 0), 1);
        }

        watch = new System.Diagnostics.Stopwatch();
        watch.Start();
        LinearGravity(asteroids);

        watch.Stop();
        Debug.LogFormat("processed {0} objects in: {1}", asteroids.Length, watch.Elapsed.TotalMilliseconds);
        watch.Reset();
        watch.Start();

        float sq             = NthRoot(numAsteroids, 1);
        float asixNumThreads = sq;

        Debug.Log(asixNumThreads);
        int numGroups = (int)System.Math.Ceiling((float)asixNumThreads / 256);

        Debug.Log(numGroups);

        ComputeBuffer bufferIn  = new ComputeBuffer(numAsteroids, 20);
        ComputeBuffer bufferOut = new ComputeBuffer(numAsteroids, 8);

        bufferIn.SetData(asteroids);
        int kernal = shader.FindKernel("GravityComp");

        shader.SetBuffer(kernal, "dataIn", bufferIn);
        shader.SetBuffer(kernal, "dataOut", bufferOut);
        shader.SetFloat("numAsteroids", numAsteroids);
        shader.Dispatch(kernal, numGroups, 1, 1);

        watch.Stop();
        Debug.Log("shader execution time: " + watch.Elapsed.Milliseconds);
        watch.Reset();
        watch.Start();

        bufferOut.GetData(outAsteroids);

        watch.Stop();
        Debug.Log("get data time: " + watch.Elapsed.Milliseconds);

        //Debug.Log("shader execution time: " + (watch.ElapsedTicks / (float)System.Diagnostics.Stopwatch.Frequency));

        bufferIn.Dispose();
        bufferOut.Dispose();
    }
Ejemplo n.º 16
0
    public void FlagAsteroid(Asteroid asteroid)
    {
        if (flaggedAsteroids.ContainsKey(asteroid.id))
        {
            return;
        }

        asteroid.flagged = true;
        AsteroidData ad = new AsteroidData();

        ad.index = asteroid.id;
        flaggedAsteroids.Add(ad.index, ad);
    }
    public AsteroidData[] ReadAsteroids()
    {
        // Read array from file.
        asteroidArray = UtilScript.ReadJSONFromFile(Application.dataPath, "SavedAsteroids.txt") as JSONArray;

        AsteroidData[] asteroidDatas = new AsteroidData[asteroidArray.Count];

        for (int i = 0; i < asteroidArray.Count; i++)
        {
            asteroidDatas[i] = new AsteroidData(asteroidArray[i] as JSONClass);
        }

        return(asteroidDatas);
    }
Ejemplo n.º 18
0
    // Use this for initialization
    void Start()
    {
        AsteroidData obj = new AsteroidData(buffers, materials, object_lists,
                                            action_controller, score_keeper, action_dim, camera, lights, constraints);

        string str  = JsonUtility.ToJson(obj);
        string path = "Assets/assets/scene.json";

        using (FileStream fs = new FileStream(path, FileMode.Create)){
            using (StreamWriter writer = new StreamWriter(fs)){
                writer.Write(str);
            }
        }
        UnityEditor.AssetDatabase.Refresh();
    }
Ejemplo n.º 19
0
    /// <summary>
    /// Sets the ellipse parameters for epoch provided.
    /// </summary>
    /// <param name="epoch">Epoch.</param>
    /// <param name="ellipseBase">Ellipse base.</param>
    public void SetEllipseForEpoch(float epoch, EllipseBase ellipseBase)
    {
        switch (bodyType)
        {
        case SolarSystem.Type.PLANET:
            PlanetData.SetEllipse(epoch, ellipseBase, this);
            break;

        case SolarSystem.Type.ASTEROID:
            AsteroidData.SetEllipse(epoch, ellipseBase, this);
            break;

        case SolarSystem.Type.COMET:
            CometData.SetEllipse(epoch, ellipseBase, this);
            break;
        }
    }
Ejemplo n.º 20
0
    public void AsteroidDestroyed(AsteroidData asteroid, bool addPoints)
    {
        if (addPoints)
        {
            scoreNum += 100;
            score.GetComponent <TextMeshProUGUI>().text = "Score: " + scoreNum;
        }
        float x = (Random.Range(0, width) - width / 2) * 40f;
        float y = (Random.Range(0, height) - height / 2) * 40f;

        while (CheckPlayerProximity(x, y))
        {
            x = (Random.Range(0, width) - width / 2) * 40f;
            y = (Random.Range(0, height) - height / 2) * 40f;
        }
        asteroid.transform.position = new Vector3(x, y, 0);
        asteroid.Init();
    }
Ejemplo n.º 21
0
    private void SpawnAsteroid(Vector3 spawnPosition, AsteroidData asteroidData)
    {
        GameObject asteroid = PoolsManager.Instance.GetAsteroidsPool().GetAvailable();

        asteroid.transform.position = spawnPosition;
        asteroid.transform.rotation = Random.rotation;

        asteroid.SetActive(true);

        Rigidbody asteroidRB = asteroid.GetComponent <Rigidbody>();

        asteroidRB.mass = asteroidData.GetMass();
        RandomSpacePusher randomPusher = asteroid.GetComponent <RandomSpacePusher>();

        randomPusher.SetRandomPush(pushForce, angularVelocity);
        randomPusher.GivePush();
        AsteroidController asteroidController = asteroid.GetComponent <AsteroidController>();

        asteroidController.Init(asteroidData);
    }
Ejemplo n.º 22
0
    public void OnAsteroidDestroy(AsteroidDestroyEvent asteroidDestroyEvent)
    {
        Asteroid asteroid = asteroidDestroyEvent.Asteroid;

        if (GameArea.AsteroidTypeData.ContainsKey(asteroid.Type))
        {
            AsteroidData data = asteroidTypeData[asteroid.Type];
            for (int i = 0; i < data.DestroyToCount; i++)
            {
                SpawnAsteroid(data.DestroyToType, asteroid.transform.position, true);
            }
        }

        if (!asteroid.CanSplitUp() && transform.childCount == 0)
        {
            if (transform.childCount == 0)
            {
                EndRound();
            }
        }
    }
Ejemplo n.º 23
0
 void UpdateAsteroidData()
 {
     foreach (KeyValuePair <int, Asteroid> p in asteroids)
     {
         if (p.Key < 0 && p.Value == null)
         {
             flaggedAsteroids.Remove(p.Key);
         }
         else if (p.Value == null)
         {
             flaggedAsteroids[p.Key].destroyed = true;
         }
         else if (p.Value.flagged)
         {
             AsteroidData ad = flaggedAsteroids[p.Key];
             ad.mineral = p.Value.mineral;
             ad.posx    = p.Value.rigidbody2D.position.x;
             ad.posy    = p.Value.rigidbody2D.position.y;
             ad.size    = p.Value.sizeClass;
         }
     }
 }
Ejemplo n.º 24
0
 private void Start()
 {
     data = this.GetComponent <AsteroidData>();
 }
Ejemplo n.º 25
0
 public void Init(AsteroidData _data)
 {
     data = _data;
     GetComponent <SpriteRenderer>().sprite = data.mainSprite;
 }
Ejemplo n.º 26
0
 public SolarBodyCreatorWindow()
 {
     planetNames   = PlanetData.GetNames();
     asteroidNames = AsteroidData.GetNames();
     cometNames    = CometData.GetNames();
 }
Ejemplo n.º 27
0
    void OnGUI()
    {
        // check that there is a SolarSystem in the world
        solarSystem = GameObject.FindObjectOfType <SolarSystem>();
        if (solarSystem == null)
        {
            EditorGUILayout.LabelField("Please create a GameObject with a Solar System compenent first.", EditorStyles.wordWrappedLabel);
            if (GUILayout.Button("Close"))
            {
                this.Close();
            }
        }
        else
        {
            // Create a ghost game object to hold the solar body to allow a pretty print of
            // orbit params prior to adding.
            if (tempGameobject == null && solarSystem.planetPrefab != null)
            {
                tempGameobject           = Instantiate(solarSystem.planetPrefab) as GameObject;
                tempGameobject.hideFlags = HideFlags.HideAndDontSave;
                sbody = tempGameobject.GetComponent <SolarBody>();
            }

            createType = (CreateType)EditorGUILayout.EnumPopup(new GUIContent("Select Solar body type", typeTip), createType);

            // Select type of object
            SolarSystem.Type solarType = SolarSystem.Type.PLANET;
            switch (createType)
            {
            case CreateType.PLANET:
                EditorGUILayout.LabelField("Select body", EditorStyles.wordWrappedLabel);
                bodyNum = EditorGUILayout.Popup(bodyNum, planetNames);
                break;

            case CreateType.ASTEROID:
                EditorGUILayout.LabelField("Select body", EditorStyles.wordWrappedLabel);
                bodyNum   = EditorGUILayout.Popup(bodyNum, asteroidNames);
                solarType = SolarSystem.Type.ASTEROID;
                break;

            case CreateType.COMET:
                EditorGUILayout.LabelField("Select body", EditorStyles.wordWrappedLabel);
                bodyNum   = EditorGUILayout.Popup(bodyNum, cometNames);
                solarType = SolarSystem.Type.COMET;
                break;

            case CreateType.JPL_ASTEROID:
                EditorGUILayout.LabelField("Enter asteroid from JPL database", EditorStyles.wordWrappedLabel);
                EditorGUILayout.LabelField("Paste a line from JPL data", EditorStyles.wordWrappedLabel);
                if (GUILayout.Button("Open Asteroid Database"))
                {
                    Application.OpenURL("http://ssd.jpl.nasa.gov/dat/ELEMENTS.NUMBR");
                }
                jplData   = EditorGUILayout.TextField("JPL DATA", jplData);
                solarType = SolarSystem.Type.COMET;
                break;

            case CreateType.JPL_COMET:
                EditorGUILayout.LabelField("Enter comet from JPL database", EditorStyles.wordWrappedLabel);
                EditorGUILayout.LabelField("Paste a line from JPL data", EditorStyles.wordWrappedLabel);
                if (GUILayout.Button("Open Comet Database"))
                {
                    Application.OpenURL("http://ssd.jpl.nasa.gov/dat/ELEMENTS.COMET");
                }
                jplData   = EditorGUILayout.TextField("JPL DATA", jplData);
                solarType = SolarSystem.Type.COMET;
                break;

            default:
                break;
            }

            // If bodyType or bodyNum has changed - get new orbit data
            if (jplData == null && (createType == CreateType.JPL_ASTEROID || createType == CreateType.JPL_COMET))
            {
                EditorGUILayout.LabelField("Paste a complete line from the orbit data base into");
                EditorGUILayout.LabelField("the JPL data box.");
                EditorGUILayout.LabelField("");
                EditorGUILayout.LabelField("");
                EditorGUILayout.LabelField("");
            }
            else if (sbody != null)
            {
                if ((createType != lastCreateType) || (bodyNum != lastBodyNum) || (jplData != lastJplData))
                {
                    switch (createType)
                    {
                    case CreateType.PLANET:
                        PlanetData.SetSolarBody(sbody, bodyNum);
                        break;

                    case CreateType.ASTEROID:
                        AsteroidData.SetSolarBody(sbody, bodyNum);
                        break;

                    case CreateType.COMET:
                        CometData.SetSolarBody(sbody, bodyNum);
                        break;

                    case CreateType.JPL_ASTEROID:
                        if (jplData != null)
                        {
                            AsteroidData.SetSolarBody(sbody, jplData);
                        }
                        break;

                    case CreateType.JPL_COMET:
                        if (jplData != null)
                        {
                            CometData.SetSolarBody(sbody, jplData);
                        }
                        break;

                    default:
                        break;
                    }
                }
                // Display orbit info
                EditorGUILayout.LabelField("Body Parameters:", EditorStyles.boldLabel);
                EditorGUILayout.LabelField(sbody.name, EditorStyles.boldLabel);
                EditorGUILayout.LabelField(string.Format("   {0,-25}\t ({1,1})\t  {2}\t AU",
                                                         "Semi-Major Axis", "a", sbody.a), EditorStyles.wordWrappedLabel);
                EditorGUILayout.LabelField(string.Format("   {0,-25}\t ({1,1})\t  {2}\t Unity m",
                                                         "\t(scaled)", "a", sbody.a * GravityEngine.Instance().GetLengthScale()), EditorStyles.wordWrappedLabel);
                EditorGUILayout.LabelField(string.Format("   {0,-25}\t ({1,1})\t  {2}",
                                                         "Eccentricity", "e", sbody.ecc), EditorStyles.wordWrappedLabel);
                EditorGUILayout.LabelField(string.Format("   {0,-25}\t ({1,1})\t  {2}\t degrees",
                                                         "Incliniation", "i", sbody.inclination), EditorStyles.wordWrappedLabel);
                EditorGUILayout.LabelField(string.Format("   {0,-25}\t ({1,1})\t  {2}\t degress",
                                                         "Arg. of pericenter", "\u03c9", sbody.omega_lc), EditorStyles.wordWrappedLabel);
                EditorGUILayout.LabelField(string.Format("   {0,-25}\t ({1,1})\t  {2}\t degress",
                                                         "Longitude of node", "\u03a9", sbody.omega_uc), EditorStyles.wordWrappedLabel);
                EditorGUILayout.LabelField(string.Format("   {0,-25}\t ({1,1})\t  {2}\t degress",
                                                         "Longitude", "L", sbody.longitude), EditorStyles.wordWrappedLabel);
            }
            lastCreateType = createType;
            lastBodyNum    = bodyNum;
            lastJplData    = jplData;

            GUILayout.Space(20);
            if (GUILayout.Button("Create"))
            {
                GameObject go = solarSystem.AddObject(solarType, sbody);
                if (go != null)
                {
                    Undo.RegisterCreatedObjectUndo(go, sbody.name);
                }
                DestroyImmediate(tempGameobject);
                this.Close();
            }

            if (GUILayout.Button("Cancel"))
            {
                DestroyImmediate(tempGameobject);
                this.Close();
            }
        }
    }
Ejemplo n.º 28
0
	public void Load(AsteroidData[] ad) {
		flaggedAsteroids = new SortedList<int, AsteroidData>();
		foreach (AsteroidData a in ad) {
			flaggedAsteroids.Add (a.index, a);
		}
	}
Ejemplo n.º 29
0
	void SpawnAsteroidFromData(AsteroidData ad) {
		gen.transform.position = new Vector3(ad.posx,ad.posy,gen.transform.position.z);
		Asteroid clone = gen.GenerateAsteroid(ad.mineral, ad.size, chunkSeed+ad.index);
		clone.gen = gen;
		clone.chunk = this;
		clone.id = ad.index;
		clone.flagged = true;

		asteroids.Add(clone.id, clone);
	}
Ejemplo n.º 30
0
	public void FlagAsteroid(Asteroid asteroid) {
		if (flaggedAsteroids.ContainsKey(asteroid.id))
		    return;

		asteroid.flagged = true;
		AsteroidData ad = new AsteroidData();
		ad.index = asteroid.id;
		flaggedAsteroids.Add(ad.index, ad);
	}
Ejemplo n.º 31
0
 public void Init(AsteroidData ad)
 {
     asteroidData         = ad;
     transform.localScale = originalLocalScale * asteroidData.GetScale();
 }
Ejemplo n.º 32
0
 public void SetData(AsteroidData inData)
 {
     data = inData;
 }
Ejemplo n.º 33
0
    // Use this for initialization
    void Start()
    {
        AsteroidData loadAD = new AsteroidData("Asteroid.txt");

        print(loadAD.position);
    }