예제 #1
0
        /*--------------------------------------------------------------------------------------------*/
        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);
        }
예제 #2
0
        /*--------------------------------------------------------------------------------------------*/
        private void HandleColorRandomToggle(NavItem <bool> pItem)
        {
            if (!pItem.Value)
            {
                return;
            }

            for (int i = 0; i < Count; ++i)
            {
                GameObject cube     = vCubes[i];
                DemoCube   cubeData = cube.GetComponent <DemoCube>();
                cube.renderer.sharedMaterial.color = cubeData.ColorRandom;
            }

            vNavItems.ColorHue.IsEnabled = false;
        }
예제 #3
0
        /*--------------------------------------------------------------------------------------------*/
        private void BuildCube(int pIndex)
        {
            float radius        = RandomFloat(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 = gameObject.transform;
            vHolds[pIndex]        = hold;

            DemoCubeHold holdData = hold.AddComponent <DemoCubeHold>();

            holdData.OrbitAxis    = RandomUnitVector();
            holdData.OrbitSpeed   = RandomFloat(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.renderer.sharedMaterial = new Material(Shader.Find("Diffuse"));
            vCubes[pIndex]               = cube;

            DemoCube cubeData = cube.AddComponent <DemoCube>();

            cubeData.ColorRandom  = RandomUnitColor(0.1f, 1);
            cubeData.SpinAxis     = RandomUnitVector();
            cubeData.SpinSpeed    = RandomFloat(0.5f, 1, 2);
            cubeData.SpinInitRot  = UnityEngine.Random.rotationUniform;
            cubeData.BobSpeed     = RandomFloat(0.5f, 1, 2);
            cubeData.BobInitPos   = RandomFloat(-1, 1);
            cubeData.BobRadiusMin = radius;
            cubeData.BobRadiusMax = cubeData.BobRadiusMin + 3;
            cubeData.GrowSpeed    = RandomFloat(0.5f, 1, 2);
            cubeData.GrowInitPos  = RandomFloat(-1, 1);
            cubeData.GrowScaleMin = RandomUnitVector(0.4f) * 0.6f;
            cubeData.GrowScaleMax = RandomUnitVector(0.4f) * 1.2f;
        }
예제 #4
0
        /*--------------------------------------------------------------------------------------------*/
        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);

            if (vNavItems.ColorHue.IsStickySelected)
            {
                UpdateCubeHue(cube);
                float value = vNavItems.ColorHue.Value;
                cube.renderer.sharedMaterial.color = HsvToColor(value * 360, 1, 1);
            }
        }