// Update is called once per frame
    void Update()
    {
        GameTick currentTick = ApplicationState.CurrentGame.TimeMachine.GetCurrentTick();

        textMesh.text = sub.GetDrillerCount().ToString();
        if (ApplicationState.CurrentGame.TimeMachine.GetState().SubExists(sub))
        {
            // Update the position and rotation of the sub.
            Vector3   location  = new Vector3(sub.GetCurrentPosition(currentTick).X, sub.GetCurrentPosition(currentTick).Y, 0);
            Transform transform = GetComponent <Transform>();
            transform.localPosition = location;

            int rotationAngle = (int)(sub.GetRotationRadians() * (360 / (2 * Math.PI)) - 90);
            transform.rotation = Quaternion.Euler(0, 0, rotationAngle);
        }
        else
        {
            /*
             * if ( PrefabUtility.IsPartOfPrefabInstance(transform) )
             * {
             *  //if a part of a prefab instance then get the instance handle
             *  Object prefabInstance = PrefabUtility.GetPrefabInstanceHandle(transform);
             *  //destroy the handle
             *  GameObject.DestroyImmediate(prefabInstance);
             * }
             */
            //the usual destroy immediate to clean up scene objects
            GameObject.DestroyImmediate(transform.gameObject, true);
        }
    }
Esempio n. 2
0
 /// <summary>
 /// Validates a sub
 /// </summary>
 /// <param name="sub">The sub to validate</param>
 /// <returns>If the sub is valid</returns>
 public static bool ValidateSub(GameState state, Sub sub)
 {
     if (sub == null)
     {
         return(false);
     }
     if (!state.SubExists(sub))
     {
         return(false);
     }
     if (sub.GetDrillerCount() < 0)
     {
         return(false);
     }
     if (sub.GetSpecialistManager() == null)
     {
         return(false);
     }
     if (sub.GetSpecialistManager().GetSpecialistCount() < 0)
     {
         return(false);
     }
     if (sub.GetSpecialistManager().GetSpecialistCount() > sub.GetSpecialistManager().GetCapacity())
     {
         return(false);
     }
     if (!state.PlayerExists(sub.GetOwner()))
     {
         return(false);
     }
     return(true);
 }
Esempio n. 3
0
 /// <summary>
 /// Switches the control of the outpost to the owner of the sub
 /// </summary>
 public void TransferOwnership()
 {
     _outpost.SetOwner(_sub.GetOwner());
     _outpost.SetDrillerCount(_sub.GetDrillerCount());
     Game.TimeMachine.GetState().RemoveSub(_sub);
     _wasOwnershipTransferred = true;
 }
Esempio n. 4
0
 public void Constructor()
 {
     Assert.AreEqual(_location.X, _sub.GetInitialPosition().X);
     Assert.AreEqual(_location.Y, _sub.GetInitialPosition().Y);
     Assert.AreEqual(_location.X, _sub.GetDestinationLocation().X);
     Assert.AreEqual(_location.Y, _sub.GetDestinationLocation().Y);
     Assert.AreEqual(_tick, _sub.GetLaunchTick());
     Assert.AreEqual(0, _sub.GetDrillerCount());
 }
Esempio n. 5
0
 // Update is called once per frame
 void Update()
 {
     textMesh.text = sub.GetDrillerCount().ToString();
     if (Game.TimeMachine.GetState().SubExists(sub))
     {
         // Update the position and rotation of the sub.
         Vector3   location  = new Vector3(sub.GetCurrentPosition().X, sub.GetCurrentPosition().Y, 0);
         Transform transform = GetComponent <Transform>();
         transform.localPosition = location;
         transform.rotation      = Quaternion.Euler(0, 0, (int)(sub.GetRotation() * (360 / (2 * Math.PI))) - 135);
     }
     else
     {
         if (PrefabUtility.IsPartOfPrefabInstance(transform))
         {
             //if a part of a prefab instance then get the instance handle
             Object prefabInstance = PrefabUtility.GetPrefabInstanceHandle(transform);
             //destroy the handle
             GameObject.DestroyImmediate(prefabInstance);
         }
         //the usual destroy immediate to clean up scene objects
         GameObject.DestroyImmediate(transform.gameObject, true);
     }
 }
Esempio n. 6
0
 /// <summary>
 /// Undoes a sub launch
 /// </summary>
 /// <param name="sub"> The sub to undo</param>
 public void UndoLaunch(Sub sub)
 {
     this.AddDrillers(sub.GetDrillerCount());
     Game.TimeMachine.GetState().RemoveSub(sub);
 }