void Awake() { ItsRandom.setRandomSeed(1234567890, "bags"); ItsRandom.setRandomSeed(987654321, "people"); // "Download" people config - TODO - this should be done elsewhere, preloaded per mission string peopleConfigUrl = "http://samlingar.com/whatareyoucarryingsir/example-people-config-2.xml"; StartCoroutine(loadPeopleConfig(peopleConfigUrl)); // Set framerate only for editor - Should do based on device later?! //#if UNITY_EDITOR QualitySettings.vSyncCount = 0; // VSync must be disabled Application.targetFrameRate = 90; //#endif Game.instance = this; CameraHandler.SetPerspectiveCamera(gameCamera); swipeRecognizer = new TKSwipeRecognizer(); twoTapRecognizer = new TKTapRecognizer(); tapRecognizer = new TKTapRecognizer(); continousHoldRecognizer = new TKContinousHoldRecognizer(); // Last in line for click triggering PubSub.subscribe("Click", this, Int32.MaxValue); pauseGame(true); }
private void createNewPerson() { Vector3 startPoint = currentXrayMachine.bagDropPoint + currentXrayMachine.transform.position; startPoint.z = 5; Person newPerson = Instantiate(personPrefab, startPoint, Quaternion.identity); newPerson.setConfig(getNextPersonConfig()); newPerson.setRandomSeeds(ItsRandom.popRandomTypeForParentType("people"), ItsRandom.popRandomTypeForParentType("bags")); newPerson.greetingPositionX = currentXrayMachine.scanRight; float walkingManStartPositionRelativePersonCube = 20f; Vector3 walkingManStartPoint = new Vector3(startPoint.x - walkingManStartPositionRelativePersonCube, 0, startPoint.z + 12); WalkingMan newWalkingMan = Instantiate(walkingMan, walkingManStartPoint, walkingMan.transform.rotation); newWalkingMan.person = newPerson; newPerson.walkingMan = newWalkingMan; newPerson.soundObject = newWalkingMan.spawningSoundObject; Vector3 bagDropPositionRelativeXrayMachine = currentXrayMachine.bagDropPoint; Vector3 bagDropPosition = Misc.getWorldPosForParentRelativePos(bagDropPositionRelativeXrayMachine, currentXrayMachine.transform); newPerson.startPlaceBags(bagHandler, bagDropPosition); allPeople.Add(newPerson); }
public static bool randomBool(string type = DEFAULT_TYPE) { bool randomVal = getRandomObj(type).NextDouble() < 0.5d; ItsRandom.PrintStack(randomVal, type); return(randomVal); }
public void assign() { var randomText = ItsRandom.pickRandom(texts.ToList()); objectWithText1.text = randomText; objectWithText2.text = randomText; }
public static int randomRange(int min, int max, string type = DEFAULT_TYPE) { int randomVal = getRandomObj(type).Next(min, max); ItsRandom.PrintStack(randomVal, type); return(randomVal); }
public void assign() { Material picked = ItsRandom.pickRandom(materials.ToList()); objectToSetMaterial.material = picked; objectToSetMaterial.materialIndex = materialIndex; }
private void buildMission() { MissionConfig mission = MissionConfig.Instance; // Pick the correct X-ray machine string locationXrayMachineName = room.GetComponent <Room>().setLocation(mission.location); GameObject locationXrayMachine = null; foreach (GameObject xrayMachine in xrayMachines) { if (xrayMachine.name == locationXrayMachineName) { locationXrayMachine = xrayMachine; break; } } if (locationXrayMachine == null) { locationXrayMachine = xrayMachines[0]; } GameObject xrayMachineGameObject = Instantiate(locationXrayMachine, locationXrayMachine.transform.position, Quaternion.identity); currentXrayMachine = xrayMachineGameObject.GetComponent <XRayMachine> (); currentXrayMachine.attachConnectingConveyors(); // Pick the correct time piece GameObject locationClock = null; foreach (GameObject clock in clocks) { if (clock.name == mission.clockType) { locationClock = clock; break; } } if (locationClock == null) { locationClock = clocks[0]; } GameObject clockObject = Instantiate(locationClock); currentClock = clockObject.GetComponent <Clock> (); currentClock.setTime(mission.startTime); currentClock.speed = mission.timeSpeed; currentClock.notifyOnTime(mission.endTime); PubSub.subscribe("MISSION_TIME_END", this); currentClock.setRandomPosition = false; currentClock.clockPosition = mission.clockPosition; // Set the encounter and bag seeds ItsRandom.setRandomSeeds(mission.seedsConfig.bags, "bags"); ItsRandom.setRandomSeeds(mission.seedsConfig.people, "people"); }
public static K pickRandomKey <K, V>(Dictionary <K, V> dict, string type = DEFAULT_TYPE) { if (dict.Count > 0) { return(dict.ElementAt(ItsRandom.randomRange(0, dict.Count, type)).Key); } return(default(K)); }
public static T pickRandom <T>(List <T> list, string type = DEFAULT_TYPE) { if (list.Count > 0) { return(list[ItsRandom.randomRange(0, list.Count, type)]); } return(default(T)); }
public static float randomRange(float min, float max, string type = DEFAULT_TYPE) { double value = getRandomObj(type).NextDouble(); float randomVal = min + (max - min) * (float)value; ItsRandom.PrintStack(randomVal, type); return(randomVal); }
public Generic.CONSEQUENCE getConsequence() { if (consequences.Length > 0) { return(consequences[ItsRandom.randomRange(0, consequences.Length)]); } return(Generic.CONSEQUENCE.NOTHING); }
// Start is called before the first frame update void Awake() { AudioSource audioSource = GetComponent <AudioSource>(); audioSource.time = ItsRandom.randomRange(0, audioSource.clip.length - 1); // Debug.Log(audioSource.time); // Debug.Log(audioSource.clip.length); }
private IEnumerator reactOnAction(string action) { yield return(new WaitForSeconds(ItsRandom.randomRange(0.5f, 1.5f, personRandom))); List <AudioClip> reactionAudioClips = clips.FindAll(i => i.name.Contains(action + "-")); yield return(playVoice(ItsRandom.pickRandom(reactionAudioClips, personRandom))); }
public void run() { Vector3 chosenScale = ItsRandom.pickRandom(possibleScales.ToList()); BagContentProperties bagContentProperties = this.GetComponent <BagContentProperties>(); bagContentProperties.objectSize = Vector3.Scale(bagContentProperties.objectSize, chosenScale); bagContentProperties.transform.localScale = chosenScale; bagContentProperties.GetComponent <Rigidbody>().mass = chosenScale.magnitude; }
public void reportPositionX(float positionX) { targetPositionX = positionX; if (targetPositionX > transform.position.x && timeLeftToMoveTowardsBag == 0f && !isWalking) { timeLeftToMoveTowardsBag = ItsRandom.randomRange(MAX_TIME_TO_WAIT_TO_CATCHUP - 0.5f, MAX_TIME_TO_WAIT_TO_CATCHUP + 0.5f); } }
public void reportToAuthorities() { // TODO - was it really a mistake to "report person"? worstMistake = "false arrest"; playVoice(ItsRandom.pickRandom(clips.FindAll(i => i.name.StartsWith("false_arrest-")), personRandom)); bagDefinition.bags.ForEach(bag => bag.bagFinished(false)); passport.animateAndDestroy(); Destroy(walkingMan.gameObject); finishPerson(); }
public void assign() { MeshAndPosition randomMeshAndPosition = ItsRandom.pickRandom(meshesAndPositions.ToList()); foreach (AssignMeshAndPositionToObject objectToSetMeshAndPosition in objectsToSetMeshAndPosition) { objectToSetMeshAndPosition.mesh = randomMeshAndPosition.mesh; objectToSetMeshAndPosition.position = randomMeshAndPosition.position; } }
public Tuple2 <string, string> getRandomBook() { if (books.Count > 0) { Tuple2 <string, string> book = ItsRandom.pickRandom(books, personRandom); int bookIndex = books.IndexOf(book); books.RemoveAt(bookIndex); return(book); } return(null); }
public void Start() { ClockPositions clockPositions = GetComponent <ClockPositions>(); if (setRandomPosition) { clockPosition = ItsRandom.randomRange(0, clockPositions.positions.Length); } ClockPosition clockPositionObj = clockPositions.positions[clockPosition]; setClockPosition(clockPositionObj); StartCoroutine(calculateTime()); }
public void putMessageOnQueue(string type, int severity, float delay = 0f) { Debug.Log("Play sound: " + type); AudioClip warningMessage = ItsRandom.pickRandom(clips.FindAll(i => i.name.Contains(type + "-") && i.name.Contains("-severity-" + severity))); Debug.Log("SOUND: " + warningMessage); if (warningMessage != null) { putMessageOnQueue(warningMessage, delay); } else { Debug.LogError("Audio not found for " + type + ", severity " + severity); } }
public void createBag(Vector3 bagDropPosition, String randomSeed) { // TODO - Random bag - Some distribution factor? Maybe not plastic tray except for certain content? int randomBagIndex = ItsRandom.randomRange(0, bags.Length, randomSeed); GameObject bagGameObject = Instantiate(bags [randomBagIndex], bagDropPosition, Quaternion.identity); BagProperties bagProperties = bagGameObject.GetComponent <BagProperties> (); bagGameObject.transform.position = new Vector3(bagDropPosition.x, bagDropPosition.y + bagProperties.halfBagHeight, bagDropPosition.z); currentBagPlacing = bagProperties; activeBags.Add(bagProperties); if (bagProperties.lid != null) { bagProperties.lid.SetActive(false); } }
public static GameObject pickRandomWithWeights(List <int> weights, List <GameObject> gameObjects, string type = DEFAULT_TYPE) { int weightSum = weights.Sum(); int random = ItsRandom.randomRange(0, weightSum, type); int index; int accumulatedSum; for (index = 0, accumulatedSum = 0; index <= weights.Count; accumulatedSum += weights[index], index++) { if (accumulatedSum + weights[index] > random) { break; } } return(gameObjects[index]); }
// Start is called before the first frame update void Start() { ItsRandom.setRandomSeed(9); // Trigger "random"-functions on it RandomInterface[] randomInterfaces = GetComponents <RandomInterface>(); foreach (RandomInterface randomInterface in randomInterfaces) { randomInterface.run(); } // ActionOnInspect[] actionInterfaces = GetComponents<ActionOnInspect>(); // foreach (ActionOnInspect actionInterface in actionInterfaces) { // actionInterface.run(); // } }
public void run(bool reverse) { if (!reverse) { videoPlayer.playOnAwake = true; if (!chosenVideoClip) { // Duplicate the material of the screen GameObject videoPlayerGameObject = videoPlayer.gameObject; Renderer componentRenderer = videoPlayerGameObject.GetComponent <Renderer>(); Material copyOfMaterial = new Material(componentRenderer.material); RenderTexture copyOfTexture = new RenderTexture((RenderTexture)copyOfMaterial.mainTexture); copyOfMaterial.mainTexture = copyOfTexture; componentRenderer.material = copyOfMaterial; videoPlayer.targetTexture = copyOfTexture; // Create audio source to play sound through audioSource = videoPlayer.gameObject.AddComponent <AudioSource>(); audioSource.playOnAwake = true; audioSource.volume = 1f; audioSource.spatialBlend = 1f; //Set Audio Output to AudioSource videoPlayer.audioOutputMode = VideoAudioOutputMode.AudioSource; //Assign the Audio from Video to AudioSource to be played videoPlayer.EnableAudioTrack(0, true); videoPlayer.SetTargetAudioSource(0, audioSource); videoPlayer.controlledAudioTrackCount = 1; // Pick video clip VideoClip videoClip = ItsRandom.pickRandom(videoClips.ToList()); videoPlayer.clip = videoClip; chosenVideoClip = true; } running = true; StartCoroutine(playWhenReady()); } else { running = false; videoPlayer.Stop(); audioSource.Stop(); } }
private IEnumerator reactOnItemInspection(BagContentProperties item) { // Get applicable audio clips string coroutineKey = "inspect-reaction-" + item.id; List <AudioClip> itemAudioClips = clips.FindAll(i => i.name.Contains(item.category + "-")); yield return(new WaitForSeconds(ItsRandom.randomRange(4f, 8f, personRandom))); while (Misc.HasCoroutine(coroutineKey)) { if (ItsRandom.randomRange(0, 100, personRandom) < 25) { yield return(playVoice(ItsRandom.pickRandom(itemAudioClips, personRandom))); } yield return(new WaitForSeconds(ItsRandom.randomRange(3f, 5f, personRandom))); } }
public void run() { PillsToRandomize chosenPillsConfig = ItsRandom.pickRandom(pillsToRandomize.ToList()); chosenPillsConfig.assign(pillBottle, objectWithMaterial, materialIndex, pillsContainer, pillsContainerXray, liquidContainer, liquidContainerXray, organicMaterialXray); if (!chosenPillsConfig.needsPrescription) { SlideInOtherObjectInspectAction slideInOtherObjectInspectAction = this.gameObject.GetComponent <SlideInOtherObjectInspectAction>(); foreach (SlideInOtherObjectDefinition slideInOtherObjectDefinition in slideInOtherObjectInspectAction.slideInObjectDefinitions) { if (slideInOtherObjectDefinition.gameObjectToSlideIn.name.StartsWith("Doctors Note")) { slideInOtherObjectDefinition.enabled = false; } } } }
// Use this for initialization void Start() { Debug.Log("CONFIG"); Debug.Log(config); // Choose greeting greeting = ItsRandom.pickRandom(clips.FindAll(i => i.name.StartsWith("greetings-")), personRandom); bagDefinition.person = this; currentX = this.transform.position.x; walkingMan.reportPositionX(currentX); walkingMan.setColors(bodyColor, chosenFavoriteColor); PubSub.subscribe("belt_movement", this); // Subscribe to inspection on items in own bags PubSub.subscribe("bag_inspect_item", this); }
private void assignProppertiesBasedOnBagContentProperties(BagContentProperties bagContentProperties) { // Assign paper material Material[] materials = paperMaterialObject.GetComponent <Renderer>().materials; materials[0] = ItsRandom.pickRandom(paperMaterials); paperMaterialObject.GetComponent <Renderer>().materials = materials; // Medicine name string displayName = bagContentProperties.displayName; string pillName = displayName.Substring("Bottle of \"".Length); string medicineNameStr = pillName.Substring(0, pillName.Length - 1); medicineName.text = " - " + medicineNameStr; // Person name Person person = BagHandler.instance.currentBagInspect.bagDefinition.person; string patientNameStr = person.personName; patientName.text = patientNameStr; // Doctor name // TODO - Real logic ("real"/fake names) string doctorNameStr = ItsRandom.pickRandom(new List <string>() { "Nick Riviera", "Julius Hibbert", "Hannibal Lecter", "Saw U Apart", "Genital Fondler", "Pepper" }); doctorName.text = "Dr. " + doctorNameStr; doctorSignature.font = ItsRandom.pickRandom(signatureFonts); doctorSignature.text = doctorNameStr; PillBottle pillBottle = bagContentProperties.gameObject.GetComponent <PillBottle>(); Debug.Log("Color 1: " + pillBottle.colorHalf1.ToString()); Debug.Log("Color 2: " + pillBottle.colorHalf2.ToString()); pillColorHalf1.color = pillBottle.colorHalf1; pillColorHalf2.color = pillBottle.colorHalf2; }
IEnumerator placeItemsInBagAndDrop(BagProperties bagProperties, List <BagContentProperties> items, String randomSeed) { Vector3 bagSize = bagProperties.placingCube.transform.localScale; foreach (BagContentProperties item in items) { item.transform.parent = bagProperties.contents.transform; Vector3 objectSize = item.objectSize; item.transform.localPosition = new Vector3(ItsRandom.randomPlusMinus(0f, (bagSize.x - objectSize.x) / 2f, randomSeed), bagProperties.halfBagHeight, ItsRandom.randomPlusMinus(0f, (bagSize.z - objectSize.z) / 2f, randomSeed)); item.transform.localScale = Vector3.one; bagProperties.bagContents.Add(item); bagProperties.freezeContents(true); yield return(new WaitForSeconds(0.1f)); } yield return(new WaitForSeconds(0.6f)); dropBag(Vector3.zero); }
private void reactOnInspectAction(InspectUIButton.INSPECT_TYPE action, BagContentProperties item) { if (action == InspectUIButton.INSPECT_TYPE.MANUAL_INSPECT || action == InspectUIButton.INSPECT_TYPE.MANUAL_INSPECT_NEW) { // TODO - Maybe don't react on 50% (ajdust level) if (ItsRandom.randomBool(personRandom)) { StartCoroutine(reactOnAction("manual")); } } else if (action == InspectUIButton.INSPECT_TYPE.TRASHCAN) { StartCoroutine(reactOnAction("throw")); } else if (action == InspectUIButton.INSPECT_TYPE.POLICE) { StartCoroutine(reactOnAction("police")); } }