Esempio n. 1
0
        public override Gradient AssembleValue(ObjectModel value, AssemblyContext context)
        {
            ColorAssembler assembler = new ColorAssembler();
            Gradient       gradient  = new Gradient();

            gradient.mode      = value.GetValue <GradientMode>("Mode");
            gradient.colorKeys = value.GetArray("ColorKeys").Select(x => new GradientColorKey((Color)assembler.Assemble((x as ObjectModel).GetObject("Color"), context), (x as ObjectModel).GetValue <float>("Time"))).ToArray();
            gradient.alphaKeys = value.GetArray("AlphaKeys").Select(x => new GradientAlphaKey((x as ObjectModel).GetValue <float>("Alpha"), (x as ObjectModel).GetValue <float>("Time"))).ToArray();

            return(gradient);
        }
Esempio n. 2
0
        public void Assemble(ValueModel source, AssemblyContext context)
        {
            ObjectModel obj = (source as ObjectModel);

            Name        = obj.GetValue <string>("Name");
            Description = obj.GetValue <string>("Description");
            Identifier  = obj.GetValue <string>("Identifier");
            Width       = obj.GetValue <int>("Width");
            Height      = obj.GetValue <int>("Height");
            Tiles       = AssembleTileData(obj.GetArray("Tiles"), context);
            Objects     = obj.GetArray("Objects").Elements.Cast <ObjectModel>().ToArray();
        }
Esempio n. 3
0
        private GameObject RecursiveAssemble(ObjectModel model, AssemblyContext context, Transform parent)
        {
            GameObject obj = new GameObject(model.GetValue <string>("Name"))
            {
                tag      = model.GetValue <string>("Tag"),
                layer    = model.GetValue <int>("Layer"),
                isStatic = model.GetValue <bool>("Static")
            };

            Vector3    pos   = obj.transform.position;
            Quaternion rot   = obj.transform.rotation;
            Vector3    scale = obj.transform.localScale;

            obj.transform.SetParent(parent, true);

            obj.transform.localPosition = pos;
            obj.transform.localRotation = rot;
            obj.transform.localScale    = scale;

            obj.SetActive(false);
            var components = model.GetArray("Components");

            foreach (var component in components)
            {
                _componentAssembler.Assemble(component as ObjectModel, obj, context);
            }

            var children = model.GetArray("Children");

            foreach (var child in children)
            {
                GameObject childObj = RecursiveAssemble(child as ObjectModel, context, obj.transform);
            }
            obj.SetActive(true);

            return(context.MakeReferencable(obj, model.Guid));
        }
        public TurretComponent Assemble(ObjectModel model, Transform parent, TurretAssembly assembly, AssemblyContext context)
        {
            IContentCachedPrefab component    = GetComponent(model.GetValue <string>("UniqueIdentifier"));
            ValueAssembler       assembler    = new ValueAssembler();
            GameObject           obj          = component.Instantiate();
            TurretComponent      newComponent = obj.GetComponent <TurretComponent>();

            if (parent != null)
            {
                obj.transform.SetParent(parent.transform);
                var position = (Vector2)assembler.Assemble(model.GetObject("LocalPosition"), typeof(Vector2), context);

                obj.transform.localPosition = (Vector3)position + Vector3.back * 0.1f;

                if (model.HasProperty("Angle"))
                {
                    obj.transform.localRotation = Quaternion.Euler(0f, 0f, model.GetValue <float>("Angle"));
                }
                if (model.HasProperty("Flipped"))
                {
                    if (model.GetValue <bool>("Flipped"))
                    {
                        newComponent.Flip();
                    }
                }

                TurretComponent parentComponent = parent.GetComponent <TurretComponent>();
                foreach (var point in newComponent.AttachmentPoints)
                {
                    AttachmentSlot slot = FindSlotForPoint(parentComponent.AttachmentSlots.GetSupportingPoints(point), point, obj.transform, parent.transform);
                    if (slot != null)
                    {
                        slot.Attach(newComponent);
                    }
                }
            }
            else
            {
                obj.transform.SetParent(assembly.transform);
                obj.transform.localPosition = Vector3.zero;
            }

            foreach (ValueModel child in model.GetArray("Children"))
            {
                Assemble(child as ObjectModel, newComponent.transform, assembly, context);
            }

            return(newComponent);
        }
        public override void Assemble(ObjectModel model, LineRenderer target, AssemblyContext context)
        {
            ValueAssembler    assembler      = new ValueAssembler();
            RendererAssembler baseSerializer = new RendererAssembler();

            target.positionCount = model.GetValue <int>("PositionCount");
            SetPositions(target, model.GetArray("Positions").Select(x => (Vector3)assembler.Assemble(x, typeof(Vector3), context)).ToArray());
            target.widthCurve    = (AnimationCurve)assembler.Assemble(model.GetProperty("Curve"), typeof(AnimationCurve), context);
            target.colorGradient = (Gradient)assembler.Assemble(model.GetProperty("Colors"), typeof(Gradient), context);

            target.numCornerVertices    = model.GetValue <int>("CornerVerticies");
            target.numCapVertices       = model.GetValue <int>("CapVerticies");
            target.alignment            = model.GetValue <LineAlignment>("Alignment");
            target.textureMode          = model.GetValue <LineTextureMode>("TextureMode");
            target.shadowBias           = model.GetValue <float>("ShadowBias");
            target.generateLightingData = model.GetValue <bool>("GenerateLighingData");
            target.useWorldSpace        = model.GetValue <bool>("UseWorldSpace");

            baseSerializer.Assemble(model, target, context);
        }