private void UpdateFingerTips() { for (int i = 0; i < fingerTips.Length; i++) { FingerTip fingerTip = fingerTips[i]; fingerTipSlimeColor.a = fingerTip.SlimeIntensity; fingerTip.SlimeIntensity = goopSlimes[i].isActiveAndEnabled ? 1 : Mathf.Clamp01(fingerTip.SlimeIntensity - Time.deltaTime * fingerTipSlimeFadeSpeed); fingerTip.Renderer.materials[1].color = fingerTipSlimeColor; fingerTips[i] = fingerTip; } }
private void OnTriggerExit(Collider other) { if (fingerTip && other.gameObject == fingerTip.gameObject) { onRelease.Invoke(); p = 0.0f; fingerTip.controlDisplay.offset = Vector3.zero; fingerTip = null; isContacted = false; } }
protected override void Awake() { base.Awake(); growthChaosAudio.volume = 0; fingerTips = new FingerTip[fingers.Length]; for (int i = 0; i < fingers.Length; i++) { FingerTip fingerTip = new FingerTip(); fingerTip.Renderer = fingers[i].GetComponentInChildren <Renderer>(); fingerTips[i] = fingerTip; } }
private void OnTriggerEnter(Collider other) { fingerTip = other.gameObject.GetComponent <FingerTip>(); if (fingerTip) { onContact.Invoke(); isContacted = true; if (vibrotactorHaptics) { Syntacts.Signal sig; if (touchSignal != "" && Syntacts.Library.LoadSignal(out sig, touchSignal)) { fingerTip.bracelet.tactors.VibrateAll(sig); } } } }
private void UpdateImpacts() { UpdateVolumeImpacts(gen0); UpdateVolumeImpacts(gen1); UpdateVolumeImpacts(gen2); UpdateVolumeImpacts(gen3); for (int i = 0; i < fingerTips.Length; i++) { FingerTip ft = fingerTips[i]; if (fingers[i].gameObject.activeSelf) { Color impactColor = fingerImpactGradient.Evaluate(ft.ImpactIntensity); ft.Block.SetColor("_EmissiveColor", ft.BaseColor + impactColor); ft.Renderer.SetPropertyBlock(ft.Block); ft.ImpactIntensity = Mathf.Clamp01(ft.ImpactIntensity - (Time.deltaTime * fingerImpactFadeTime)); fingerTips[i] = ft; } } }
// Start is called before the first frame update void Start() { indexTip = FindChildByNameThatContains("IndexTip"); thumbTip = FindChildByNameThatContains("ThumbTip"); if (indexTip != null) { GameObject go = Instantiate(fingerTipPrefab, indexTip.position, indexTip.rotation, indexTip); FingerTip f = go.GetComponent <FingerTip>(); f.finger = EFinger.Index; f.manager = this; } if (thumbTip != null) { GameObject go = Instantiate(fingerTipPrefab, thumbTip.position, thumbTip.rotation, thumbTip); FingerTip f = go.GetComponent <FingerTip>(); f.finger = EFinger.Thumb; f.manager = this; } }
private void OnImpact(ChunkImpacts chunk, Vector3 impactPoint) { chunk.ImpactAudio.pitch = UnityEngine.Random.Range(0.8f, 1.2f); chunk.ImpactAudio.clip = impactClips[UnityEngine.Random.Range(0, impactClips.Length)]; chunk.ImpactAudio.volume = (chunk.LastImpactIntensity * impactVolume) * chunk.Radius / largestRadius; chunk.ImpactAudio.Play(); // Create an impact event if (chunk.LastImpactIntensity > minImpactParticleIntensity) { for (int i = 0; i < impactParticles.Length; i++) { if (!impactParticles[i].gameObject.activeSelf) { impactParticles[i].transform.position = impactPoint; impactParticles[i].gameObject.SetActive(true); break; } } } if (chunk.LastImpactType == ChunkImpacts.ImpactType.Finger) { // Find the finger we collided with for (int i = 0; i < fingerRigidBodies.Length; i++) { if (fingerRigidBodies[i].name == chunk.LastOtherCollider.name) { FingerTip ft = fingerTips[i]; ft.ImpactIntensity = 1; ft.ImpactAudio.pitch = UnityEngine.Random.Range(0.8f, 1.2f); ft.ImpactAudio.clip = fingerImpactClip; ft.ImpactAudio.volume = chunk.LastImpactIntensity * impactVolume; ft.ImpactAudio.Play(); fingerTips[i] = ft; break; } } } }
private void DrawBlorbs() { Color centerPoppedColor = centerPoppedGradient.Evaluate(centerPoppedCurve.Evaluate(Time.time - timeLastPopped)); bool applyPoppedColor = centerPoppedColor.r > 0; float popScale = popRecoveryScaleCurve.Evaluate(Time.time - timeLastPopped); for (int i = 0; i < blorbs.Length; i++) { Blorb e = blorbs[i]; if (e.Popped) { float poppedTime = (Time.time - e.TimePopped) / respawnTime; e.Goop.Renderer.SetPropertyBlock(emptyBlock); e.Goop.transform.localScale = Vector3.one * Mathf.Lerp(minRadius, e.Radius + e.Bloat, poppedTime); } else { float normalizedBloat = Mathf.Clamp01(e.Bloat / maxBloatBeforePop); e.Goop.transform.localPosition = e.Point; e.Goop.transform.forward = e.Dir; e.Goop.transform.Rotate(0f, 0f, e.Rotation, Space.Self); e.Goop.transform.localScale = Vector3.one * (e.Radius + e.Bloat) * popScale; if (normalizedBloat > 0.01f || applyPoppedColor) { Color bloatColor = bloatGradientEmission.Evaluate(normalizedBloat); bloatColor += centerPoppedColor; e.Goop.PropertyBlock.SetColor(emissionColorPropName, bloatColor); e.Goop.Renderer.SetPropertyBlock(e.Goop.PropertyBlock); } else { e.Goop.Renderer.SetPropertyBlock(emptyBlock); } } } if (popEvents.Count > 0) { Blorb popEvent = popEvents.Dequeue(); // Try getting a random one first int randomIndex = Random.Range(0, popParticles.Length); if (!popParticles[randomIndex].gameObject.activeSelf) { popParticles[randomIndex].transform.localPosition = popEvent.Point; popParticles[randomIndex].transform.forward = popEvent.Dir; popParticles[randomIndex].gameObject.SetActive(true); return; } // If that didn't work just go through the list for (int i = 0; i < popParticles.Length; i++) { if (popParticles[i].gameObject.activeSelf) { continue; } popParticles[i].transform.localPosition = popEvent.Point; popParticles[i].transform.forward = popEvent.Dir; popParticles[i].gameObject.SetActive(true); break; } // Slime all fingers nearby for (int i = 0; i < fingerTips.Length; i++) { if (Vector3.Distance(popEvent.Point, fingers[i].position) < maxDistToFinger) { FingerTip fingerTip = fingerTips[i]; fingerTip.SlimeIntensity = 1; fingerTips[i] = fingerTip; } } } popEvents.Clear(); }
public override void Initialize(Vector3 surfacePosition) { base.Initialize(surfacePosition); emptyBlock = new MaterialPropertyBlock(); fingerTips = new FingerTip[fingerRigidBodies.Length]; for (int i = 0; i < fingerRigidBodies.Length; i++) { FingerTip ft = new FingerTip(); ft.ImpactAudio = fingerColliders[i].GetComponentInChildren <AudioSource>(); ft.Renderer = fingers[i].GetComponentInChildren <Renderer>(); ft.Block = new MaterialPropertyBlock(); ft.ImpactIntensity = 0; ft.BaseColor = baseFingerColor; fingerTips[i] = ft; } largestRadius = 0; //await new WaitForBackgroundThread(); // GEN 0 List <Chunk> genList = new List <Chunk>(); // Add one really big one in the middle Chunk core = new Chunk(); core.Parent = -1; core.Generation = 0; core.Radius = coreRadius; core.TargetPoint = RandomInsideSphere(random) * SurfaceRadius * 0.1f; core.TargetDir = Vector3.up; genList.Add(core); // Then put a bunch around the core for (int i = 0; i < gen0Core; i++) { Chunk volume = new Chunk(); volume.Parent = -1; volume.Generation = 0; volume.Radius = RandomRange(random, gen0RadiusMin, gen0RadiusMax); // Make sure the volume exists inside the sphere volume.TargetPoint = RandomInsideSphere(random) * (SurfaceRadius - volume.Radius * 1.25f); volume.TargetDir = volume.TargetPoint.normalized; genList.Add(volume); } // Then put a bunch around the edge for (int i = 0; i < gen0Surface; i++) { Chunk volume = new Chunk(); volume.Parent = -1; volume.Generation = 0; volume.Radius = RandomRange(random, gen0RadiusMin, gen0RadiusMax); volume.TargetPoint = RandomOnSphere(random) * (SurfaceRadius - volume.Radius); volume.TargetDir = volume.TargetPoint.normalized; genList.Add(volume); } gen0 = genList.ToArray(); genList.Clear(); // GEN 1 // Generate filler volumes around the big volumes // Pre-emptively cull volumes that go outside the sphere radius while (genList.Count < gen1Count) { for (int i = 0; i < gen0.Length; i++) { Chunk parent = gen0[i]; Chunk volume = new Chunk(); volume.Generation = 1; volume.Parent = i; volume.Radius = RandomRange(random, gen1RadiusMin, gen1RadiusMax); volume.TargetPoint = parent.TargetPoint + (RandomOnSphere(random) * (parent.Radius + volume.Radius)); volume.TargetDir = parent.TargetPoint - volume.TargetPoint; // Now see if we're outside the sphere float outerEdgeDist = volume.TargetPoint.magnitude + volume.Diameter; // If we are, skip adding this volume if (outerEdgeDist > SurfaceRadius) { continue; } genList.Add(volume); } } gen1 = genList.ToArray(); genList.Clear(); // GEN 2 while (genList.Count < gen2Count) { for (int i = 0; i < gen1.Length; i++) { Chunk parent = gen1[i]; Chunk volume = new Chunk(); volume.Generation = 2; volume.Parent = i; volume.Radius = RandomRange(random, gen2RadiusMin, gen2RadiusMax); volume.TargetPoint = parent.TargetPoint + (RandomOnSphere(random) * (parent.Radius + volume.Radius)); volume.TargetDir = parent.TargetPoint - volume.TargetPoint; // Now see if we're outside the sphere float outerEdgeDist = volume.TargetPoint.magnitude + volume.Diameter; // If we are, skip adding this volume if (outerEdgeDist > SurfaceRadius) { continue; } genList.Add(volume); } } gen2 = genList.ToArray(); genList.Clear(); // GEN 3 // This generation will live on the outside shell while (genList.Count < gen3Count) { for (int i = 0; i < gen2.Length; i++) { Chunk parent = gen2[i]; Chunk volume = new Chunk(); volume.Generation = 3; volume.Parent = i; volume.Radius = RandomRange(random, gen3RadiusMin, gen3RadiusMax); // Put on the outside shell volume.TargetPoint = parent.TargetPoint.normalized * (SurfaceRadius - volume.Radius); volume.TargetDir = parent.TargetPoint - volume.TargetPoint; genList.Add(volume); } } gen3 = genList.ToArray(); genList.Clear(); matrixes = new Matrix4x4[gen0.Length + gen1.Length + gen2.Length + gen3.Length]; // Jitter volumes into place for (int i = 0; i < 5; i++) { JitterVolumes(gen0, null, 100, false); JitterVolumes(gen1, gen0, 25, false); JitterVolumes(gen2, gen1, 15, false); JitterVolumes(gen3, gen2, 100, true); } // Get back onto the main thread //await new WaitForEndOfFrame(); // Create volume objects for (int i = 0; i < gen0.Length; i++) { gen0[i] = CreateVolumeObject(gen0[i]); } for (int i = 0; i < gen1.Length; i++) { gen1[i] = CreateVolumeObject(gen1[i]); } for (int i = 0; i < gen2.Length; i++) { gen2[i] = CreateVolumeObject(gen2[i]); } for (int i = 0; i < gen3.Length; i++) { gen3[i] = CreateVolumeObject(gen3[i]); } if (drawConnections) { // Create lines int numConnections = gen1.Length + gen2.Length + gen3.Length; lineRenderers = new LineRenderer[numConnections]; for (int i = 0; i < numConnections; i++) { GameObject lineObject = GameObject.Instantiate(linePrefab, transform); LineRenderer lineRenderer = lineObject.GetComponent <LineRenderer>(); lineRenderer.colorGradient = connectionColor; lineRenderers[i] = lineRenderer; } // Set connection width int lineIndex = 0; for (int i = 0; i < gen1.Length; i++) { Chunk v = gen1[i]; lineRenderers[lineIndex].colorGradient = connectionGradientGen1; lineIndex++; } for (int i = 0; i < gen2.Length; i++) { Chunk v = gen2[i]; lineRenderers[lineIndex].colorGradient = connectionGradientGen2; lineIndex++; } for (int i = 0; i < gen3.Length; i++) { Chunk v = gen3[i]; lineRenderers[lineIndex].colorGradient = connectionGradientGen3; lineIndex++; } } centralParticles.gameObject.SetActive(true); }