Exemplo n.º 1
0
 public void OnEnterSpaceBodyRange(SpaceBody space_body)
 {
     Log.Print($"enter {space_body}");
     Debug.Assert(!space_bodies_in_reach.Contains(space_body));
     space_bodies_in_reach.Add(space_body);
     UpdateNearestSpaceBody();
 }
Exemplo n.º 2
0
 protected override void UpgradeClass(ITemplateManager templateManager,
                                      SpaceBody spaceBody,
                                      Mapping upgradeMapping)
 {
     spaceBody.gameObject.layer          = LayerHelper.Sun;
     spaceBody.mappingUpgradeSpaceObject = upgradeMapping;
 }
Exemplo n.º 3
0
    void Start()
    {
        textUpdateMass = GetComponent <Text>();
        GameObject playerPlanet = GameObject.FindGameObjectWithTag(EnumTags.Player);
        SpaceBody  bodyPlanet   = playerPlanet.GetComponent <SpaceBody>();

        bodyPlanet.NotifyChangeMass += BodyPlanet_NotifyChangeMass;
    }
Exemplo n.º 4
0
 private void DeleteComponent <T>(SpaceBody spaceBody)
     where T : UnityEngine.Object
 {
     if (spaceBody.TryGetComponent <T>(out var component))
     {
         Destroy(component);
     }
 }
Exemplo n.º 5
0
        public SpaceBody GetFullObject(SpaceClasses spaceClass)
        {
            SpaceBody spaceBody = GenerateSpaceBody;

            spaceBody.SpaceClass     = spaceClass;
            spaceBody.upgradeManager = this;
            Upgrade(spaceClass, spaceBody);
            spaceBody.mappingUpgradeSpaceObject = AvailableMapping.First(x => x.Source == spaceBody.SpaceClass);
            return(spaceBody);
        }
Exemplo n.º 6
0
 public void Upgrade(SpaceBody spaceBody, Mapping mapping)
 {
     if (mapping.criticalMassUpgrade < spaceBody.Mass)
     {
         Upgrade(mapping.Upgrade, spaceBody);
     }
     else if (mapping.criticalMassDowngrade > spaceBody.Mass)
     {
         Upgrade(mapping.Downgrade, spaceBody);
     }
 }
Exemplo n.º 7
0
 // -------------------------------------------------------------------------------------------------------------------
 public Simulation(Assets.StarSystem starSystem, double initTime)
 {
     this.starSystem = starSystem;
     planets         = new Planet[starSystem.planets.Length];
     star            = new SpaceBody(this, starSystem.star);
     for (int i = 0; i < planets.Length; ++i)
     {
         planets[i] = Instantiator.CreatePlanet(this, starSystem.planets[i]);
     }
     SetTime(initTime);
 }
Exemplo n.º 8
0
        public void PlaceGameObject(
            SpaceBody gameObject,
            Vector3?placePosition = null)
        {
            var movement = gameObject.GetComponent <MovementBehaviour>();

            movement.MaxVelocity = MaxSpeedForObjects;

            gameObject.transform.parent   = transform;
            gameObject.transform.position = placePosition ??
                                            new Vector3(Random.Range(0f, Width), Random.Range(0f, Height), 0f);
        }
Exemplo n.º 9
0
        public async Task <SpaceBody> StoreSpaceBody(SpaceBody spaceBody)
        {
            if (spaceBody.Id == Guid.Empty)
            {
                spaceBody.Id = Guid.NewGuid();
            }

            // TODO validate
            var result = await _db.SpaceBodyCollection.ReplaceOneAsync(GetIdFilterSpaceBody(spaceBody.Id), spaceBody, _db.UpsertOptions);

            return(spaceBody);
        }
Exemplo n.º 10
0
    public void OnExitSpaceBodyRange(SpaceBody space_body)
    {
        Log.Print($"exit {space_body}");
        Debug.Assert(space_bodies_in_reach.Contains(space_body));
        space_bodies_in_reach.Remove(space_body);

        if (nearest_space_body != space_body)
        {
            return;
        }
        nearest_space_body = null;
        UpdateNearestSpaceBody();
    }
Exemplo n.º 11
0
        public GravitationBehaviour SetUpGravitation(SpaceBody spaceBody)
        {
            var gravitation = FindChild <GravitationBehaviour>(spaceBody.transform);

            if (gravitation == null)
            {
                gravitation =
                    Instantiate(GravitationTemplate, spaceBody.transform)
                    .GetComponent <GravitationBehaviour>();
            }

            return(gravitation);
        }
Exemplo n.º 12
0
    // Start is called before the first frame update
    void Start()
    {
        GameObject PlayerPlanet = GameObject.FindGameObjectWithTag(EnumTags.Player);

        BodyPlanet = PlayerPlanet.GetComponent <SpaceBody>();
        BodyPlanet.NotifyChangeMass += EventChangeSizeIconPlanet;
        _pastMass = BodyPlanet.Mass;
        MeshRenderer[] meshRenderers = PlayerPlanet.GetComponentsInChildren <MeshRenderer>().Skip(1).ToArray();
        foreach (var meshPlayerPlanet in meshRenderers)
        {
            GameObject meshRenderIcon = Instantiate(meshPlayerPlanet.gameObject);
            meshRenderIcon.transform.SetParent(transform);
            meshRenderIcon.transform.localPosition = new Vector3(0, 0, 0);
            meshRenderIcon.transform.localScale    = new Vector3(10f, 10f, 10f);
            meshRenderIcon.layer = LayerHelper.UI;
            meshRendersIcon.Add(meshRenderIcon);
        }
    }
Exemplo n.º 13
0
    private void UpdateNearestSpaceBody()
    {
        if (space_bodies_in_reach.Count == 0)
        {
            return;
        }

        if (!nearest_space_body)
        {
            nearest_space_body = space_bodies_in_reach.First();
        }

        foreach (var space_body in space_bodies_in_reach)
        {
            if (space_body.GetSqrPlayerDistance() < nearest_space_body.GetSqrPlayerDistance())
            {
                nearest_space_body = space_body;
            }
        }
    }
Exemplo n.º 14
0
        protected override void UpgradeClass(
            ITemplateManager templateManager,
            SpaceBody spaceBody,
            Mapping upgradeMapping)
        {
            int    colourSettingsRandom = UnityEngine.Random.Range(0, planetSettings.colourSettings.Length);
            int    shapeSettingsRandom  = UnityEngine.Random.Range(0, planetSettings.shapeSettings.Length);
            Planet planet = spaceBody.gameObject.AddComponent <Planet>();

            planet.Init(planetSettings.shapeSettings[shapeSettingsRandom], planetSettings.colourSettings[colourSettingsRandom], planetSettings.resolution);
            var graviatation = templateManager.SetUpGravitation(spaceBody);

            spaceBody.Mass += 10;
            var satelliteManager = spaceBody.GetComponent <SatelliteManager>();

            satelliteManager.MaxCountSattelites = 2;
            spaceBody.gameObject.layer          = LayerHelper.Planet;
            spaceBody = SpinPlanet(spaceBody);
            spaceBody.mappingUpgradeSpaceObject = upgradeMapping;
        }
Exemplo n.º 15
0
        private void Upgrade(SpaceClasses spaceClass, SpaceBody spaceBody)
        {
            Mapping upgradeMapping = new Mapping();

            try
            {
                upgradeMapping = AvailableMapping.First(x => x.Source == spaceClass);
            }
            catch
            {
            }
            foreach (var element in AvailableUpgrades)
            {
                if (element.SpaceClasses == spaceClass)
                {
                    element.UpgradeBase.Upgrade(this, spaceBody, upgradeMapping);
                    break;
                }
            }
            spaceBody.mappingUpgradeSpaceObject = AvailableMapping.First(x => x.Source == spaceBody.SpaceClass);
        }
Exemplo n.º 16
0
 protected abstract void UpgradeClass(ITemplateManager templateManager, SpaceBody spaceBody, Mapping upgradeMapping);
Exemplo n.º 17
0
 /// <summary>
 /// Крутим планету при инициализации(ебашу чистые функции чтобы попасть в рай
 /// </summary>
 /// <param name="spaceBody">Объект планеты</param>
 /// <returns></returns>
 private SpaceBody SpinPlanet(SpaceBody spaceBody)
 {
     spaceBody.gameObject.transform.Rotate(new Vector3(0, UnityEngine.Random.Range(0f, 359f), 0));
     return(spaceBody);
 }
Exemplo n.º 18
0
 public void Upgrade(ITemplateManager templateManager, SpaceBody spaceBody, Mapping upgradeMapping)
 {
     ClearMesh(spaceBody);
     UpgradeClass(templateManager, spaceBody, upgradeMapping);
 }
Exemplo n.º 19
0
    void updateObject(SpaceBody obj)
    {
        var diff = obj.position - originPosition;
        var dist = diff.magnitude;

        int numLayers = layerMasks.Length;

        if (numLayers != obj.spawnedObjects.Length)
        {
            obj.destroyObjects();
            obj.spawnedObjects = new GameObject[numLayers];
        }

        var radius = 1.0;

        if (obj.prefab)
        {
            radius = obj.radius;
        }
        var minDist = dist - radius;
        var maxDist = dist - radius;

        var absDiff = DVec3.abs(diff);
        var absMin  = absDiff - new DVec3(radius, radius, radius);
        var absMax  = absDiff + new DVec3(radius, radius, radius);

        double currentScale = 1.0;
        double farClip      = scaleFactor;
        double nearClip     = 0.0;

        for (int curIndex = 0; curIndex < layerMasks.Length; curIndex++)
        {
            var curLayer     = layerIndexes[curIndex];
            var curLayerMask = layerMasks[curIndex];
            var clipped      = ((absMax.x < nearClip) && (absMax.y < nearClip) && (absMax.z < nearClip));

            if (curIndex < (layerMasks.Length - 1))
            {
                clipped = clipped || (absMin.x > farClip) || (absMin.y > farClip) || (absMin.z > farClip);
            }

            if (obj.hidden)
            {
                clipped = true;
            }

            if (clipped)
            {
                if (obj.spawnedObjects[curIndex])
                {
                    Destroy(obj.spawnedObjects[curIndex]);
                    obj.spawnedObjects[curIndex] = null;
                }
            }
            else
            {
                if (obj.prefab)
                {
                    var    prefab   = obj.prefab;
                    double scale    = obj.radius / (prefab.prefabRadius * currentScale);
                    var    localPos = diff / currentScale;

                    if (!obj.spawnedObjects[curIndex])
                    {
                        var displayObj = Instantiate <GameObject>(obj.prefab.gameObject);
                        moveToLayer(displayObj, curLayer);
                        obj.spawnedObjects[curIndex] = displayObj;

                        var lights = displayObj.GetComponentsInChildren <Light>();
                        for (int i = 0; i < lights.Length; i++)
                        {
                            var curLight = lights[i];
                            if (!curLight)
                            {
                                continue;
                            }
                            curLight.cullingMask = curLayerMask;
                            curLight.range      *= (float)scale;
                        }

                        displayObj.name = string.Format("{0}: layer {1}", prefab.gameObject.name, curIndex);
                    }

                    var displayObject = obj.spawnedObjects[curIndex];
                    var spawnedData   = displayObject.GetComponent <SpawnedSpaceObjectData>();
                    if (!spawnedData)
                    {
                        spawnedData = displayObject.AddComponent <SpawnedSpaceObjectData>();
                    }
                    spawnedData.modelScale  = scale;
                    spawnedData.layerIndex  = curIndex;
                    spawnedData.scaleFactor = currentScale;
                    spawnedData.radius      = obj.radius;

                    displayObject.transform.localScale = new Vector3((float)scale, (float)scale, (float)scale);
                    displayObject.transform.position   = new Vector3((float)localPos.x, (float)localPos.y, (float)localPos.z);
                }
            }

            currentScale *= scaleFactor;
            nearClip      = farClip;
            farClip      *= scaleFactor;
        }
    }
Exemplo n.º 20
0
 protected void ClearMesh(SpaceBody spaceBody)
 {
     DeleteComponent <MeshRenderer>(spaceBody);
     DeleteComponent <MeshFilter>(spaceBody);
 }
Exemplo n.º 21
0
 protected override void UpgradeClass(ITemplateManager templateManager, SpaceBody spaceBody, Mapping UpgradeMapping)
 {
     spaceBody.gameObject.layer = LayerHelper.Asteroid;
     //base.Upgrade(templateManager, spaceBody);
 }