コード例 #1
0
        private void CreateObject(MovePhoneData data)
        {
            Vector2 position      = new Vector2(data.startX.RangeValue(), data.startY.RangeValue());
            Vector2 moveDirection = data.moveDirection.normalized;
            float   destroyX      = data.destroyX;
            float   speed         = data.speedRange.RangeValue();
            float   acceleration  = data.accelerationRange.RangeValue();

            float scaleRatio = (speed - data.speedRange.minValue) / (data.speedRange.maxValue - data.speedRange.minValue);
            float scaleValue = Mathf.Lerp(1.2f, 0.8f, scaleRatio);


            MovePhoneObjData createData = new MovePhoneObjData
            {
                Acceleration  = acceleration,
                DestroyX      = destroyX,
                Position      = position,
                MoveDirection = moveDirection,
                Speed         = speed,
                Scale         = new Vector3(scaleValue, scaleValue, 1)
            };

            GameObject    prefab            = SelectPrefab(data);
            GameObject    instance          = Instantiate <GameObject>(prefab, new Vector3(40000, 40000), Quaternion.identity);
            RectTransform instanceTransform = instance.GetComponent <RectTransform>();

            instanceTransform.SetParent(transform, false);
            instance.GetComponent <MovingPhoneObject>().Setup(createData);
        }
コード例 #2
0
        private GameObject SelectPrefab(MovePhoneData data)
        {
            switch (data.objectType)
            {
            case PhoneObjectType.Asteroid:
                return(asteroidPrefabs[UnityEngine.Random.Range(0, asteroidPrefabs.Length)]);

            case PhoneObjectType.Meteor:
                return(meteorPrefabs[UnityEngine.Random.Range(0, meteorPrefabs.Length)]);

            default:
                throw new UnityException($"invalid object data");
            }
        }