public static SkinDef CreateSkinDef(string skinName, Sprite skinIcon, CharacterModel.RendererInfo[] rendererInfos, SkinnedMeshRenderer mainRenderer, GameObject root, string unlockName, Mesh skinMesh)
        {
            LoadoutAPI.SkinDefInfo skinDefInfo = new LoadoutAPI.SkinDefInfo
            {
                BaseSkins             = Array.Empty <SkinDef>(),
                GameObjectActivations = new SkinDef.GameObjectActivation[0],
                Icon             = skinIcon,
                MeshReplacements = new SkinDef.MeshReplacement[]
                {
                    new SkinDef.MeshReplacement
                    {
                        renderer = mainRenderer,
                        mesh     = skinMesh
                    }
                },
                MinionSkinReplacements = new SkinDef.MinionSkinReplacement[0],
                Name      = skinName,
                NameToken = skinName,
                ProjectileGhostReplacements = new SkinDef.ProjectileGhostReplacement[0],
                RendererInfos  = rendererInfos,
                RootObject     = root,
                UnlockableName = unlockName
            };

            SkinDef skin = LoadoutAPI.CreateNewSkinDef(skinDefInfo);

            return(skin);
        }
        private ModelSkinController AddDefaultSkin(GameObject def)
        {
            base.Logger.LogInfo("Adding default skin to " + def);

            ModelSkinController component = def.GetComponentInChildren <ModelLocator>().modelTransform.gameObject.AddComponent <ModelSkinController>();
            CharacterModel      model     = def.GetComponentInChildren <ModelLocator>().modelTransform.GetComponentInChildren <CharacterModel>();

            LoadoutAPI.SkinDefInfo skinDefInfo = default(LoadoutAPI.SkinDefInfo);
            skinDefInfo.BaseSkins             = new SkinDef[0];
            skinDefInfo.Icon                  = LoadoutAPI.CreateSkinIcon(Color.black, Color.white, Color.black, Color.white);
            skinDefInfo.NameToken             = "Default";
            skinDefInfo.UnlockableName        = "";
            skinDefInfo.RootObject            = def.GetComponentInChildren <ModelLocator>().modelTransform.gameObject;
            skinDefInfo.RendererInfos         = model.baseRendererInfos;
            skinDefInfo.MeshReplacements      = new SkinDef.MeshReplacement[0];
            skinDefInfo.GameObjectActivations = new SkinDef.GameObjectActivation[1] {
                new SkinDef.GameObjectActivation()
                {
                    gameObject = def, shouldActivate = true
                }
            };
            skinDefInfo.Name = "DEFAULT_" + def.name + "_SKIN";

            if (model)
            {
                skinDefInfo.RendererInfos = model.baseRendererInfos;

                for (int i = 0; i < skinDefInfo.RendererInfos.Length; i++)
                {
                    skinDefInfo.RendererInfos[i].defaultMaterial.enableInstancing         = true;
                    skinDefInfo.RendererInfos[i].renderer.material.enableInstancing       = true;
                    skinDefInfo.RendererInfos[i].renderer.sharedMaterial.enableInstancing = true;
                }

                SkinDef skinDef3 = LoadoutAPI.CreateNewSkinDef(skinDefInfo);
                component.skins = new SkinDef[1] {
                    skinDef3
                };

                LoadoutAPI.AddSkinToCharacter(def, skinDef3);

                SkinDef[] skins = component.skins;

                SkinDef[][] newSkins = typeof(BodyCatalog).GetFieldValue <SkinDef[][]>("skins");
                newSkins[BodyCatalog.FindBodyIndex(def)] = skins;
                typeof(BodyCatalog).SetFieldValue <SkinDef[][]>("skins", newSkins);
            }
            else
            {
                base.Logger.LogError("Unable to create new skin for " + def);
            }

            return(component);
        }
Beispiel #3
0
        public static void RegisterSkins()
        {
            GameObject bodyPrefab = GrovetenderPlugin.myCharacter;

            GameObject     model          = bodyPrefab.GetComponentInChildren <ModelLocator>().modelTransform.gameObject;
            CharacterModel characterModel = model.GetComponent <CharacterModel>();

            if (model.GetComponent <ModelSkinController>())
            {
                GrovetenderPlugin.Destroy(model.GetComponent <ModelSkinController>());
            }

            ModelSkinController skinController = model.AddComponent <ModelSkinController>();
            ChildLocator        childLocator   = model.GetComponent <ChildLocator>();

            SkinnedMeshRenderer mainRenderer = Reflection.GetFieldValue <SkinnedMeshRenderer>(characterModel, "mainSkinnedMeshRenderer");

            LanguageAPI.Add("GROVETENDERBODY_DEFAULT_SKIN_NAME", "Default");

            LoadoutAPI.SkinDefInfo skinDefInfo = default(LoadoutAPI.SkinDefInfo);
            skinDefInfo.BaseSkins = Array.Empty <SkinDef>();
            skinDefInfo.ProjectileGhostReplacements = new SkinDef.ProjectileGhostReplacement[0];
            skinDefInfo.MinionSkinReplacements      = new SkinDef.MinionSkinReplacement[0];

            skinDefInfo.GameObjectActivations = Array.Empty <SkinDef.GameObjectActivation>();

            skinDefInfo.Icon             = LoadoutAPI.CreateSkinIcon(new Color(0.09f, 0.03f, 0.03f), new Color(0.039f, 0.039f, 0.078f), new Color(0.61f, 0.59f, 0.5f), new Color(0.9f, 0.9f, 0.9f));
            skinDefInfo.MeshReplacements = new SkinDef.MeshReplacement[0];

            /*{
             *  new SkinDef.MeshReplacement
             *  {
             *      renderer = mainRenderer,
             *      mesh = mainRenderer.sharedMesh
             *  }
             * };*/
            skinDefInfo.Name           = "GROVETENDERBODY_DEFAULT_SKIN_NAME";
            skinDefInfo.NameToken      = "GROVETENDERBODY_DEFAULT_SKIN_NAME";
            skinDefInfo.RendererInfos  = characterModel.baseRendererInfos;
            skinDefInfo.RootObject     = model;
            skinDefInfo.UnlockableName = "";

            SkinDef defaultSkin = LoadoutAPI.CreateNewSkinDef(skinDefInfo);

            skinController.skins = new SkinDef[1]
            {
                defaultSkin
            };
        }
Beispiel #4
0
        private static void SkinSetup()
        {
            GameObject     model          = survivorPrefab.GetComponentInChildren <ModelLocator>().modelTransform.gameObject;
            CharacterModel characterModel = model.GetComponent <CharacterModel>();

            if (model.GetComponent <ModelSkinController>())
            {
                DiggerPlugin.Destroy(model.GetComponent <ModelSkinController>());
            }

            ModelSkinController skinController = model.AddComponent <ModelSkinController>();
            ChildLocator        childLocator   = model.GetComponent <ChildLocator>();

            SkinnedMeshRenderer mainRenderer = Reflection.GetFieldValue <SkinnedMeshRenderer>(characterModel, "mainSkinnedMeshRenderer");

            LanguageAPI.Add("DIRESEEKER_BODY_DEFAULT_SKIN_NAME", "Default");

            LoadoutAPI.SkinDefInfo skinDefInfo = default(LoadoutAPI.SkinDefInfo);
            skinDefInfo.BaseSkins = Array.Empty <SkinDef>();
            skinDefInfo.ProjectileGhostReplacements = new SkinDef.ProjectileGhostReplacement[0];
            skinDefInfo.MinionSkinReplacements      = new SkinDef.MinionSkinReplacement[0];

            skinDefInfo.GameObjectActivations = Array.Empty <SkinDef.GameObjectActivation>();

            skinDefInfo.Icon             = Assets.mainAssetBundle.LoadAsset <Sprite>("texMoltenAchievement");
            skinDefInfo.MeshReplacements = new SkinDef.MeshReplacement[0];

            /*{
             *  new SkinDef.MeshReplacement
             *  {
             *      renderer = mainRenderer,
             *      mesh = mainRenderer.sharedMesh
             *  }
             * };*/
            skinDefInfo.Name           = "DIRESEEKER_BODY_DEFAULT_SKIN_NAME";
            skinDefInfo.NameToken      = "DIRESEEKER_BODY_DEFAULT_SKIN_NAME";
            skinDefInfo.RendererInfos  = characterModel.baseRendererInfos;
            skinDefInfo.RootObject     = model;
            skinDefInfo.UnlockableName = "";

            SkinDef defaultSkin = LoadoutAPI.CreateNewSkinDef(skinDefInfo);

            skinController.skins = new SkinDef[1]
            {
                defaultSkin
            };
        }
Beispiel #5
0
        public static void RegisterSkins()
        {
            GameObject bodyPrefab = Templar.myCharacter;

            GameObject          model          = bodyPrefab.GetComponentInChildren <ModelLocator>().modelTransform.gameObject;
            CharacterModel      characterModel = model.GetComponent <CharacterModel>();
            ModelSkinController skinController = model.AddComponent <ModelSkinController>();
            ChildLocator        childLocator   = model.GetComponent <ChildLocator>();
            SkinnedMeshRenderer mainRenderer   = Reflection.GetFieldValue <SkinnedMeshRenderer>(characterModel, "mainSkinnedMeshRenderer");

            #region Default Skin
            LanguageAPI.Add("Templar_DEFAULT_SKIN", "Default");
            LoadoutAPI.SkinDefInfo skinDefInfo = default(LoadoutAPI.SkinDefInfo);
            skinDefInfo.BaseSkins = Array.Empty <SkinDef>();
            skinDefInfo.MinionSkinReplacements      = new SkinDef.MinionSkinReplacement[0];
            skinDefInfo.ProjectileGhostReplacements = new SkinDef.ProjectileGhostReplacement[0];
            skinDefInfo.Icon             = LoadoutAPI.CreateSkinIcon(new Color(0.64f, 0.31f, 0.22f), new Color(0.54f, 0.21f, 0.12f), new Color(0.64f, 0.31f, 0.22f), new Color(0.54f, 0.21f, 0.12f));
            skinDefInfo.MeshReplacements = new SkinDef.MeshReplacement[0];
            skinDefInfo.Name             = "Templar_DEFAULT_SKIN";
            skinDefInfo.NameToken        = "Templar_DEFAULT_SKIN";
            skinDefInfo.RendererInfos    = characterModel.baseRendererInfos;
            skinDefInfo.RootObject       = model;
            CharacterModel.RendererInfo[] rendererInfos = skinDefInfo.RendererInfos;
            CharacterModel.RendererInfo[] array         = new CharacterModel.RendererInfo[rendererInfos.Length];
            rendererInfos.CopyTo(array, 0);
            Material material = array[0].defaultMaterial;
            if (material)
            {
                material = UnityEngine.Object.Instantiate <Material>(LegacyResourcesAPI.Load <GameObject>("Prefabs/CharacterBodies/ClayBruiserBody").GetComponentInChildren <CharacterModel>().baseRendererInfos[0].defaultMaterial);
                array[0].defaultMaterial = material;
            }
            skinDefInfo.RendererInfos = array;
            SkinDef defaultSkin = LoadoutAPI.CreateNewSkinDef(skinDefInfo);
            #endregion

            var skinDefs = new List <SkinDef>()
            {
                defaultSkin
            };

            skinController.skins = skinDefs.ToArray();
        }
Beispiel #6
0
        public static void Create()
        {
            body = PrefabAPI.InstantiateClone(Resources.Load <GameObject>("Prefabs/CharacterBodies/CommandoBody"), "UrsaBody", true);
            NetworkIdentity networkIdentity = body.GetComponent <NetworkIdentity>();

            networkIdentity.localPlayerAuthority = true;

            GameObject model = CreateModel(body);

            GameObject gameObject = new GameObject("ModelBase");

            gameObject.transform.parent        = body.transform;
            gameObject.transform.localPosition = new Vector3(0f, -0.81f, 0f);
            gameObject.transform.localRotation = Quaternion.identity;
            gameObject.transform.localScale    = new Vector3(1f, 1f, 1f);

            GameObject gameObject2 = new GameObject("CameraPivot");

            gameObject2.transform.parent        = gameObject.transform;
            gameObject2.transform.localPosition = new Vector3(0f, 1.6f, 0f);
            gameObject2.transform.localRotation = Quaternion.identity;
            gameObject2.transform.localScale    = Vector3.one;

            GameObject gameObject3 = new GameObject("AimOrigin");

            gameObject3.transform.parent        = gameObject.transform;
            gameObject3.transform.localPosition = new Vector3(0f, 1.4f, 0f);
            gameObject3.transform.localRotation = Quaternion.identity;
            gameObject3.transform.localScale    = Vector3.one;

            Transform transform = model.transform;

            transform.parent        = gameObject.transform;
            transform.localPosition = Vector3.zero;
            transform.localScale    = new Vector3(1f, 1f, 1f);
            transform.localRotation = Quaternion.identity;

            CharacterDirection characterDirection = body.GetComponent <CharacterDirection>();

            characterDirection.moveVector      = Vector3.zero;
            characterDirection.targetTransform = gameObject.transform;
            characterDirection.overrideAnimatorForwardTransform = null;
            characterDirection.rootMotionAccumulator            = null;
            characterDirection.modelAnimator         = model.GetComponentInChildren <Animator>();
            characterDirection.driveFromRootRotation = false;
            characterDirection.turnSpeed             = 720f;

            CharacterBody bodyComponent = body.GetComponent <CharacterBody>();

            bodyComponent.bodyIndex             = BodyIndex.None;
            bodyComponent.baseNameToken         = "URSA_NAME";
            bodyComponent.subtitleNameToken     = "URSA_SUBTITLE";
            bodyComponent.bodyFlags             = CharacterBody.BodyFlags.ImmuneToExecutes;
            bodyComponent.rootMotionInMainState = false;
            bodyComponent.mainRootSpeed         = 0;
            bodyComponent.baseMaxHealth         = Core.Config.baseMaxHealth.Value;
            bodyComponent.levelMaxHealth        = Core.Config.levelMaxHealth.Value;
            bodyComponent.baseRegen             = Core.Config.baseRegen.Value;
            bodyComponent.levelRegen            = Core.Config.levelRegen.Value;
            bodyComponent.baseMaxShield         = Core.Config.baseMaxShield.Value;
            bodyComponent.levelMaxShield        = Core.Config.levelMaxShield.Value;
            bodyComponent.baseMoveSpeed         = Core.Config.baseMoveSpeed.Value;
            bodyComponent.levelMoveSpeed        = Core.Config.levelMoveSpeed.Value;
            bodyComponent.baseAcceleration      = Core.Config.baseAcceleration.Value;
            bodyComponent.baseJumpPower         = Core.Config.baseJumpPower.Value;
            bodyComponent.levelJumpPower        = Core.Config.levelJumpPower.Value;
            bodyComponent.baseJumpCount         = Core.Config.baseJumpCount.Value;
            bodyComponent.baseDamage            = Core.Config.baseDamage.Value;
            bodyComponent.levelDamage           = Core.Config.levelDamage.Value;
            bodyComponent.baseAttackSpeed       = Core.Config.baseAttackSpeed.Value;
            bodyComponent.levelAttackSpeed      = Core.Config.levelAttackSpeed.Value;
            bodyComponent.baseCrit   = Core.Config.baseCrit.Value;
            bodyComponent.levelCrit  = Core.Config.levelCrit.Value;
            bodyComponent.baseArmor  = Core.Config.baseArmor.Value;
            bodyComponent.levelArmor = Core.Config.levelArmor.Value;
            bodyComponent.sprintingSpeedMultiplier = Core.Config.sprintingSpeedMultiplier.Value;
            bodyComponent.wasLucky           = false;
            bodyComponent.hideCrosshair      = false;
            bodyComponent.crosshairPrefab    = Resources.Load <GameObject>("prefabs/crosshair/simpledotcrosshair");
            bodyComponent.aimOriginTransform = gameObject3.transform;
            bodyComponent.hullClassification = HullClassification.Human;
            bodyComponent.portraitIcon       = Core.Assets.portrait.texture;
            bodyComponent.isChampion         = false;
            bodyComponent.currentVehicle     = null;
            bodyComponent.skinIndex          = 0U;

            LoadoutAPI.AddSkill(typeof(States.UrsaMain));
            var stateMachine = body.GetComponent <EntityStateMachine>();

            stateMachine.mainStateType = new SerializableEntityStateType(typeof(States.UrsaMain));

            CharacterMotor characterMotor = body.GetComponent <CharacterMotor>();

            characterMotor.walkSpeedPenaltyCoefficient = 1f;
            characterMotor.characterDirection          = characterDirection;
            characterMotor.muteWalkMotion = false;
            characterMotor.mass           = 200f;
            characterMotor.airControl     = 0.25f;
            characterMotor.disableAirControlUntilCollision = false;
            characterMotor.generateParametersOnAwake       = true;
            //characterMotor.useGravity = true;
            //characterMotor.isFlying = false;

            InputBankTest inputBankTest = body.GetComponent <InputBankTest>();

            inputBankTest.moveVector = Vector3.zero;

            CameraTargetParams cameraTargetParams = body.GetComponent <CameraTargetParams>();

            cameraTargetParams.cameraParams         = Resources.Load <GameObject>("Prefabs/CharacterBodies/CommandoBody").GetComponent <CameraTargetParams>().cameraParams;
            cameraTargetParams.cameraPivotTransform = null;
            cameraTargetParams.aimMode             = CameraTargetParams.AimType.Standard;
            cameraTargetParams.recoil              = Vector2.zero;
            cameraTargetParams.idealLocalCameraPos = Vector3.zero;
            cameraTargetParams.dontRaycastToPivot  = false;

            ModelLocator modelLocator = body.GetComponent <ModelLocator>();

            modelLocator.modelTransform           = transform;
            modelLocator.modelBaseTransform       = gameObject.transform;
            modelLocator.dontReleaseModelOnDeath  = false;
            modelLocator.autoUpdateModelTransform = true;
            modelLocator.dontDetatchFromParent    = false;
            modelLocator.noCorpse         = false;
            modelLocator.normalizeToFloor = true;
            modelLocator.preserveModel    = false;

            ChildLocator childLocator = model.GetComponent <ChildLocator>();

            HitBoxGroup rightClawHitBoxGroup = model.AddComponent <HitBoxGroup>();
            HitBoxGroup leftClawHitBoxGroup  = model.AddComponent <HitBoxGroup>();

            GameObject rightClawGameObject = new GameObject("RightClawHitBox");
            Transform  rightClaw           = childLocator.FindChild("R_Hand");

            rightClawGameObject.transform.parent        = rightClaw;
            rightClawGameObject.transform.localPosition = new Vector3(-0.2f, 0.2f, 0.3f);
            rightClawGameObject.transform.localScale    = Vector3.one * 6.25f;
            rightClawGameObject.transform.localRotation = Quaternion.identity;
            HitBox rightClawHitBox = rightClawGameObject.AddComponent <HitBox>();

            GameObject leftClawGameObject = new GameObject("LeftClawHitBox");
            Transform  leftClaw           = childLocator.FindChild("L_Hand");

            leftClawGameObject.transform.parent        = leftClaw;
            leftClawGameObject.transform.localPosition = new Vector3(-0.2f, 0.2f, 0.3f);
            leftClawGameObject.transform.localScale    = Vector3.one * 6.25f;
            leftClawGameObject.transform.localRotation = Quaternion.identity;
            HitBox leftClawHitBox = leftClawGameObject.AddComponent <HitBox>();

            rightClawHitBoxGroup.hitBoxes  = new HitBox[] { rightClawHitBox };
            rightClawHitBoxGroup.groupName = "RightClaw";
            leftClawHitBoxGroup.hitBoxes   = new HitBox[] { leftClawHitBox };
            leftClawHitBoxGroup.groupName  = "LeftClaw";

            Light rightLight = rightClaw.gameObject.AddComponent <Light>();

            rightLight.type      = LightType.Point;
            rightLight.color     = Color.yellow;
            rightLight.range     = 0.85f;
            rightLight.intensity = 95f;
            rightLight.enabled   = false;

            Light leftLight = leftClaw.gameObject.AddComponent <Light>();

            leftLight.type      = LightType.Point;
            leftLight.color     = Color.yellow;
            leftLight.range     = 0.85f;
            leftLight.intensity = 95f;
            leftLight.enabled   = false;

            CharacterModel characterModel = model.AddComponent <CharacterModel>();

            characterModel.body = bodyComponent;
            List <CharacterModel.RendererInfo> rendererInfos = new List <CharacterModel.RendererInfo>();

            foreach (SkinnedMeshRenderer i in model.GetComponentsInChildren <SkinnedMeshRenderer>())
            {
                CharacterModel.RendererInfo info = new CharacterModel.RendererInfo
                {
                    defaultMaterial          = i.material,
                    renderer                 = i,
                    defaultShadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.On,
                    ignoreOverlays           = false
                };
                rendererInfos.Add(info);
            }
            characterModel.baseRendererInfos = rendererInfos.ToArray();

            characterModel.autoPopulateLightInfos = true;
            characterModel.invisibilityCount      = 0;
            characterModel.temporaryOverlays      = new List <TemporaryOverlay>();

            ModelSkinController skinController = model.AddComponent <ModelSkinController>();

            LoadoutAPI.SkinDefInfo skinDefInfo = new LoadoutAPI.SkinDefInfo
            {
                BaseSkins             = Array.Empty <SkinDef>(),
                GameObjectActivations = new SkinDef.GameObjectActivation[0],
                Icon                        = Core.Assets.defaultSkinIcon,
                MeshReplacements            = new SkinDef.MeshReplacement[0],
                MinionSkinReplacements      = new SkinDef.MinionSkinReplacement[0],
                Name                        = "URSA_SKIN_DEFAULT_NAME",
                NameToken                   = "URSA_SKIN_DEFAULT_NAME",
                ProjectileGhostReplacements = new SkinDef.ProjectileGhostReplacement[0],
                RendererInfos               = rendererInfos.ToArray(),
                RootObject                  = model,
            };
            SkinDef skin = LoadoutAPI.CreateNewSkinDef(skinDefInfo);

            skinController.skins = new SkinDef[] { skin };

            TeamComponent teamComponent = null;

            if (body.GetComponent <TeamComponent>() != null)
            {
                teamComponent = body.GetComponent <TeamComponent>();
            }
            else
            {
                teamComponent = body.GetComponent <TeamComponent>();
            }
            teamComponent.hideAllyCardDisplay = false;
            teamComponent.teamIndex           = TeamIndex.None;

            HealthComponent healthComponent = body.GetComponent <HealthComponent>();

            healthComponent.health            = 90f;
            healthComponent.shield            = 0f;
            healthComponent.barrier           = 0f;
            healthComponent.magnetiCharge     = 0f;
            healthComponent.body              = null;
            healthComponent.dontShowHealthbar = false;
            healthComponent.globalDeathEventChanceCoefficient = 1f;

            body.GetComponent <Interactor>().maxInteractionDistance     = 3f;
            body.GetComponent <InteractionDriver>().highlightInteractor = true;

            CharacterDeathBehavior characterDeathBehavior = body.GetComponent <CharacterDeathBehavior>();

            characterDeathBehavior.deathStateMachine = body.GetComponent <EntityStateMachine>();
            characterDeathBehavior.deathState        = new SerializableEntityStateType(typeof(GenericCharacterDeath));

            SfxLocator sfxLocator = body.GetComponent <SfxLocator>();

            sfxLocator.deathSound      = "Play_ui_player_death";
            sfxLocator.barkSound       = "";
            sfxLocator.openSound       = "";
            sfxLocator.landingSound    = "Play_char_land";
            sfxLocator.fallDamageSound = "Play_char_land_fall_damage";
            sfxLocator.aliveLoopStart  = "";
            sfxLocator.aliveLoopStop   = "";

            Rigidbody rigidbody = body.GetComponent <Rigidbody>();

            rigidbody.mass                   = 100f;
            rigidbody.drag                   = 0f;
            rigidbody.angularDrag            = 0f;
            rigidbody.useGravity             = false;
            rigidbody.isKinematic            = true;
            rigidbody.interpolation          = RigidbodyInterpolation.None;
            rigidbody.collisionDetectionMode = CollisionDetectionMode.Discrete;
            rigidbody.constraints            = RigidbodyConstraints.None;

            CapsuleCollider capsuleCollider = body.GetComponent <CapsuleCollider>();

            capsuleCollider.isTrigger = false;
            capsuleCollider.material  = null;
            capsuleCollider.center    = new Vector3(0f, 0f, 0f);
            capsuleCollider.radius    = 0.5f;
            capsuleCollider.height    = 1.82f;
            capsuleCollider.direction = 1;

            KinematicCharacterMotor kinematicCharacterMotor = body.GetComponent <KinematicCharacterMotor>();

            kinematicCharacterMotor.CharacterController = characterMotor;
            kinematicCharacterMotor.Capsule             = capsuleCollider;
            kinematicCharacterMotor.Rigidbody           = rigidbody;

            capsuleCollider.radius   = 0.5f;
            capsuleCollider.height   = 1.82f;
            capsuleCollider.center   = new Vector3(0, 0, 0);
            capsuleCollider.material = null;

            kinematicCharacterMotor.DetectDiscreteCollisions     = false;
            kinematicCharacterMotor.GroundDetectionExtraDistance = 0f;
            kinematicCharacterMotor.MaxStepHeight                     = 0.2f;
            kinematicCharacterMotor.MinRequiredStepDepth              = 0.1f;
            kinematicCharacterMotor.MaxStableSlopeAngle               = 55f;
            kinematicCharacterMotor.MaxStableDistanceFromLedge        = 0.5f;
            kinematicCharacterMotor.PreventSnappingOnLedges           = false;
            kinematicCharacterMotor.MaxStableDenivelationAngle        = 55f;
            kinematicCharacterMotor.RigidbodyInteractionType          = RigidbodyInteractionType.None;
            kinematicCharacterMotor.PreserveAttachedRigidbodyMomentum = true;
            kinematicCharacterMotor.HasPlanarConstraint               = false;
            kinematicCharacterMotor.PlanarConstraintAxis              = Vector3.up;
            kinematicCharacterMotor.StepHandling  = StepHandlingMethod.None;
            kinematicCharacterMotor.LedgeHandling = true;
            kinematicCharacterMotor.InteractiveRigidbodyHandling = true;
            kinematicCharacterMotor.SafeMovement = false;

            HurtBoxGroup hurtBoxGroup = model.AddComponent <HurtBoxGroup>();

            HurtBox componentInChildren = model.GetComponentInChildren <CapsuleCollider>().gameObject.AddComponent <HurtBox>();

            componentInChildren.gameObject.layer = LayerIndex.entityPrecise.intVal;
            componentInChildren.healthComponent  = healthComponent;
            componentInChildren.isBullseye       = true;
            componentInChildren.damageModifier   = HurtBox.DamageModifier.Normal;
            componentInChildren.hurtBoxGroup     = hurtBoxGroup;
            componentInChildren.indexInGroup     = 0;

            hurtBoxGroup.hurtBoxes = new HurtBox[]
            {
                componentInChildren
            };

            hurtBoxGroup.mainHurtBox   = componentInChildren;
            hurtBoxGroup.bullseyeCount = 1;

            FootstepHandler footstepHandler = model.AddComponent <FootstepHandler>();

            footstepHandler.baseFootstepString           = "Play_player_footstep";
            footstepHandler.sprintFootstepOverrideString = "";
            footstepHandler.enableFootstepDust           = true;
            footstepHandler.footstepDustPrefab           = Resources.Load <GameObject>("Prefabs/GenericFootstepDust");

            RagdollController ragdollController = model.AddComponent <RagdollController>();

            ragdollController.bones = null;
            ragdollController.componentsToDisableOnRagdoll = null;

            AimAnimator aimAnimator = model.AddComponent <AimAnimator>();

            aimAnimator.inputBank          = inputBankTest;
            aimAnimator.directionComponent = characterDirection;
            aimAnimator.pitchRangeMax      = 55f;
            aimAnimator.pitchRangeMin      = -50f;
            aimAnimator.yawRangeMin        = -44f;
            aimAnimator.yawRangeMax        = 44f;
            aimAnimator.pitchGiveupRange   = 30f;
            aimAnimator.yawGiveupRange     = 10f;
            aimAnimator.giveupDuration     = 8f;

            // Adds component used for keeping track of individual Ursa's Fury Swipes damage bonus from Enrage.
            body.AddComponent <Miscellaneous.FurySwipesController>();

            // Particle System that only emits when Overpower buff is active.
            ParticleSystem.EmissionModule overpowerParticleSystemEmission = childLocator.FindChild("OverpowerParticles").GetComponent <ParticleSystem>().emission;
            overpowerParticleSystemEmission.enabled = false;

            //Doppelganger
            doppelgangerMaster = PrefabAPI.InstantiateClone(Resources.Load <GameObject>("Prefabs/CharacterMasters/CommandoMonsterMaster"), "UrsaDoppelGanger", true);

            CharacterMaster component = doppelgangerMaster.GetComponent <CharacterMaster>();

            component.bodyPrefab = body;
        }
Beispiel #7
0
        public static void RegisterSkins()
        {
            GameObject bodyPrefab = DiggerPlugin.characterPrefab;

            GameObject     model          = bodyPrefab.GetComponentInChildren <ModelLocator>().modelTransform.gameObject;
            CharacterModel characterModel = model.GetComponent <CharacterModel>();

            ModelSkinController skinController = model.AddComponent <ModelSkinController>();
            ChildLocator        childLocator   = model.GetComponent <ChildLocator>();

            SkinnedMeshRenderer mainRenderer = Reflection.GetFieldValue <SkinnedMeshRenderer>(characterModel, "mainSkinnedMeshRenderer");

            GameObject diamondPickL = childLocator.FindChild("DiamondPickL").gameObject;
            GameObject diamondPickR = childLocator.FindChild("DiamondPickR").gameObject;

            GameObject[] allObjects = new GameObject[]
            {
                diamondPickL,
                diamondPickR
            };

            LanguageAPI.Add("MINERBODY_DEFAULT_SKIN_NAME", "Default");
            LanguageAPI.Add("MINERBODY_MOLTEN_SKIN_NAME", "Molten");
            LanguageAPI.Add("MINERBODY_TYPHOON_SKIN_NAME", "Conqueror");
            LanguageAPI.Add("MINERBODY_PUPLE_SKIN_NAME", "Puple");
            LanguageAPI.Add("MINERBODY_TUNDRA_SKIN_NAME", "Tundra");
            LanguageAPI.Add("MINERBODY_BLACKSMITH_SKIN_NAME", "Blacksmith");
            LanguageAPI.Add("MINERBODY_IRON_SKIN_NAME", "Iron");
            LanguageAPI.Add("MINERBODY_GOLD_SKIN_NAME", "Gold");
            LanguageAPI.Add("MINERBODY_DIAMOND_SKIN_NAME", "Diamond");
            LanguageAPI.Add("MINERBODY_STEVE_SKIN_NAME", "Minecraft");
            LanguageAPI.Add("MINERBODY_DRIP_SKIN_NAME", "Drip");

            LoadoutAPI.SkinDefInfo skinDefInfo = default(LoadoutAPI.SkinDefInfo);
            skinDefInfo.BaseSkins = Array.Empty <SkinDef>();
            skinDefInfo.MinionSkinReplacements      = new SkinDef.MinionSkinReplacement[0];
            skinDefInfo.ProjectileGhostReplacements = new SkinDef.ProjectileGhostReplacement[0];

            skinDefInfo.GameObjectActivations = getActivations(allObjects);

            skinDefInfo.Icon             = Resources.Load <GameObject>("Prefabs/CharacterBodies/CommandoBody").GetComponentInChildren <ModelSkinController>().skins[0].icon;
            skinDefInfo.MeshReplacements = new SkinDef.MeshReplacement[]
            {
                new SkinDef.MeshReplacement
                {
                    renderer = mainRenderer,
                    mesh     = mainRenderer.sharedMesh
                }
            };
            skinDefInfo.Name          = "MINERBODY_DEFAULT_SKIN_NAME";
            skinDefInfo.NameToken     = "MINERBODY_DEFAULT_SKIN_NAME";
            skinDefInfo.RendererInfos = characterModel.baseRendererInfos;
            skinDefInfo.RootObject    = model;

            CharacterModel.RendererInfo[] rendererInfos = skinDefInfo.RendererInfos;
            CharacterModel.RendererInfo[] array         = new CharacterModel.RendererInfo[rendererInfos.Length];
            rendererInfos.CopyTo(array, 0);

            Material commandoMat = Resources.Load <GameObject>("Prefabs/CharacterBodies/CommandoBody").GetComponentInChildren <CharacterModel>().baseRendererInfos[0].defaultMaterial;

            //clone commando material for that spicy hopoo shader
            Material material = array[0].defaultMaterial;

            if (material)
            {
                material = UnityEngine.Object.Instantiate <Material>(commandoMat);
                material.SetColor("_Color", Color.white);
                material.SetTexture("_MainTex", Assets.mainAssetBundle.LoadAsset <Material>("matMiner").GetTexture("_MainTex"));
                material.SetColor("_EmColor", Color.white);
                material.SetFloat("_EmPower", 0f);
                material.SetTexture("_EmTex", Assets.mainAssetBundle.LoadAsset <Material>("matMiner").GetTexture("_EmissionMap"));
                material.SetFloat("_NormalStrength", 0);
                //material.SetTexture("_NormalTex", Assets.mainAssetBundle.LoadAsset<Material>("matMiner").GetTexture("_BumpMap"));

                array[0].defaultMaterial = material;
            }

            //and do the same for the diamond picks
            material = array[1].defaultMaterial;

            if (material)
            {
                material = UnityEngine.Object.Instantiate <Material>(commandoMat);
                material.SetColor("_Color", Color.white);
                material.SetTexture("_MainTex", Assets.mainAssetBundle.LoadAsset <Material>("matDiamondPick").GetTexture("_MainTex"));
                material.SetColor("_EmColor", Color.white);
                material.SetFloat("_EmPower", 0f);
                material.SetFloat("_NormalStrength", 0);

                array[1].defaultMaterial = material;
            }

            material = array[2].defaultMaterial;

            if (material)
            {
                material = UnityEngine.Object.Instantiate <Material>(commandoMat);
                material.SetColor("_Color", Color.white);
                material.SetTexture("_MainTex", Assets.mainAssetBundle.LoadAsset <Material>("matDiamondPick").GetTexture("_MainTex"));
                material.SetColor("_EmColor", Color.white);
                material.SetFloat("_EmPower", 0f);
                material.SetFloat("_NormalStrength", 0);

                array[2].defaultMaterial = material;
            }

            skinDefInfo.RendererInfos = array;

            #region Default
            SkinDef defaultSkin = LoadoutAPI.CreateNewSkinDef(skinDefInfo);
            #endregion

            #region Molten
            LoadoutAPI.SkinDefInfo moltenSkinDefInfo = default(LoadoutAPI.SkinDefInfo);
            moltenSkinDefInfo.BaseSkins = Array.Empty <SkinDef>();
            moltenSkinDefInfo.MinionSkinReplacements      = new SkinDef.MinionSkinReplacement[0];
            moltenSkinDefInfo.ProjectileGhostReplacements = new SkinDef.ProjectileGhostReplacement[0];

            moltenSkinDefInfo.GameObjectActivations = getActivations(allObjects);

            moltenSkinDefInfo.Icon             = Assets.mainAssetBundle.LoadAsset <Sprite>("texMoltenAchievement");
            moltenSkinDefInfo.MeshReplacements = new SkinDef.MeshReplacement[]
            {
                new SkinDef.MeshReplacement
                {
                    renderer = mainRenderer,
                    mesh     = mainRenderer.sharedMesh
                }
            };
            moltenSkinDefInfo.Name          = "MINERBODY_MOLTEN_SKIN_NAME";
            moltenSkinDefInfo.NameToken     = "MINERBODY_MOLTEN_SKIN_NAME";
            moltenSkinDefInfo.RendererInfos = characterModel.baseRendererInfos;
            moltenSkinDefInfo.RootObject    = model;

            rendererInfos = skinDefInfo.RendererInfos;
            array         = new CharacterModel.RendererInfo[rendererInfos.Length];
            rendererInfos.CopyTo(array, 0);

            material = array[0].defaultMaterial;

            if (material)
            {
                material = UnityEngine.Object.Instantiate <Material>(material);
                material.SetTexture("_MainTex", Assets.mainAssetBundle.LoadAsset <Material>("matMinerMolten").GetTexture("_MainTex"));
                material.SetColor("_EmColor", Color.white);
                material.SetFloat("_EmPower", 5);
                material.SetTexture("_EmTex", Assets.mainAssetBundle.LoadAsset <Material>("matMinerMolten").GetTexture("_EmissionMap"));

                array[0].defaultMaterial = material;
            }

            moltenSkinDefInfo.RendererInfos = array;

            SkinDef moltenSkin = LoadoutAPI.CreateNewSkinDef(moltenSkinDefInfo);
            #endregion

            #region Puple
            LoadoutAPI.SkinDefInfo pupleSkinDefInfo = default(LoadoutAPI.SkinDefInfo);
            pupleSkinDefInfo.BaseSkins = Array.Empty <SkinDef>();
            pupleSkinDefInfo.MinionSkinReplacements      = new SkinDef.MinionSkinReplacement[0];
            pupleSkinDefInfo.ProjectileGhostReplacements = new SkinDef.ProjectileGhostReplacement[0];
            pupleSkinDefInfo.GameObjectActivations       = getActivations(allObjects);
            pupleSkinDefInfo.Icon             = Assets.mainAssetBundle.LoadAsset <Sprite>("texPupleAchievement");
            pupleSkinDefInfo.MeshReplacements = new SkinDef.MeshReplacement[]
            {
                new SkinDef.MeshReplacement
                {
                    renderer = mainRenderer,
                    mesh     = mainRenderer.sharedMesh
                }
            };
            pupleSkinDefInfo.Name          = "MINERBODY_PUPLE_SKIN_NAME";
            pupleSkinDefInfo.NameToken     = "MINERBODY_PUPLE_SKIN_NAME";
            pupleSkinDefInfo.RendererInfos = characterModel.baseRendererInfos;
            pupleSkinDefInfo.RootObject    = model;

            rendererInfos = skinDefInfo.RendererInfos;
            array         = new CharacterModel.RendererInfo[rendererInfos.Length];
            rendererInfos.CopyTo(array, 0);

            material = array[0].defaultMaterial;

            if (material)
            {
                material = UnityEngine.Object.Instantiate <Material>(material);
                material.SetTexture("_MainTex", Assets.mainAssetBundle.LoadAsset <Material>("matMinerPuple").GetTexture("_MainTex"));
                material.SetColor("_EmColor", Color.white);
                material.SetFloat("_EmPower", 1);
                material.SetTexture("_EmTex", Assets.mainAssetBundle.LoadAsset <Material>("matMinerPuple").GetTexture("_EmissionMap"));

                array[0].defaultMaterial = material;
            }

            pupleSkinDefInfo.RendererInfos = array;

            SkinDef pupleSkin = LoadoutAPI.CreateNewSkinDef(pupleSkinDefInfo);
            #endregion

            #region Tundra
            LoadoutAPI.SkinDefInfo tundraSkinDefInfo = default(LoadoutAPI.SkinDefInfo);
            tundraSkinDefInfo.BaseSkins = Array.Empty <SkinDef>();
            tundraSkinDefInfo.MinionSkinReplacements      = new SkinDef.MinionSkinReplacement[0];
            tundraSkinDefInfo.ProjectileGhostReplacements = new SkinDef.ProjectileGhostReplacement[0];
            tundraSkinDefInfo.GameObjectActivations       = getActivations(allObjects);
            tundraSkinDefInfo.Icon             = Assets.mainAssetBundle.LoadAsset <Sprite>("texTundraAchievement");
            tundraSkinDefInfo.MeshReplacements = new SkinDef.MeshReplacement[]
            {
                new SkinDef.MeshReplacement
                {
                    renderer = mainRenderer,
                    mesh     = Assets.tundraMesh
                }
            };
            tundraSkinDefInfo.Name          = "MINERBODY_TUNDRA_SKIN_NAME";
            tundraSkinDefInfo.NameToken     = "MINERBODY_TUNDRA_SKIN_NAME";
            tundraSkinDefInfo.RendererInfos = characterModel.baseRendererInfos;
            tundraSkinDefInfo.RootObject    = model;

            rendererInfos = skinDefInfo.RendererInfos;
            array         = new CharacterModel.RendererInfo[rendererInfos.Length];
            rendererInfos.CopyTo(array, 0);

            material = array[0].defaultMaterial;

            if (material)
            {
                material = UnityEngine.Object.Instantiate <Material>(material);
                material.SetTexture("_MainTex", Assets.mainAssetBundle.LoadAsset <Material>("matMinerTundra").GetTexture("_MainTex"));
                material.SetColor("_EmColor", Color.white);
                material.SetFloat("_EmPower", 0);
                material.SetTexture("_EmTex", Assets.mainAssetBundle.LoadAsset <Material>("matMinerTundra").GetTexture("_EmissionMap"));

                array[0].defaultMaterial = material;
            }

            tundraSkinDefInfo.RendererInfos = array;

            SkinDef tundraSkin = LoadoutAPI.CreateNewSkinDef(tundraSkinDefInfo);
            #endregion

            #region GrandMastery
            LoadoutAPI.SkinDefInfo grandMasterySkinDefInfo = default(LoadoutAPI.SkinDefInfo);
            grandMasterySkinDefInfo.BaseSkins = Array.Empty <SkinDef>();
            grandMasterySkinDefInfo.MinionSkinReplacements      = new SkinDef.MinionSkinReplacement[0];
            grandMasterySkinDefInfo.ProjectileGhostReplacements = new SkinDef.ProjectileGhostReplacement[0];
            grandMasterySkinDefInfo.GameObjectActivations       = getActivations(allObjects);
            grandMasterySkinDefInfo.Icon             = Assets.mainAssetBundle.LoadAsset <Sprite>("texGrandMasteryAchievement");
            grandMasterySkinDefInfo.MeshReplacements = new SkinDef.MeshReplacement[]
            {
                new SkinDef.MeshReplacement
                {
                    renderer = mainRenderer,
                    mesh     = Assets.grandMasteryMesh
                }
            };
            grandMasterySkinDefInfo.Name          = "MINERBODY_TYPHOON_SKIN_NAME";
            grandMasterySkinDefInfo.NameToken     = "MINERBODY_TYPHOON_SKIN_NAME";
            grandMasterySkinDefInfo.RendererInfos = characterModel.baseRendererInfos;
            grandMasterySkinDefInfo.RootObject    = model;

            rendererInfos = skinDefInfo.RendererInfos;
            array         = new CharacterModel.RendererInfo[rendererInfos.Length];
            rendererInfos.CopyTo(array, 0);

            material = array[0].defaultMaterial;

            if (material)
            {
                material = UnityEngine.Object.Instantiate <Material>(material);
                material.SetTexture("_MainTex", Assets.mainAssetBundle.LoadAsset <Material>("matMinerGM").GetTexture("_MainTex"));
                material.SetColor("_EmColor", Color.white);
                material.SetFloat("_EmPower", 0);
                material.SetTexture("_EmTex", Assets.mainAssetBundle.LoadAsset <Material>("matMinerGM").GetTexture("_EmissionMap"));

                array[0].defaultMaterial = material;
            }

            grandMasterySkinDefInfo.RendererInfos = array;

            SkinDef grandMasterySkin = LoadoutAPI.CreateNewSkinDef(grandMasterySkinDefInfo);
            #endregion

            #region Iron
            LoadoutAPI.SkinDefInfo ironSkinDefInfo = default(LoadoutAPI.SkinDefInfo);
            ironSkinDefInfo.BaseSkins = Array.Empty <SkinDef>();
            ironSkinDefInfo.MinionSkinReplacements      = new SkinDef.MinionSkinReplacement[0];
            ironSkinDefInfo.ProjectileGhostReplacements = new SkinDef.ProjectileGhostReplacement[0];
            ironSkinDefInfo.GameObjectActivations       = getActivations(allObjects);
            ironSkinDefInfo.Icon             = Resources.Load <GameObject>("Prefabs/CharacterBodies/HuntressBody").GetComponentInChildren <ModelSkinController>().skins[1].icon;
            ironSkinDefInfo.MeshReplacements = new SkinDef.MeshReplacement[]
            {
                new SkinDef.MeshReplacement
                {
                    renderer = mainRenderer,
                    mesh     = mainRenderer.sharedMesh
                }
            };
            ironSkinDefInfo.Name          = "MINERBODY_IRON_SKIN_NAME";
            ironSkinDefInfo.NameToken     = "MINERBODY_IRON_SKIN_NAME";
            ironSkinDefInfo.RendererInfos = characterModel.baseRendererInfos;
            ironSkinDefInfo.RootObject    = model;

            rendererInfos = skinDefInfo.RendererInfos;
            array         = new CharacterModel.RendererInfo[rendererInfos.Length];
            rendererInfos.CopyTo(array, 0);

            material = array[0].defaultMaterial;

            if (material)
            {
                material = UnityEngine.Object.Instantiate <Material>(material);
                material.SetTexture("_MainTex", Assets.mainAssetBundle.LoadAsset <Material>("matMinerIron").GetTexture("_MainTex"));
                material.SetColor("_EmColor", Color.white);
                material.SetFloat("_EmPower", 0);

                array[0].defaultMaterial = material;
            }

            ironSkinDefInfo.RendererInfos = array;

            SkinDef ironSkin = LoadoutAPI.CreateNewSkinDef(ironSkinDefInfo);
            #endregion

            #region Gold
            LoadoutAPI.SkinDefInfo goldSkinDefInfo = default(LoadoutAPI.SkinDefInfo);
            goldSkinDefInfo.BaseSkins = Array.Empty <SkinDef>();
            goldSkinDefInfo.MinionSkinReplacements      = new SkinDef.MinionSkinReplacement[0];
            goldSkinDefInfo.ProjectileGhostReplacements = new SkinDef.ProjectileGhostReplacement[0];
            goldSkinDefInfo.GameObjectActivations       = getActivations(allObjects);
            goldSkinDefInfo.Icon             = Resources.Load <GameObject>("Prefabs/CharacterBodies/CommandoBody").GetComponentInChildren <ModelSkinController>().skins[1].icon;
            goldSkinDefInfo.MeshReplacements = new SkinDef.MeshReplacement[]
            {
                new SkinDef.MeshReplacement
                {
                    renderer = mainRenderer,
                    mesh     = mainRenderer.sharedMesh
                }
            };
            goldSkinDefInfo.Name          = "MINERBODY_GOLD_SKIN_NAME";
            goldSkinDefInfo.NameToken     = "MINERBODY_GOLD_SKIN_NAME";
            goldSkinDefInfo.RendererInfos = characterModel.baseRendererInfos;
            goldSkinDefInfo.RootObject    = model;

            rendererInfos = skinDefInfo.RendererInfos;
            array         = new CharacterModel.RendererInfo[rendererInfos.Length];
            rendererInfos.CopyTo(array, 0);

            material = array[0].defaultMaterial;

            if (material)
            {
                material = UnityEngine.Object.Instantiate <Material>(material);
                material.SetTexture("_MainTex", Assets.mainAssetBundle.LoadAsset <Material>("matMinerGold").GetTexture("_MainTex"));
                material.SetColor("_EmColor", Color.white);
                material.SetFloat("_EmPower", 0f);
                material.SetTexture("_EmTex", Assets.mainAssetBundle.LoadAsset <Material>("matMinerGold").GetTexture("_EmissionMap"));

                array[0].defaultMaterial = material;
            }

            goldSkinDefInfo.RendererInfos = array;

            SkinDef goldSkin = LoadoutAPI.CreateNewSkinDef(goldSkinDefInfo);
            #endregion

            #region Diamond
            LoadoutAPI.SkinDefInfo diamondSkinDefInfo = default(LoadoutAPI.SkinDefInfo);
            diamondSkinDefInfo.BaseSkins = Array.Empty <SkinDef>();
            diamondSkinDefInfo.MinionSkinReplacements      = new SkinDef.MinionSkinReplacement[0];
            diamondSkinDefInfo.ProjectileGhostReplacements = new SkinDef.ProjectileGhostReplacement[0];
            diamondSkinDefInfo.GameObjectActivations       = getActivations(allObjects);
            diamondSkinDefInfo.Icon             = Resources.Load <GameObject>("Prefabs/CharacterBodies/MercBody").GetComponentInChildren <ModelSkinController>().skins[0].icon;
            diamondSkinDefInfo.MeshReplacements = new SkinDef.MeshReplacement[]
            {
                new SkinDef.MeshReplacement
                {
                    renderer = mainRenderer,
                    mesh     = mainRenderer.sharedMesh
                }
            };
            diamondSkinDefInfo.Name          = "MINERBODY_DIAMOND_SKIN_NAME";
            diamondSkinDefInfo.NameToken     = "MINERBODY_DIAMOND_SKIN_NAME";
            diamondSkinDefInfo.RendererInfos = characterModel.baseRendererInfos;
            diamondSkinDefInfo.RootObject    = model;

            rendererInfos = skinDefInfo.RendererInfos;
            array         = new CharacterModel.RendererInfo[rendererInfos.Length];
            rendererInfos.CopyTo(array, 0);

            material = array[0].defaultMaterial;

            if (material)
            {
                material = UnityEngine.Object.Instantiate <Material>(material);
                material.SetTexture("_MainTex", Assets.mainAssetBundle.LoadAsset <Material>("matMinerDiamond").GetTexture("_MainTex"));
                material.SetColor("_EmColor", Color.white);
                material.SetFloat("_EmPower", 0.75f);
                material.SetTexture("_EmTex", Assets.mainAssetBundle.LoadAsset <Material>("matMinerDiamond").GetTexture("_EmissionMap"));

                array[0].defaultMaterial = material;
            }

            diamondSkinDefInfo.RendererInfos = array;

            SkinDef diamondSkin = LoadoutAPI.CreateNewSkinDef(diamondSkinDefInfo);
            #endregion

            #region Blacksmith
            LoadoutAPI.SkinDefInfo blacksmithSkinDefInfo = default(LoadoutAPI.SkinDefInfo);
            blacksmithSkinDefInfo.BaseSkins = Array.Empty <SkinDef>();
            blacksmithSkinDefInfo.MinionSkinReplacements      = new SkinDef.MinionSkinReplacement[0];
            blacksmithSkinDefInfo.ProjectileGhostReplacements = new SkinDef.ProjectileGhostReplacement[0];
            blacksmithSkinDefInfo.GameObjectActivations       = getActivations(allObjects);
            blacksmithSkinDefInfo.Icon             = Assets.mainAssetBundle.LoadAsset <Sprite>("texBlacksmithAchievement");
            blacksmithSkinDefInfo.MeshReplacements = new SkinDef.MeshReplacement[]
            {
                new SkinDef.MeshReplacement
                {
                    renderer = mainRenderer,
                    mesh     = Assets.blacksmithMesh
                }
            };
            blacksmithSkinDefInfo.Name          = "MINERBODY_BLACKSMITH_SKIN_NAME";
            blacksmithSkinDefInfo.NameToken     = "MINERBODY_BLACKSMITH_SKIN_NAME";
            blacksmithSkinDefInfo.RendererInfos = characterModel.baseRendererInfos;
            blacksmithSkinDefInfo.RootObject    = model;

            rendererInfos = skinDefInfo.RendererInfos;
            array         = new CharacterModel.RendererInfo[rendererInfos.Length];
            rendererInfos.CopyTo(array, 0);

            material = array[0].defaultMaterial;

            if (material)
            {
                material = UnityEngine.Object.Instantiate <Material>(material);
                material.SetTexture("_MainTex", Assets.mainAssetBundle.LoadAsset <Material>("matBlacksmith").GetTexture("_MainTex"));
                material.SetColor("_EmColor", Color.white);
                material.SetFloat("_EmPower", 0f);
                material.SetTexture("_EmTex", Assets.mainAssetBundle.LoadAsset <Material>("matBlacksmith").GetTexture("_EmissionMap"));

                array[0].defaultMaterial = material;
            }

            blacksmithSkinDefInfo.RendererInfos = array;

            SkinDef blacksmithSkin = LoadoutAPI.CreateNewSkinDef(blacksmithSkinDefInfo);
            #endregion

            #region Drip
            LoadoutAPI.SkinDefInfo dripSkinDefInfo = default(LoadoutAPI.SkinDefInfo);
            dripSkinDefInfo.BaseSkins = Array.Empty <SkinDef>();
            dripSkinDefInfo.MinionSkinReplacements      = new SkinDef.MinionSkinReplacement[0];
            dripSkinDefInfo.ProjectileGhostReplacements = new SkinDef.ProjectileGhostReplacement[0];
            dripSkinDefInfo.GameObjectActivations       = getActivations(allObjects);
            dripSkinDefInfo.Icon             = Assets.mainAssetBundle.LoadAsset <Sprite>("texDripSkin");
            dripSkinDefInfo.MeshReplacements = new SkinDef.MeshReplacement[]
            {
                new SkinDef.MeshReplacement
                {
                    renderer = mainRenderer,
                    mesh     = Assets.dripMesh
                }
            };
            dripSkinDefInfo.Name          = "MINERBODY_DRIP_SKIN_NAME";
            dripSkinDefInfo.NameToken     = "MINERBODY_DRIP_SKIN_NAME";
            dripSkinDefInfo.RendererInfos = characterModel.baseRendererInfos;
            dripSkinDefInfo.RootObject    = model;

            rendererInfos = skinDefInfo.RendererInfos;
            array         = new CharacterModel.RendererInfo[rendererInfos.Length];
            rendererInfos.CopyTo(array, 0);

            material = array[0].defaultMaterial;

            if (material)
            {
                material = UnityEngine.Object.Instantiate <Material>(material);
                material.SetTexture("_MainTex", Assets.mainAssetBundle.LoadAsset <Material>("matDripMiner").GetTexture("_MainTex"));
                material.SetColor("_EmColor", Color.white);
                material.SetFloat("_EmPower", 0f);
                material.SetTexture("_EmTex", Assets.mainAssetBundle.LoadAsset <Material>("matDripMiner").GetTexture("_EmissionMap"));

                array[0].defaultMaterial = material;
            }

            dripSkinDefInfo.RendererInfos = array;

            SkinDef dripSkin = LoadoutAPI.CreateNewSkinDef(dripSkinDefInfo);
            #endregion

            #region Steve
            LoadoutAPI.SkinDefInfo steveSkinDefInfo = default(LoadoutAPI.SkinDefInfo);
            steveSkinDefInfo.BaseSkins = Array.Empty <SkinDef>();
            steveSkinDefInfo.MinionSkinReplacements      = new SkinDef.MinionSkinReplacement[0];
            steveSkinDefInfo.ProjectileGhostReplacements = new SkinDef.ProjectileGhostReplacement[0];
            steveSkinDefInfo.GameObjectActivations       = getActivations(allObjects, diamondPickL, diamondPickR);
            steveSkinDefInfo.Icon             = Resources.Load <GameObject>("Prefabs/CharacterBodies/CommandoBody").GetComponentInChildren <ModelSkinController>().skins[0].icon;
            steveSkinDefInfo.MeshReplacements = new SkinDef.MeshReplacement[]
            {
                new SkinDef.MeshReplacement
                {
                    renderer = mainRenderer,
                    mesh     = Assets.steveMesh
                }
            };
            steveSkinDefInfo.Name          = "MINERBODY_STEVE_SKIN_NAME";
            steveSkinDefInfo.NameToken     = "MINERBODY_STEVE_SKIN_NAME";
            steveSkinDefInfo.RendererInfos = characterModel.baseRendererInfos;
            steveSkinDefInfo.RootObject    = model;

            rendererInfos = skinDefInfo.RendererInfos;
            array         = new CharacterModel.RendererInfo[rendererInfos.Length];
            rendererInfos.CopyTo(array, 0);

            material = array[0].defaultMaterial;

            if (material)
            {
                material = UnityEngine.Object.Instantiate <Material>(material);
                material.SetTexture("_MainTex", Assets.mainAssetBundle.LoadAsset <Material>("matMinerSteve").GetTexture("_MainTex"));
                material.SetColor("_EmColor", Color.white);
                material.SetFloat("_EmPower", 0.75f);
                material.SetTexture("_EmTex", Assets.mainAssetBundle.LoadAsset <Material>("matMinerSteve").GetTexture("_EmissionMap"));

                array[0].defaultMaterial = material;
            }

            steveSkinDefInfo.RendererInfos = array;

            SkinDef steveSkin = LoadoutAPI.CreateNewSkinDef(steveSkinDefInfo);
            #endregion

            var skinDefs = new List <SkinDef>();

            if (DiggerPlugin.starstormInstalled)
            {
                skinDefs = new List <SkinDef>()
                {
                    defaultSkin,
                    moltenSkin,
                    grandMasterySkin,
                    tundraSkin,
                    pupleSkin,
                    blacksmithSkin
                };
            }
            else
            {
                skinDefs = new List <SkinDef>()
                {
                    defaultSkin,
                    moltenSkin,
                    tundraSkin,
                    pupleSkin,
                    blacksmithSkin
                };
            }

            if (DiggerPlugin.extraSkins.Value)
            {
                skinDefs.Add(dripSkin);
                skinDefs.Add(steveSkin);
                skinDefs.Add(ironSkin);
                skinDefs.Add(goldSkin);
                skinDefs.Add(diamondSkin);
            }

            skinController.skins = skinDefs.ToArray();
        }
Beispiel #8
0
        internal static void CreatePrefab()
        {
            // first clone the commando prefab so we can turn that into our own survivor
            characterPrefab = PrefabAPI.InstantiateClone(Resources.Load <GameObject>("Prefabs/CharacterBodies/CommandoBody"), "WispPreview", true, "C:\\Users\\test\\Documents\\ror2mods\\ExampleSurvivor\\ExampleSurvivor\\ExampleSurvivor\\ExampleSurvivor.cs", "CreatePrefab", 151);
            //Debug.Log("Loaded prefab");
            characterPrefab.GetComponent <NetworkIdentity>().localPlayerAuthority = true;
            //Debug.Log("Set local player authority");

            #region charactermodel
            // create the model here, we're gonna replace commando's model with our own
            GameObject model = CreateModel(characterPrefab);

            GameObject gameObject = new GameObject("ModelBase");
            gameObject.transform.parent        = characterPrefab.transform;
            gameObject.transform.localPosition = new Vector3(0f, -0.81f, 0f);
            gameObject.transform.localRotation = Quaternion.identity;
            gameObject.transform.localScale    = new Vector3(1f, 1f, 1f);
            //Debug.Log("Created model base");

            GameObject gameObject2 = new GameObject("CameraPivot");
            gameObject2.transform.parent        = gameObject.transform;
            gameObject2.transform.localPosition = new Vector3(0f, 1.6f, 0f);
            gameObject2.transform.localRotation = Quaternion.identity;
            gameObject2.transform.localScale    = Vector3.one;
            //Debug.Log("Created camera pivot");

            GameObject gameObject3 = new GameObject("AimOrigin");
            gameObject3.transform.parent        = gameObject.transform;
            gameObject3.transform.localPosition = new Vector3(0f, 1.4f, 0f);
            gameObject3.transform.localRotation = Quaternion.identity;
            gameObject3.transform.localScale    = Vector3.one;
            //Debug.Log("Created aim origin");

            Transform transform = model.transform;
            transform.parent        = gameObject.transform;
            transform.localPosition = Vector3.zero;
            transform.localScale    = new Vector3(1f, 1f, 1f);
            transform.localRotation = Quaternion.identity;
            //Debug.Log("Created character transform");

            CharacterDirection characterDirection = characterPrefab.GetComponent <CharacterDirection>();
            characterDirection.moveVector      = Vector3.zero;
            characterDirection.targetTransform = gameObject.transform;
            characterDirection.overrideAnimatorForwardTransform = null;
            characterDirection.rootMotionAccumulator            = null;
            characterDirection.modelAnimator         = model.GetComponentInChildren <Animator>();
            characterDirection.driveFromRootRotation = false;
            characterDirection.turnSpeed             = 720f;
            //Debug.Log("Set character direction");
            #endregion

            #region basestats
            // set up the character body here
            CharacterBody bodyComponent = characterPrefab.GetComponent <CharacterBody>();
            bodyComponent.bodyIndex             = -1;
            bodyComponent.baseNameToken         = "WISP_NAME";     // name token
            bodyComponent.subtitleNameToken     = "WISP_SUBTITLE"; // subtitle token- used for umbras
            bodyComponent.bodyFlags             = CharacterBody.BodyFlags.ImmuneToExecutes;
            bodyComponent.rootMotionInMainState = false;
            bodyComponent.mainRootSpeed         = 0;
            bodyComponent.baseMaxHealth         = 82.5f;
            bodyComponent.levelMaxHealth        = 24.75f;
            bodyComponent.baseRegen             = 1f;
            bodyComponent.levelRegen            = 0.25f;
            bodyComponent.baseMaxShield         = 0;
            bodyComponent.levelMaxShield        = 0f;
            bodyComponent.baseMoveSpeed         = 7;
            bodyComponent.levelMoveSpeed        = 0;
            bodyComponent.baseAcceleration      = 80;
            bodyComponent.baseJumpPower         = 15;
            bodyComponent.levelJumpPower        = 0;
            bodyComponent.baseDamage            = 6;
            bodyComponent.levelDamage           = 1.2f;
            bodyComponent.baseAttackSpeed       = 1;
            bodyComponent.levelAttackSpeed      = 0;
            bodyComponent.baseCrit                 = 1;
            bodyComponent.levelCrit                = 0;
            bodyComponent.baseArmor                = 0;
            bodyComponent.levelArmor               = 0;
            bodyComponent.baseJumpCount            = 1;
            bodyComponent.sprintingSpeedMultiplier = 1.45f;
            bodyComponent.wasLucky                 = false;
            bodyComponent.hideCrosshair            = false;
            bodyComponent.aimOriginTransform       = gameObject3.transform;
            bodyComponent.hullClassification       = HullClassification.Human;
            bodyComponent.portraitIcon             = Assets.charPortrait;
            bodyComponent.isChampion               = false;
            bodyComponent.currentVehicle           = null;
            bodyComponent.skinIndex                = 0U;
            //Debug.Log("Created character body");
            #endregion

            #region spawning-and-states
            //Replace the existing spawn animation
            EntityStateMachine entityStateMachine = characterPrefab.GetComponent <EntityStateMachine>();
            entityStateMachine.initialStateType     = new SerializableEntityStateType(typeof(EntityStates.WispSurvivorStates.Spawn));
            bodyComponent.currentVehicle            = null;
            bodyComponent.preferredPodPrefab        = null;
            bodyComponent.preferredInitialStateType = entityStateMachine.initialStateType;


            //Change our main state to account for the float functionality
            entityStateMachine.mainStateType = new SerializableEntityStateType(typeof(EntityStates.WispSurvivorStates.WispCharacterMain));

            characterPrefab.AddComponent <TetherHandler>();
            #endregion

            #region movement-camera
            // the charactermotor controls the survivor's movement and stuff
            CharacterMotor characterMotor = characterPrefab.GetComponent <CharacterMotor>();
            characterMotor.walkSpeedPenaltyCoefficient = 1f;
            characterMotor.characterDirection          = characterDirection;
            characterMotor.muteWalkMotion = false;
            characterMotor.mass           = 100f;
            //characterMotor.airControl = 0.75f;
            characterMotor.airControl = 5f;
            characterMotor.disableAirControlUntilCollision = false;
            characterMotor.generateParametersOnAwake       = true;
            //characterMotor.useGravity = true;
            //characterMotor.isFlying = false;
            //Debug.Log("Created character motor");

            InputBankTest inputBankTest = characterPrefab.GetComponent <InputBankTest>();
            inputBankTest.moveVector = Vector3.zero;

            CameraTargetParams cameraTargetParams = characterPrefab.GetComponent <CameraTargetParams>();
            cameraTargetParams.cameraParams         = Resources.Load <GameObject>("Prefabs/CharacterBodies/CommandoBody").GetComponent <CameraTargetParams>().cameraParams;
            cameraTargetParams.cameraPivotTransform = null;
            cameraTargetParams.aimMode             = CameraTargetParams.AimType.Standard;
            cameraTargetParams.recoil              = Vector2.zero;
            cameraTargetParams.idealLocalCameraPos = Vector3.zero;
            cameraTargetParams.dontRaycastToPivot  = false;
            //Debug.Log("Created camera target parameters");

            // this component is used to locate the character model(duh), important to set this up here
            ModelLocator modelLocator = characterPrefab.GetComponent <ModelLocator>();
            modelLocator.modelTransform           = transform;
            modelLocator.modelBaseTransform       = gameObject.transform;
            modelLocator.dontReleaseModelOnDeath  = false;
            modelLocator.autoUpdateModelTransform = true;
            modelLocator.dontDetatchFromParent    = false;
            modelLocator.noCorpse         = false;
            modelLocator.normalizeToFloor = false; // set true if you want your character to rotate on terrain like acrid does
            modelLocator.preserveModel    = false;
            //Debug.Log("Created model locator");
            #endregion


            // childlocator is something that must be set up in the unity project, it's used to find any child objects for things like footsteps or muzzle flashes
            // also important to set up if you want quality
            ChildLocator childLocator = model.GetComponent <ChildLocator>();
            //Debug.Log("Established child locator reference");

            // this component is used to handle all overlays and whatever on your character, without setting this up you won't get any cool effects like burning or freeze on the character
            // it goes on the model object of course
            CharacterModel characterModel = model.AddComponent <CharacterModel>();
            characterModel.body = bodyComponent;
            characterModel.baseRendererInfos = new CharacterModel.RendererInfo[]
            {
                // set up multiple rendererinfos if needed, but for this example there's only the one
                new CharacterModel.RendererInfo
                {
                    defaultMaterial          = model.GetComponentInChildren <SkinnedMeshRenderer>().material,
                    renderer                 = model.GetComponentInChildren <SkinnedMeshRenderer>(),
                    defaultShadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.On,
                    ignoreOverlays           = true //Disable overlays for incorrectly formatted character
                }
            };

            characterModel.autoPopulateLightInfos = true;
            characterModel.invisibilityCount      = 0;
            characterModel.temporaryOverlays      = new List <TemporaryOverlay>();
            //Debug.Log("Created character model");

            #region skin
            SkinnedMeshRenderer mainRenderer = (characterModel.baseRendererInfos[0].renderer as SkinnedMeshRenderer);
            if (!mainRenderer)
            {
                Debug.LogError("No main renderer found!");
            }
            if (!mainRenderer.sharedMesh)
            {
                Debug.LogError("No shared mesh found for main renderer!");
            }
            ModelSkinController modelSkinController = model.AddComponent <ModelSkinController>();
            LanguageAPI.Add("WISP_DEFAULT_SKIN", "Default");

            LoadoutAPI.SkinDefInfo skinDefInfo = default(LoadoutAPI.SkinDefInfo);
            skinDefInfo.BaseSkins = Array.Empty <SkinDef>();
            skinDefInfo.MinionSkinReplacements      = new SkinDef.MinionSkinReplacement[0];
            skinDefInfo.ProjectileGhostReplacements = new SkinDef.ProjectileGhostReplacement[0];

            GameObject[] allObjects = new GameObject[0];
            skinDefInfo.GameObjectActivations = getActivations(allObjects);

            skinDefInfo.Icon             = Assets.skin;
            skinDefInfo.MeshReplacements = new SkinDef.MeshReplacement[]
            {
                new SkinDef.MeshReplacement
                {
                    renderer = mainRenderer,
                    mesh     = mainRenderer.sharedMesh
                }
            };
            skinDefInfo.Name           = "WISP_DEFAULT_SKIN";
            skinDefInfo.NameToken      = "WISP_DEFAULT_SKIN";
            skinDefInfo.RendererInfos  = characterModel.baseRendererInfos;
            skinDefInfo.RootObject     = model;
            skinDefInfo.UnlockableName = "";
            SkinDef defaultSkin = LoadoutAPI.CreateNewSkinDef(skinDefInfo);

            var skinDefs = new List <SkinDef>()
            {
                defaultSkin
            };
            modelSkinController.skins = skinDefs.ToArray();
            //Debug.Log("Created skin");
            #endregion

            #region team-health
            TeamComponent teamComponent = null;
            if (characterPrefab.GetComponent <TeamComponent>() != null)
            {
                teamComponent = characterPrefab.GetComponent <TeamComponent>();
            }
            else
            {
                teamComponent = characterPrefab.GetComponent <TeamComponent>();
            }
            teamComponent.hideAllyCardDisplay = false;
            teamComponent.teamIndex           = TeamIndex.None;

            HealthComponent healthComponent = characterPrefab.GetComponent <HealthComponent>();
            healthComponent.health            = 82.5f;
            healthComponent.shield            = 0f;
            healthComponent.barrier           = 0f;
            healthComponent.magnetiCharge     = 0f;
            healthComponent.body              = null;
            healthComponent.dontShowHealthbar = false;
            healthComponent.globalDeathEventChanceCoefficient = 1f;
            //Debug.Log("Created components");
            #endregion

            characterPrefab.GetComponent <Interactor>().maxInteractionDistance     = 3f;
            characterPrefab.GetComponent <InteractionDriver>().highlightInteractor = true;

            // this disables ragdoll since the character's not set up for it, and instead plays a death animation
            CharacterDeathBehavior characterDeathBehavior = characterPrefab.GetComponent <CharacterDeathBehavior>();
            characterDeathBehavior.deathStateMachine = characterPrefab.GetComponent <EntityStateMachine>();
            characterDeathBehavior.deathState        = new SerializableEntityStateType(typeof(GenericCharacterDeath));

            // edit the sfxlocator if you want different sounds
            SfxLocator sfxLocator = characterPrefab.GetComponent <SfxLocator>();
            sfxLocator.deathSound      = "Play_ui_player_death";
            sfxLocator.barkSound       = "";
            sfxLocator.openSound       = "";
            sfxLocator.landingSound    = "Play_char_land";
            sfxLocator.fallDamageSound = "Play_char_land_fall_damage";
            sfxLocator.aliveLoopStart  = "";
            sfxLocator.aliveLoopStop   = "";
            //Debug.Log("Created sfx");

            Rigidbody rigidbody = characterPrefab.GetComponent <Rigidbody>();
            rigidbody.mass                   = 50f;
            rigidbody.drag                   = 0f;
            rigidbody.angularDrag            = 0f;
            rigidbody.useGravity             = false;
            rigidbody.isKinematic            = true;
            rigidbody.interpolation          = RigidbodyInterpolation.None;
            rigidbody.collisionDetectionMode = CollisionDetectionMode.Discrete;
            rigidbody.constraints            = RigidbodyConstraints.None;
            //Debug.Log("Created rigidbody");

            CapsuleCollider capsuleCollider = characterPrefab.GetComponent <CapsuleCollider>();
            capsuleCollider.isTrigger = false;
            capsuleCollider.material  = null;
            capsuleCollider.center    = new Vector3(0f, 0f, 0f);
            capsuleCollider.radius    = 0.5f;
            capsuleCollider.height    = 1.82f;
            capsuleCollider.direction = 1;
            //Debug.Log("Created capsule collider");

            KinematicCharacterMotor kinematicCharacterMotor = characterPrefab.GetComponent <KinematicCharacterMotor>();
            kinematicCharacterMotor.CharacterController = characterMotor;
            kinematicCharacterMotor.Capsule             = capsuleCollider;
            kinematicCharacterMotor.Rigidbody           = rigidbody;

            capsuleCollider.radius   = 0.5f;
            capsuleCollider.height   = 1.82f;
            capsuleCollider.center   = new Vector3(0, 0, 0);
            capsuleCollider.material = null;

            kinematicCharacterMotor.DetectDiscreteCollisions     = false;
            kinematicCharacterMotor.GroundDetectionExtraDistance = 0f;
            kinematicCharacterMotor.MaxStepHeight                     = 0.2f;
            kinematicCharacterMotor.MinRequiredStepDepth              = 0.1f;
            kinematicCharacterMotor.MaxStableSlopeAngle               = 55f;
            kinematicCharacterMotor.MaxStableDistanceFromLedge        = 0.5f;
            kinematicCharacterMotor.PreventSnappingOnLedges           = false;
            kinematicCharacterMotor.MaxStableDenivelationAngle        = 55f;
            kinematicCharacterMotor.RigidbodyInteractionType          = RigidbodyInteractionType.None;
            kinematicCharacterMotor.PreserveAttachedRigidbodyMomentum = true;
            kinematicCharacterMotor.HasPlanarConstraint               = false;
            kinematicCharacterMotor.PlanarConstraintAxis              = Vector3.up;
            kinematicCharacterMotor.StepHandling  = StepHandlingMethod.None;
            kinematicCharacterMotor.LedgeHandling = true;
            kinematicCharacterMotor.InteractiveRigidbodyHandling = true;
            kinematicCharacterMotor.SafeMovement = false;
            //Debug.Log("Set physics");

            // this sets up the character's hurtbox, kinda confusing, but should be fine as long as it's set up in unity right
            HurtBoxGroup hurtBoxGroup = model.AddComponent <HurtBoxGroup>();
            //Debug.Log("Set reference to hurtBoxGroup");
            if (model.GetComponentInChildren <CapsuleCollider>() == null)
            {
                Debug.LogError("Could not find capsule collider!");
            }
            HurtBox componentInChildren = model.GetComponentInChildren <CapsuleCollider>().gameObject.AddComponent <HurtBox>();
            //Debug.Log("Added hurtbox component to capsule collider");
            componentInChildren.gameObject.layer = LayerIndex.entityPrecise.intVal;
            componentInChildren.healthComponent  = healthComponent;
            componentInChildren.isBullseye       = true;
            componentInChildren.damageModifier   = HurtBox.DamageModifier.Normal;
            componentInChildren.hurtBoxGroup     = hurtBoxGroup;
            componentInChildren.indexInGroup     = 0;

            hurtBoxGroup.hurtBoxes = new HurtBox[]
            {
                componentInChildren
            };

            hurtBoxGroup.mainHurtBox   = componentInChildren;
            hurtBoxGroup.bullseyeCount = 1;

            //Debug.Log("Set components");

            // this is for handling footsteps, not needed but polish is always good
            FootstepHandler footstepHandler = model.AddComponent <FootstepHandler>();
            footstepHandler.baseFootstepString           = "Play_player_footstep";
            footstepHandler.sprintFootstepOverrideString = "";
            footstepHandler.enableFootstepDust           = true;
            footstepHandler.footstepDustPrefab           = Assets.footstepPrefab;

            // ragdoll controller is a pain to set up so we won't be doing that here..
            RagdollController ragdollController = model.AddComponent <RagdollController>();
            ragdollController.bones = null;
            ragdollController.componentsToDisableOnRagdoll = null;

            // this handles the pitch and yaw animations, but honestly they are nasty and a huge pain to set up so i didn't bother
            AimAnimator aimAnimator = model.AddComponent <AimAnimator>();
            aimAnimator.inputBank          = inputBankTest;
            aimAnimator.directionComponent = characterDirection;
            aimAnimator.pitchRangeMax      = 55f;
            aimAnimator.pitchRangeMin      = -50f;
            aimAnimator.yawRangeMin        = -44f;
            aimAnimator.yawRangeMax        = 44f;
            aimAnimator.pitchGiveupRange   = 30f;
            aimAnimator.yawGiveupRange     = 10f;
            aimAnimator.giveupDuration     = 8f;
            //Debug.Log("Finished setup");
        }
        public static void Create()
        {
            stanWorshipperBody = PrefabAPI.InstantiateClone(Resources.Load <GameObject>("prefabs/characterbodies/BanditBody"), "StanWorshipperBody", true);
            stanWorshipperBody.GetComponent <NetworkIdentity>().localPlayerAuthority = true;

            CharacterBody bodyComponent = stanWorshipperBody.GetComponent <CharacterBody>();

            bodyComponent.bodyIndex             = BodyIndex.None;
            bodyComponent.baseNameToken         = "STANWORSHIPPER_NAME";
            bodyComponent.subtitleNameToken     = "STANWORSHIPPER_SUBTITLE";
            bodyComponent.bodyFlags             = CharacterBody.BodyFlags.ImmuneToExecutes;
            bodyComponent.rootMotionInMainState = false;
            bodyComponent.mainRootSpeed         = 0;
            bodyComponent.baseMaxHealth         = 100;
            bodyComponent.levelMaxHealth        = 28;
            bodyComponent.baseRegen             = 0.5f;
            bodyComponent.levelRegen            = 0.25f;
            bodyComponent.baseMaxShield         = 0;
            bodyComponent.levelMaxShield        = 0;
            bodyComponent.baseMoveSpeed         = 7;
            bodyComponent.levelMoveSpeed        = 0;
            bodyComponent.baseAcceleration      = 80;
            bodyComponent.baseJumpPower         = 15;
            bodyComponent.levelJumpPower        = 0;
            bodyComponent.baseDamage            = 13;
            bodyComponent.levelDamage           = 3.3f;
            bodyComponent.baseAttackSpeed       = 1;
            bodyComponent.levelAttackSpeed      = 0;
            bodyComponent.baseCrit                 = 1;
            bodyComponent.levelCrit                = 0;
            bodyComponent.baseArmor                = 5;
            bodyComponent.levelArmor               = 0;
            bodyComponent.baseJumpCount            = 1;
            bodyComponent.sprintingSpeedMultiplier = 1.45f;
            bodyComponent.wasLucky                 = false;
            bodyComponent.hideCrosshair            = false;
            bodyComponent.hullClassification       = HullClassification.Human;
            bodyComponent.portraitIcon             = Resources.Load <Texture>("textures/bodyicons/ScavBody");
            bodyComponent.isChampion               = false;
            bodyComponent.currentVehicle           = null;
            bodyComponent.skinIndex                = 0U;
            bodyComponent.bodyColor                = new Color(0.6f, 0.3f, 0f);

            NetworkStateMachine networkStateMachine      = stanWorshipperBody.GetComponent <NetworkStateMachine>();
            EntityStateMachine  customEntityStateMachine = stanWorshipperBody.AddComponent <EntityStateMachine>();

            customEntityStateMachine.customName       = "Sacrifice";
            customEntityStateMachine.mainStateType    = new SerializableEntityStateType(typeof(Idle));
            customEntityStateMachine.initialStateType = new SerializableEntityStateType(typeof(Idle));
            ArrayUtils.ArrayAppend(ref networkStateMachine.stateMachines, customEntityStateMachine);

            //Adds a default placeholder skin to prevent weird errors (another disgusting waste of my time :D).
            GameObject          model          = stanWorshipperBody.GetComponent <ModelLocator>().modelTransform.gameObject;
            CharacterModel      characterModel = model.GetComponent <CharacterModel>();
            ModelSkinController skinController = model.AddComponent <ModelSkinController>();

            CharacterModel.RendererInfo[] renderInfos = characterModel.baseRendererInfos;
            LoadoutAPI.SkinDefInfo        skinDefInfo = new LoadoutAPI.SkinDefInfo
            {
                BaseSkins             = Array.Empty <SkinDef>(),
                GameObjectActivations = new SkinDef.GameObjectActivation[0],
                Icon                        = Assets.emptyIcon,
                MeshReplacements            = new SkinDef.MeshReplacement[0],
                MinionSkinReplacements      = new SkinDef.MinionSkinReplacement[0],
                Name                        = "STANWORSHIPPER_NAME",
                NameToken                   = "STANWORSHIPPER_NAME",
                ProjectileGhostReplacements = new SkinDef.ProjectileGhostReplacement[0],
                RendererInfos               = renderInfos,
                RootObject                  = model
            };
            SkinDef skin = LoadoutAPI.CreateNewSkinDef(skinDefInfo);

            skinController.skins = new SkinDef[] { skin };

            //Doppelganger
            stanWorshipperDoppelganger = PrefabAPI.InstantiateClone(Resources.Load <GameObject>("Prefabs/CharacterMasters/CommandoMonsterMaster"), "StanWorshipperMonsterMaster", true);
            if (!stanWorshipperDoppelganger.GetComponent <NetworkIdentity>())
            {
                stanWorshipperDoppelganger.AddComponent <NetworkIdentity>();
            }

            CharacterMaster component = stanWorshipperDoppelganger.GetComponent <CharacterMaster>();

            component.bodyPrefab = stanWorshipperBody;
        }
Beispiel #10
0
        private void Awake()
        {
            using (var assetStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("SkinTest.skintest"))
            {
                var MainAssetBundle = AssetBundle.LoadFromStream(assetStream);
                ResourcesAPI.AddProvider(new AssetBundleResourcesProvider("@SkinTest", MainAssetBundle));
            }

            var commandoPrefab = Resources.Load <GameObject>("prefabs/characterbodies/CommandoBody").InstantiateClone("CommandoCopy");
            var commandoBody   = commandoPrefab.GetComponent <CharacterBody>();

            commandoBody.baseNameToken = "test";

            Debug.Log(string.Join(", ", commandoPrefab.GetComponentInChildren <SkinnedMeshRenderer>().bones.Select(el => "'" + el.name + "'")));
            BodyCatalog.getAdditionalEntries += (list) => list.Add(commandoPrefab);

            var mySurvivorDef = new SurvivorDef
            {
                name             = "Test commando" + Environment.NewLine,
                bodyPrefab       = commandoPrefab,
                descriptionToken = "Test commando",
                displayPrefab    = Resources.Load <GameObject>("prefabs/characterdisplays/CommandoDisplay").InstantiateClone("CommandoTestDisplay", false),
                primaryColor     = new Color(0.8039216f, 0.482352942f, 0.843137264f),
                unlockableName   = "",
            };

            SurvivorAPI.AddSurvivor(mySurvivorDef);

            var skinController = commandoPrefab.GetComponentInChildren <ModelSkinController>();
            var mdl            = skinController.gameObject;
            var renderer       = mdl.GetComponentInChildren <SkinnedMeshRenderer>();
            var renderers      = mdl.transform.GetChild(0).GetComponentsInChildren <Renderer>();

            var altSkin = new LoadoutAPI.SkinDefInfo();

            altSkin.Name           = "ComandoCustomAlt";
            altSkin.NameToken      = "TEST_SKIN";
            altSkin.RootObject     = mdl;
            altSkin.BaseSkins      = new SkinDef[0];// { skinController.skins[0] };
            altSkin.UnlockableName = "";
            altSkin.RendererInfos  = new CharacterModel.RendererInfo[]
            {
                new CharacterModel.RendererInfo()
                {
                    defaultMaterial          = Resources.Load <Material>("@SkinTest:Assets/Resources/matMercAlt.mat"),
                    defaultShadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.On,
                    ignoreOverlays           = false,
                    renderer = renderer
                },
                new CharacterModel.RendererInfo()
                {
                    defaultMaterial          = Resources.Load <Material>("@SkinTest:Assets/Resources/matMercAlt.mat"),
                    defaultShadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.On,
                    ignoreOverlays           = false,
                    renderer = renderers[0]
                },
                new CharacterModel.RendererInfo()
                {
                    defaultMaterial          = Resources.Load <Material>("@SkinTest:Assets/Resources/matMercAlt.mat"),
                    defaultShadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.On,
                    ignoreOverlays           = false,
                    renderer = renderers[1]
                }
            };
            altSkin.GameObjectActivations = new SkinDef.GameObjectActivation[0];
            //altSkin.MinionSkinReplacements = new SkinDef.MinionSkinReplacement[0];
            //altSkin.ProjectileGhostReplacements = new SkinDef.ProjectileGhostReplacement[0];
            altSkin.MeshReplacements = new SkinDef.MeshReplacement[]
            {
                new SkinDef.MeshReplacement()
                {
                    mesh     = Resources.Load <Mesh>("@SkinTest:Assets/Resources/skintest.blend"),
                    renderer = renderer
                }
            };

            Array.Resize(ref skinController.skins, skinController.skins.Length + 1);
            skinController.skins[skinController.skins.Length - 1] = LoadoutAPI.CreateNewSkinDef(altSkin);
        }
Beispiel #11
0
        private void EditModelSkins()
        {
            var model      = this.sniperBody.GetComponent <ModelLocator>().modelTransform;
            var charModel  = model.GetComponent <CharacterModel>();
            var modelSkins = model.GetComponent <ModelSkinController>();

            var baseSkin = modelSkins.skins[0];

            var skinDef = LoadoutAPI.CreateNewSkinDef(new LoadoutAPI.SkinDefInfo());

            skinDef.baseSkins             = Array.Empty <SkinDef>();
            skinDef.gameObjectActivations = Array.Empty <SkinDef.GameObjectActivation>();
            skinDef.icon          = Resources.Load <Sprite>("NotAPath"); // TODO: Grab skin icon generator and implement
            skinDef.rendererInfos = new CharacterModel.RendererInfo[3]
            {
                new CharacterModel.RendererInfo
                {
                    defaultMaterial          = this.sniperPistolMaterial,
                    defaultShadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.On,
                    ignoreOverlays           = false,
                    renderer = baseSkin.rendererInfos[0].renderer
                },
                new CharacterModel.RendererInfo
                {
                    defaultMaterial          = this.sniperRifleMaterial,
                    defaultShadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.On,
                    ignoreOverlays           = false,
                    renderer = baseSkin.rendererInfos[1].renderer
                },
                new CharacterModel.RendererInfo
                {
                    defaultMaterial          = this.sniperBodyMaterial,
                    defaultShadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.On,
                    ignoreOverlays           = false,
                    renderer = baseSkin.rendererInfos[2].renderer
                }
            };
            skinDef.meshReplacements = new SkinDef.MeshReplacement[3]
            {
                new SkinDef.MeshReplacement
                {
                    mesh     = this.sniperBodyMesh,
                    renderer = baseSkin.meshReplacements[0].renderer
                },
                new SkinDef.MeshReplacement
                {
                    mesh     = this.sniperRifleMesh,
                    renderer = baseSkin.rendererInfos[0].renderer
                },
                new SkinDef.MeshReplacement
                {
                    mesh     = this.knifeMesh3,
                    renderer = baseSkin.rendererInfos[1].renderer
                }
            };
            skinDef.rootObject     = baseSkin.rootObject;
            skinDef.unlockableName = "";

            modelSkins.skins = new SkinDef[1]
            {
                skinDef
            };
        }
    /// <summary>
    /// Create a survivor prefab from a model. Don't register the prefab that it outputs, because the method already does that for you.
    /// </summary>
    /// <returns>The prefab created from the model.</returns>
    public GameObject CreatePrefab()
    {
        if (prefabName == "")
        {
            Log.LogW("Prefab name has not been set.");
            prefabName = "RandomAssSurvivorBody";
        }

        GameObject prefab = PrefabAPI.InstantiateClone(Resources.Load <GameObject>("Prefabs/CharacterBodies/CommandoBody"), prefabName, true);

        prefab.GetComponent <NetworkIdentity>().localPlayerAuthority = true;

        SetupModelBase();
        SetupCamera();
        SetupAim();

        void SetupModelBase()
        {
            UnityEngine.Object.Destroy(prefab.transform.Find("ModelBase").gameObject);
            UnityEngine.Object.Destroy(prefab.transform.Find("CameraPivot").gameObject);
            UnityEngine.Object.Destroy(prefab.transform.Find("AimOrigin").gameObject);

            modelBase.transform.parent        = prefab.transform;
            modelBase.transform.localPosition = new Vector3(0f, -0.81f, 0f);
            modelBase.transform.localRotation = Quaternion.identity;
            //modelBase.transform.localScale = Vector3.one;
        }

        void SetupCamera()
        {
            camPivot.transform.parent        = prefab.transform;
            camPivot.transform.localPosition = new Vector3(0f, -0.81f, 0f);
            camPivot.transform.rotation      = Quaternion.identity;
            camPivot.transform.localScale    = Vector3.one;
        }

        void SetupAim()
        {
            aimOrigin.transform.parent        = prefab.transform;
            aimOrigin.transform.localPosition = new Vector3(0f, 1.4f, 0f);
            aimOrigin.transform.rotation      = Quaternion.identity;
            aimOrigin.transform.localScale    = Vector3.one;
        }

        if (!model)
        {
            Log.LogE("Character model has not been loaded, returning null. " + prefabName + " will not function properly.");
            return(null);
        }

        Transform          transform = model.transform;
        CharacterDirection dir       = prefab.GetComponent <CharacterDirection>();
        CharacterBody      body      = prefab.GetComponent <CharacterBody>();
        CharacterMotor     motor     = prefab.GetComponent <CharacterMotor>();
        CameraTargetParams camParams = prefab.GetComponent <CameraTargetParams>();
        ModelLocator       locator   = prefab.GetComponent <ModelLocator>();
        CharacterModel     charModel = transform.gameObject.AddComponent <CharacterModel>();
        ChildLocator       childLoc  = model.GetComponent <ChildLocator>();

        TeamComponent teamComponent = null;

        if (prefab.GetComponent <TeamComponent>() != null)
        {
            teamComponent = prefab.GetComponent <TeamComponent>();
        }
        else
        {
            teamComponent = prefab.GetComponent <TeamComponent>();
        }

        HealthComponent        health        = prefab.GetComponent <HealthComponent>();
        CharacterDeathBehavior deathBehavior = prefab.GetComponent <CharacterDeathBehavior>();
        Rigidbody               rigidbody    = prefab.GetComponent <Rigidbody>();
        CapsuleCollider         collider     = prefab.GetComponent <CapsuleCollider>();
        KinematicCharacterMotor kMotor       = prefab.GetComponent <KinematicCharacterMotor>();
        HurtBoxGroup            hurtbox      = model.AddComponent <HurtBoxGroup>();
        CapsuleCollider         coll1        = model.GetComponentInChildren <CapsuleCollider>();
        HurtBox         hb       = coll1.gameObject.AddComponent <HurtBox>();
        FootstepHandler footstep = model.AddComponent <FootstepHandler>();
        AimAnimator     aimer    = model.AddComponent <AimAnimator>();

        SetupModelTransform();
        SetupCharacterDirection();
        SetupCharacterBody();
        SetupCharacterMotor();
        SetupCameraParams();
        SetupModelLocator();
        SetupModel();
        SetupShaders();
        SetupSkins();
        SetupTeamComponent();
        SetupHealthComponent();
        SetupInteractors();
        SetupDeathBehavior();
        SetupRigidBody();
        SetupCollider();
        SetupKCharacterMotor();
        SetupHurtbox();
        SetupFootstep();
        SetupAimAnimator();
        SetupHitbox();

        void SetupModelTransform()
        {
            transform.parent = modelBase.transform;
            //transform.localPosition = Vector3.zero;
            transform.localRotation = Quaternion.identity;
        }

        void SetupCharacterDirection()
        {
            dir.moveVector      = Vector3.zero;
            dir.targetTransform = modelBase.transform;
            dir.overrideAnimatorForwardTransform = null;
            dir.rootMotionAccumulator            = null;
            dir.modelAnimator         = model.GetComponentInChildren <Animator>();
            dir.driveFromRootRotation = false;
            dir.turnSpeed             = 720f;
        }

        void SetupCharacterBody()
        {
            body.name                  = prefabName;
            body.bodyFlags             = CharacterBody.BodyFlags.ImmuneToExecutes;
            body.rootMotionInMainState = false;
            body.mainRootSpeed         = 0;
            body.bodyIndex             = -1;
            body.aimOriginTransform    = aimOrigin.transform;
            body.hullClassification    = HullClassification.Human;
        }

        void SetupCharacterMotor()
        { //CharacterMotor motor = prefab.GetComponent<CharacterMotor>();
            motor.walkSpeedPenaltyCoefficient = 1f;
            motor.characterDirection          = dir;
            motor.muteWalkMotion = false;
            motor.mass           = 100f;
            motor.airControl     = 0.25f;
            motor.disableAirControlUntilCollision = false;
            motor.generateParametersOnAwake       = true;
        }

        void SetupCameraParams()
        {
            camParams.cameraParams         = Resources.Load <GameObject>("Prefabs/CharacterBodies/CommandoBody").GetComponent <CameraTargetParams>().cameraParams;
            camParams.cameraPivotTransform = null;
            camParams.aimMode             = CameraTargetParams.AimType.Standard;
            camParams.recoil              = Vector2.zero;
            camParams.idealLocalCameraPos = Vector3.zero;
            camParams.dontRaycastToPivot  = false;
        }

        void SetupModelLocator()
        {
            locator.modelTransform           = transform;
            locator.modelBaseTransform       = modelBase.transform;
            locator.dontReleaseModelOnDeath  = false;
            locator.autoUpdateModelTransform = true;
            locator.dontDetatchFromParent    = false;
            locator.noCorpse         = false;
            locator.normalizeToFloor = false;
            locator.preserveModel    = false;
        }

        void SetupTeamComponent()
        {
            teamComponent.hideAllyCardDisplay = false;
            teamComponent.teamIndex           = TeamIndex.None;
        }

        void SetupHealthComponent()
        {
            health.body = null;
            health.dontShowHealthbar = false;
            health.globalDeathEventChanceCoefficient = 1f;
        }

        void SetupInteractors()
        {
            prefab.GetComponent <Interactor>().maxInteractionDistance     = 3f;
            prefab.GetComponent <InteractionDriver>().highlightInteractor = true;
        }

        void SetupDeathBehavior()
        {
            deathBehavior.deathStateMachine = prefab.GetComponent <EntityStateMachine>();
            deathBehavior.deathState        = new SerializableEntityStateType(typeof(GenericCharacterDeath));
        }

        void SetupRigidBody()
        {
            rigidbody.mass                   = 100f;
            rigidbody.drag                   = 0f;
            rigidbody.angularDrag            = 0f;
            rigidbody.useGravity             = false;
            rigidbody.isKinematic            = true;
            rigidbody.interpolation          = RigidbodyInterpolation.None;
            rigidbody.collisionDetectionMode = CollisionDetectionMode.Discrete;
            rigidbody.constraints            = RigidbodyConstraints.None;
        }

        void SetupCollider()
        {
            collider.isTrigger = false;
            collider.material  = null;
            collider.center    = Vector3.zero;
            collider.direction = 1;
        }

        void SetupModel()
        {
            charModel.body = body;
            List <CharacterModel.RendererInfo> infos = new List <CharacterModel.RendererInfo>();

            infos.Add(new CharacterModel.RendererInfo
            {
                defaultMaterial          = model.GetComponentInChildren <SkinnedMeshRenderer>().material,
                renderer                 = model.GetComponentInChildren <SkinnedMeshRenderer>(),
                defaultShadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off,
                ignoreOverlays           = false
            });

            SkinnedMeshRenderer[] skinnedMeshRenderer = model.GetComponentsInChildren <SkinnedMeshRenderer>();
            for (int i = 0; i < skinnedMeshRenderer.Length; i++)
            {
                infos.Add(new CharacterModel.RendererInfo
                {
                    defaultMaterial          = skinnedMeshRenderer[i].material,
                    renderer                 = skinnedMeshRenderer[i],
                    defaultShadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.On,
                    ignoreOverlays           = false
                });
            }

            charModel.baseRendererInfos      = infos.ToArray();
            charModel.autoPopulateLightInfos = true;
            charModel.invisibilityCount      = 0;
            charModel.temporaryOverlays      = new List <TemporaryOverlay>();
        }

        void SetupKCharacterMotor()
        {
            kMotor.CharacterController               = motor;
            kMotor.Capsule                           = collider;
            kMotor.Rigidbody                         = rigidbody;
            kMotor.DetectDiscreteCollisions          = false;
            kMotor.GroundDetectionExtraDistance      = 0f;
            kMotor.MaxStepHeight                     = 0.2f;
            kMotor.MinRequiredStepDepth              = 0.1f;
            kMotor.MaxStableSlopeAngle               = 55f;
            kMotor.MaxStableDistanceFromLedge        = 0.5f;
            kMotor.PreventSnappingOnLedges           = false;
            kMotor.MaxStableDenivelationAngle        = 55f;
            kMotor.RigidbodyInteractionType          = RigidbodyInteractionType.None;
            kMotor.PreserveAttachedRigidbodyMomentum = true;
            kMotor.HasPlanarConstraint               = false;
            kMotor.PlanarConstraintAxis              = Vector3.up;
            kMotor.StepHandling                      = StepHandlingMethod.None;
            kMotor.LedgeHandling                     = true;
            kMotor.InteractiveRigidbodyHandling      = true;
            kMotor.SafeMovement                      = false;
        }

        void SetupHurtbox()
        {
            hb.gameObject.layer = LayerIndex.entityPrecise.intVal;

            hb.healthComponent = health;
            hb.isBullseye      = true;
            hb.damageModifier  = HurtBox.DamageModifier.Normal;
            hb.hurtBoxGroup    = hurtbox;
            hb.indexInGroup    = 0;

            hurtbox.hurtBoxes     = new HurtBox[] { hb };
            hurtbox.mainHurtBox   = hb;
            hurtbox.bullseyeCount = 1;
        }

        void SetupFootstep()
        {
            footstep.baseFootstepString           = "Play_player_footstep";
            footstep.sprintFootstepOverrideString = "";
            footstep.enableFootstepDust           = true;
            footstep.footstepDustPrefab           = Resources.Load <GameObject>("Prefabs/GenericFootstepDust");
        }

        //RagdollController ragdoll = model.GetComponent<RagdollController>();
        //TODO
        //ragdoll.bones = null;
        //ragdoll.componentsToDisableOnRagdoll = null;

        void SetupAimAnimator()
        {
            aimer.inputBank          = prefab.GetComponent <InputBankTest>();
            aimer.directionComponent = dir;
            aimer.pitchRangeMax      = 60f;
            aimer.pitchRangeMin      = -60f;
            aimer.yawRangeMax        = 90f;
            aimer.yawRangeMin        = -90f;
            aimer.pitchGiveupRange   = 30f;
            aimer.yawGiveupRange     = 10f;
            aimer.giveupDuration     = 3f;
        }

        void SetupHitbox()
        {
            foreach (Transform child in transform)
            {
                if (child.name.Contains("Hitbox"))
                {
                    var hitBoxGroup = model.AddComponent <HitBoxGroup>();
                    var hitBox      = child.gameObject.AddComponent <HitBox>();
                    hitBoxGroup.groupName = child.name;
                    hitBoxGroup.hitBoxes  = new HitBox[] { hitBox };
                }
            }
        }

        void SetupShaders()
        {
            foreach (Transform child in transform)
            {
                var renderer = child.gameObject.GetComponent <Renderer>();
                if (renderer)
                {
                    var material = CreateMaterial(renderer.material, 10, Color.white, 0);
                    renderer.material = material;
                }
            }
        }

        void SetupSkins()
        {
            //LanguageAPI.Add("NEMMANDO_DEFAULT_SKIN_NAME", "Default");

            var obj            = transform.gameObject;
            var mdl            = obj.GetComponent <CharacterModel>();
            var skinController = obj.AddComponent <ModelSkinController>();

            LoadoutAPI.SkinDefInfo skinDefInfo = new LoadoutAPI.SkinDefInfo
            {
                Name                        = "DEFAULT_SKIN",
                NameToken                   = "DEFAULT_SKIN",
                Icon                        = defaultSkinIcon,
                RootObject                  = obj,
                RendererInfos               = mdl.baseRendererInfos,
                GameObjectActivations       = Array.Empty <SkinDef.GameObjectActivation>(),
                MeshReplacements            = Array.Empty <SkinDef.MeshReplacement>(),
                BaseSkins                   = Array.Empty <SkinDef>(),
                MinionSkinReplacements      = Array.Empty <SkinDef.MinionSkinReplacement>(),
                ProjectileGhostReplacements = Array.Empty <SkinDef.ProjectileGhostReplacement>(),
                UnlockableName              = ""
            };


            CharacterModel.RendererInfo[] rendererInfos = skinDefInfo.RendererInfos;
            CharacterModel.RendererInfo[] array         = new CharacterModel.RendererInfo[rendererInfos.Length];
            rendererInfos.CopyTo(array, 0);

            array[0].defaultMaterial = masterySkinDelegate.Invoke();

            LoadoutAPI.SkinDefInfo masteryInfo = new LoadoutAPI.SkinDefInfo
            {
                Name                        = "DEFAULT_SKIN",
                NameToken                   = "DEFAULT_SKIN",
                Icon                        = defaultSkinIcon,
                RootObject                  = obj,
                RendererInfos               = array,
                GameObjectActivations       = Array.Empty <SkinDef.GameObjectActivation>(),
                MeshReplacements            = Array.Empty <SkinDef.MeshReplacement>(),
                BaseSkins                   = Array.Empty <SkinDef>(),
                MinionSkinReplacements      = Array.Empty <SkinDef.MinionSkinReplacement>(),
                ProjectileGhostReplacements = Array.Empty <SkinDef.ProjectileGhostReplacement>(),
                UnlockableName              = masteryAchievementUnlockable
            };

            SkinDef skinDefault = LoadoutAPI.CreateNewSkinDef(skinDefInfo);
            SkinDef mastery     = LoadoutAPI.CreateNewSkinDef(masteryInfo);

            SkinDef[] skinDefs = new SkinDef[2]
            {
                skinDefault,
                mastery
            };

            skinController.skins = skinDefs;
        }

        API.RegisterNewBody(prefab);

        return(prefab);
    }
Beispiel #13
0
        private void AddSkins(GameObject bodyObject)    //credits to rob
        {
            GameObject     bodyPrefab     = bodyObject;
            GameObject     model          = bodyPrefab.GetComponentInChildren <ModelLocator>().modelTransform.gameObject;
            CharacterModel characterModel = model.GetComponent <CharacterModel>();

            ModelSkinController skinController = null;

            if (model.GetComponent <ModelSkinController>())
            {
                skinController = model.GetComponent <ModelSkinController>();
            }
            else
            {
                skinController = model.AddComponent <ModelSkinController>();
            }

            SkinnedMeshRenderer mainRenderer = Reflection.GetFieldValue <SkinnedMeshRenderer>(characterModel, "mainSkinnedMeshRenderer");

            if (mainRenderer == null)
            {
                CharacterModel.RendererInfo[] bRI = Reflection.GetFieldValue <CharacterModel.RendererInfo[]>(characterModel, "baseRendererInfos");
                if (bRI != null)
                {
                    foreach (CharacterModel.RendererInfo rendererInfo in bRI)
                    {
                        if (rendererInfo.renderer is SkinnedMeshRenderer)
                        {
                            mainRenderer = (SkinnedMeshRenderer)rendererInfo.renderer;
                            break;
                        }
                    }
                    if (mainRenderer != null)
                    {
                        characterModel.SetFieldValue <SkinnedMeshRenderer>("mainSkinnedMeshRenderer", mainRenderer);
                    }
                }
            }

            LoadoutAPI.SkinDefInfo skinDefInfo = default(LoadoutAPI.SkinDefInfo);
            skinDefInfo.BaseSkins             = Array.Empty <SkinDef>();
            skinDefInfo.GameObjectActivations = Array.Empty <SkinDef.GameObjectActivation>();
            skinDefInfo.Icon             = LoadoutAPI.CreateSkinIcon(Color.white, Color.white, Color.white, Color.white);
            skinDefInfo.MeshReplacements = new SkinDef.MeshReplacement[]
            {
                new SkinDef.MeshReplacement
                {
                    renderer = mainRenderer,
                    mesh     = mainRenderer.sharedMesh
                }
            };
            skinDefInfo.Name                        = "PYRO_DEFAULT_SKIN_NAME";
            skinDefInfo.NameToken                   = "PYRO_DEFAULT_SKIN_NAME";
            skinDefInfo.RendererInfos               = characterModel.baseRendererInfos;
            skinDefInfo.RootObject                  = model;
            skinDefInfo.UnlockableName              = "";
            skinDefInfo.MinionSkinReplacements      = new SkinDef.MinionSkinReplacement[0];
            skinDefInfo.ProjectileGhostReplacements = new SkinDef.ProjectileGhostReplacement[0];

            SkinDef defaultSkin = LoadoutAPI.CreateNewSkinDef(skinDefInfo);

            skinController.skins = new SkinDef[1]
            {
                defaultSkin,
            };
        }