/// <summary>
        /// This method instantiates a game object with the required components and applies this data object to the component.
        /// </summary>
        /// <param name="defaults">References to the prefabs.</param>
        /// <returns></returns>
        internal ISerializableComponent Deserialize(DefaultReferences defaults)
        {
            ISerializableComponent serializableComponent = InstantiateComponent(defaults);

            serializableComponent.ApplyData(this);
            return(serializableComponent);
        }
Beispiel #2
0
        public override IEnumerable <PPtr <Object> > FetchDependencies(DependencyContext context)
        {
            foreach (PPtr <Object> asset in base.FetchDependencies(context))
            {
                yield return(asset);
            }

#if UNIVERSAL
            if (HasDefaultProperties(context.Version, context.Flags))
            {
                yield return(context.FetchDependency(DefaultProperties, DefaultReferencesName));
            }
            if (HasDefaultReferences(context.Version, context.Flags))
            {
                foreach (PPtr <Object> asset in context.FetchDependencies(DefaultReferences.Select(t => t.Value), DefaultReferencesName))
                {
                    yield return(asset);
                }
            }
            if (HasIcon(context.Version, context.Flags))
            {
                yield return(context.FetchDependency(Icon, IconName));
            }
#endif
        }
        public IEnumerator SetUpScene()
        {
            yield return(SceneManager.LoadSceneAsync("CommandTestScene", LoadSceneMode.Single));

            this.Defaults = GameObject.FindObjectOfType <SketchWorld>().defaults;
            yield return(null);
        }
Beispiel #4
0
        internal override ISerializableComponent InstantiateComponent(DefaultReferences defaults)
        {
            ISerializableComponent serializableComponent = null;

            if (Interpolation == InterpolationType.Cubic)
            {
                serializableComponent = GameObject.Instantiate(defaults.StrokeSketchObjectPrefab).GetComponent <ISerializableComponent>();
            }
            else if (Interpolation == InterpolationType.Linear)
            {
                serializableComponent = GameObject.Instantiate(defaults.LinearInterpolationStrokeSketchObjectPrefab).GetComponent <ISerializableComponent>();
            }
            return(serializableComponent);
        }
Beispiel #5
0
        protected override YAMLMappingNode ExportYAMLRoot(IExportContainer container)
        {
            YAMLMappingNode node = base.ExportYAMLRoot(container);

            node.AddSerializedVersion(ToSerializedVersion(container.ExportVersion));
            if (HasDefaultReferences(container.ExportVersion))
            {
                node.Add(DefaultReferencesName, DefaultReferences.ExportYAML(container));
            }
            if (HasExecutionOrder(container.ExportVersion))
            {
                node.Add(ExecutionOrderName, ExecutionOrder);
                node.Add(IconName, Icon.ExportYAML(container));
            }
            PostExportYAML(container, node);
            return(node);
        }
Beispiel #6
0
        protected override YAMLMappingNode ExportYAMLRoot()
        {
            YAMLMappingNode node = base.ExportYAMLRoot();

            if (IsReadScript)
            {
                node.Add("m_Script", Script);
                node.Add("m_DefaultReferences", DefaultReferences.ExportYAML());
                node.Add("m_Icon", Icon.ExportYAML());
            }
            node.Add("m_ExecutionOrder", ExecutionOrder);
            node.Add("m_ClassName", ClassName);
            node.Add("m_Namespace", Namespace);
            node.Add("m_AssemblyName", AssemblyName);
            node.Add("m_IsEditorScript", IsEditorScript);
            return(node);
        }
Beispiel #7
0
        protected override YAMLMappingNode ExportYAMLRoot(IExportContainer container)
        {
#warning TODO: values acording to read version (current 2017.3.0f3)
            YAMLMappingNode node = base.ExportYAMLRoot(container);
            if (IsReadScript(container.Flags))
            {
                node.Add("m_Script", Script);
                node.Add("m_DefaultReferences", DefaultReferences.ExportYAML(container));
                node.Add("m_Icon", Icon.ExportYAML(container));
            }
            node.Add("m_ExecutionOrder", ExecutionOrder);
            node.Add("m_ClassName", ClassName);
            node.Add("m_Namespace", IsReadNamespace(container.Version) ? Namespace : string.Empty);
            node.Add("m_AssemblyName", AssemblyNameOrigin);
            node.Add("m_IsEditorScript", IsEditorScript);
            return(node);
        }
Beispiel #8
0
        public override void Write(AssetWriter writer)
        {
            base.Write(writer);

            if (HasDefaultReferences(writer.Version))
            {
                DefaultReferences.Write(writer);
            }
            if (HasExecutionOrder(writer.Version))
            {
                writer.Write(ExecutionOrder);
                writer.AlignStream();

                Icon.Write(writer);
            }

            PostWrite(writer);
        }
    private static IEnumerable <NamedTest> GetSelfVerifyingFacts <TTargetCompiler, TLanguageConversion>(string sourceFileText,
                                                                                                        List <NamedTest> runnableTestsInSource) where TTargetCompiler : ICompiler, new()
        where TLanguageConversion : ILanguageConversion, new()
    {
        // Lazy to avoid confusing test runner on error, but also avoid calculating multiple times
        var conversionResultAsync = new AsyncLazy <ConversionResult>(() => {
            var xUnitReferences = DefaultReferences.With(typeof(FactAttribute).Assembly, typeof(Assert).Assembly);
            return(ProjectConversion.ConvertTextAsync <TLanguageConversion>(sourceFileText, new TextConversionOptions(xUnitReferences)));
        });

        var runnableTestsInTarget = new AsyncLazy <Dictionary <string, NamedTest> >(async() => GetConvertedNamedFacts <TTargetCompiler>(runnableTestsInSource,
                                                                                                                                        await conversionResultAsync.GetValueAsync()));

        return(runnableTestsInSource.Select(sourceFact =>
                                            new NamedTest(sourceFact.Name, async() =>
        {
            try
            {
                await sourceFact.Execute();
            }
            catch (TargetInvocationException ex)
            {
                throw new XunitException(
                    $"Source test failed, ensure the source is correct for \"{sourceFact.Name}\": {(ex.InnerException ?? ex)}");
            }

            try {
                var test = await runnableTestsInTarget.GetValueAsync();
                await test[sourceFact.Name].Execute();
            }
            catch (TargetInvocationException ex) {
                var conversionResult = await conversionResultAsync.GetValueAsync();
                throw new XunitException(
                    $"Converted test failed, the conversion is incorrect for \"{sourceFact.Name}\": {(ex.InnerException ?? ex)}\r\nConverted Code: {conversionResult.ConvertedCode ?? conversionResult.GetExceptionsAsString()}");
            }
        })
                                            ));
    }
    /// <summary>
    /// Compiles the given string of source code into an IL byte array.
    /// </summary>
    /// <remarks>The transitive closure of the references for <paramref name="requiredAssemblies"/> are added.</remarks>
    public static Assembly AssemblyFromCode(this ICompiler compiler, SyntaxTree syntaxTree, params Assembly[] requiredAssemblies)
    {
        var allReferences = DefaultReferences.With(requiredAssemblies);
        var compilation   = compiler.CreateCompilationFromTree(syntaxTree, allReferences);

        using (var dllStream = new MemoryStream())
            using (var pdbStream = new MemoryStream()) {
                var result = compilation.Emit(dllStream, pdbStream);
                if (!result.Success)
                {
                    string codeLines = string.Join("\r\n", Utils.HomogenizeEol(syntaxTree.ToString())
                                                   .Split(new[] { "\r\n" }, StringSplitOptions.None)
                                                   .Select((l, i) => $"{i+1:000}: {l}"));
                    throw new CompilationException(
                              $"{compiler.GetType().Name} error:\r\n{string.Join("\r\n", result.Diagnostics)}\r\n\r\nSource code:\r\n{codeLines}"
                              );
                }

                dllStream.Seek(0, SeekOrigin.Begin);
                pdbStream.Seek(0, SeekOrigin.Begin);
                return(Assembly.Load(dllStream.ToArray(), pdbStream.ToArray()));
            }
    }
 /// <summary>
 /// This method instantiates the correct prefab for the data object type and returns it.
 /// </summary>
 /// <param name="defaults">References to the prefabs.</param>
 /// <returns></returns>
 internal abstract ISerializableComponent InstantiateComponent(DefaultReferences defaults);
Beispiel #12
0
 internal override ISerializableComponent InstantiateComponent(DefaultReferences defaults)
 {
     return(GameObject.Instantiate(defaults.SketchObjectGroupPrefab).GetComponent <SketchObjectGroup>());
 }