Exemplo n.º 1
0
        public static ConstructableBase TryPlaceBase(GameObject targetBaseGameObject)
        {
#pragma warning disable CS0618
            //Disabling warning as we dont have the FModAsset to use instead.
            Utils.PlayEnvSound(PLACE_SOUND, ghostModel.transform.position);
#pragma warning restore CS0618
            ConstructableBase componentInParent = ghostModel.GetComponentInParent <ConstructableBase>();
            BaseGhost         component         = ghostModel.GetComponent <BaseGhost>();
            component.GhostBase.transform.position = OverridePosition;
            component.Place();

            componentInParent.transform.position = OverridePosition;

            Transform transform = component.transform;
            transform.position = OverridePosition;
            transform.rotation = OverrideQuaternion;

            if (targetBaseGameObject)
            {
                Base targetBase = targetBaseGameObject.GetComponent <Base>();

                if (targetBase != null)
                {
                    component.targetBase = targetBase;
                    componentInParent.transform.SetParent(targetBase.transform, true);
                }
                else
                {
                    Log.Error("Could not find base component on the given game object: " + targetBaseGameObject.name);
                }
            }

            componentInParent.SetState(false);

            component.GhostBase.transform.position = OverridePosition;

            ghostModel       = null;
            prefab           = null;
            RotationMetadata = Optional.Empty;

            return(componentInParent);
        }
Exemplo n.º 2
0
        public static ConstructableBase TryPlaceBase(Optional <GameObject> opTargetBaseGameObject)
        {
            MultiplayerBuilder.Initialize();
            global::Utils.PlayEnvSound(MultiplayerBuilder.placeSound, MultiplayerBuilder.ghostModel.transform.position, 10f);
            ConstructableBase componentInParent = MultiplayerBuilder.ghostModel.GetComponentInParent <ConstructableBase>();
            BaseGhost         component         = MultiplayerBuilder.ghostModel.GetComponent <BaseGhost>();

            component.GhostBase.transform.position = overridePosition;
            component.Place();

            componentInParent.transform.position = overridePosition;

            component.transform.position = overridePosition;
            component.transform.rotation = overrideQuaternion;

            if (opTargetBaseGameObject.IsPresent())
            {
                GameObject targetBaseGameObject = opTargetBaseGameObject.Get();
                Base       targetBase           = targetBaseGameObject.GetComponent <Base>();

                if (targetBase != null)
                {
                    component.ReflectionSet("targetBase", targetBase);
                    componentInParent.transform.SetParent(targetBase.transform, true);
                }
                else
                {
                    Console.WriteLine("Could not find base component on the given game object");
                }
            }

            componentInParent.SetState(false, true);

            component.GhostBase.transform.position = overridePosition;

            MultiplayerBuilder.ghostModel = null;
            MultiplayerBuilder.prefab     = null;
            MultiplayerBuilder.canPlace   = false;

            return(componentInParent);
        }
Exemplo n.º 3
0
        public static ConstructableBase TryPlaceBase(GameObject targetBaseGameObject)
        {
            MultiplayerBuilder.Initialize();
            global::Utils.PlayEnvSound(MultiplayerBuilder.placeSound, MultiplayerBuilder.ghostModel.transform.position, 10f);
            ConstructableBase componentInParent = MultiplayerBuilder.ghostModel.GetComponentInParent <ConstructableBase>();
            BaseGhost         component         = MultiplayerBuilder.ghostModel.GetComponent <BaseGhost>();

            component.GhostBase.transform.position = overridePosition;
            component.Place();

            componentInParent.transform.position = overridePosition;

            component.transform.position = overridePosition;
            component.transform.rotation = overrideQuaternion;

            if (targetBaseGameObject)
            {
                Base targetBase = targetBaseGameObject.GetComponent <Base>();

                if (targetBase != null)
                {
                    component.targetBase = targetBase;
                    componentInParent.transform.SetParent(targetBase.transform, true);
                }
                else
                {
                    Log.Error("Could not find base component on the given game object: " + targetBaseGameObject.name);
                }
            }

            componentInParent.SetState(false, true);

            component.GhostBase.transform.position = overridePosition;

            MultiplayerBuilder.ghostModel = null;
            MultiplayerBuilder.prefab     = null;
            MultiplayerBuilder.canPlace   = false;

            return(componentInParent);
        }
Exemplo n.º 4
0
        // Token: 0x06002B9D RID: 11165
        public static bool TryPlace()
        {
            MultiplayerBuilder.Initialize();
            if (MultiplayerBuilder.prefab == null || !MultiplayerBuilder.canPlace)
            {
                return(false);
            }

            global::Utils.PlayEnvSound(MultiplayerBuilder.placeSound, MultiplayerBuilder.ghostModel.transform.position, 10f);
            ConstructableBase componentInParent = MultiplayerBuilder.ghostModel.GetComponentInParent <ConstructableBase>();

            if (componentInParent != null)
            {
                BaseGhost component = MultiplayerBuilder.ghostModel.GetComponent <BaseGhost>();
                component.GhostBase.transform.position = overridePosition;
                component.Place();

                componentInParent.transform.position = overridePosition;

                component.transform.position = overridePosition;
                component.transform.rotation = overrideQuaternion;
                if (component.TargetBase != null)
                {
                    componentInParent.transform.SetParent(component.TargetBase.transform, true);
                }

                componentInParent.SetState(false, true);

                component.GhostBase.transform.position = overridePosition;

                if (component.TargetBase != null)
                {
                    component.TargetBase.transform.position = overridePosition;
                }
            }
            else
            {
                GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(MultiplayerBuilder.prefab);
                bool       flag       = false;
                bool       flag2      = false;
                SubRoot    currentSub = Player.main.GetCurrentSub();
                if (currentSub != null)
                {
                    flag  = currentSub.isBase;
                    flag2 = currentSub.isCyclops;
                    gameObject.transform.parent = currentSub.GetModulesRoot();
                }
                else if (MultiplayerBuilder.placementTarget != null && MultiplayerBuilder.allowedOutside)
                {
                    SubRoot componentInParent2 = MultiplayerBuilder.placementTarget.GetComponentInParent <SubRoot>();
                    if (componentInParent2 != null)
                    {
                        gameObject.transform.parent = componentInParent2.GetModulesRoot();
                    }
                }

                Transform expr_138 = gameObject.transform;
                expr_138.position = MultiplayerBuilder.placePosition;
                expr_138.rotation = MultiplayerBuilder.placeRotation;
                Constructable componentInParent3 = gameObject.GetComponentInParent <Constructable>();
                componentInParent3.SetState(false, true);
                global::Utils.SetLayerRecursively(gameObject, LayerMask.NameToLayer((!flag) ? "Interior" : "Default"), true, -1);
                componentInParent3.SetIsInside(flag | flag2);
                SkyEnvironmentChanged.Send(gameObject, currentSub);
                gameObject.transform.position = overridePosition;
                gameObject.transform.rotation = overrideQuaternion;
            }

            MultiplayerBuilder.ghostModel = null;
            MultiplayerBuilder.prefab     = null;
            MultiplayerBuilder.canPlace   = false;
            return(true);
        }
Exemplo n.º 5
0
        // Token: 0x060030FF RID: 12543 RVA: 0x0012D7E8 File Offset: 0x0012B9E8
        public static bool TryPlace(out GameObject outObject, out Constructable outConstructable)
        {
            outObject        = null;
            outConstructable = null;

            MultiplayerBuilder.Initialize();

            if (MultiplayerBuilder.prefab == null)
            {
                return(false);
            }

            Utils.PlayEnvSound(MultiplayerBuilder.placeSound, MultiplayerBuilder.ghostModel.transform.position, 10f);
            ConstructableBase componentInParent = MultiplayerBuilder.ghostModel.GetComponentInParent <ConstructableBase>();

            if (componentInParent != null)
            {
                MultiplayerBuilder.Update();
                BaseGhost component = MultiplayerBuilder.ghostModel.GetComponent <BaseGhost>();

                component.Place();
                if (component.TargetBase != null)
                {
                    componentInParent.transform.SetParent(component.TargetBase.transform, true);
                }
                componentInParent.SetState(false, true);

                componentInParent.transform.position = overridePosition;
                componentInParent.transform.rotation = overrideRotation;

                outObject        = componentInParent.gameObject;
                outConstructable = componentInParent;
            }
            else
            {
                MultiplayerBuilder.placementTarget = GuidHelper.Find(targetGuid);

                GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(MultiplayerBuilder.prefab);
                bool       flag       = false;
                bool       flag2      = false;

                SubRoot currentSub = Player.main.GetCurrentSub();
                if (currentSub != null)
                {
                    flag  = currentSub.isBase;
                    flag2 = currentSub.isCyclops;
                    gameObject.transform.parent = currentSub.GetModulesRoot();
                }
                else if (MultiplayerBuilder.placementTarget != null && MultiplayerBuilder.allowedOutside)
                {
                    SubRoot componentInParent2 = MultiplayerBuilder.placementTarget.GetComponentInParent <SubRoot>();
                    if (componentInParent2 != null)
                    {
                        gameObject.transform.parent = componentInParent2.GetModulesRoot();
                    }
                }
                Transform transform = gameObject.transform;
                transform.localPosition = overridePosition;
                transform.localRotation = overrideRotation;

                Constructable componentInParent3 = gameObject.GetComponentInParent <Constructable>();
                componentInParent3.SetState(false, true);
                Utils.SetLayerRecursively(gameObject, LayerMask.NameToLayer((!flag) ? "Interior" : "Default"), true, -1);
                if (MultiplayerBuilder.ghostModel != null)
                {
                    UnityEngine.Object.Destroy(MultiplayerBuilder.ghostModel);
                }
                componentInParent3.SetIsInside(flag || flag2);
                SkyEnvironmentChanged.Send(gameObject, currentSub);

                transform.localPosition = overridePosition;
                transform.localRotation = overrideRotation;

                outObject        = gameObject;
                outConstructable = componentInParent3;
            }
            MultiplayerBuilder.ghostModel = null;
            MultiplayerBuilder.prefab     = null;
            MultiplayerBuilder.canPlace   = false;
            return(true);
        }