示例#1
0
    protected void Move()
    {
        if (!isActive)
        {
            return;
        }

        switch (moveType)
        {
        case MoveType.straight:
            transform.Translate(Vector3.left * speed * Time.deltaTime, Space.World);
            break;

        case MoveType.itween:
            if (hasItweenMoving)
            {
                return;
            }

            MyiTweenPath iPath = GetComponent <MyiTweenPath>();
            if (iPath == null)
            {
                break;
            }

            for (int i = 0; i < iPath.nodeCount; i++)
            {
                iPath.nodes[i] = (iPath.nodes[i] - transform.position) + transform.localPosition;
            }
            string pathName = iPath.pathName;
            hasItweenMoving = true;
            iTween.MoveTo(gameObject, iTween.Hash("movetopath", false,
                                                  "path", MyiTweenPath.GetPath(pathName),
                                                  "time", iTweenDuration,
                                                  "easetype", iTween.EaseType.easeOutSine,
                                                  "isLocal", true,
                                                  "oncomplete", "SecondMove"));
            break;
        }
    }
示例#2
0
    void OnEnable()
    {
        _target    = (MyiTweenPath)target;
        components = ((MonoBehaviour)target).gameObject.GetComponents <MyiTweenPath>();
        for (int i = 0; i < components.Length; i++)
        {
            if (ReferenceEquals(_target, components[i]))
            {
                index = i;
            }
        }

        //lock in a default path name:
        if (!_target.initialized)
        {
            _target.initialized = true;
            _target.pathName    = "My New Path " + ++count;
            _target.initialName = _target.pathName;
            _target.nodes[0]    = _target.transform.position;
            _target.nodes[1]    = _target.transform.position + Vector3.left * 35;
        }
    }