Beispiel #1
0
        public static void Initialize()
        {
            FactoryManager.Initialize();
            PlanetManager.Initialize();
            Initialized = true;
            ExitingMultiplayerSession = false;

            using (GetRemotePlayersModels(out var remotePlayersModels))
            {
                remotePlayersModels.Clear();
            }
        }
Beispiel #2
0
        /// <summary>
        /// Creates the planet with serialized parameters (this happens every play/stop in editor)
        /// </summary>
        protected override void Awake()
        {
            if ((int)PlanetManager.DebugLevel > 0)
            {
                Debug.Log("GasPlanet.cs: Awake()");
            }
            if ((int)PlanetManager.DebugLevel > 0)
            {
                Debug.Log("- PlanetVersion: " + PLANET_VERSION);
            }

            // Set Shader property int IDs for increased performance when updating property parameters
            _shaderID_LocalStarPosition         = Shader.PropertyToID("_LocalStarPosition");
            _shaderID_LocalStarColor            = Shader.PropertyToID("_LocalStarColor");
            _shaderID_LocalStarIntensity        = Shader.PropertyToID("_LocalStarIntensity");
            _shaderID_LocalStarAmbientIntensity = Shader.PropertyToID("_LocalStarAmbientIntensity");

            if (planetBlueprintIndex != -1 || blueprint == null)
            {
                SetPlanetBlueprint(planetBlueprintIndex, true, false);
            }

            // Ensure that there is a LocalStar in the scene.
            if (FindObjectOfType <LocalStar>() == null)
            {
                Debug.LogWarning("There is no LocalStar in the scene. Planet will not be lit. Create a game object and add the LocalStar component. The position of the game object will be the light source.");
            }

            // Get reference to the MeshFilter component
            meshFilter = gameObject.GetComponent <MeshFilter>();

            // Force initialization of PlanetManager if it is not yet initialized. We need the procedural mesh.
            if (!PlanetManager.IsInitialized || PlanetManager.MeshLODMeshes == null || PlanetManager.MeshLODMeshes.Length < meshLODLevel)
            {
                PlanetManager.Initialize();
            }

            // Use Mesh with appropriate Level of Detail (LOD) from Manager
            meshFilter.sharedMesh = PlanetManager.MeshLODMeshes[meshLODLevel];

            // Get reference to MeshRenderer Component
            _meshRenderer = gameObject.GetComponent <MeshRenderer>();

            // Create the planet material and set the material for the MeshRenderer component
            if (_material == null)
            {
                if (QualitySettings.activeColorSpace == ColorSpace.Linear)
                {
                    _material = new Material(Shader.Find("ProceduralPlanets/GasPlanetLinear"));
                }
                else
                {
                    _material = new Material(Shader.Find("ProceduralPlanets/GasPlanetGamma"));
                }

                _meshRenderer.material = _material;
            }

            if (QualitySettings.activeColorSpace == ColorSpace.Linear)
            {
                _material.shader = Shader.Find("ProceduralPlanets/GasPlanetLinear");
            }
            else
            {
                _material.shader = Shader.Find("ProceduralPlanets/GasPlanetGamma");
            }

            // Clear properties lists
            propertyFloats.Clear();
            propertyMaterials.Clear();
            propertyColors.Clear();

            // Add property materials
            AddPropertyMaterial("gas", "Gas*", PlanetManager.Instance.gasMaterials.ToArray(), 1, new string[] { "Maps" });

            // Update dictionaries (for materials a this stage)
            UpdateDictionariesIfNeeded(true);

            // Set default properties (for materials at this stage)
            SetDefaultProperties();

            // Get references to newly created property materials
            _proceduralMaterialMaps = PlanetManager.Instance.GetUniqueProceduralMaterial(_dictionaryMaterials["gas"].GetPropertyMaterial(), gameObject, "gas");

            // Add Float (within a range of min/max) and color properties
            AddPropertyFloat("horizontalTiling", "HorizontalTiling", 1, 10, false, true, 5, false, new string[] { "StormMask" }, _material, "_HTiling", PropertyFloat.Method.VALUE, PropertyFloat.DataType.INT);
            AddPropertyFloat("verticalTiling", "Vertical Tiling", 1, 10, false, true, 8, false, new string[] { "StormMask" }, _material, "_VTiling", PropertyFloat.Method.VALUE, PropertyFloat.DataType.INT);
            AddPropertyFloat("gasSeed", "Gas Seed*", 0, 255, false, true, 10, true, new string[] { "Maps" }, _proceduralMaterialMaps, "Composition_Random_Seed", PropertyFloat.Method.VALUE, PropertyFloat.DataType.INT);
            AddPropertyFloat("turbulenceSeed", "Turbulence Seed*", 0, 255, false, true, 20, true, new string[] { "Maps" }, _proceduralMaterialMaps, "Turbulence_Random_Seed", PropertyFloat.Method.VALUE, PropertyFloat.DataType.INT);
            AddPropertyFloat("turbulence", "Turbulence*", 0.0f, 0.2f, true, false, 20, false, new string[] { "Maps" }, new Substance.Game.SubstanceGraph[] { _proceduralMaterialMaps }, "Turbulence", PropertyFloat.Method.LERP, PropertyFloat.DataType.FLOAT);
            AddPropertyFloat("turbulenceScale", "Turbulence Scale*", 1, 10, false, false, 30, false, new string[] { "Maps" }, new Substance.Game.SubstanceGraph[] { _proceduralMaterialMaps }, "Turbulence_Scale", PropertyFloat.Method.VALUE, PropertyFloat.DataType.INT);
            AddPropertyFloat("turbulenceDisorder", "Turbulence Disorder*", 0.0f, 1.0f, true, false, 40, false, new string[] { "Maps" }, new Substance.Game.SubstanceGraph[] { _proceduralMaterialMaps }, "Turbulence_Disorder", PropertyFloat.Method.LERP, PropertyFloat.DataType.FLOAT);
            AddPropertyFloat("separation", "Separation*", 0.0f, 1.0f, true, false, 50, false, new string[] { "Maps" }, new Substance.Game.SubstanceGraph[] { _proceduralMaterialMaps }, "Separation", PropertyFloat.Method.LERP, PropertyFloat.DataType.FLOAT);
            AddPropertyFloat("smoothness", "Smoothness*", 0.0f, 100.0f, true, false, 60, false, new string[] { "Maps" }, new Substance.Game.SubstanceGraph[] { _proceduralMaterialMaps }, "Smoothness", PropertyFloat.Method.LERP, PropertyFloat.DataType.FLOAT);
            AddPropertyFloat("blurriness", "Blurriness*", 0.0f, 16.0f, true, false, 70, false, new string[] { "Maps" }, new Substance.Game.SubstanceGraph[] { _proceduralMaterialMaps }, "Blurriness", PropertyFloat.Method.LERP, PropertyFloat.DataType.FLOAT);
            AddPropertyFloat("palette", "Palette*", 1, 8, false, true, 80, false, new string[] { "Maps" }, new Substance.Game.SubstanceGraph[] { _proceduralMaterialMaps }, "Palette", PropertyFloat.Method.VALUE, PropertyFloat.DataType.INT);
            AddPropertyFloat("detail", "Detail*", 0.0f, 1.0f, true, false, 90, false, new string[] { "Maps" }, new Substance.Game.SubstanceGraph[] { _proceduralMaterialMaps }, "Detail", PropertyFloat.Method.LERP, PropertyFloat.DataType.FLOAT);
            AddPropertyFloat("detailOffset", "Detail Offset*", 0.0f, 1.0f, true, false, 100, false, new string[] { "Maps" }, new Substance.Game.SubstanceGraph[] { _proceduralMaterialMaps }, "Detail_Offset", PropertyFloat.Method.LERP, PropertyFloat.DataType.FLOAT);
            AddPropertyFloat("contrast", "Contrast*", -0.6f, 0.6f, true, false, 110, false, new string[] { "Maps" }, new Substance.Game.SubstanceGraph[] { _proceduralMaterialMaps }, "Contrast", PropertyFloat.Method.LERP, PropertyFloat.DataType.FLOAT);
            AddPropertyFloat("hue", "Hue*", 0.0f, 1.0f, true, false, 120, false, new string[] { "Maps" }, new Substance.Game.SubstanceGraph[] { _proceduralMaterialMaps }, "Hue", PropertyFloat.Method.LERP, PropertyFloat.DataType.FLOAT);
            AddPropertyFloat("saturation", "Saturation*", 0.0f, 1.0f, true, false, 130, false, new string[] { "Maps" }, new Substance.Game.SubstanceGraph[] { _proceduralMaterialMaps }, "Saturation", PropertyFloat.Method.LERP, PropertyFloat.DataType.FLOAT);
            AddPropertyFloat("brightness", "Brightness*", 0.0f, 1.0f, true, false, 150, false, new string[] { "Maps" }, new Substance.Game.SubstanceGraph[] { _proceduralMaterialMaps }, "Brightness", PropertyFloat.Method.LERP, PropertyFloat.DataType.FLOAT);
            AddPropertyFloat("banding", "Banding", 0.0f, 1.0f, true, false, 160, false, null, _material, "_Banding", PropertyFloat.Method.LERP, PropertyFloat.DataType.FLOAT);
            AddPropertyFloat("solidness", "Solidness", 0.0f, 1.0f, true, false, 170, false, null, _material, "_Solidness", PropertyFloat.Method.LERP, PropertyFloat.DataType.FLOAT);
            AddPropertyFloat("faintness", "Faintness", 0.0f, 1.0f, true, false, 180, false, null, _material, "_Faintness", PropertyFloat.Method.LERP, PropertyFloat.DataType.FLOAT);
            AddPropertyColor("faintnessColor", "Faintness Color", new Color(0.5f, 0.5f, 0.5f, 1.0f), 0.2f, 0.2f, 0.2f, 190, true, _material, "_FaintnessColor");
            AddPropertyFloat("roughness", "Roughness*", 0.0f, 1.0f, true, false, 200, false, null, _material, "_Roughness", PropertyFloat.Method.LERP, PropertyFloat.DataType.FLOAT);
            AddPropertyColor("twilightColor", "Twilight Color", new Color(0.15f, 0.0f, 0.15f, 1.0f), 0.2f, 0.2f, 0.2f, 210, true, _material, "_ColorTwilight");
            AddPropertyFloat("stormMaskIndex", "Storm Mask Index", 0.0f, 1.0f, true, false, 220, true, new string[] { "StormMask" });
            AddPropertyFloat("stormSquash", "Storm Squash*", 0.0f, 1.0f, true, false, 230, false, new string[] { "Maps" }, new Substance.Game.SubstanceGraph[] { _proceduralMaterialMaps }, "Storm_Squash", PropertyFloat.Method.LERP, PropertyFloat.DataType.FLOAT);
            AddPropertyColor("stormColor", "Storm Color", new Color(0.78f, 0.13f, 0.28f, 1.0f), 0.2f, 0.2f, 0.2f, 240, true, _material, "_StormColor");
            AddPropertyFloat("stormTint", "Storm Tint", 0.0f, 1.0f, true, false, 250, false, null, _material, "_StormTint", PropertyFloat.Method.LERP, PropertyFloat.DataType.FLOAT);
            AddPropertyFloat("stormScale", "Storm Scale*", 0.0f, 1.0f, true, false, 260, false, new string[] { "Maps" }, new Substance.Game.SubstanceGraph[] { _proceduralMaterialMaps }, "Storm_Scale", PropertyFloat.Method.LERP, PropertyFloat.DataType.FLOAT);
            AddPropertyFloat("stormNoise", "Storm Noise*", 0.0f, 1.0f, true, false, 270, false, new string[] { "Maps" }, new Substance.Game.SubstanceGraph[] { _proceduralMaterialMaps }, "Storm_Noise", PropertyFloat.Method.LERP, PropertyFloat.DataType.FLOAT);
            AddPropertyColor("atmosphereColor", "Atmosphere Color", new Color(0.48f, 0.48f, 0.3f, 1.0f), 0.2f, 0.2f, 0.2f, 280, true, _material, "_AtmosphereColor");
            AddPropertyFloat("atmosphereFalloff", "Atmospehre Falloff", 1.0f, 20.0f, true, false, 290, false, null, _material, "_AtmosphereFalloff", PropertyFloat.Method.LERP, PropertyFloat.DataType.FLOAT);

            // Update dictionaries (again, now with all Float and Color properties too)
            UpdateDictionariesIfNeeded(true);

            // Set default properties based on seed (this time for all properties)
            SetDefaultProperties();


            if (initJSONSettings != "")
            {
                // If initJSON string is set, configure planet according to the init string
                ImportFromJSON(initJSONSettings);
                initJSONSettings = "";
            }
            else
            {
                // Load planet settings from cache (if this is not a new planet) - this overwrites default settings if changes have been made
                if (serializedPlanetCache != null)
                {
                    if (serializedPlanetCache.Length > 0)
                    {
                        ImportFromJSON(serializedPlanetCache, false);
                    }
                }
            }

            // Update lookup textures (e.g. create lookup textures for liquid level so shader knows where on hight map to apply water)
            UpdateLookupTextures();

            // Update shader for planet lighting
            UpdateShaderLocalStar(true);

            // Force rebuild of planet textures to use all the correct properties for the planet
            RebuildTextures(true);

            _updateShaderNeeded = true;
        }
Beispiel #3
0
    public void SetLevelSettings(LevelSettingsEditor settings)
    {
        _planets = new PlanetManager();
        _planets.Initialize(settings);

        _bounds = new Bounds(settings.Bounds.position, settings.Bounds.size);
        _startPosition = settings.StartPosition;
        _gravity = settings.Gravity;
        _rotationAcceleration = settings.RotationAcceleration;
        _equilibriumSpeed = settings.EquilibriumSpeed;
        _orbitAccelerationTime = settings.OrbitAccelerationTime;
    }