| | 1 | | using System; |
| | 2 | | using UnityEngine; |
| | 3 | |
|
| | 4 | | namespace Builder |
| | 5 | | { |
| | 6 | | public static class DCLBuilderConfig |
| | 7 | | { |
| | 8 | | public static event Action<BuilderConfig> OnConfigChanged; |
| 4 | 9 | | public static BuilderConfig config { get; private set; } = BuilderConfig.DefaultBuilderConfig; |
| | 10 | |
|
| | 11 | | public static void SetConfig(BuilderConfig newBuilderConfig) |
| | 12 | | { |
| 0 | 13 | | config = newBuilderConfig; |
| 0 | 14 | | OnConfigChanged?.Invoke(config); |
| 0 | 15 | | } |
| | 16 | |
|
| | 17 | | public static void SetConfig(string configJson) |
| | 18 | | { |
| | 19 | | try |
| | 20 | | { |
| 0 | 21 | | JsonUtility.FromJsonOverwrite(configJson, config); |
| 0 | 22 | | SetConfig(config.Clone()); |
| 0 | 23 | | } |
| 0 | 24 | | catch (Exception e) |
| | 25 | | { |
| 0 | 26 | | Debug.LogError($"Error setting builder's configuration {e.Message}"); |
| 0 | 27 | | } |
| 0 | 28 | | } |
| | 29 | | } |
| | 30 | |
|
| | 31 | | [Serializable] |
| | 32 | | public class BuilderConfig |
| | 33 | | { |
| | 34 | | [Serializable] |
| | 35 | | public class Camera |
| | 36 | | { |
| | 37 | | public float zoomMin; |
| | 38 | | public float zoomMax; |
| | 39 | | public float zoomDefault; |
| | 40 | | } |
| | 41 | |
|
| | 42 | | [Serializable] |
| | 43 | | public class Environment |
| | 44 | | { |
| | 45 | | public bool disableFloor; |
| | 46 | | } |
| | 47 | |
|
| | 48 | | public static BuilderConfig DefaultBuilderConfig |
| | 49 | | { |
| | 50 | | get |
| | 51 | | { |
| | 52 | | return new BuilderConfig() |
| | 53 | | { |
| | 54 | | camera = new Camera() { zoomMin = 1f, zoomMax = 100f, zoomDefault = 32 }, |
| | 55 | | environment = new Environment() { disableFloor = false } |
| | 56 | | }; |
| | 57 | | } |
| | 58 | | } |
| | 59 | |
|
| | 60 | | public BuilderConfig Clone() => (BuilderConfig)MemberwiseClone(); |
| | 61 | |
|
| | 62 | | public Camera camera; |
| | 63 | | public Environment environment; |
| | 64 | | } |
| | 65 | | } |