Пример #1
0
    void UpdateMove()
    {
        int rem = 0;

        for (int i = 0; i < motorUnits.Count; i++)
        {
            MotorUnit m          = motorUnits[i];
            float     currentdis = m.CurrentDistance;
            currentdis += speed * Time.deltaTime;
            if (currentdis > m.AllDistance && m.id >= keyFrameGameobjects.Count - 1)
            {
                rem++;
                continue;
            }
            break;
        }

        while (rem > 0)
        {
            Destroy(motorUnits[0].moveGameobject);
            motorUnits.RemoveAt(0);
            rem--;
        }

        if (motorUnits.Count > 0)
        {
            float newdis = motorUnits[0].AllDistance - motorUnits[0].CurrentDistance - speed * Time.deltaTime;
            if (newdis < 0)
            {
                motorUnits[0].id++;
                motorUnits[0].start           = keyFrameGameobjects[motorUnits[0].id - 1];
                motorUnits[0].end             = keyFrameGameobjects[motorUnits[0].id];
                motorUnits[0].CurrentDistance = Mathf.Abs(newdis);
            }
            else
            {
                motorUnits[0].CurrentDistance += speed * Time.deltaTime;
            }
        }
        if (motorUnits.Count > 1)
        {
            for (int i = 1; i < motorUnits.Count; i++)
            {
                TargetCreatPara para = GetKeyFrameID(motorUnits[i - 1], distance);
                if (para.id > 0)
                {
                    motorUnits[i].id              = para.id;
                    motorUnits[i].start           = keyFrameGameobjects[para.id - 1];
                    motorUnits[i].end             = keyFrameGameobjects[para.id];
                    motorUnits[i].CurrentDistance = para.distance;
                }
            }
        }
    }
Пример #2
0
 void CreatElement()
 {
     if (templetGameobject == null)
     {
         return;
     }
     if (motorUnits.Count == 0)
     {
         GameObject game = Object.Instantiate <GameObject>(templetGameobject);
         if (parentGo != null)
         {
             game.transform.parent = parentGo.transform;
         }
         MotorUnit mu = new MotorUnit();
         mu.moveGameobject  = game;
         mu.start           = keyFrameGameobjects[0];
         mu.end             = keyFrameGameobjects[1];
         mu.CurrentDistance = 0;
         mu.id = 1;
         motorUnits.Add(mu);
     }
     else
     {
         int i = 10;
         while (i > 1)
         {
             MotorUnit       father = motorUnits[motorUnits.Count - 1];
             TargetCreatPara para   = GetKeyFrameID(father, distance);
             if (para.id > 0)
             {
                 GameObject game     = Object.Instantiate <GameObject>(templetGameobject);
                 GameObject parentGo = GameObject.Find("SLFather");
                 if (parentGo != null)
                 {
                     game.transform.parent = parentGo.transform;
                 }
                 MotorUnit mu = new MotorUnit();
                 mu.moveGameobject  = game;
                 mu.start           = keyFrameGameobjects[para.id - 1];
                 mu.end             = keyFrameGameobjects[para.id];
                 mu.CurrentDistance = para.distance;
                 mu.id = para.id;
                 motorUnits.Add(mu);
             }
             i = para.id;
         }
         // print("CreatElement__11");
     }
 }
Пример #3
0
    void UpdateMoveFixedDistance()
    {
        DestroyGameobject();
        List <MotorUnit> removeRest = new List <MotorUnit>();

        if (motorUnits.Count > 0)
        {
            float newdis = motorUnits[0].AllDistance - motorUnits[0].CurrentDistance - speed * Time.deltaTime;
            if (newdis < 0)
            {
                motorUnits[0].id++;
                motorUnits[0].start           = keyFrameGameobjects[motorUnits[0].id - 1];
                motorUnits[0].end             = keyFrameGameobjects[motorUnits[0].id];
                motorUnits[0].CurrentDistance = Mathf.Abs(newdis);
            }
            else
            {
                motorUnits[0].CurrentDistance += speed * Time.deltaTime;
            }
        }
        if (motorUnits.Count > 1)
        {
            for (int i = 1; i < motorUnits.Count; i++)
            {
                TargetCreatPara para = GetKeyFrameID(motorUnits[i - 1], distance);
                if (para.id > 0)
                {
                    motorUnits[i].id              = para.id;
                    motorUnits[i].start           = keyFrameGameobjects[para.id - 1];
                    motorUnits[i].end             = keyFrameGameobjects[para.id];
                    motorUnits[i].CurrentDistance = para.distance;
                }
                else
                {
                    removeRest.Add(motorUnits[i]);
                }
            }
        }
        while (removeRest.Count > 0)
        {
            GameObject.Destroy(removeRest[0].moveGameobject);
            motorUnits.Remove(removeRest[0]);
            removeRest.RemoveAt(0);
        }
    }
Пример #4
0
 void CreatElement()
 {
     if (templetGameobject == null)
     {
         return;
     }
     if (motorUnits.Count == 0)
     {
         CreatFirst();
     }
     else
     {
         if (playMode == PlayMode.FixedDistance)
         {
             int i = 10;
             while (i > 1)
             {
                 MotorUnit       father = motorUnits[motorUnits.Count - 1];
                 TargetCreatPara para   = GetKeyFrameID(father, distance);
                 if (para.id > 0)
                 {
                     GameObject game = UnityEngine.Object.Instantiate <GameObject>(templetGameobject);
                     MotorUnit  mu   = new MotorUnit();
                     mu.moveGameobject  = game;
                     mu.start           = keyFrameGameobjects[para.id - 1];
                     mu.end             = keyFrameGameobjects[para.id];
                     mu.CurrentDistance = para.distance;
                     mu.id = para.id;
                     motorUnits.Add(mu);
                 }
                 i = para.id;
             }
         }
         if (playMode == PlayMode.FixedCreatSpeed)
         {
             if (Time.time - creatTime > creatSpeed)
             {
                 creatTime = Time.time;
                 CreatFirst();
             }
         }
     }
 }