private void CreateRenderMeshes() { ResetRenderMeshes(); if (m_precomputedCollisionMeshes.Count > 0) { var renderMeshes = new List <UnityEngine.Mesh>(); var renderColors = new List <Color>(); var prevState = Random.state; Random.InitState(GetInstanceID()); foreach (var collisionMesh in PrecomputedCollisionMeshes) { var meshes = collisionMesh.CreateRenderMeshes(transform); renderMeshes.AddRange(meshes); var color = Random.ColorHSV(); renderColors.AddRange(Enumerable.Repeat(color, meshes.Length)); } Random.state = prevState; m_renderMeshes = renderMeshes.ToArray(); m_renderColors = renderColors.ToArray(); } else { // Avoid rendering of meshes that hasn't been modified. To render // these it's possible to do: // m_renderMeshes = SourceObjects; // var prevState = Random.state; // Random.InitState( GetInstanceID() ); // var color = Random.ColorHSV(); // m_renderColors = Enumerable.Repeat( color, m_renderMeshes.Length ).ToArray(); // Random.state = prevState; } }
public void Split() { var scale = transform.localScale / 1.5f; var ballLeft = Instantiate( gameObject, rigidbody2d.position + Vector2.left / 4f, Quaternion.identity, gameManager.transform); var ballRight = Instantiate( gameObject, rigidbody2d.position + Vector2.right / 4f, Quaternion.identity, gameManager.transform); ballLeft.transform.localScale = scale; ballRight.transform.localScale = scale; var randomColor = Random.ColorHSV( 0f, 1f, 1f, 1f, 0.5f, 1f); ballLeft.GetComponent <SpriteRenderer>().color = randomColor; ballRight.GetComponent <SpriteRenderer>().color = randomColor; ballLeft.GetComponent <Ball>().StartForce = new Vector2(-2, 5); ballRight.GetComponent <Ball>().StartForce = new Vector2(2, 5); gameManager.Events.EventScored(); gameManager.Balls.Add(ballLeft); gameManager.Balls.Add(ballRight); Destroy(gameObject); }
public Nav2dNode(Vector3 worldPos) { this.worldPos = worldPos; this.neighbors = new C5.HashSet <Nav2dNode>(); zone = Random.ColorHSV(); }
private void Start() { foreach (var item in loopScrollRects) { item.OnInstantiateNextItem = OnInstantiateNextItem; } for (int i = 0; i < 100; i++) { gridDatas.Add(new LSR_GridData() { index = i, number = Random.Range(0, 1000), color = Random.ColorHSV(0f, 1f, 1f, 1f, 0.5f, 1f) }); } foreach (var item in loopScrollRects) { item.prefabSource = new LoopScrollPrefabSource() { prefab = prefab, poolSize = 5 }; item.totalCount = gridDatas.Count; item.RefillCells(); } }
public override void Initialize() { _bonus = _bonus == 0 ? Random.Range(1, 11) : _bonus; _startFlyPosition = transform.localPosition.x - transform.localScale.x; _material = GetComponent <Renderer>().material; _material.color = Random.ColorHSV(); }
/* * IEnumerator syncEvenSecond() { * int millisecond_remain = c; * if (DateTime.UtcNow.Second % 2 == 0) { * yield return new WaitForSeconds ((float)(millisecond_remain / 1000 + 1.0f)); * InvokeRepeating ("SpawnCube", spawnTime, spawnTime); * } else { * yield return new WaitForSeconds((float)(millisecond_remain / 1000)); * InvokeRepeating ("SpawnCube", spawnTime, spawnTime); * } * } */ void SpawnCube() { if (distance <= 10) { distance++; } var instantiatedObject = GameObject.Instantiate(cubeObject, cubeObject.transform.position + (cubeObject.transform.right * distance), cubeObject.transform.rotation); instantiatedObject.transform.parent = cubeContainerObject.transform; instantiatedObject.GetComponent <MeshRenderer>().material.color = Random.ColorHSV(0f, 1f, 1f, 1f, 0.5f, 1f); if (cubeContainerObject.transform.childCount > 10) { Destroy(cubeContainerObject.transform.GetChild(0).gameObject); for (int i = 0; i < cubeContainerObject.transform.childCount; i++) { cubeContainerObject.transform.GetChild(i).Translate(-cubeObject.transform.right * 1); } } /*localGameObjectList.Add (instantiatedObject); * if (localGameObjectList.Count > 10) { * localGameObjectList.RemoveAt (0); * }*/ }
void Awake() { _collider = GetComponent <BoxCollider2D>(); _rb = GetComponent <Rigidbody2D>(); GetComponent <SpriteRenderer>().color = Random.ColorHSV(); }
private async void Start() { Camera.main.orthographicSize = GameFieldSize.y / 2f; Camera.main.transform.position = new Vector3(GameFieldSize.x / 2f, GameFieldSize.y / 2f, Camera.main.transform.position.z); GameObject gameFieldGo = new GameObject("GameField"); SpriteRenderer gameFieldSpriteRenderer = gameFieldGo.AddComponent <SpriteRenderer>(); gameFieldSpriteRenderer.sprite = SquareSprite; gameFieldSpriteRenderer.sortingOrder = -1; gameFieldSpriteRenderer.color = Color.black; gameFieldGo.transform.localScale = new Vector3(GameFieldSize.x, GameFieldSize.y, 1f); gameFieldGo.transform.position = GameFieldSize * 0.5f; // Pick nice random color for this player this.color = Random.ColorHSV(0, 1, 1, 1, 1, 1); // The private key is used to sign transactions sent to the DAppChain. // Usually you'd generate one private key per player, or let them provide their own. // In this sample we just generate a new key every time. var privateKey = CryptoUtils.GeneratePrivateKey(); var publicKey = CryptoUtils.PublicKeyFromPrivateKey(privateKey); this.client = new TileChainContractClient(privateKey, publicKey, Debug.unityLogger); this.client.TileMapStateUpdated += ClientOnTileMapStateUpdated; await ConnectClient(); }
private void CreateCubes() { int cubesCount = _config.CubesCount; float respRadius = _config.RespRadius; float respHeight = _config.RespHeight; for (int i = 0; i < cubesCount; i++) { var cube = _factory.Create <Cube>("Cube", transform); if (cube == null) { return; } var pos = Random.insideUnitCircle * respRadius; cube.transform.localPosition = new Vector3(pos.x, respHeight, pos.y); cube.CollisionEnter += OnCubeCollisionEnter; var color = Random.ColorHSV(); cube.SetColor(color); _cubes.Add(cube); if (_mainMenu != null) { _mainMenu.AddButton(i, color); } } }
IEnumerator SpawnEnemyCoroutine() { int enemyNumber = 0; while (true) { float waitTime = Random.Range(minSpawnTime, maxSpawnTime); yield return(new WaitForSeconds(waitTime)); if (playerTransform == null) { yield break; } float playerDistance = Random.Range(minSpawnRange, maxSpawnRange); Vector2 newPosition = (Vector2)playerTransform.position + Random.insideUnitCircle.normalized * playerDistance; GameObject newEnemy = Instantiate(enemyPrefab, newPosition, Quaternion.identity); newEnemy.name = string.Format("Enemy #{0:00}", enemyNumber++); newEnemy.GetComponent <SpriteRenderer>().color = Random.ColorHSV(); S06_Enemy enemy = newEnemy.AddComponent <S06_Enemy>(); enemy.player = playerTransform; enemy.enemySpeed = Random.Range(minEnemySpeed, maxEnemySpeed); enemy.killDistance = killDistance; } }
private void RandomizeColors() { foreach (var mat in GetComponentsInChildren <MeshRenderer>()) { mat.material.color = Random.ColorHSV(); } }
private void GenerateIsland() { if (islanderToSpawn.Count == 0) { return; } foreach (var person in islanderToSpawn) { if (spawnLocations.Count == 0) { return; // if there are no locations to spawn at dont spawn. } var locId = Random.Range(0, spawnLocations.Count); // pick random location from list var location = spawnLocations[locId]; var position = location.position; var islander = Instantiate(person, position, quaternion.identity, location); var color = Random.ColorHSV(0f, 1f, 1f, 1f, 0.5f, 1f); var stats = islander.GetComponent <Islander>(); stats.SetShirtColor(color); stats._islanderData.personalityType = types[Random.Range(0, types.Length)]; var tentLoc = location.GetChild(0); var tentID = Random.Range(0, tentsToSpawn.Count); var tent = Instantiate(tentsToSpawn[tentID], tentLoc.position, quaternion.identity, tentLoc); tent.GetComponentInChildren <MeshRenderer>().material.color = color; spawnLocations.RemoveAt(locId); // remove location from possible spawn locations } }
private void Start() { morphGod = FindObjectOfType <MorphGod>(); randomTargets = new List <TransformStruct>(); morphGod.botPool = new Queue <MicroBot>(); poolToList = new List <MicroBot>(); for (int i = 0; i < 1800; i++) { var newPoolObject = GameObject.CreatePrimitive(PrimitiveType.Sphere); newPoolObject.transform.SetParent(morphGod.gameObject.transform); newPoolObject.transform.position = transform.position; newPoolObject.transform.localScale = new Vector3(0.3f, 0.3f, 0.3f); newPoolObject.TryGetComponent(out Renderer _r); var _color = Random.ColorHSV(); _r.material.color = _color; _r.material.EnableKeyword("_EMISSION"); _r.material.SetColor(EmissionColor, _color * 2f); randomTargets.Add(new TransformStruct(new Vector3(Random.Range(30, -30), 0, Random.Range(30, -30)), new Vector3(Random.Range(90, -90), Random.Range(90, -90), Random.Range(90, -90)))); newPoolObject.name = i.ToString() + " Pool"; newPoolObject.SetActive(true); morphGod.botPool.Enqueue(new MicroBot(null, newPoolObject.transform, _r.material.color)); } poolToList = morphGod.botPool.ToList(); moving = true; Invoke(nameof(StopInit), 5f); }
private void GenerateMaterials() { Scene.Materials.Clear(); var materialCount = Rand.Range(MaterialCountMinMax); for (var i = 0; i < materialCount; i++) { var material = new SceneMaterial(); var color = Random.ColorHSV(); var colorVector = new Vector3(color.r, color.g, color.b); var isMetallic = Rand.Chance(MetallicChance); var specular = Rand.Range(SpecularRange); if (isMetallic) { material.Albedo = colorVector * specular; material.Specular = colorVector; } else { material.Albedo = colorVector; material.Specular = Vector3.zero; } Scene.Materials.Add(material); } if (materialComputeBuffer != null) { materialComputeBuffer.Release(); } MakeBuffer(ref materialComputeBuffer, materialCount, Scene.Materials[0].Stride, Scene.Materials.ToArray()); }
private void AddVideoObject() { var newCam = new GameObject($"Camera{objectIndex}").AddComponent <Camera>(); newCam.backgroundColor = Random.ColorHSV(); newCam.transform.SetParent(cameraParent); cameras.Add(newCam); var newSource = new GameObject($"SourceImage{objectIndex}").AddComponent <RawImage>(); newSource.transform.SetParent(sourceImageParent); sourceImages.Add(newSource); var newReceive = new GameObject($"ReceiveImage{objectIndex}").AddComponent <RawImage>(); newReceive.transform.SetParent(receiveImageParent); receiveImages.Add(newReceive); try { videoStreamTrackList.Add(newCam.CaptureStreamTrack(width, height, 0)); newSource.texture = newCam.targetTexture; } catch (Exception e) { Debug.LogError(e.Message); HangUp(); return; } objectIndex++; addTracksButton.interactable = true; }
public void ReadyUp() { if (!ready) { defaultAction = new float[actionRange.Length]; for (var i = 0; i < actionRange.Length; i++) { defaultAction[i] = actionRange[i].getDefaultInRange(); } goal = Instantiate(goalPrefab); agent = GetComponent <Transform>(); areaCenter = area.GetComponent <Transform>().position; agentRb = agent.GetComponent <Rigidbody>(); SetColor(Random.ColorHSV(0f, 1f, 0.5f, 1f, 0.75f, 1f)); ready = true; // agentRb.maxAngularVelocity = 1.0f; selfGoalCollider = goal.GetComponent <BoxCollider>(); pidRotationController.Reset(); pidVelocityController.Reset(); goalRadius = goal.GetComponent <SphereCollider>().radius; areaDimensions = Vector3.Scale( area.transform.localScale, area.transform.GetChild(0).GetComponent <MeshFilter>().mesh.bounds.size ); } }
void OnAdd(ReorderableList list) { var standardColorList = new List <Color>(s_StandardColors); for (int i = 0; i < list.serializedProperty.arraySize; i++) { var item = list.serializedProperty.GetArrayElementAtIndex(i); standardColorList.Remove(item.FindPropertyRelative(nameof(SemanticSegmentationLabelEntry.color)).colorValue); } var index = list.serializedProperty.arraySize; list.serializedProperty.InsertArrayElementAtIndex(index); var element = list.serializedProperty.GetArrayElementAtIndex(index); var labelProperty = element.FindPropertyRelative(nameof(SemanticSegmentationLabelEntry.label)); labelProperty.stringValue = ""; var colorProperty = element.FindPropertyRelative(nameof(SemanticSegmentationLabelEntry.color)); if (standardColorList.Any()) { colorProperty.colorValue = standardColorList.First(); } else { colorProperty.colorValue = Random.ColorHSV(0, 1, .5f, 1, 1, 1); } serializedObject.ApplyModifiedProperties(); EditorUtility.SetDirty(target); }
public Vector3 GeneratePoint() { Vector3 result = Vector3.one; for (int i = 0; i < 100; i++) { var x = Random.Range(_sizeOfPlatform.x - (_sizeOfPlatform.z / 2), _sizeOfPlatform.x + (_sizeOfPlatform.z / 2)); var y = 0.5f; var z = Random.Range(_sizeOfPlatform.y - (_sizeOfPlatform.w / 2), _sizeOfPlatform.y + (_sizeOfPlatform.w / 2)); var checkPoint = new Vector3(x, y, z); var _ = new Collider[2]; int numColliders = Physics.OverlapSphereNonAlloc(checkPoint, 2.0f, _); if (numColliders == 1) { if (_isEnabledViewSpawnPoint) { var point = Instantiate(_prefab, checkPoint, Quaternion.identity); point.name = ManagerName.SPAWNPOINT; point.GetComponent <MeshRenderer>().material.color = Random.ColorHSV(); } return(checkPoint); } } return(result); }
private void RandomSpawn() { for (int i = 0; i < shapeCount; i++) { float r = Random.Range(-1, 1); Shape sp = SpawnShape(r < 0 ? sphereResource : cubeResource, RandomPositionInBounds(worldBounds.bounds), Quaternion.identity, Random.Range(0, 5) * Vector3.one, Random.ColorHSV()); int recheckCount = 10; while (IsOverlapping(sp) && recheckCount > 0) { sp.transform.position = RandomPositionInBounds(worldBounds.bounds); recheckCount--; } if (r < 0) { spheres.Add(sp); } else { cubes.Add(sp); } } }
void IAction.Action() { if (TryGetComponent(out Renderer renderer)) { renderer.material.color = Random.ColorHSV(); } }
void Start() { var path = Path.Combine(Application.dataPath, fontDataPath); if (File.Exists(path)) { var source = File.ReadAllText(path); fontData = JsonConvert.DeserializeObject <MSDFFontData>(source); MeshInfo info = MSDFTextMesh.GetMeshInfo("hello", fontData, true); Debug.Log(info.uvs.Length); } //numTextGroups = GetTextGroupCount(); textSettings = new TextSettings[1]; var text = ""; for (var i = 0; i < textSettings.Length; ++i) { text = quotes[Random.Range(0, quotes.Count)]; textSettings[i] = new TextSettings(text, MSDFTextMesh.GetMeshInfo(text, fontData, true)); } instanceMesh = CreateMesh(); instanceMaterial = new Material(Shader.Find("Unlit/InstanceShader")); instanceMaterial.SetColor("_Color", Random.ColorHSV()); instanceMaterial.SetTexture("_MainTex", msdfTexture); argsBuffer = new ComputeBuffer(1, args.Length * sizeof(uint), ComputeBufferType.IndirectArguments); UpdateBuffers(); }
private void CreateCube(int x, int z) { GameObject cube = new GameObject("Cube", typeof(MeshFilter), typeof(MeshRenderer), typeof(BoxCollider)); cube.GetComponent <MeshFilter>().mesh = mesh; cube.GetComponent <MeshRenderer>().material = material; var tempMaterial = new Material(cube.GetComponent <MeshRenderer>().sharedMaterial); var localScaleOrig = cube.transform.localScale; cube.transform.parent = cubeContainer.transform; var transformPosition = cube.transform.position; transformPosition = new Vector3(x, transformPosition.y, z); localScaleOrig = new Vector3(localScaleOrig.x + scale - 1, localScaleOrig.y, localScaleOrig.z + scale - 1); var localScaleNew = localScaleOrig; var position = transformPosition; float randomHeight = Random.Range(minHeight, maxHeight); localScaleOrig = new Vector3(localScaleNew.x, randomHeight, localScaleNew.x); cube.transform.localScale = localScaleOrig; transformPosition = new Vector3(position.x, randomHeight / 2, position.z); cube.transform.position = transformPosition; Color color = Random.ColorHSV(colorHueMin, colorHueMax, colorSatMin, colorSatMax, colorValMin, colorValMax); tempMaterial.color = color; cube.GetComponent <MeshRenderer>().sharedMaterial = tempMaterial; objects.Add(cube); }
public void SetupPlayer() { BoltLog.Info("SetupPlayer"); localPlayer = this; nameInput.interactable = true; remoteIcone.gameObject.SetActive(false); localIcone.gameObject.SetActive(true); removePlayerButton.gameObject.SetActive(false); removePlayerButton.interactable = false; ChangeReadyButtonColor(JoinColor); readyButton.transform.GetChild(0).GetComponent <Text>().text = "JOIN"; readyButton.interactable = true; //we switch from simple name display to name input colorButton.interactable = true; nameInput.interactable = true; nameInput.onEndEdit.RemoveAllListeners(); // nameInput.onEndEdit.AddListener((text => { playerName = text; })); colorButton.onClick.RemoveAllListeners(); colorButton.onClick.AddListener(() => { playerColor = Random.ColorHSV(); }); readyButton.onClick.RemoveAllListeners(); readyButton.onClick.AddListener(OnReadyClicked); OnClientReady(state.Ready); }
private void CreateSnake(int snakeSize, Vector3 position, bool changeColor) { _snakeSegmentList = new List <SnakeBodyPart>(); if (changeColor) { _tailColor = Random.ColorHSV(); } for (int i = 0; i < snakeSize - 1; i++) { var tailInstance = Instantiate(_snakeTailPrefab, position, Quaternion.identity); tailInstance.LastPostion = position; tailInstance.SetOnCollisionCallback(OnTailCollision); tailInstance.transform.SetParent(this.transform); position.x += size; tailInstance.SetColor(_tailColor); _snakeSegmentList.Add(tailInstance); } var headInstance = Instantiate(_snakeHeadPrefab, position, Quaternion.identity); headInstance.SetOnCollisionCallback(OnHeadCollision); headInstance.transform.SetParent(this.transform); _snakeSegmentList.Insert(0, headInstance); }
private void Start() { if (_back) { _back.color = Random.ColorHSV(); } }
private void SetUpScene() { List <Sphere> spheres = new List <Sphere>(); // Add a number of random spheres for (int i = 0; i < SpheresMax; i++) { Sphere sphere = new Sphere(); // Radius and radius sphere.radius = SphereRadius.x + Random.value * (SphereRadius.y - SphereRadius.x); Vector2 randomPos = Random.insideUnitCircle * SpherePlacementRadius; sphere.position = new Vector3(randomPos.x, sphere.radius, randomPos.y); // Reject spheres that are intersecting others foreach (Sphere other in spheres) { float minDist = sphere.radius + other.radius; if (Vector3.SqrMagnitude(sphere.position - other.position) < minDist * minDist) { goto SkipSphere; } } // Albedo and specular color Color color = Random.ColorHSV(); bool metal = Random.value < 0.5f; sphere.albedo = metal ? Vector3.zero : new Vector3(color.r, color.g, color.b); sphere.specular = metal ? new Vector3(color.r, color.g, color.b) : Vector3.one * 0.04f; // Add the sphere to the list spheres.Add(sphere); SkipSphere: continue; } // Assign to compute buffer _sphereBuffer = new ComputeBuffer(spheres.Count, 40); _sphereBuffer.SetData(spheres); }
void Start() { _sprite = GetComponent <SpriteRenderer>(); hueIndex = 0f; if (IsRoot()) { deadCleanup = Random.Range(info.deadCleanupInterval.x, info.deadCleanupInterval.y); baseScale = Random.Range(info.startScale.x, info.startScale.y); seeds = Mathf.CeilToInt(Random.Range(info.startSeeds.x, info.startSeeds.y)); #if UNITY_EDITOR hueIndex = Utils.Remap(sea.debugLight, 0f, 1000f, 0f, 1f);; #else hueIndex = Utils.Remap(sea.lightSensorData.value, 0f, 1000f, 0f, 1f); #endif } else { deadCleanup = parent.deadCleanup; baseScale = 1f * info.branchScaleDecay; hueIndex = parent.hueIndex; } transform.localScale = Vector3.one * baseScale; chanceToBranch = 0f; chanceToStop = 0f; hasStopped = false; nextRollTime = CalculateTimeToNextRoll(); health = 1f; isDead = false; // color calculations for this coral piece float value = 1f - Utils.Remap(depthLevel, 0f, info.maxDepthLevel, 0.2f, 0.8f); _sprite.color = Random.ColorHSV(hueIndex, hueIndex, saturation.x, saturation.y, value, value); _sprite.sortingLayerName = "Alive"; }
private void SetUpScene() { Random.InitState(SphereSeed); List <Sphere> spheres = new List <Sphere>(); // Add a number of random spheres for (int i = 0; i < SpheresMax; i++) { Sphere sphere = new Sphere(); // Radius and radius sphere.radius = SphereRadius.x + Random.value * (SphereRadius.y - SphereRadius.x); Vector2 randomPos = Random.insideUnitCircle * SpherePlacementRadius; sphere.position = new Vector3(randomPos.x, sphere.radius, randomPos.y); // Reject spheres that are intersecting others foreach (Sphere other in spheres) { float minDist = sphere.radius + other.radius; if (Vector3.SqrMagnitude(sphere.position - other.position) < minDist * minDist) { goto SkipSphere; } } // Albedo and specular color Color color = Random.ColorHSV(); float chance = Random.value; if (chance < 0.8f) { bool metal = chance < 0.4f; sphere.albedo = metal ? Vector4.zero : new Vector4(color.r, color.g, color.b); sphere.specular = metal ? new Vector4(color.r, color.g, color.b) : new Vector4(0.04f, 0.04f, 0.04f); sphere.smoothness = Random.value; } else { Color emission = Random.ColorHSV(0, 1, 0, 1, 3.0f, 8.0f); sphere.emission = new Vector3(emission.r, emission.g, emission.b); } // Add the sphere to the list spheres.Add(sphere); SkipSphere: continue; } // Assign to compute buffer if (_sphereBuffer != null) { _sphereBuffer.Release(); } if (spheres.Count > 0) { _sphereBuffer = new ComputeBuffer(spheres.Count, 56); _sphereBuffer.SetData(spheres); } }
private static Color RandomColor() { return(Random.ColorHSV( hueMin: 0f, hueMax: 1f, saturationMin: 0.5f, saturationMax: 1f, valueMin: 0.8f, valueMax: 1f )); }
public void Action() { _color = Random.ColorHSV(); if (TryGetComponent(out Renderer renderer)) { renderer.material.color = _color; } }