Esempio n. 1
0
    public static PetalDrop GetInstance(PetalDrop prefab)     //TODO: если будет реализован пул, переделать под него
    {
        if (petals == null)
        {
            petals = new Dictionary <PetalDrop, Stack <PetalDrop> >();
        }
        Stack <PetalDrop> stack;

        if (!petals.TryGetValue(prefab, out stack))
        {
            petals[prefab] = (stack = new Stack <PetalDrop>());
        }

        PetalDrop instance;

        if (stack.Count < 1)
        {
            instance        = Instantiate(prefab);
            instance.prefab = prefab;
        }
        else
        {
            instance = stack.Pop();
        }
        instance.gameObject.SetActive(true);
        return(instance);
    }
Esempio n. 2
0
    void FixedUpdate()
    {
#if UNITY_EDITOR
        if (!Application.isPlaying)
        {
            return;
        }
#endif
        if (state == State.Drag)
        {
            var offset = anchor.forward * flower.petalDragCenterOffset * petalSize;
            var dir    = nextPos - (anchor.position + offset);

            float dist = (new Vector2(dir.x, dir.y).magnitude / petalSize) - (flower.petalDragStart - flower.petalDragCenterOffset);
            if (dist > 0f)
            {
                dist *= Mathf.Clamp01(dist / (1f - flower.petalDragStart));
                if (!flower.MovePetal(anchor.position + dir.normalized * petalSize * dist))
                {
                    state = State.None;

                    var drop = PetalDrop.GetInstance(petalDropPrefab);
                    this.eventData.pointerDrag = drop.gameObject;
                    this.eventData             = null;
                    drop.Init(color, bones);

                    flower.RemovePetal(index);
                }
            }
        }
        else if (state == State.None)
        {
            target.localPosition = Vector3.Lerp(target.localPosition, targetOffset + Vector3.ClampMagnitude(anchor.InverseTransformVector(lastPos - anchor.position), 0.25f), Time.deltaTime);
            lastPos = anchor.position + Vector3.Lerp(Vector3.ClampMagnitude(lastPos - anchor.position, 0.25f), Vector3.zero, Time.deltaTime * 8f);
        }
    }