示例#1
0
        private void OnVehiclePrefabLoaded(GameObject prefab, string guid, Vector3 spawnPosition, Quaternion spawnRotation, Optional <List <InteractiveChildObjectIdentifier> > interactiveChildIdentifiers, Optional <string> dockingBayGuid)
        {
            // Partially copied from SubConsoleCommand.OnSubPrefabLoaded
            GameObject gameObject = Utils.SpawnPrefabAt(prefab, null, spawnPosition);

            gameObject.transform.rotation = spawnRotation;
            gameObject.SetActive(true);
            gameObject.SendMessage("StartConstruction", SendMessageOptions.DontRequireReceiver);
            CrafterLogic.NotifyCraftEnd(gameObject, CraftData.GetTechType(gameObject));
            Rigidbody rigidBody = gameObject.GetComponent <Rigidbody>();

            rigidBody.isKinematic = false;
            GuidHelper.SetNewGuid(gameObject, guid);
            if (interactiveChildIdentifiers.IsPresent())
            {
                VehicleChildObjectIdentifierHelper.SetInteractiveChildrenGuids(gameObject, interactiveChildIdentifiers.Get()); //Copy From ConstructorBeginCraftingProcessor
            }

            if (dockingBayGuid.IsPresent())
            {
                GameObject        dockingBayBase = GuidHelper.RequireObjectFrom(dockingBayGuid.Get());
                VehicleDockingBay dockingBay     = dockingBayBase.GetComponentInChildren <VehicleDockingBay>();

                Vehicle vehicle = gameObject.GetComponent <Vehicle>();

                dockingBay.DockVehicle(vehicle);
            }
        }
        public override void Process(ConstructorBeginCrafting packet)
        {
            GameObject gameObject = GuidHelper.RequireObjectFrom(packet.ConstructorGuid);
            Crafter    crafter    = gameObject.RequireComponentInChildren <Crafter>(true);

            vehicles.AddVehicle(VehicleModelFactory.BuildFrom(packet));
            MethodInfo onCraftingBegin = typeof(Crafter).GetMethod("OnCraftingBegin", BindingFlags.NonPublic | BindingFlags.Instance);

            Validate.NotNull(onCraftingBegin);
            onCraftingBegin.Invoke(crafter, new object[] { packet.TechType.Enum(), packet.Duration }); //TODO: take into account latency for duration

            Optional <object> opConstructedObject = TransientLocalObjectManager.Get(TransientObjectType.CONSTRUCTOR_INPUT_CRAFTED_GAMEOBJECT);

            if (opConstructedObject.IsPresent())
            {
                GameObject constructedObject = (GameObject)opConstructedObject.Get();
                constructedObject.AddComponent <NitroxEntity>();
                GuidHelper.SetNewGuid(constructedObject, packet.ConstructedItemGuid);
                VehicleChildObjectIdentifierHelper.SetInteractiveChildrenGuids(constructedObject, packet.InteractiveChildIdentifiers);
            }
            else
            {
                Log.Error("Could not find constructed object!");
            }
        }
示例#3
0
        public void UpdateVehicleChildren(string guid, List <InteractiveChildObjectIdentifier> interactiveChildrenGuids)
        {
            Optional <GameObject> Object = GuidHelper.GetObjectFrom(guid);

            if (Object.IsPresent())
            {
                GameObject T = Object.Get();
                VehicleChildObjectIdentifierHelper.SetInteractiveChildrenGuids(T, interactiveChildrenGuids);
            }
        }
示例#4
0
        private void OnVehiclePrefabLoaded(TechType techType, GameObject prefab, string guid, Vector3 spawnPosition, Quaternion spawnRotation, Optional <List <InteractiveChildObjectIdentifier> > interactiveChildIdentifiers, Optional <string> dockingBayGuid, string name, Vector3[] hsb, Vector3[] colours)
        {
            // Partially copied from SubConsoleCommand.OnSubPrefabLoaded
            GameObject gameObject = Utils.SpawnPrefabAt(prefab, null, spawnPosition);

            gameObject.transform.rotation = spawnRotation;
            gameObject.SetActive(true);
            gameObject.SendMessage("StartConstruction", SendMessageOptions.DontRequireReceiver);
            CrafterLogic.NotifyCraftEnd(gameObject, CraftData.GetTechType(gameObject));
            Rigidbody rigidBody = gameObject.GetComponent <Rigidbody>();

            rigidBody.isKinematic = false;
            GuidHelper.SetNewGuid(gameObject, guid);

            // Updates names and colours with persisted data .....yeah.....
            if (techType == TechType.Seamoth || techType == TechType.Exosuit)
            { // Seamoth & Prawn suit
                Vehicle vehicle = gameObject.GetComponent <Vehicle>();
                if (dockingBayGuid.IsPresent())
                {
                    GameObject        dockingBayBase = GuidHelper.RequireObjectFrom(dockingBayGuid.Get());
                    VehicleDockingBay dockingBay     = dockingBayBase.GetComponentInChildren <VehicleDockingBay>();
                    dockingBay.DockVehicle(vehicle);
                }

                if (!string.IsNullOrEmpty(name))
                {
                    vehicle.vehicleName = name;
                    vehicle.subName.DeserializeName(vehicle.vehicleName);
                }

                if (colours != null)
                {
                    Vector3[] colour = new Vector3[5];

                    for (int i = 0; i < hsb.Length; i++)
                    {
                        colour[i] = hsb[i];
                    }
                    vehicle.vehicleColors = colour;
                    vehicle.subName.DeserializeColors(vehicle.vehicleColors);
                }
            }
            else if (techType == TechType.Cyclops) // Cyclops
            {
                GameObject   target        = GuidHelper.RequireObjectFrom(guid);
                SubNameInput subNameInput  = target.RequireComponentInChildren <SubNameInput>();
                SubName      subNameTarget = (SubName)subNameInput.ReflectionGet("target");
                subNameInput.OnNameChange(name);
                for (int i = 0; i < hsb.Length; i++)
                {
                    subNameInput.SetSelected(i);
                    Color tmpColour = new Vector4(colours[i].x, colours[i].y, colours[i].z);
                    subNameTarget.SetColor(i, hsb[i], tmpColour);
                    subNameTarget.DeserializeColors(hsb);
                }
            }

            if (interactiveChildIdentifiers.IsPresent())
            {
                VehicleChildObjectIdentifierHelper.SetInteractiveChildrenGuids(gameObject, interactiveChildIdentifiers.Get()); //Copy From ConstructorBeginCraftingProcessor
            }
        }