コード例 #1
0
        public override void Assemble(ObjectModel model, BoxCollider2D target, AssemblyContext context)
        {
            Vector2Assembler assembler = new Vector2Assembler();

            target.offset = assembler.AssembleValue(model.GetObject("Offset"), context);
            target.size   = assembler.AssembleValue(model.GetObject("Size"), context);
        }
コード例 #2
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);
        }
コード例 #3
0
        public override void Assemble(ObjectModel model, Transform target, AssemblyContext context)
        {
            Vector3Assembler assembler = new Vector3Assembler();

            Vector3 position = assembler.AssembleValue(model.GetObject("Position"), context);
            Vector3 rotation = assembler.AssembleValue(model.GetObject("Rotation"), context);
            Vector3 scale    = assembler.AssembleValue(model.GetObject("Scale"), context);

            target.localPosition = position;
            target.localRotation = Quaternion.Euler(rotation);
            target.localScale    = scale;
        }
コード例 #4
0
        public override void Assemble(ObjectModel model, CircleCollider2D target, AssemblyContext context)
        {
            Vector2Assembler vs = new Vector2Assembler();

            target.radius         = model.GetValue <float>("Radius");
            target.offset         = vs.AssembleValue(model.GetObject("Offset"), context);
            target.isTrigger      = model.GetValue <bool>("IsTrigger");
            target.usedByEffector = model.GetValue <bool>("UsedByEffector");
        }
コード例 #5
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);
        }