コード例 #1
0
        public TurretAssembly Assemble(RootModel model)
        {
            GameObject     assemblyObject = UnityEngine.Object.Instantiate(Resources.Load <GameObject>(ASSEMBLY_PREFAB_PATH));
            TurretAssembly assembly       = assemblyObject.GetComponent <TurretAssembly>();
            ObjectModel    obj            = model.Root as ObjectModel;

            assembly.Name        = obj.GetValue <string>("Name");
            assembly.Description = obj.GetValue <string>("Description");
            ObjectModel tiers    = obj.GetObject("Tiers");
            UpgradeMap  upgrades = _valueAssembler.Assemble(obj.GetObject("UpgradeMap"), typeof(UpgradeMap), new AssemblyContext()) as UpgradeMap;

            foreach (var tierProperty in tiers.GetProperties())
            {
                Transform tierObj = AssembleTier(tierProperty.Model as ObjectModel, assembly).transform;
                Tier      tier    = Tier.Parse(tierProperty.Name);

                tierObj.gameObject.SetActive(false);
                tierObj.gameObject.name = tier.ToString();

                assembly.AddTier(tierObj, tier);
            }

            assembly.UpgradeMap = upgrades;
            assembly.SetTier(Tier.Initial);
            return(assembly);
        }
コード例 #2
0
        public override void Assemble(ObjectModel model, TrailRenderer target, AssemblyContext context)
        {
            ValueAssembler    assembler     = new ValueAssembler();
            RendererAssembler baseAssembler = new RendererAssembler();

            target.widthCurve           = (AnimationCurve)assembler.Assemble(model.GetProperty("Curve"), typeof(AnimationCurve), context);
            target.time                 = model.GetValue <float>("Time");
            target.minVertexDistance    = model.GetValue <float>("MinVertexDistance");
            target.autodestruct         = model.GetValue <bool>("Autodestruct");
            target.emitting             = model.GetValue <bool>("Emitting");
            target.colorGradient        = (Gradient)assembler.Assemble(model.GetProperty("Color"), typeof(Gradient), context);
            target.numCornerVertices    = model.GetValue <int>("CornerVertices");
            target.numCapVertices       = model.GetValue <int>("CapVertices");
            target.alignment            = model.GetValue <LineAlignment>("Alignment");
            target.textureMode          = model.GetValue <LineTextureMode>("TextureMode");
            target.generateLightingData = model.GetValue <bool>("GenerateLigtingData");
            target.shadowBias           = model.GetValue <float>("ShadowBias");

            baseAssembler.Assemble(model, target, context);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }