Ejemplo n.º 1
0
        public override GameObject GetGameObject()
        {
            GameObject prefab = GameObject.Instantiate(this.GameObject);

            prefab.name = this.ClassID;

            if (!ConfigSwitcher.AlienRelic6Animation)
            {
                prefab.GetComponentInChildren <Animator>().enabled = false;
            }

            // Get objects
            GameObject relicCtrl = prefab.FindChild("alien_relic_02_core_ctrl");

            // Move
            relicCtrl.transform.localPosition = new Vector3(relicCtrl.transform.localPosition.x, relicCtrl.transform.localPosition.y + 0.22f, relicCtrl.transform.localPosition.z);

            // Update TechTag
            var techTag = prefab.GetComponent <TechTag>();

            techTag.type = this.TechType;

            // Update EntityTag
            var entityTag = prefab.GetComponent <EntityTag>();

            entityTag.slotType = EntitySlot.Type.Small;

            // Update prefab ID
            var prefabId = prefab.GetComponent <PrefabIdentifier>();

            prefabId.ClassId = this.ClassID;

            // Remove rigid body to prevent bugs
            //GameObject.DestroyImmediate(prefab.GetComponent<Rigidbody>());
            //var rb = prefab.GetComponent<Rigidbody>();
            //rb.mass = 0.0f;
            //rb.detectCollisions = false;

            // Update sky applier
            var applier = prefab.GetComponent <SkyApplier>();

            applier.anchorSky    = Skies.Auto;
            applier.updaterIndex = 0;

            // Adjust colliders
            var collider = prefab.GetComponent <CapsuleCollider>();

            collider.radius    = 0.1f;
            collider.height    = 0.16f;
            collider.center    = new Vector3(0f, 0.08f, 0f);
            collider.isTrigger = true;
            var sCollider = prefab.GetComponentInChildren <SphereCollider>();

            sCollider.radius   *= 0.5f;
            sCollider.isTrigger = true;
            var bCollider = prefab.GetComponentInChildren <BoxCollider>();

            bCollider.size      = new Vector3(2f, 2f, 2f);
            bCollider.center    = Vector3.zero;
            bCollider.isTrigger = true;
            Targeting.AddToIgnoreList(bCollider.transform.parent);

            // We can pick this item
            var pickupable = prefab.AddComponent <Pickupable>();

            pickupable.isPickupable = true;
            pickupable.randomizeRotationWhenDropped = true;

            // We can place this item
            prefab.AddComponent <CustomPlaceToolController>();
            var placeTool = prefab.AddComponent <GenericPlaceTool>();

            placeTool.allowedInBase          = true;
            placeTool.allowedOnBase          = true;
            placeTool.allowedOnCeiling       = true;
            placeTool.allowedOnConstructable = true;
            placeTool.allowedOnGround        = true;
            placeTool.allowedOnRigidBody     = true;
            placeTool.allowedOnWalls         = true;
            placeTool.allowedOutside         = ConfigSwitcher.AllowPlaceOutside;
            placeTool.rotationEnabled        = true;
            placeTool.enabled              = true;
            placeTool.hasAnimations        = false;
            placeTool.hasBashAnimation     = false;
            placeTool.hasFirstUseAnimation = false;
            placeTool.mainCollider         = collider;
            placeTool.pickupable           = pickupable;

            // Add fabricating animation
            var fabricating = prefab.AddComponent <VFXFabricating>();

            fabricating.localMinY   = -0.2f;
            fabricating.localMaxY   = 0.8f;
            fabricating.posOffset   = new Vector3(0f, 0f, 0f);
            fabricating.eulerOffset = new Vector3(0f, 0f, 0f);
            fabricating.scaleFactor = 0.7f;

            return(prefab);
        }
        private void HandleInput()
        {
            if (handleInputFrame == Time.frameCount)
            {
                return;
            }
            handleInputFrame = Time.frameCount;
            if (!AvatarInputHandler.main.IsEnabled())
            {
                return;
            }
            bool flag = TryDisplayNoPowerTooltip();

            if (flag)
            {
                return;
            }
            Targeting.AddToIgnoreList(Player.main.gameObject);
            Targeting.GetTarget(60f, out GameObject gameObject, out float num);
            if (gameObject == null)
            {
                return;
            }
            bool          buttonHeld    = GameInput.GetButtonHeld(GameInput.Button.LeftHand);
            bool          buttonDown    = GameInput.GetButtonDown(GameInput.Button.Deconstruct);
            bool          buttonHeld2   = GameInput.GetButtonHeld(GameInput.Button.Deconstruct);
            bool          quickbuild    = GameInput.GetButtonHeld(GameInput.Button.Sprint);
            Constructable constructable = gameObject.GetComponentInParent <Constructable>();

            if (constructable != null && num > constructable.placeMaxDistance * 2)
            {
                constructable = null;
            }
            if (constructable != null)
            {
                OnHover(constructable);
                if (buttonHeld)
                {
                    Construct(constructable, true);
                    if (quickbuild)
                    {
                        Construct(constructable, true);
                        Construct(constructable, true);
                        Construct(constructable, true);
                    }
                }
                else if (constructable.DeconstructionAllowed(out string text))
                {
                    if (buttonHeld2)
                    {
                        if (constructable.constructed)
                        {
                            constructable.SetState(false, false);
                        }
                        else
                        {
                            Construct(constructable, false);
                            if (quickbuild)
                            {
                                Construct(constructable, false);
                                Construct(constructable, false);
                                Construct(constructable, false);
                            }
                        }
                    }
                }
                else if (buttonDown && !string.IsNullOrEmpty(text))
                {
                    ErrorMessage.AddMessage(text);
                }
            }
            else
            {
                BaseDeconstructable baseDeconstructable = gameObject.GetComponentInParent <BaseDeconstructable>();
                if (baseDeconstructable == null)
                {
                    BaseExplicitFace componentInParent = gameObject.GetComponentInParent <BaseExplicitFace>();
                    if (componentInParent != null)
                    {
                        baseDeconstructable = componentInParent.parent;
                    }
                }
                else
                {
                    if (baseDeconstructable.DeconstructionAllowed(out string text))
                    {
                        OnHover(baseDeconstructable);
                        if (buttonDown)
                        {
                            baseDeconstructable.Deconstruct();
                        }
                    }
                    else if (buttonDown && !string.IsNullOrEmpty(text))
                    {
                        ErrorMessage.AddMessage(text);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        //=====================================================================
        // HandleInput
        //
        // Called by Update. Checks for input events and operates the Builder
        // accordingly
        //=====================================================================
        private void HandleInput()
        {
            if (this.handleInputFrame == Time.frameCount)
            {
                return;
            }
            this.handleInputFrame = Time.frameCount;
            if (Builder.isPlacing || !AvatarInputHandler.main.IsEnabled())
            {
                return;
            }
            Targeting.AddToIgnoreList(Player.main.gameObject);
            GameObject gameObject;
            float      num;

            // Range increased to 40 to give the seamoth more room
            Targeting.GetTarget(hitRange, out gameObject, out num, null);
            if (gameObject == null)
            {
                return;
            }
            // Bring up the construct menu on alt tool use
            //      (because the seamoth has lights bound to right hand)
            if (GameInput.GetButtonDown(GameInput.Button.AltTool))
            {
                uGUI_BuilderMenu.Show();
                return;
            }
            bool          constructHeld   = GameInput.GetButtonHeld(GameInput.Button.LeftHand);
            bool          deconstructDown = GameInput.GetButtonDown(GameInput.Button.Deconstruct);
            bool          deconstructHeld = GameInput.GetButtonHeld(GameInput.Button.Deconstruct);
            Constructable constructable   = gameObject.GetComponentInParent <Constructable>();

            if (constructable != null && num > constructable.placeMaxDistance)
            {
                constructable = null;
            }
            if (constructable != null)
            {
                this.OnHover(constructable);
                string text;
                if (constructHeld)
                {
                    this.Construct(constructable, true);
                }
                else if (constructable.DeconstructionAllowed(out text))
                {
                    if (deconstructHeld)
                    {
                        if (constructable.constructed)
                        {
                            constructable.SetState(false, false);
                        }
                        else
                        {
                            this.Construct(constructable, false);
                        }
                    }
                }
                else if (deconstructDown && !string.IsNullOrEmpty(text))
                {
                    ErrorMessage.AddMessage(text);
                }
            }
            else
            {
                BaseDeconstructable baseDeconstructable = gameObject.GetComponentInParent <BaseDeconstructable>();
                if (baseDeconstructable == null)
                {
                    BaseExplicitFace componentInParent = gameObject.GetComponentInParent <BaseExplicitFace>();
                    if (componentInParent != null)
                    {
                        baseDeconstructable = componentInParent.parent;
                    }
                }
                if (baseDeconstructable != null)
                {
                    string text;
                    if (baseDeconstructable.DeconstructionAllowed(out text))
                    {
                        this.OnHover(baseDeconstructable);
                        if (deconstructDown)
                        {
                            baseDeconstructable.Deconstruct();
                        }
                    }
                    else if (deconstructDown && !string.IsNullOrEmpty(text))
                    {
                        ErrorMessage.AddMessage(text);
                    }
                }
            }
        }