private void LoadWorkspace(Project project)
        {
            m_CurrentWorkspaceKey = GetWorkspaceKey(project);
            if (EditorPrefs.HasKey(m_CurrentWorkspaceKey))
            {
                try
                {
                    var serializedWorkspace = EditorPrefs.GetString(m_CurrentWorkspaceKey);
                    if (!string.IsNullOrEmpty(serializedWorkspace))
                    {
                        m_CurrentWorkspace = JsonSerialization.DeserializeFromString <Workspace>(serializedWorkspace);
                        m_CurrentWorkspace.Initialize();
                    }
                    else
                    {
                        CreateNewWorkspace();
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError($"Unable to deserialize workspace for project {project.Name}");
                    Debug.LogException(e);

                    CreateNewWorkspace();
                }
            }
            else
            {
                CreateNewWorkspace();
            }
        }
Example #2
0
        public void JsonSerialization_Serialize_Enums()
        {
            var src = new EnumContainer
            {
                BasicEnum    = BasicEnum.A,
                EnumToByte   = EnumToByte.B,
                EnumToInt    = EnumToInt.C,
                EnumToLong   = EnumToLong.A,
                EnumToShort  = EnumToShort.B,
                EnumToUint   = EnumToUint.C,
                EnumToSByte  = EnumToSByte.A,
                EnumToULong  = EnumToULong.B,
                EnumToUShort = EnumToUShort.C
            };
            var dst = new EnumContainer();

            var json = JsonSerialization.Serialize(src);

            using (JsonSerialization.DeserializeFromString(json, ref dst))
            {
                Assert.That(dst.BasicEnum, Is.EqualTo(src.BasicEnum));
                Assert.That(dst.EnumToByte, Is.EqualTo(src.EnumToByte));
                Assert.That(dst.EnumToInt, Is.EqualTo(src.EnumToInt));
                Assert.That(dst.EnumToLong, Is.EqualTo(src.EnumToLong));
                Assert.That(dst.EnumToShort, Is.EqualTo(src.EnumToShort));
                Assert.That(dst.EnumToUint, Is.EqualTo(src.EnumToUint));
                Assert.That(dst.EnumToSByte, Is.EqualTo(src.EnumToSByte));
                Assert.That(dst.EnumToULong, Is.EqualTo(src.EnumToULong));
                Assert.That(dst.EnumToUShort, Is.EqualTo(src.EnumToUShort));
            }
        }
        public void JsonSerialization_SerializeAsString_Struct()
        {
            var src = new TestStruct {
                A = 10, B = 32
            };
            var dst = new TestStruct();

            var json = JsonSerialization.Serialize(src);

            using (JsonSerialization.DeserializeFromString(json, ref dst))
            {
                Assert.That(src, Is.EqualTo(dst));
            }
        }
        public void JsonSerialization_Serialize_SystemDateTime()
        {
            var src = new SystemDateTimeContainer {
                Value = DateTime.Now
            };
            var json = JsonSerialization.Serialize(src);

            Debug.Log(json);
            Assert.That(json, Does.Match(@".*""\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{7}Z"".*"));

            var dst = new SystemDateTimeContainer();

            using (JsonSerialization.DeserializeFromString(json, ref dst))
            {
                Assert.That(dst.Value, Is.EqualTo(src.Value));
            }
        }
        public void JsonSerialization_Serialize_SystemTimeSpan()
        {
            var src = new SystemTimeSpanContainer {
                Value = new TimeSpan(1, 2, 3, 4, 5)
            };
            var json = JsonSerialization.Serialize(src);

            Debug.Log(json);
            Assert.That(json, Does.Match(@".*""(-?\d+[.])?\d{2}:\d{2}:\d{2}([.]\d{7})?"".*"));

            var dst = new SystemTimeSpanContainer();

            using (JsonSerialization.DeserializeFromString(json, ref dst))
            {
                Assert.That(dst.Value, Is.EqualTo(src.Value));
            }
        }
Example #6
0
        public void JsonSerialization_Serialize_SystemGuid()
        {
            var src = new SystemGuidContainer {
                Value = Guid.NewGuid()
            };
            var json = JsonSerialization.Serialize(src);

            Debug.Log(json);
            Assert.That(json, Does.Match(@".*""[\da-f]{32}"".*"));

            var dst = new SystemGuidContainer();

            using (JsonSerialization.DeserializeFromString(json, ref dst))
            {
                Assert.That(dst.Value, Is.EqualTo(src.Value));
            }
        }
Example #7
0
        public void JsonSerialization_Serialize_UnityEditorGUID()
        {
            var src = new UnityEditorGUIDContainer {
                Value = UnityEditor.GUID.Generate()
            };
            var json = JsonSerialization.Serialize(src);

            Debug.Log(json);
            Assert.That(json, Does.Match(@".*""[\da-f]{32}"".*"));

            var dst = new UnityEditorGUIDContainer();

            using (JsonSerialization.DeserializeFromString(json, ref dst))
            {
                Assert.That(dst.Value, Is.EqualTo(src.Value));
            }
        }
Example #8
0
        public void JsonSerialization_Serialize_UnityEngineObject()
        {
            var src = new UnityEngineObjectContainer {
                Value = AssetDatabase.LoadAssetAtPath <Texture2D>(k_AssetPath)
            };
            var json = JsonSerialization.Serialize(src);

            Debug.Log(json);
            Assert.That(json, Does.Match(@".*""GlobalObjectId_V\d-\d-[\da-f]{32}-\d{7}-\d"".*"));

            var dst = new UnityEngineObjectContainer();

            using (JsonSerialization.DeserializeFromString(json, ref dst))
            {
                Assert.That(dst.Value, Is.Not.Null);
                Assert.That(dst.Value, Is.Not.False);
                Assert.That(AssetDatabase.GetAssetPath(dst.Value), Is.EqualTo(k_AssetPath));
            }
        }
Example #9
0
        public void JsonSerialization_Serialize_SystemIOFileInfo()
        {
            var src = new SystemIOFileInfoContainer
            {
                AbsoluteFile = new FileInfo(k_AbsoluteFile),
                RelativeFile = new FileInfo(k_RelativeFile)
            };

            var json = JsonSerialization.Serialize(src);

            Debug.Log(json);
            Assert.That(json, Does.Contain(k_AbsoluteFile + '\"'));
            Assert.That(json, Does.Contain('\"' + k_RelativeFile + '\"'));

            var dst = new SystemIOFileInfoContainer();

            using (JsonSerialization.DeserializeFromString(json, ref dst))
            {
                Assert.That(dst.AbsoluteFile, Is.Not.Null);
                Assert.That(dst.AbsoluteFile.FullName, Is.EqualTo(src.AbsoluteFile.FullName));
                Assert.That(dst.RelativeFile, Is.Not.Null);
                Assert.That(dst.RelativeFile.FullName, Is.EqualTo(src.RelativeFile.FullName));
            }
        }
        public void JsonSerialization_Serialize_Null()
        {
            var src = new ContainerWithClassContainerFields
            {
                String     = null,
                Value      = null,
                Array      = new ClassContainer[3],
                MixedArray = new[] { null, new ClassContainer(), null, new ClassContainer(), new ClassContainer(), null }
            };
            var json = JsonSerialization.Serialize(src);

            Debug.Log(json);
            Assert.That(json, Is.EqualTo("{\n    \"String\": null,\n    \"Value\": null,\n    \"Array\": [\n        null,\n        null,\n        null\n    ],\n    \"MixedArray\": [\n        null, {},\n        null, {}, {},\n        null\n    ]\n}"));

            var dst = new ContainerWithClassContainerFields();

            using (JsonSerialization.DeserializeFromString(json, ref dst))
            {
                Assert.That(dst.String, Is.Null);
                Assert.That(dst.Value, Is.Null);
                Assert.That(dst.Array, Is.EqualTo(new ClassContainer[3]));
                Assert.That(dst.MixedArray, Is.EqualTo(new[] { null, new ClassContainer(), null, new ClassContainer(), new ClassContainer(), null }));
            }
        }
Example #11
0
        public void JsonSerialization_Serialize_FormerlySerializedAs()
        {
            var srcStructJson = $"{{ \"Data\": {{ \"$type\": \"{OriginalStructContainerAssemblyTypeName}\", \"Value\": 1 }} }}";
            var srcClassJson  = $"{{ \"Data\": {{ \"$type\": \"{OriginalClassContainerAssemblyTypeName}\", \"Value\": 2 }} }}";

            var dstStructContainer = new StructContainerWithInterfaceMember();
            var dstClassContainer  = new ClassContainerWithInterfaceMember();

            using (var result = JsonSerialization.DeserializeFromString(srcStructJson, ref dstStructContainer))
            {
                Assert.That(result.Succeeded, Is.True);
                Assert.That(dstStructContainer.Data, Is.Not.Null);
                Assert.That(dstStructContainer.Data is RenamedStructContainer, Is.True);
                Assert.That(((RenamedStructContainer)dstStructContainer.Data).Value, Is.EqualTo(1));
            }

            using (var result = JsonSerialization.DeserializeFromString(srcClassJson, ref dstClassContainer))
            {
                Assert.That(result.Succeeded, Is.True);
                Assert.That(dstClassContainer.Data, Is.Not.Null);
                Assert.That(dstClassContainer.Data is RenamedClassContainer, Is.True);
                Assert.That(((RenamedClassContainer)dstClassContainer.Data).Value, Is.EqualTo(2));
            }
        }
Example #12
0
        private void ProcessBuilds()
        {
            EditorApplication.delayCall -= ProcessBuilds;

            if (m_OriginalBuildTarget <= 0)
            {
                var invalidTarget = m_OriginalBuildTarget;
                Clear();
                throw new Exception($"Original build target is invalid: {invalidTarget}");
            }

            // Editor is compiling, wait until other frame
            if (EditorApplication.isCompiling)
            {
                EditorApplication.delayCall += ProcessBuilds;
                return;
            }

            QueuedBuild currentBuild = GetNextUnfinishedBuild();

            while (currentBuild != null)
            {
                var t = (UnityEditor.BuildTarget)currentBuild.sortingIndex;
                var b = ToBuildConfiguration(currentBuild.buildConfigurationGuid);

                if (t == UnityEditor.BuildTarget.NoTarget || t == EditorUserBuildSettings.activeBuildTarget)
                {
                    currentBuild.buildPipelineResult = JsonSerialization.Serialize(b.Build());
                    currentBuild.buildFinished       = true;
                }
                else
                {
                    try
                    {
                        if (b.GetComponent <IBuildPipelineComponent>().SetupEnvironment())
                        {
                            // Show dialog before actual build dialog, this way it's clear what's happening
                            EditorUtility.DisplayProgressBar("Hold on...", $"Switching to {t}", 0.0f);
                            return;
                        }
                    }
                    catch
                    {
                        m_QueueBuilds.Clear();
                        throw;
                    }
                }

                currentBuild = GetNextUnfinishedBuild();
            }


            // No more builds to run?
            if (currentBuild == null)
            {
                // We're done
                if (m_OriginalBuildTarget == EditorUserBuildSettings.activeBuildTarget)
                {
                    EditorUtility.ClearProgressBar();
                    m_OnAllBuildsCompletedEvent.Invoke(m_QueueBuilds.Select(m =>
                    {
                        var buildPipelineResult = TypeConstruction.Construct <BuildPipelineResult>();
                        JsonSerialization.DeserializeFromString <BuildPipelineResult>(m.buildPipelineResult, ref buildPipelineResult);
                        return(buildPipelineResult);
                    }).ToArray());
                    Clear();
                }
                else
                {
                    EditorUtility.DisplayProgressBar("Hold on...", $"Switching to original build target {m_OriginalBuildTarget}", 0.0f);
                    // Restore original build target
                    EditorUserBuildSettings.SwitchActiveBuildTarget(UnityEditor.BuildPipeline.GetBuildTargetGroup(m_OriginalBuildTarget), m_OriginalBuildTarget);
                }
                return;
            }
        }