Esempio n. 1
0
        /// <summary>
        /// Creates the object of the template (To get the prefab version use .ToPrefab() after calling this)
        /// </summary>
        public override SlimeTemplate Create()
        {
            // Builds the slime required stuff
            if (!isGordo)
            {
                BuildModule();
            }
            RegisterDefinition();

            // Create conditional components
            Create <SlimeFeral> slimeFeral = new Create <SlimeFeral>((feral) =>
            {
                feral.auraPrefab         = EffectObjects.fxFeralAura;
                feral.dynamicToFeral     = false;
                feral.dynamicFromFeral   = true;
                feral.feralLifetimeHours = 3;
            });

            // Create main object
            mainObject.AddComponents(
                new Create <SlimeAppearanceApplicator>((app) =>
            {
                app.SlimeDefinition = definition;
                app.SlimeExpression = SlimeFace.SlimeExpression.Happy;
            }),
                new Create <Identifiable>((ident) => ident.id     = ID),
                new Create <RegionMember>((rg) => rg.canHibernate = true),
                new Create <SlimeVarietyModules>((modules) =>
            {
                modules.baseModule   = definition.BaseModule;
                modules.slimeModules = slimeModule?.Group() ?? definition.SlimeModules;
            }),
                new Create <SlimeEat>((eat) =>
            {
                eat.slimeDefinition    = definition;
                eat.damagePerAttack    = 20;
                eat.EatFX              = EffectObjects.fxSlimeEat;
                eat.EatFavoriteFX      = EffectObjects.fxSlimeFavEat;
                eat.ProduceFX          = EffectObjects.fxSlimeProduce;
                eat.TransformFX        = EffectObjects.fxSlimeTrans;
                eat.minDriveToEat      = driveToEat;
                eat.drivePerEat        = drivePerEat;
                eat.agitationPerEat    = agitPerEat;
                eat.agitationPerFavEat = agitPerFavEat;
            }),
                new Create <ReactToToyNearby>((react) => react.slimeDefinition = definition),
                new Create <SphereCollider>((col) =>
            {
                col.center         = Vector3.zero;
                col.radius         = 0.5f;
                col.sharedMaterial = BaseObjects.originPhysMaterial["Slime"];
            }),
                new Create <Rigidbody>((body) =>
            {
                body.drag        = 0.2f;
                body.angularDrag = 5f;
                body.mass        = 0.5f;
                body.useGravity  = true;
            }),
                new Create <Vacuumable>((vac) => vac.size = vacSize),
                new Create <GotoConsumable>((goT) =>
            {
                goT.maxJump            = 10;
                goT.attemptTime        = 10;
                goT.giveUpTime         = 10;
                goT.minSearchRad       = 5;
                goT.maxSearchRad       = 30;
                goT.facingStability    = 1;
                goT.facingSpeed        = 5;
                goT.pursuitSpeedFactor = 1;
                goT.minDist            = 0;
            }),
                new Create <SlimeRandomMove>((move) =>
            {
                move.verticalFactor   = 1;
                move.scootSpeedFactor = 1;
            }),
                new Create <SlimeHealth>((health) => health.maxHealth = maxHealth),
                new Create <SlimeEmotions>((emo) =>
            {
                emo.initHunger    = hungerState;
                emo.initAgitation = agitationState;
                emo.initFear      = fearState;
            }),
                new Create <SlimeSubbehaviourPlexer>(null),
                new Create <KeepUpright>((keep) =>
            {
                keep.stability = 0.7f;
                keep.speed     = 4f;
            }),
                new Create <FleeThreats>((flee) =>
            {
                flee.fearProfile     = fearProfile;
                flee.driver          = SlimeEmotions.Emotion.FEAR;
                flee.maxJump         = 4;
                flee.facingStability = 0.2f;
                flee.facingSpeed     = 1;
            }),
                new Create <SlimeAudio>((audio) => audio.slimeSounds = definition.Sounds),
                new Create <SECTR_PointSource>(null),
                canBeFeral ? slimeFeral : null,
                new Create <EscapeStuck>(null),
                new Create <MaybeCullOnReenable>(null),
                new Create <DragFloatReactor>((drag) => drag.floatDragMultiplier = 25f),
                new Create <SplatOnImpact>((splat) =>
            {
                splat.splatPrefab   = BaseObjects.splatQuad;
                splat.splatFXPrefab = EffectObjects.fxSplat;
            }),
                new Create <AweTowardsLargos>((awe) =>
            {
                awe.minSearchRad       = 5;
                awe.maxSearchRad       = 15;
                awe.facingStability    = 1;
                awe.facingSpeed        = 5;
                awe.pursuitSpeedFactor = 1;
                awe.minDist            = 0;
            }),
                new Create <SlimeFaceAnimator>(null),
                new Create <CalmedByWaterSpray>((spray) =>
            {
                spray.agitationReduction = 0.1f;
                spray.calmedHours        = 0.3333f;
            }),
                new Create <TotemLinkerHelper>(null),
                new Create <CollisionAggregator>(null),
                new Create <AweTowardsAttractors>((awe) =>
            {
                awe.facingSpeed     = 2.5f;
                awe.facingStability = 1;
            }),
                new Create <AttachFashions>((fash) => fash.gordoMode = false),
                new Create <SlimeEyeComponents>(null),
                new Create <SlimeMouthComponents>(null),
                new Create <PlayWithToys>((play) =>
            {
                play.slimeDefinition    = definition;
                play.onlyFloatingToys   = false;
                play.minSearchRad       = 5;
                play.maxSearchRad       = 15;
                play.facingSpeed        = 5;
                play.facingStability    = 1;
                play.pursuitSpeedFactor = 1;
                play.minDist            = 0;
            }),
                new Create <SlimeIgniteReact>((react) => react.igniteFX = EffectObjects.fxStars),
                canBeAGlitch ? new Create <GlitchSlime>(null) : null,
                new Create <Chomper>((chop) => chop.timePerAttack = 3)
                );

            mainObject
            .AddComponents(extras.ToArray())
            .AddAfterChildren(SetValuesAfterBuild)
            .SetTransform(Vector3.zero, Vector3.zero, Vector3.one * (isGordo ? 4 : definition.PrefabScale))
            .AddAwakeAction("buildSlime")
            .AddStartAction("populateSlime")
            .AddStartAction("fixSlime." + mainObject.Name);

            TemplateActions.RegisterAction("fixSlime." + mainObject.Name, ApplyTrueForm);

            // Create eat trigger
            mainObject.AddChild(new GameObjectTemplate("EatTrigger",
                                                       new Create <SphereCollider>((col) =>
            {
                col.center    = Vector3.zero;
                col.radius    = 0.45f;
                col.isTrigger = true;
            }),
                                                       new Create <SlimeEatTrigger>(null)
                                                       ));

            // Create totem linker
            mainObject.AddChild(new GameObjectTemplate("TotemLinker",
                                                       new Create <SphereCollider>((col) =>
            {
                col.center    = Vector3.zero;
                col.radius    = 0.1f;
                col.isTrigger = true;
            }),
                                                       new Create <TotemLinker>((totem) =>
            {
                totem.receptivenessProb       = 0.25f;
                totem.rethinkReceptivenessMin = 6;
                totem.rethinkReceptivenessMax = 12;
                totem.gravFactorWhileTotemed  = 0.5f;
            })
                                                       ));

            // Create delaunch
            mainObject.AddChild(new GameObjectTemplate("DelaunchTrigger",
                                                       new Create <SphereCollider>((col) =>
            {
                col.center    = Vector3.zero;
                col.radius    = 0.1f;
                col.isTrigger = true;
            }),
                                                       new Create <VacDelaunchTrigger>(null)
                                                       ).SetTransform(Vector3.zero, Vector3.zero, delaunchScale));

            mainObject.Layer = BaseObjects.layers["Actor"];

            return(this);
        }
Esempio n. 2
0
        // Populates required values
        internal static void Populate()
        {
            // Gets unity stuff
            for (int i = 0; i < 32; i++)
            {
                string name = LayerMask.LayerToName(i);
                if (!name.Equals(string.Empty) && !layers.ContainsKey(name))
                {
                    layers.Add(name, i);
                }
            }

            // Obtains objects loaded into the game that might be useful
            foreach (Mesh mesh in Resources.FindObjectsOfTypeAll <Mesh>())
            {
                if (!mesh.name.Equals(string.Empty) && !originMesh.ContainsKey(mesh.name.Replace("(Instance)", "")))
                {
                    originMesh.Add(mesh.name.Replace("(Instance)", ""), mesh);
                }
            }

            foreach (Material mat in Resources.FindObjectsOfTypeAll <Material>())
            {
                if (!mat.name.Equals(string.Empty) && !originMaterial.ContainsKey(mat.name.Replace("(Instance)", "")) &&
                    !mat.name.StartsWith("Hidden/") && !materialBlacklist.Contains(mat.name.Replace("(Instance)", "")))
                {
                    originMaterial.Add(mat.name.Replace("(Instance)", ""), mat);
                }
            }

            foreach (PhysicMaterial mat in Resources.FindObjectsOfTypeAll <PhysicMaterial>())
            {
                if (!mat.name.Equals(string.Empty) && !originPhysMaterial.ContainsKey(mat.name.Replace("(Instance)", "")))
                {
                    originPhysMaterial.Add(mat.name.Replace("(Instance)", ""), mat);
                }
            }

            foreach (Texture tex in Resources.FindObjectsOfTypeAll <Texture>())
            {
                if (!tex.name.Equals(string.Empty) && !originTexture.ContainsKey(tex.name.Replace("(Instance)", "")))
                {
                    originTexture.Add(tex.name.Replace("(Instance)", ""), tex);
                }
            }

            foreach (Sprite sprite in Resources.FindObjectsOfTypeAll <Sprite>())
            {
                if (!sprite.name.Equals(string.Empty) && !originSprite.ContainsKey(sprite.name.Replace("(Instance)", "")))
                {
                    originSprite.Add(sprite.name.Replace("(Instance)", ""), sprite);
                }
            }

            foreach (AudioClip clip in Resources.FindObjectsOfTypeAll <AudioClip>())
            {
                if (!clip.name.Equals(string.Empty) && !originClips.ContainsKey(clip.name.Replace("(Instance)", "")))
                {
                    originClips.Add(clip.name.Replace("(Instance)", ""), clip);
                }
            }

            foreach (SECTR_AudioCue cue in Resources.FindObjectsOfTypeAll <SECTR_AudioCue>())
            {
                if (!cue.name.Equals(string.Empty) && !originCues.ContainsKey(cue.name.Replace("(Instance)", "")))
                {
                    originCues.Add(cue.name.Replace("(Instance)", ""), cue);
                }
            }

            foreach (SlimeSounds sound in Resources.FindObjectsOfTypeAll <SlimeSounds>())
            {
                if (!sound.name.Equals(string.Empty) && !originSounds.ContainsKey(sound.name.Replace("(Instance)", "")))
                {
                    originSounds.Add(sound.name.Replace("(Instance)", ""), sound);
                }
            }

            foreach (RuntimeAnimatorController animator in Resources.FindObjectsOfTypeAll <RuntimeAnimatorController>())
            {
                if (!animator.name.Equals(string.Empty) && !originAnimators.ContainsKey(animator.name.Replace("(Instance)", "")))
                {
                    originAnimators.Add(animator.name.Replace("(Instance)", ""), animator);
                }
            }

            foreach (Avatar avatar in Resources.FindObjectsOfTypeAll <Avatar>())
            {
                if (!avatar.name.Equals(string.Empty) && !originAvatars.ContainsKey(avatar.name.Replace("(Instance)", "")))
                {
                    originAvatars.Add(avatar.name.Replace("(Instance)", ""), avatar);
                }
            }

            foreach (GameObject obj in Resources.FindObjectsOfTypeAll <GameObject>())
            {
                if (!(obj.name.StartsWith("FX ") || obj.name.StartsWith("fx")))
                {
                    continue;
                }

                if (!obj.name.Equals(string.Empty) && !originFXs.ContainsKey(obj.name.Replace("(Instance)", "")))
                {
                    originFXs.Add(obj.name.Replace("(Instance)", ""), obj);
                }
            }

            // Load Bones
            originSkinnedMesh.Add("HenSkinned", Director.GetPrefab(Identifiable.Id.HEN).GetChildCopy("Hen Hen/mesh_body1"));
            originBones.Add("HenBones", Director.GetPrefab(Identifiable.Id.HEN).GetChildCopy("Hen Hen/root"));

            originBones.Add("SlimeBones", Director.GetPrefab(Identifiable.Id.PINK_SLIME).GetChildCopy("Appearance"));
            originBones.Add("GordoBones", Director.GetGordo(Identifiable.Id.PINK_GORDO).GetChildCopy("Vibrating"));

            // Gets the cube for the markers
            cubeMesh = originMesh["Cube"];

            debugSystem = new GameObject("DebugSystem", typeof(DebugSystem));
            Object.DontDestroyOnLoad(debugSystem);

            // Adds markers to objects
            foreach (GameObject obj in Director.plotPrefabs)
            {
                obj.GetReadyForMarker(MarkerType.Plot, 8f);
            }

            foreach (GameObject obj in Director.resourceSpawnerPrefabs)
            {
                foreach (GameObject child in obj.FindChildrenWithPartialName("SpawnJoint"))
                {
                    child.GetReadyForMarker(MarkerType.SpawnPoint);
                }

                foreach (GameObject child in obj.FindChildrenWithPartialName("NodeLoc"))
                {
                    child.GetReadyForMarker(MarkerType.DroneNode, 3f);
                }
            }

            // Single Objects
            splatQuad = Director.GetPrefab(Identifiable.Id.PINK_SLIME).GetComponent <SplatOnImpact>().splatPrefab;

            // Register Global Template Actions
            TemplateActions.RegisterAction("buildSlime", AssembleModules);
            TemplateActions.RegisterAction("populateSlime", PopulateSlimeInfo);

            // Populates all other object classes
            GardenObjects.Populate();
            TheWildsObjects.Populate();
            RanchObjects.Populate();
            EffectObjects.Populate();

            // Adds Late Populate method
            SceneManager.sceneLoaded += LatePopulate;
        }