private void Client_SpawnGameObject(ClientBase sender, SpawnGameObject packet) { Console.WriteLine(packet); //To avoid duplicates and possibly infinite spawn loop. if (gameObjects.ContainsKey(packet.UID)) { return; } GameObject gameObject = ObjectInstantiator.Instantiate((Objects)packet.ObjType); gameObject.name = packet.name; gameObject.UID = packet.UID; if (packet.parentUID == 0) { world.AddChild(gameObject, false); } else { gameObjects[packet.parentUID].AddChild(gameObject, false); //TODO: It errors here with gameObjects[packet.parentUID] not existing, but it happens randomly } gameObjects[gameObject.UID] = gameObject; //TODO: MOVE THIS CODE ELSEWHERE Game1.worldActionScript.SetVariable(new string[] { gameObject.name }, new Dictionary <string, object>()); Game1.worldActionScript.SetVariable(new string[] { gameObject.name, "object" }, gameObject); }
private void Client_SpawnGameObject(ClientBase sender, SpawnGameObject packet) { //To avoid duplicates and possibly infinite spawn loop. //TODO: Restrict the amount of temp ids. if (gameObjects.ContainsKey(packet.UID)) { return; //Send back an error. } if (!clientObjectIdsToServerObjectIds.ContainsKey(sender)) { clientObjectIdsToServerObjectIds.Add(sender, new Dictionary <int, int>()); } Dictionary <int, int> clientToServerIds = clientObjectIdsToServerObjectIds[sender]; GameObject gameObject = ObjectInstantiator.Instantiate((Objects)packet.ObjType); gameObject.UID = GenerateFreeId(); clientToServerIds[packet.UID] = gameObject.UID; sender.Send(new ChangeGameObjectUID() { oldUID = packet.UID, newUID = gameObject.UID }); if (packet.parentUID == 0) { world.AddChild(gameObject); } else { gameObjects[clientToServerIds[packet.parentUID]].AddChild(gameObject); } }
void CreateNewForm(int level, FormRotation formRotation) { Log.Message("Создание новой формы."); var prefab = ResourceLoader.Load <GameObject>(path, nameTemplate + level, null); var instantiatedForm = ObjectInstantiator.Instantiate(prefab, transform, transform.position, Quaternion.Euler(0, 90, 0)); if (instantiatedForm == null) { return; } currentForm = instantiatedForm; GetComponent <FormColorizer>().Colorize(currentForm); formRotation.RotateByAngle(currentForm.transform, angleY: -90, rotationSpeed: animationSpeed); }
public GameObject Generate() { Log.Message("Генерация сферы."); if (randomGenerationX) { spawnPosition.x = Random.Range(-spawnPositionXThreshold, spawnPositionXThreshold); } else { spawnPosition.x = 0; } var generatedOrb = ObjectInstantiator.Instantiate(prefab, transform, spawnPosition, Quaternion.identity); Log.Message("Сфера сгенерирована в позиции " + spawnPosition); return(generatedOrb); }
private void Lang_ComponentAddBinder(string objectName, string componentName) { if (objectName != "$$TEMP$$" + tempObjectId) { instantiateInstructions[objectName] += () => Lang_ComponentAddBinder("$$TEMP$$" + tempObjectId, componentName); if (dontSpawnList.Contains(objectName) || objectName == PlayerObject) { return; } } GameObject gameObject = gameObjects[objectName]; switch (componentName) { case "dontSpawn": { //TODO: Add a check to make sure this is topmost. if (!objectName.StartsWith("$$TEMP$$")) { dontSpawnList.Add(objectName); } } break; case "draggable": if (gameObject.GetFirst <MouseClickableComponent>() == null) { gameObject.AddChild(new MouseClickableComponent()); } gameObject.AddChild(new DragComponent()); break; default: gameObject.AddChild(ObjectInstantiator.Instantiate(componentName)); break; } }