public static List <MysticsItemsSpotterHighlight> Create(CharacterBody targetBody, TeamIndex teamIndex) { List <MysticsItemsSpotterHighlight> components = new List <MysticsItemsSpotterHighlight>(); foreach (CameraRigController cameraRigController in CameraRigController.readOnlyInstancesList) { if (TeamComponent.GetObjectTeam(cameraRigController.targetBody.gameObject) == teamIndex) { MysticsItemsSpotterHighlight component = Object.Instantiate <GameObject>(highlightPrefab).GetComponent <MysticsItemsSpotterHighlight>(); component.targetBody = targetBody; component.canvas.worldCamera = cameraRigController.uiCam; component.uiCam = cameraRigController.uiCam; component.sceneCam = cameraRigController.sceneCam; components.Add(component); } } return(components); }
public void SetTarget(GameObject newTarget) { ClearTarget(); if (NetworkServer.active) { new SyncSetTarget(gameObject.GetComponent <NetworkIdentity>().netId, newTarget.GetComponent <NetworkIdentity>().netId).Send(NetworkDestination.Clients); } CharacterBody newTargetBody = newTarget.GetComponent <CharacterBody>(); if (newTargetBody) { target = newTargetBody; highlights = highlights.Concat(MysticsItemsSpotterHighlight.Create(target, TeamComponent.GetObjectTeam(body.gameObject))).ToList(); if (NetworkServer.active) { target.AddTimedBuff(buffDef, duration); } } }
public override void OnLoad() { base.OnLoad(); itemDef.name = "MysticsItems_Spotter"; SetItemTierWhenAvailable(ItemTier.Tier2); itemDef.tags = new ItemTag[] { ItemTag.Damage }; MysticsItemsContent.Resources.unlockableDefs.Add(GetUnlockableDef()); itemDef.pickupModelPrefab = PrepareModel(Main.AssetBundle.LoadAsset <GameObject>("Assets/Items/Spotter/Model.prefab")); itemDef.pickupIconSprite = Main.AssetBundle.LoadAsset <Sprite>("Assets/Items/Spotter/Icon.png"); Material mat = itemDef.pickupModelPrefab.transform.Find("mdlSpotterBroken").gameObject.GetComponent <MeshRenderer>().sharedMaterial; HopooShaderToMaterial.Standard.Apply(mat); HopooShaderToMaterial.Standard.Gloss(mat, 0.2f, 1f); HopooShaderToMaterial.Standard.Emission(mat, 1f); itemDisplayPrefab = PrepareItemDisplayModel(PrefabAPI.InstantiateClone(itemDef.pickupModelPrefab, itemDef.pickupModelPrefab.name + "Display", false)); MysticsRisky2Utils.Utils.CopyChildren(itemDef.pickupModelPrefab, unlockInteractablePrefab); ModelPanelParameters modelPanelParameters = itemDef.pickupModelPrefab.GetComponent <ModelPanelParameters>(); modelPanelParameters.minDistance = 6f; modelPanelParameters.maxDistance = 12f; itemDisplayPrefab.transform.localScale = Vector3.one * 0.2f; itemDisplayPrefab.transform.localRotation = Quaternion.Euler(new Vector3(0f, -90f, 0f)); Rigidbody rigidbody = enemyFollowerPrefab.AddComponent <Rigidbody>(); rigidbody.useGravity = false; enemyFollowerPrefab.AddComponent <GenericOwnership>(); MysticsItemsSpotterController component = enemyFollowerPrefab.AddComponent <MysticsItemsSpotterController>(); component.follower = PrefabAPI.InstantiateClone(itemDisplayPrefab, "SpotterFollower", false); component.follower.transform.SetParent(enemyFollowerPrefab.transform); SimpleLeash leash = component.leash = enemyFollowerPrefab.AddComponent <SimpleLeash>(); leash.minLeashRadius = 0f; leash.maxLeashRadius = Mathf.Infinity; leash.smoothTime = 0.2f; SimpleRotateToDirection rotateToDirection = component.rotateToDirection = enemyFollowerPrefab.AddComponent <SimpleRotateToDirection>(); rotateToDirection.maxRotationSpeed = 720f; rotateToDirection.smoothTime = 0.1f; unlockInteractablePrefab.transform.localScale *= 0.4f; unlockInteractablePrefab.AddComponent <MysticsItemsSpotterUnlockInteraction>(); GameObject sparks = PrefabAPI.InstantiateClone(LegacyResourcesAPI.Load <GameObject>("Prefabs/NetworkedObjects/RadarTower").transform.Find("mdlRadar").Find("Sparks").gameObject, "Sparks", false); sparks.transform.localPosition = new Vector3(0f, 1f, 0f); ParticleSystem.MainModule particleSystem = sparks.GetComponentInChildren <ParticleSystem>().main; particleSystem.scalingMode = ParticleSystemScalingMode.Hierarchy; sparks.transform.SetParent(unlockInteractablePrefab.transform); Highlight highlight = unlockInteractablePrefab.AddComponent <Highlight>(); highlight.targetRenderer = unlockInteractablePrefab.GetComponentInChildren <Renderer>(); highlight.highlightColor = Highlight.HighlightColor.interactive; PurchaseInteraction purchaseInteraction = unlockInteractablePrefab.AddComponent <PurchaseInteraction>(); purchaseInteraction.displayNameToken = "MYSTICSITEMS_BROKENSPOTTER_NAME"; purchaseInteraction.contextToken = "MYSTICSITEMS_BROKENSPOTTER_CONTEXT"; purchaseInteraction.costType = CostTypeIndex.VolatileBattery; purchaseInteraction.available = true; purchaseInteraction.cost = 1; purchaseInteraction.automaticallyScaleCostWithDifficulty = false; purchaseInteraction.requiredUnlockable = ""; purchaseInteraction.setUnavailableOnTeleporterActivated = false; GameObject entityLocatorHolder = unlockInteractablePrefab.transform.Find("EntityLocatorHolder").gameObject; entityLocatorHolder.layer = LayerIndex.pickups.intVal; SphereCollider sphereCollider = entityLocatorHolder.AddComponent <SphereCollider>(); sphereCollider.radius = 12f; sphereCollider.isTrigger = true; entityLocatorHolder.AddComponent <EntityLocator>().entity = unlockInteractablePrefab; On.RoR2.SceneDirector.PopulateScene += (orig, self) => { orig(self); if (SceneCatalog.GetSceneDefForCurrentScene().baseSceneName == "rootjungle") { GameObject obj = Object.Instantiate(unlockInteractablePrefab, new Vector3(-139.576f, -0.824233f - 1f, 35.42688f), Quaternion.Euler(new Vector3(-29f, 25f, 348f))); NetworkServer.Spawn(obj); } }; On.RoR2.CharacterBody.Awake += (orig, self) => { orig(self); self.onInventoryChanged += delegate() { if (NetworkServer.active) { self.AddItemBehavior <MysticsItemsSpotterBehaviour>(self.inventory.GetItemCount(MysticsItemsContent.Items.MysticsItems_Spotter)); } }; }; repairSoundEventDef = ScriptableObject.CreateInstance <NetworkSoundEventDef>(); repairSoundEventDef.eventName = "Play_drone_repair"; MysticsItemsContent.Resources.networkSoundEventDefs.Add(repairSoundEventDef); highlightPrefab = Main.AssetBundle.LoadAsset <GameObject>("Assets/Items/Spotter/SpotterTargetHighlight.prefab"); MysticsItemsSpotterHighlight highlightComponent = highlightPrefab.AddComponent <MysticsItemsSpotterHighlight>(); highlightComponent.insideViewObject = highlightPrefab.transform.Find("Pivot").gameObject; highlightComponent.outsideViewObject = highlightPrefab.transform.Find("PivotOutsideView").gameObject; highlightComponent.textTargetName = highlightPrefab.transform.Find("Pivot/Rectangle/Enemy Name").gameObject.GetComponent <TextMeshProUGUI>(); highlightComponent.textTargetName.gameObject.AddComponent <MysticsRisky2Utils.MonoBehaviours.MysticsRisky2UtilsTextMeshUseLanguageDefaultFont>(); highlightComponent.textTargetHP = highlightPrefab.transform.Find("Pivot/Rectangle/Health").gameObject.GetComponent <TextMeshProUGUI>(); highlightComponent.textTargetHP.gameObject.AddComponent <MysticsRisky2Utils.MonoBehaviours.MysticsRisky2UtilsTextMeshUseLanguageDefaultFont>(); RoR2Application.onLateUpdate += MysticsItemsSpotterHighlight.UpdateAll; }