/// <summary>
 ///  the class initialisation.
 /// </summary>
 void Start()
 {
     eventscon = GetComponent <VRTK_ControllerEvents>();
     eventscon.TriggerPressed += new ControllerInteractionEventHandler(trigger);
     lineren            = GetComponent <LineRenderer>();
     lineren.startWidth = 0.002f;
     lineren.endWidth   = 0.002f;
     lineren.enabled    = false;
     righthandinstant   = GetComponent <RightHand_triggerInstantOrder>();
     audio = GetComponent <AudioSource>();
 }
Exemple #2
0
 /// <summary>
 /// initiate all the controller event deligates.
 /// </summary>
 void Awake()
 {
     SceneManager.sceneLoaded += OnLevelFinishedLoading;
     righthandscript           = GameObject.Find("RightController").GetComponent <RightHand_triggerInstantOrder>();
     MenuObj.SetActive(false);
     vrtkcontrolevents = GetComponent <VRTK_ControllerEvents>();
     vrtkcontrolevents.TouchpadPressed  += new ControllerInteractionEventHandler(Touchpaddown);
     vrtkcontrolevents.TouchpadReleased += new ControllerInteractionEventHandler(Touchpadup);
     vrtkcontrolevents.TriggerPressed   += new ControllerInteractionEventHandler(Trigger);
     vrtkcontrolevents.TriggerReleased  += new ControllerInteractionEventHandler(TriggerUp);
     vrtkcontrolevents.GripPressed      += new ControllerInteractionEventHandler(gripdownin);
     vrtkcontrolevents.GripReleased     += new ControllerInteractionEventHandler(gripupin);
     vrtkcontrolevents.ButtonTwoPressed += new ControllerInteractionEventHandler(Menu);
     vrtkcontrolevents.ButtonOnePressed += new ControllerInteractionEventHandler(turnbutton);
 }
Exemple #3
0
    /// <summary>
    // called every second to update the AIs orders to adapt to the situation.
    /// <summary>
    public void GiveOrderwait(int waittime)
    {
        if (TrueSyncManager.Time > 0 && randominst != null)
        {
            ships.Clear();
            ships = unitcontrol.teammembersout(team);
            List <TSTransform> temp           = unitcontrol.targetsout(team);
            List <GameObject>  removableships = new List <GameObject>();
            List <TSTransform> enemyremovable = new List <TSTransform>();
            foreach (GameObject ship in ships)
            {
                if (ship == null || ship.gameObject == null)
                {
                    removableships.Add(ship);
                }
            }
            foreach (GameObject remov in removableships)
            {
                ships.Remove(remov);
            }
            foreach (TSTransform ship in temp)
            {
                if (ship == null || ship.gameObject == null)
                {
                    enemyremovable.Add(ship);
                }
            }
            foreach (TSTransform remov in enemyremovable)
            {
                temp.Remove(remov);
            }
            debugmaxcount = ships.Count.ToString() + " out of " + UnitMovementcommandcontroller.getmaxshipnumbers().ToString();
            if (startpos == new TSVector(0, 0, 0) && ships.Count > 0)
            {
                startpos = ships[0].GetComponent <TSTransform>().position + new TSVector(1, 0, 0);
            }
            Target = getclosesttarget();

            if (((ismission == false && ships.Count > 0) || (crosslevelvar.campaign == true && crosslevelvar.campaignlevel.objective == MainMenuCampaignControlScript.eMissionObjective.Survive)) && unitcontrol)
            {
                BuyShip();
            }

            if (temp.Count != 0)
            {
                enemyships = temp.ToArray();
            }
            if (ships != null && ships.Count != 0 && ships.Count > 4)
            {
                state = AIstate.attacking;
            }
            if (ships != null && ships.Count != 0 && ships.Count <= 3)
            {
                state = AIstate.retreating;
            }
            if (ships != null && ships.Count != 0 && ships.Count > 2 && ships.Count < 4)
            {
                state = AIstate.maintain;
            }
            if (ships != null && ships.Count != 0 && state == AIstate.retreating && TSVector.Distance(ships[0].GetComponent <TSTransform>().position, startpos) < 1000)
            {
                state = AIstate.holding;
            }
            if (ships != null && ships != null && ships.Count != 0 && ships[0] && Target != null && ships[0].gameObject != null && state == AIstate.holding && TSVector.Distance(ships[0].GetComponent <TSTransform>().position, Target.GetComponent <TSTransform>().position) < 1000)
            {
                state = AIstate.attacking;
            }
            if (ships != null && ships.Count != 0 && state == AIstate.maintain && ships.Count > 0 && TSVector.Distance(ships[0].GetComponent <TSTransform>().position, startpos) < 1000)
            {
                state = AIstate.retreating;
            }
            if (ships != null && ships.Count != 0 && state == AIstate.maintain && ships.Count > 0 && TSVector.Distance(ships[0].GetComponent <TSTransform>().position, startpos) > 1000)
            {
                state = AIstate.attacking;
            }
            if (ismission && timepassedactual > 30)
            {
                state = AIstate.attacking;
            }
            if (ismission && timepassedactual < 30)
            {
                state = AIstate.holding;
            }
            if (ismission && unitcontrol.crosslevelholder.campaignlevel.objective == MainMenuCampaignControlScript.eMissionObjective.Survive)
            {
                state = AIstate.attacking;
            }
            int i = 0;

            foreach (GameObject ship in ships)
            {
                if (Target != null && ship.gameObject != null && state == AIstate.attacking)
                {
                    ship.GetComponent <_Ship>().asignMoveOrder(Target.GetComponent <TSTransform>().position, Target.gameObject, RightHand_triggerInstantOrder.calculate_average_speed(ships.ToArray()), false);
                }
                if (ship.gameObject != null && state == AIstate.retreating)
                {
                    ship.GetComponent <_Ship>().asignMoveOrder(TargetPosition(i, startpos, ships.Count), null, RightHand_triggerInstantOrder.calculate_average_speed(ships.ToArray()), false);
                }
                if (ship.gameObject != null && state == AIstate.holding)
                {
                    _Ship shipscript = ship.GetComponent <_Ship>();
                    if (shipscript.HullType == eHullType.Light)
                    {
                        shipscript.asignMoveOrder(startpos, null, RightHand_triggerInstantOrder.calculate_average_speed(ships.ToArray()), false);
                    }
                    else
                    {
                        shipscript.asignMoveOrder(ship.GetComponent <TSTransform>().position, null, RightHand_triggerInstantOrder.calculate_average_speed(ships.ToArray()), false);
                    }
                }
                i++;
            }
        }
    }