示例#1
0
        /// <summary>
        /// Creates the object of the template (To get the prefab version use .ToPrefab() after calling this)
        /// </summary>
        public override FashionAttachTemplate Create()
        {
            // Create model
            GameObjectTemplate model = new GameObjectTemplate("model_fp").SetTransform(modelTrans);

            int num = 1;

            foreach (LayerInfo layer in layers)
            {
                model.AddChild(new GameObjectTemplate("layer" + num,
                                                      new Create <MeshFilter>((filter) => filter.sharedMesh        = layer.mesh),
                                                      new Create <MeshRenderer>((render) => render.sharedMaterials = layer.materials)
                                                      ));
            }

            mainObject.AddChild(model);

            return(this);
        }
示例#2
0
        /// <summary>
        /// Creates the object of the template (To get the prefab version use .ToPrefab() after calling this)
        /// </summary>
        public override FruitPlantableTemplate Create()
        {
            // Create main object
            mainObject.AddComponents(
                new Create <SpawnResource>((spawn) =>
            {
                spawn.BonusChance = bonusChance;
                spawn.forceDestroyLeftoversOnSpawn = false;
                spawn.id = resID;
                spawn.MaxActiveSpawns           = 0;
                spawn.MaxObjectsSpawned         = maxSpawn;
                spawn.MaxSpawnIntervalGameHours = maxHours;
                spawn.MaxTotalSpawns            = 0;
                spawn.minBonusSelections        = minBonusSelection;
                spawn.MinNutrientObjectsSpawned = minNutrient;
                spawn.MinObjectsSpawned         = minSpawn;
                spawn.MinSpawnIntervalGameHours = minHours;
                spawn.wateringDurationHours     = waterHours;
                spawn.ObjectsToSpawn            = toSpawn.ToArray();
                spawn.BonusObjectsToSpawn       = bonusToSpawn.ToArray();
            }),
                new Create <BoxCollider>((col) =>
            {
                col.size      = new Vector3(8, 0.1f, 8);
                col.center    = new Vector3(0, 0, 0.1f);
                col.isTrigger = true;
            })
                ).AddAfterChildren(GrabJoints).AddAfterChildren(SetNetworkNodes);

            if (!isDeluxe)
            {
                mainObject.AddComponents(
                    new Create <ScaleMarker>((scale) => scale.doNotScaleAsReplacement = false)
                    );
            }

            // Add network nodes
            GameObjectTemplate[] droneNetworkNodes = new GameObjectTemplate[4];

            for (int i = 0; i < 4; i++)
            {
                droneNetworkNodes[i] = new GameObjectTemplate($"DroneNetworkNode{(i + 1).ToString("00")}",
                                                              new Create <PathingNetworkNode>(null)
                                                              ).AddChild(new GameObjectTemplate("NodeLoc").SetTransform(new Vector3(0, 2, 0), Vector3.zero, Vector3.one).SetDebugMarker(MarkerType.DroneNode))
                                       .AddAfterChildren((obj) => obj.GetComponent <PathingNetworkNode>().nodeLoc = obj.transform.GetChild(0))
                                       .SetTransform(GardenObjects.droneNodes[i]);
            }

            mainObject.AddChild(new GameObjectTemplate("DroneSubnetwork", new Create <GardenDroneSubnetwork>(null))
                                .AddChild(droneNetworkNodes[0])
                                .AddChild(droneNetworkNodes[1])
                                .AddChild(droneNetworkNodes[2])
                                .AddChild(droneNetworkNodes[3])
                                );

            // Add tree
            GameObjectTemplate treeObj = new GameObjectTemplate("tree_bark",
                                                                new Create <MeshFilter>((filter) => filter.sharedMesh        = tree ?? GardenObjects.modelTreeMeshs[treeID] ?? GardenObjects.modelTreeMeshs[SpawnResource.Id.POGO_TREE]),
                                                                new Create <MeshRenderer>((render) => render.sharedMaterials = treeMaterials ?? GardenObjects.modelTreeMaterials[treeID] ?? GardenObjects.modelTreeMaterials[SpawnResource.Id.POGO_TREE]),
                                                                new Create <MeshCollider>((col) =>
            {
                col.sharedMesh = treeCol ?? GardenObjects.modelTreeCols[treeID] ?? GardenObjects.modelTreeCols[SpawnResource.Id.POGO_TREE];
                col.convex     = treeCol == tree;
            })
                                                                ).SetTransform(Vector3.zero, Vector3.zero, customTreeScale ? treeScale : Vector3.one * 0.7f);

            GameObjectTemplate leavesObj = new GameObjectTemplate("leaves_tree",
                                                                  new Create <MeshFilter>((filter) => filter.sharedMesh        = leaves ?? GardenObjects.modelLeavesMeshs[leavesID] ?? GardenObjects.modelLeavesMeshs[SpawnResource.Id.POGO_TREE]),
                                                                  new Create <MeshRenderer>((render) => render.sharedMaterials = leavesMaterials ?? GardenObjects.modelLeavesMaterials[leavesID] ?? GardenObjects.modelLeavesMaterials[SpawnResource.Id.POGO_TREE]),
                                                                  new Create <MeshCollider>((col) =>
            {
                col.sharedMesh = leavesCol ?? GardenObjects.modelLeavesCols[leavesID] ?? GardenObjects.modelLeavesCols[SpawnResource.Id.POGO_TREE];
                col.convex     = leavesCol == leaves;
            })
                                                                  ).SetTransform(leavesPosition, Vector3.zero, customLeavesScale ? leavesScale : Vector3.one);

            if (!isDeluxe)
            {
                mainObject.AddChild(treeObj.AddChild(leavesObj));
            }
            else
            {
                mainObject.AddChild(treeObj.AddComponents(
                                        new Create <ScaleMarker>((scale) => scale.doNotScaleAsReplacement = false)
                                        ).AddChild(leavesObj));
            }

            // Add spawn joints
            for (int i = 0; i < 20; i++)
            {
                mainObject.AddChild(new GameObjectTemplate($"SpawnJoint{(i + 1).ToString("00")}",
                                                           new Create <MeshFilter>((filter) => filter.sharedMesh        = GardenObjects.modelMeshs.ContainsKey(ID) ? GardenObjects.modelMeshs[ID] : modelMesh),
                                                           new Create <MeshRenderer>((render) => render.sharedMaterials = GardenObjects.modelMaterials.ContainsKey(ID) ? GardenObjects.modelMaterials[ID] : modelMaterials),
                                                           new Create <Rigidbody>((body) =>
                {
                    body.drag        = 0;
                    body.angularDrag = 0.05f;
                    body.mass        = 1;
                    body.useGravity  = false;
                    body.isKinematic = true;
                }),
                                                           new Create <FixedJoint>(null),
                                                           new Create <HideOnStart>(null)
                                                           ).SetTransform(customSpawnJoints == null ? GardenObjects.treeSpawnJoints[leavesID][i] : customSpawnJoints[i])
                                    .SetDebugMarker(MarkerType.SpawnPoint)
                                    );
            }

            // Add Deluxe Stuff
            if (isDeluxe)
            {
                // Add spawn joints
                for (int i = 20; i < 34; i++)
                {
                    mainObject.AddChild(new GameObjectTemplate($"SpawnJoint{(i + 1).ToString("00")}",
                                                               new Create <MeshFilter>((filter) => filter.sharedMesh        = GardenObjects.modelMeshs.ContainsKey(ID) ? GardenObjects.modelMeshs[ID] : modelMesh),
                                                               new Create <MeshRenderer>((render) => render.sharedMaterials = GardenObjects.modelMaterials.ContainsKey(ID) ? GardenObjects.modelMaterials[ID] : modelMaterials),
                                                               new Create <Rigidbody>((body) =>
                    {
                        body.drag        = 0;
                        body.angularDrag = 0.05f;
                        body.mass        = 1;
                        body.useGravity  = false;
                        body.isKinematic = true;
                    }),
                                                               new Create <FixedJoint>(null),
                                                               new Create <HideOnStart>(null)
                                                               ).SetTransform(customSpawnJoints == null ? GardenObjects.treeSpawnJoints[leavesID][i] : customSpawnJoints[i])
                                        .SetDebugMarker(MarkerType.SpawnPoint)
                                        );
                }

                // Add trees
                mainObject.AddChild(treeObj.Clone().AddComponents(
                                        new Create <ScaleMarker>((scale) => scale.doNotScaleAsReplacement = false)
                                        ).SetTransform(new Vector3(3.8f, 0.8f, -3.8f), new Vector3(0, 225, 0), customTreeScale ? treeDeluxeScale : new Vector3(0.4f, 0.5f, 0.4f))
                                    .AddChild(leavesObj.Clone().SetTransform(leavesDeluxePosition, Vector3.zero, customLeavesScale ? leavesDeluxeScale : new Vector3(1.3f, 0.9f, 1.3f))));

                mainObject.AddChild(treeObj.Clone().AddComponents(
                                        new Create <ScaleMarker>((scale) => scale.doNotScaleAsReplacement = false)
                                        ).SetTransform(new Vector3(-3.8f, 0.8f, 3.8f), new Vector3(0, 45, 0), customTreeScale ? treeDeluxeScale : new Vector3(0.4f, 0.5f, 0.4f))
                                    .AddChild(leavesObj.Clone().SetTransform(leavesDeluxePosition, Vector3.zero, customLeavesScale ? leavesDeluxeScale : new Vector3(1.3f, 0.9f, 1.3f))));
            }

            return(this);
        }