public void Update(Vector3 pos)
        {
            //Debug.Log("Update is being called!");
            Vector3 place = pos;

            if (atmosphere)
            {
                //Debug.Log("In Atmosphere");
                if (forceUpdate)
                {
                    // Debug.Log("ForceUpdate");
                    Recenter(pos, true);
                    Magnitude = pos.magnitude;
                    VolumeList[0].Reassign(Center.localPosition, new Vector3(-radius, 0, 0), Magnitude);
                    VolumeList[1].Reassign(Center.localPosition, new Vector3(halfRad, 0, opp), Magnitude);
                    VolumeList[2].Reassign(Center.localPosition, new Vector3(halfRad, 0, -opp), Magnitude);
                }
                int mag = (int)pos.magnitude;
                int i   = mag / 3000;
                mag       = 3000 * i;
                Magnitude = mag;
                pos.Normalize();
            }
            else
            {
                //Debug.Log("Not atmosphere?"); is being called when at space center
                place *= Magnitude;
            }
            int moveCount      = 0;
            int unchangedCount = 0;

            for (int i = 0; i < VolumeList.Count; i++)
            {
                VolumeSection volumeSection = VolumeList[i];
                float         distance      = Vector3.Distance(volumeSection.Center, place);
                if (distance > outCheck || forceUpdate)
                {
                    //Debug.Log("Distance... ForceUpdate"); Is being called 3 times during Flight
                    moveSections[moveCount++] = volumeSection;
                }
                else
                {
                    //Debug.Log("!Distance...ForceUpdate"); Is being called on SpaceCenter repeatedly
                    unchangedSections[unchangedCount++] = volumeSection;
                }
            }
            forceUpdate = false;
            if (moveCount > 0)
            {
                //Debug.Log("MoveCount > 0"); is being called once on SpaceCenter
                Vector3 tmp;
                switch (moveCount)
                {
                case 1:
                    //Debug.Log("Case 1"); //Called after Case 3 has been called, repeated call over time
                    Recenter(-moveSections[0].Offset);
                    tmp = unchangedSections[0].Offset;
                    unchangedSections[0].Offset = -unchangedSections[1].Offset;
                    unchangedSections[1].Offset = -tmp;
                    moveSections[0].Reassign(Center.localPosition, -moveSections[0].Offset, Magnitude);
                    if (!atmosphere)
                    {
                        moveSections[0].Update();
                    }
                    break;

                case 2:
                    //Debug.Log("Case 2");
                    Recenter(2f * unchangedSections[0].Offset);
                    unchangedSections[0].Offset *= -1f;
                    tmp = moveSections[0].Offset;
                    moveSections[0].Reassign(Center.localPosition, -moveSections[1].Offset, Magnitude);
                    moveSections[1].Reassign(Center.localPosition, -tmp, Magnitude);
                    if (!atmosphere)
                    {
                        moveSections[0].Update();
                        moveSections[1].Update();
                    }
                    break;

                case 3:
                    //Debug.Log("Case 3"); //Case 3 was called on SpaceCenter, and Flight
                    Recenter(place, true);
                    moveSections[0].Reassign(Center.localPosition, new Vector3(-radius, 0, 0), Magnitude);
                    moveSections[1].Reassign(Center.localPosition, new Vector3(halfRad, 0, opp), Magnitude);
                    moveSections[2].Reassign(Center.localPosition, new Vector3(halfRad, 0, -opp), Magnitude);
                    if (!atmosphere)
                    {
                        //Debug.Log("Not Atmosphere"); called on  SpaceCenter
                        moveSections[0].Update();
                        moveSections[1].Update();
                        moveSections[2].Update();
                    }
                    break;
                }
            }
        }
Esempio n. 2
0
        public void Update(Vector3 pos)
        {
            Vector3 place = pos;

            if (atmosphere)
            {
                if (forceUpdate)
                {
                    Recenter(pos, true);
                    Magnitude = pos.magnitude;
                    VolumeList[0].Reassign(Center.localPosition, new Vector3(-radius, 0, 0), Magnitude);
                    VolumeList[1].Reassign(Center.localPosition, new Vector3(halfRad, 0, opp), Magnitude);
                    VolumeList[2].Reassign(Center.localPosition, new Vector3(halfRad, 0, -opp), Magnitude);
                }

                int mag = (int)pos.magnitude;
                int i   = mag / 3000;
                mag       = 3000 * i;
                Magnitude = mag;

                pos.Normalize();
            }
            else
            {
                place *= Magnitude;
            }

            int moveCount      = 0;
            int unchangedCount = 0;

            for (int i = 0; i < VolumeList.Count; i++)
            {
                VolumeSection volumeSection = VolumeList[i];
                float         distance      = Vector3.Distance(volumeSection.Center, place);

                if (distance > outCheck || forceUpdate)
                {
                    moveSections[moveCount++] = volumeSection;
                }
                else
                {
                    unchangedSections[unchangedCount++] = volumeSection;
                }
            }
            forceUpdate = false;
            if (moveCount > 0)
            {
                Vector3 tmp;
                switch (moveCount)
                {
                case 1:
                    Recenter(-moveSections[0].Offset);

                    tmp = unchangedSections[0].Offset;
                    unchangedSections[0].Offset = -unchangedSections[1].Offset;
                    unchangedSections[1].Offset = -tmp;
                    moveSections[0].Reassign(Center.localPosition, -moveSections[0].Offset, Magnitude);
                    if (!atmosphere)
                    {
                        moveSections[0].Update();
                    }
                    break;

                case 2:
                    Recenter(2f * unchangedSections[0].Offset);

                    unchangedSections[0].Offset *= -1f;
                    tmp = moveSections[0].Offset;
                    moveSections[0].Reassign(Center.localPosition, -moveSections[1].Offset, Magnitude);
                    moveSections[1].Reassign(Center.localPosition, -tmp, Magnitude);
                    if (!atmosphere)
                    {
                        moveSections[0].Update();
                        moveSections[1].Update();
                    }
                    break;

                case 3:
                    Recenter(place, true);
                    moveSections[0].Reassign(Center.localPosition, new Vector3(-radius, 0, 0), Magnitude);
                    moveSections[1].Reassign(Center.localPosition, new Vector3(halfRad, 0, opp), Magnitude);
                    moveSections[2].Reassign(Center.localPosition, new Vector3(halfRad, 0, -opp), Magnitude);
                    if (!atmosphere)
                    {
                        moveSections[0].Update();
                        moveSections[1].Update();
                        moveSections[2].Update();
                    }
                    break;
                }
            }
        }