/*--------------------------------------------------------------------------------------------*/ private void UpdateCube(int pIndex) { GameObject hold = vHolds[pIndex]; GameObject cube = vCubes[pIndex]; DemoCubeHold holdData = hold.GetComponent <DemoCubeHold>(); DemoCube cubeData = cube.GetComponent <DemoCube>(); float orbitAngle = vOrbitMotion.Position * holdData.OrbitSpeed; hold.transform.localRotation = holdData.OrbitInitRot * Quaternion.AngleAxis(orbitAngle, holdData.OrbitAxis); float spinAngle = vSpinMotion.Position * cubeData.SpinSpeed; cube.transform.localRotation = cubeData.SpinInitRot * Quaternion.AngleAxis(spinAngle, cubeData.SpinAxis); float bobPos = cubeData.BobInitPos + vBobMotion.Position * cubeData.BobSpeed; bobPos = (float)Math.Sin(bobPos * Math.PI) / 2f + 0.5f; bobPos = Mathf.Lerp(cubeData.BobRadiusMin, cubeData.BobRadiusMax, bobPos); cube.transform.localPosition = new Vector3(0, 0, bobPos); float growPos = cubeData.GrowInitPos + vGrowMotion.Position * cubeData.GrowSpeed; growPos = (float)Math.Sin(growPos * Math.PI) / 2f + 0.5f; cube.transform.localScale = Vector3.Lerp(cubeData.GrowScaleMin, cubeData.GrowScaleMax, growPos); }
//////////////////////////////////////////////////////////////////////////////////////////////// /*--------------------------------------------------------------------------------------------*/ private void BuildCube(int pIndex) { float radius = RandomUtil.Float(4, 10); float radiusPercent = (radius - 4) / 6f; float orbitSpeed = (float)Math.Pow(1 - radiusPercent, 2) * 0.2f + 0.8f; var hold = new GameObject("Hold" + pIndex); hold.transform.parent = vCubesObj.transform; vHolds[pIndex] = hold; DemoCubeHold holdData = hold.AddComponent <DemoCubeHold>(); holdData.OrbitAxis = RandomUtil.UnitVector(); holdData.OrbitSpeed = RandomUtil.Float(0.7f, 1, 2) * orbitSpeed; holdData.OrbitInitRot = UnityEngine.Random.rotationUniform; //// GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube); cube.transform.parent = hold.transform; cube.name = "Cube" + pIndex; cube.GetComponent <Renderer>().material = new Material(Shader.Find("Diffuse")); vCubes[pIndex] = cube; DemoCube cubeData = cube.AddComponent <DemoCube>(); cubeData.ColorRandom = RandomUtil.UnitColor(0.1f, 1); cubeData.SpinAxis = RandomUtil.UnitVector(); cubeData.SpinSpeed = RandomUtil.Float(0.5f, 1, 2); cubeData.SpinInitRot = UnityEngine.Random.rotationUniform; cubeData.BobSpeed = RandomUtil.Float(0.5f, 1, 2); cubeData.BobInitPos = RandomUtil.Float(-1, 1); cubeData.BobRadiusMin = radius; cubeData.BobRadiusMax = cubeData.BobRadiusMin + 3; cubeData.GrowSpeed = RandomUtil.Float(0.5f, 1, 2); cubeData.GrowInitPos = RandomUtil.Float(-1, 1); cubeData.GrowScaleMin = RandomUtil.UnitVector(0.4f) * 0.6f; cubeData.GrowScaleMax = RandomUtil.UnitVector(0.4f) * 1.2f; }