Exemple #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);
        }
Exemple #2
0
        public void Setup(MovePhoneObjData data)
        {
            Data          = data;
            selfTransform = GetComponent <RectTransform>();
            selfTransform.anchoredPosition = Data.Position;
            selfTransform.localScale       = Data.Scale;
            currentSpeed = Data.Speed;

            IsInitialized = true;
        }