public static void CreateGhostModelPrefix(PlaceTool __instance, ref bool __state) { SnapBuilder.Config.ResetToggles(); __state = __instance.ghostModel == null; SnapBuilder.ShowSnappingHint(__state); }
// Token: 0x06002BA8 RID: 11176 RVA: 0x00104A5C File Offset: 0x00102C5C public static bool CanDestroyObject(GameObject go) { Player componentInParent = go.GetComponentInParent <Player>(); if (componentInParent != null) { return(false); } LargeWorldEntity component = go.GetComponent <LargeWorldEntity>(); if (component != null && component.cellLevel >= LargeWorldEntity.CellLevel.Global) { return(false); } SubRoot componentInParent2 = go.GetComponentInParent <SubRoot>(); if (componentInParent2 != null) { return(false); } Constructable componentInParent3 = go.GetComponentInParent <Constructable>(); if (componentInParent3 != null) { return(false); } IObstacle component2 = go.GetComponent <IObstacle>(); if (component2 != null) { return(false); } Pickupable component3 = go.GetComponent <Pickupable>(); if (component3 != null && component3.attached) { return(false); } PlaceTool component4 = go.GetComponent <PlaceTool>(); return(!(component4 != null)); }
//public abstract GameObject GetGameObject(); public virtual void RegisterItem() { if (this.IsRegistered == false && this.GameObject != null) { // Associate new recipe if (this.Recipe != null) { SMLHelper.V2.Handlers.CraftDataHandler.SetTechData(this.TechType, this.Recipe); } // Update PlaceTool parameters PrefabsHelper.SetDefaultPlaceTool(this.GameObject, null, null, false, false, true); PlaceTool placeTool = this.GameObject.GetComponent <GenericPlaceTool>(); if (placeTool == null) { placeTool = this.GameObject.GetComponent <PlaceTool>(); } if (placeTool != null) { if (this.TechType == TechType.Poster || this.TechType == TechType.PosterAurora || this.TechType == TechType.PosterExoSuit1 || this.TechType == TechType.PosterExoSuit2 || this.TechType == TechType.PosterKitty #if BELOWZERO || this.TechType == TechType.PosterSpyPenguin #endif ) { placeTool.allowedOnGround = false; placeTool.allowedOnWalls = true; placeTool.hasAnimations = false; placeTool.hasBashAnimation = false; placeTool.hasFirstUseAnimation = false; } else { placeTool.allowedOnGround = true; placeTool.allowedOnWalls = false; } } // Set the buildable prefab SMLHelper.V2.Handlers.PrefabHandler.RegisterPrefab(this); this.IsRegistered = true; } }
public override GameObject GetPrefab() { GameObject prefab = GameObject.Instantiate(this.GameObject); prefab.name = this.ClassID; // Update TechTag var techTag = prefab.GetComponent <TechTag>(); techTag.type = this.TechType; // Update prefab ID var prefabId = prefab.GetComponent <PrefabIdentifier>(); prefabId.ClassId = this.ClassID; // Remove rigid body Rigidbody rb = prefab.GetComponent <Rigidbody>(); GameObject.DestroyImmediate(rb); // Update large world entity LargeWorldEntity lwe = prefab.GetComponent <LargeWorldEntity>(); lwe.cellLevel = LargeWorldEntity.CellLevel.Near; // Adjust collider BoxCollider collider = prefab.GetComponentInChildren <BoxCollider>(); collider.size = new Vector3(collider.size.x, collider.size.y - 0.022f, collider.size.z); collider.center = new Vector3(collider.center.x, collider.center.y - 0.011f, collider.center.z); if (!ConfigSwitcher.EmptyDesk_asBuildable) { // We can pick this item Pickupable pickupable = prefab.AddComponent <Pickupable>(); pickupable.isPickupable = true; pickupable.randomizeRotationWhenDropped = true; // We can place this item PlaceTool placeTool = prefab.AddComponent <PlaceTool>(); placeTool.allowedInBase = true; placeTool.allowedOnBase = false; placeTool.allowedOnCeiling = false; placeTool.allowedOnConstructable = false; placeTool.allowedOnGround = true; placeTool.allowedOnRigidBody = true; placeTool.allowedOnWalls = false; placeTool.allowedOutside = false; placeTool.rotationEnabled = true; placeTool.enabled = true; placeTool.hasAnimations = false; placeTool.hasBashAnimation = false; placeTool.hasFirstUseAnimation = false; placeTool.mainCollider = collider; placeTool.pickupable = pickupable; // Add fabricating animation VFXFabricating fabricating = prefab.FindChild("Starship_work_desk_01_empty").AddComponent <VFXFabricating>(); fabricating.localMinY = -0.1f; fabricating.localMaxY = 0.9f; fabricating.posOffset = new Vector3(-0.06f, 0f, 0.04f); fabricating.eulerOffset = new Vector3(-90f, 0f, 0f); fabricating.scaleFactor = 0.35f; } else { // Set as constructible Constructable constructible = prefab.AddComponent <Constructable>(); constructible.techType = this.TechType; constructible.allowedOnWall = false; constructible.allowedInBase = true; constructible.allowedInSub = true; constructible.allowedOutside = false; constructible.allowedOnCeiling = false; constructible.allowedOnGround = true; constructible.allowedOnConstructables = false; constructible.deconstructionAllowed = true; constructible.controlModelState = true; constructible.model = prefab.FindChild("Starship_work_desk_01_empty"); } return(prefab); }
public static bool SetDefaultPlaceTool(GameObject gameObj, Collider mainCollider = null, Pickupable pickupable = null, bool onCeiling = false, bool onWalls = false, bool onBase = false, bool alignWithSurface = false) { if (gameObj == null) { return(false); } if (gameObj.GetComponent <CustomPlaceToolController>() == null) { gameObj.AddComponent <CustomPlaceToolController>(); } PlaceTool placeTool = gameObj.GetComponent <GenericPlaceTool>(); if (placeTool == null) { placeTool = gameObj.GetComponent <PlaceTool>(); } if (placeTool == null) { placeTool = gameObj.AddComponent <GenericPlaceTool>(); } placeTool.allowedInBase = true; placeTool.allowedOnBase = onBase; placeTool.allowedOnCeiling = onCeiling; placeTool.allowedOnConstructable = true; placeTool.allowedOnGround = true; placeTool.allowedOnRigidBody = true; placeTool.allowedOnWalls = onWalls; placeTool.allowedOutside = ConfigSwitcher.AllowPlaceOutside; #if BELOWZERO placeTool.allowedUnderwater = true; #endif placeTool.reloadMode = PlayerTool.ReloadMode.None; placeTool.socket = PlayerTool.Socket.RightHand; placeTool.rotationEnabled = true; placeTool.hasAnimations = false; placeTool.hasBashAnimation = false; placeTool.hasFirstUseAnimation = false; // Try get collider if (mainCollider == null) { mainCollider = gameObj.GetComponent <Collider>(); } if (mainCollider == null) { mainCollider = gameObj.GetComponentInChildren <Collider>(); } // Associate collider if (mainCollider != null) { placeTool.mainCollider = mainCollider; } // Try get pickupable if (pickupable == null) { pickupable = gameObj.GetComponent <Pickupable>(); } // Associate pickupable placeTool.pickupable = pickupable; placeTool.drawTime = 0.5f; placeTool.dropTime = 1f; placeTool.holsterTime = 0.35f; placeTool.bleederDamage = 3f; #if BELOWZERO placeTool.spikeyTrapDamage = 1f; #endif placeTool.ikAimLeftArm = false; placeTool.ikAimRightArm = false; placeTool.useLeftAimTargetOnPlayer = false; placeTool.alignWithSurface = alignWithSurface; placeTool.hideInvalidGhostModel = false; placeTool.hideFlags = HideFlags.None; placeTool.useGUILayout = true; placeTool.enabled = true; return(true); }
protected override void OnPrefabInit() { Instance = this; tooltip = GetComponent <ToolTip>(); }
public static void DestroyInstance() { Instance = null; }
public override GameObject GetPrefab() { GameObject prefab = GameObject.Instantiate(this.GameObject); GameObject model = prefab.FindChild("discovery_lab_cart_01"); prefab.name = this.ClassID; // Set TechTag TechTag techTag = prefab.AddComponent <TechTag>(); techTag.type = this.TechType; // Update prefab identifier PrefabIdentifier prefabId = prefab.GetComponent <PrefabIdentifier>(); prefabId.ClassId = this.ClassID; GameObject cube = prefab.FindChild("Cube"); GameObject.DestroyImmediate(cube); // Remove rigid body Rigidbody rb = prefab.GetComponent <Rigidbody>(); GameObject.DestroyImmediate(rb); // Add box collider BoxCollider collider = model.AddComponent <BoxCollider>(); collider.size = new Vector3(1.026103f, 0.6288151f, 0.91f); // -90X: Y<=>Z collider.center = new Vector3(0.005f, 0.001f, 0.455f); // -90X: Y<=>Z // Update large world entity LargeWorldEntity lwe = prefab.GetComponent <LargeWorldEntity>(); lwe.cellLevel = LargeWorldEntity.CellLevel.Near; // Get renderers Renderer[] rend = prefab.GetComponentsInChildren <Renderer>(); if (!ConfigSwitcher.LabCart_asBuildable) { // Set proper shaders for crafting animation foreach (Renderer renderer in rend) { renderer.material.shader = Shader.Find("MarmosetUBER"); } // We can pick this item Pickupable pickupable = prefab.AddComponent <Pickupable>(); pickupable.isPickupable = true; pickupable.randomizeRotationWhenDropped = true; // We can place this item PlaceTool placeTool = prefab.AddComponent <PlaceTool>(); placeTool.allowedInBase = true; placeTool.allowedOnBase = true; placeTool.allowedOnCeiling = false; placeTool.allowedOnConstructable = false; placeTool.allowedOnGround = true; placeTool.allowedOnRigidBody = true; placeTool.allowedOnWalls = false; placeTool.allowedOutside = false; placeTool.rotationEnabled = true; placeTool.enabled = true; placeTool.hasAnimations = false; placeTool.hasBashAnimation = false; placeTool.hasFirstUseAnimation = false; placeTool.mainCollider = collider; placeTool.pickupable = pickupable; // Add fabricating animation VFXFabricating fabricating = model.AddComponent <VFXFabricating>(); fabricating.localMinY = -0.1f; fabricating.localMaxY = 0.9f; fabricating.posOffset = new Vector3(0f, 0f, 0.04f); fabricating.eulerOffset = new Vector3(-90f, 0f, 0f); fabricating.scaleFactor = 0.5f; } else { // Set as constructible Constructable constructible = prefab.AddComponent <Constructable>(); constructible.techType = this.TechType; constructible.allowedOnWall = false; constructible.allowedInBase = true; constructible.allowedInSub = true; constructible.allowedOutside = false; constructible.allowedOnCeiling = false; constructible.allowedOnGround = true; constructible.allowedOnConstructables = false; constructible.deconstructionAllowed = true; constructible.controlModelState = true; constructible.model = model; // Add constructible bounds ConstructableBounds bounds = prefab.AddComponent <ConstructableBounds>(); } // Update sky applier SkyApplier applier = prefab.GetComponent <SkyApplier>(); applier.anchorSky = Skies.Auto; applier.renderers = rend; return(prefab); }
public static bool LateUpdatePrefix(PlaceTool __instance) { if (__instance.usingPlayer == null || !SnapBuilder.Config.Snapping.Enabled) { Inventory.main.quickSlots.SetIgnoreHotkeyInput(false); return(true); } Inventory.main.quickSlots.SetIgnoreHotkeyInput(__instance.rotationEnabled && SnapBuilder.Config.ToggleRotation.Enabled); Transform aimTransform = Builder.GetAimTransform(); RaycastHit hit; bool bHit = Physics.Raycast(aimTransform.position, aimTransform.forward, out hit, 5f, PlaceTool.placeLayerMask, QueryTriggerInteraction.Ignore); Vector3 position = __instance.ghostModel.transform.position; Quaternion rotation = __instance.ghostModel.transform.rotation; SnapBuilder.ApplyAdditiveRotation(ref __instance.additiveRotation, out var _); if (bHit) { bHit = SnapBuilder.TryGetSnappedHitPoint(PlaceTool.placeLayerMask, out hit, out Vector3 snappedHitPoint, out Vector3 snappedHitNormal); if (bHit) { position = snappedHitPoint; PlaceTool.SurfaceType surfaceType = PlaceTool.SurfaceType.Floor; if (Mathf.Abs(hit.normal.y) < 0.3f) { surfaceType = PlaceTool.SurfaceType.Wall; } else if (hit.normal.y < 0f) { surfaceType = PlaceTool.SurfaceType.Ceiling; } if (__instance.rotationEnabled) { // New calculation of the rotation rotation = SnapBuilder.CalculateRotation(ref __instance.additiveRotation, hit, snappedHitPoint, snappedHitNormal, true); } else { // Calculate rotation in the same manner as the original method Vector3 forward; if (__instance.alignWithSurface || surfaceType == PlaceTool.SurfaceType.Wall) { forward = hit.normal; } else { forward = new Vector3(-aimTransform.forward.x, 0f, -aimTransform.forward.z).normalized; } rotation = Quaternion.LookRotation(forward, Vector3.up); if (__instance.rotationEnabled) { rotation *= Quaternion.AngleAxis(__instance.additiveRotation, Vector3.up); } } switch (surfaceType) { case PlaceTool.SurfaceType.Floor: __instance.validPosition = __instance.allowedOnGround; break; case PlaceTool.SurfaceType.Wall: __instance.validPosition = __instance.allowedOnWalls; break; case PlaceTool.SurfaceType.Ceiling: __instance.validPosition = __instance.allowedOnCeiling; break; } } } if (!bHit) { // If there is no new hit, then the position we're snapping to isn't valid position = aimTransform.position + aimTransform.forward * 1.5f; rotation = Quaternion.LookRotation(-aimTransform.forward, Vector3.up); if (__instance.rotationEnabled) { rotation *= Quaternion.AngleAxis(__instance.additiveRotation, Vector3.up); } } __instance.ghostModel.transform.position = position; __instance.ghostModel.transform.rotation = rotation; if (bHit) { Rigidbody componentInParent = hit.collider.gameObject.GetComponentInParent <Rigidbody>(); __instance.validPosition = (__instance.validPosition && (componentInParent == null || componentInParent.isKinematic || __instance.allowedOnRigidBody)); } SubRoot currentSub = Player.main.GetCurrentSub(); bool isInside = Player.main.IsInsideWalkable(); if (bHit && hit.collider.gameObject.CompareTag("DenyBuilding")) { __instance.validPosition = false; } #if BELOWZERO if (!__instance.allowedUnderwater && hit.point.y < 0) { __instance.validPosition = false; } #endif if (bHit && ((__instance.allowedInBase && isInside) || (__instance.allowedOutside && !isInside))) { GameObject root = UWE.Utils.GetEntityRoot(hit.collider.gameObject); if (!root) { SceneObjectIdentifier identifier = hit.collider.GetComponentInParent <SceneObjectIdentifier>(); if (identifier) { root = identifier.gameObject; } else { root = hit.collider.gameObject; } } if (currentSub == null) { __instance.validPosition &= Builder.ValidateOutdoor(root); } if (!__instance.allowedOnConstructable) { __instance.validPosition &= root.GetComponentInParent <Constructable>() == null; } __instance.validPosition &= Builder.CheckSpace(position, rotation, PlaceTool.localBounds, PlaceTool.placeLayerMask, hit.collider); } else { __instance.validPosition = false; } MaterialExtensions.SetColor(__instance.renderers, ShaderPropertyID._Tint, __instance.validPosition ? PlaceTool.placeColorAllow : PlaceTool.placeColorDeny); if (__instance.hideInvalidGhostModel) { __instance.ghostModel.SetActive(__instance.validPosition); } return(false); }
public static void Postfix(PlaceTool __instance, bool __state) { SnapBuilder.ShowToggleRotationHint(__state && __instance.rotationEnabled); SnapBuilder.ShowToggleFineRotationHint(__state && __instance.rotationEnabled); SnapBuilder.ShowHolsterHint(__state && __instance.rotationEnabled); }