Inheritance: MonoBehaviour
Example #1
0
 public MonoBehaviour changeMotionModel(GlobalControl.motionModels newMotionModel)
 {
     //First, remove previous motion model
     DestroyImmediate (motionComponent);
     //Add the new motion model
     switch (newMotionModel){
         case GlobalControl.motionModels.DISCRETE:
             motionComponent = (MonoBehaviour)gameObject.AddComponent<MoveDiscrete>();
             break;
         case GlobalControl.motionModels.KINEMATIC:
             motionComponent = (MonoBehaviour)gameObject.AddComponent<MoveKinematic>();
             break;
         case GlobalControl.motionModels.DYNAMIC:
             motionComponent = (MonoBehaviour)gameObject.AddComponent<MoveDynamic>();
             break;
         case GlobalControl.motionModels.DIFFERENTIAL:
             motionComponent = (MonoBehaviour)gameObject.AddComponent<MoveDifferential>();
             break;
         case GlobalControl.motionModels.CAR:
             motionComponent = (MonoBehaviour)gameObject.AddComponent<MoveCar>();
             break;
     }
     motionModel = newMotionModel;
     return motionComponent;
 }
Example #2
0
 public void changeMotionModel(GlobalControl.motionModels newMotionModel)
 {
     GlobalMove globalMove = gameObject.GetComponent<GlobalMove> ();
     switch (newMotionModel){
         case GlobalControl.motionModels.DISCRETE:{
             MonoBehaviour control = globalMove.changeMotionModel(GlobalControl.motionModels.DISCRETE);
             controller = new PController(control);
             break;
         }
         case GlobalControl.motionModels.KINEMATIC:{
             MonoBehaviour control = globalMove.changeMotionModel(GlobalControl.motionModels.KINEMATIC);
             controller = new PController(control);
             break;
         }
         case GlobalControl.motionModels.DYNAMIC:{
             MonoBehaviour control = globalMove.changeMotionModel(GlobalControl.motionModels.DYNAMIC);
             controller = new PDController(control);
             break;
         }
         case GlobalControl.motionModels.DIFFERENTIAL:{
             MonoBehaviour control = globalMove.changeMotionModel(GlobalControl.motionModels.DIFFERENTIAL);
             controller = new PController(control);
             break;
         }
         case GlobalControl.motionModels.CAR:{
             MonoBehaviour control = globalMove.changeMotionModel(GlobalControl.motionModels.CAR);
             controller = new PController(control);
             break;
         }
     }
     motionModel = newMotionModel;
 }
Example #3
0
 public void changeControlModel(GlobalControl.motionModels newMotionModel)
 {
     print ("CHANGING TO " + newMotionModel);
     //First, remove previous control model
     DestroyImmediate (controlComponent);
     //Add the new motion model
     switch (newMotionModel){
         case motionModels.DISCRETE:
             controlComponent = (MonoBehaviour)gameObject.AddComponent("ControlDiscrete");
             motionScript.changeMotionModel(motionModels.DISCRETE);
             break;
         case motionModels.KINEMATIC:
             controlComponent = (MonoBehaviour)gameObject.AddComponent("ControlKinematic");
             motionScript.changeMotionModel(motionModels.KINEMATIC);
             break;
         case motionModels.DYNAMIC:
             controlComponent = (MonoBehaviour)gameObject.AddComponent("ControlDynamic");
             motionScript.changeMotionModel(motionModels.DYNAMIC);
             break;
         case motionModels.DIFFERENTIAL:
             controlComponent = (MonoBehaviour)gameObject.AddComponent("ControlDifferential");
             motionScript.changeMotionModel(motionModels.DIFFERENTIAL);
             break;
         case motionModels.CAR:
             controlComponent = (MonoBehaviour)gameObject.AddComponent("ControlCar");
             motionScript.changeMotionModel(motionModels.CAR);
             break;
     }
     //Reset orientation
     gameObject.transform.rotation = Quaternion.identity;
 }
Example #4
0
 public void changeMotionModel(GlobalControl.motionModels newMotionModel)
 {
     //Destroy current motion model
     Destroy (control);
     //Add new motion model
     switch (newMotionModel){
         case GlobalControl.motionModels.DISCRETE:
             control = gameObject.AddComponent<MoveDiscrete>();
             controller = new PController(control);
             break;
         case GlobalControl.motionModels.KINEMATIC:
             control = gameObject.AddComponent<MoveKinematic>();
             controller = new PController(control);
             break;
         case GlobalControl.motionModels.DYNAMIC:
             control = gameObject.AddComponent<MoveDynamic>();
             controller = new PDController(control);
             break;
         case GlobalControl.motionModels.DIFFERENTIAL:
             control = gameObject.AddComponent<MoveDifferential>();
             controller = new PController(control);
             break;
         case GlobalControl.motionModels.CAR:
             control = gameObject.AddComponent<MoveCar>();
             controller = new PController(control);
             break;
         }
     motionModel = newMotionModel;
 }
Example #5
0
 void Awake()
 {
     if (Instance == null)
     {
         Instance = this;
     }
     else if (Instance != this)
     {
         Destroy (gameObject);
     }
 }
Example #6
0
 GameObject instatiateNewRobot(GameObject prefab,Transform t,int id, GlobalControl.motionModels motionModel)
 {
     GameObject newO = (GameObject)Object.Instantiate(prefab,t.position,Quaternion.identity);
     newO.name = robotName+id.ToString();
     newO.tag = robotTag;
     newO.gameObject.SetActive(true);
     //Add VS script control
     vs_Control vsControl = newO.AddComponent<vs_Control>();
     vsControl.changeMotionModel (motionModel);
     return newO;
 }
Example #7
0
    // Main function
    public void controlFunction(Transform own, Vector3 targetPosition, float minDistance, float bearing, GlobalControl.motionModels motionModel)
    {
        //Check if we consider bearing information. In this case, we want the robot to be at an exact position,
        //so we change the target to be that position, and the minDistance is 0
        Vector3 target = new Vector3(targetPosition.x,targetPosition.y,targetPosition.z);
        if (bearing != defaultNoBearing) {
            target = new Vector3(target.x+minDistance*Mathf.Cos (bearing),target.y,
                                                    target.z+minDistance*Mathf.Sin (bearing));
            minDistance = 0; //We want to be at this exact point.
        }
        float distance = Vector2.Distance (new Vector2(own.position.x,own.position.z),
                                           new Vector2(target.x,target.z));

        if(Mathf.Abs(distance-minDistance)>TOLERANCE_DISTANCE){
            Vector3 toRobotVector = target - own.position;
            float theta = Mathf.Atan2 (toRobotVector.z, toRobotVector.x);
            //Fix theta to avoid discontinuities
            if (Mathf.Abs (theta) > Mathf.PI)
                theta = theta - (2 * Mathf.PI * Mathf.Sign (theta));

            float errorX = (distance - minDistance) * Mathf.Cos (theta);
            float errorZ = (distance - minDistance) * Mathf.Sin (theta);

            switch (motionModel){
                case GlobalControl.motionModels.DISCRETE:{
                    break;
                }
                case GlobalControl.motionModels.KINEMATIC:{
                    break;
                }
                case GlobalControl.motionModels.DYNAMIC: {
                float fx = kp*errorX + kd*(errorX-prevErrorX);
                float fz = kp*errorZ + kd*(errorZ-prevErrorZ);

                    prevErrorX = errorX;
                    prevErrorZ = errorZ;
        //					Debug.DrawLine(own.position,own.position+new Vector3(fx,0,fz),Color.red);

                    ((MoveDynamic)control).applyMotion(fx,fz);
                    break;
                }
                case GlobalControl.motionModels.DIFFERENTIAL:{
                    break;
                }
                case GlobalControl.motionModels.CAR:{
                    break;
                }
            }
        }
    }
Example #8
0
    void Awake()
    {
        if (Instance == null)
        {
            //needed for cross-scene persistence
            DontDestroyOnLoad(gameObject);
            Instance = this;
        }
        else if (Instance != this)
        {
            Destroy(gameObject);
        }

        //addHiddenGameObject ("Wrapuchin");
        Debug.Log("Start");
    }
Example #9
0
    void Awake()
    {
        savedStatData       = gameObject.AddComponent <StatData>();
        savedSkillData      = gameObject.AddComponent <SkillData>();
        savedProfessionData = gameObject.AddComponent <ProfessionData>();

        if (Instance == null)
        {
            DontDestroyOnLoad(gameObject);
            Instance = this;
        }
        else if (Instance != this)
        {
            Destroy(gameObject);
        }
    }
Example #10
0
    public Vector3 playerpos;    //玩家进入地图一开始的位置

    private void Awake()
    {
        if (_instance != null && _instance != this)
        {
            Destroy(this.gameObject);
        }
        else
        {
            _instance = this;
            DontDestroyOnLoad(gameObject);
            Instance.BattleSceneindex = 0;
            Instance.playerpos        = new Vector3(-2.12f, -1.02f, 0);
            Instance.TeamLeftHP       = 100000;
            Instance.PlayerPosindex   = 0;
        }
    }
Example #11
0
    //private Counter counterScript;
    //private UserInput userInputScript;
    //private GameSaver gameSaverScript;
    //private SetStarStatus setStarStatusScript;


    void Start()
    {
        spriteRenderer = GetComponent <SpriteRenderer>();
        if (spriteRenderer.sprite == null)
        {
            spriteRenderer.sprite = buttonIn;
        }

        globalControlScript = FindObjectOfType <GlobalControl>();
        //counterScript = FindObjectOfType<Counter>();
        //userInputScript = FindObjectOfType<UserInput>();
        //gameSaverScript = FindObjectOfType<GameSaver>();
        //setStarStatusScript = FindObjectOfType<SetStarStatus>();

        sceneName = SceneManager.GetActiveScene().name;
    }
    void Start()
    {
        app        = FindObjectOfType <App>();
        gc         = FindObjectOfType <GlobalControl>();
        currentLvl = gc.GetSelectedLevel();

        app.playerFactory.playerModel.lives
        .ObserveEveryValueChanged(l => l.Value)
        .Subscribe(l => {
            if (l <= 0)
            {
                PlayerDie();
            }
        }).AddTo(this);
        LevelGenerate(currentLvl);
    }
Example #13
0
    //load previous scene
    public void loadBack()
    {
        GlobalControl gc = GameObject.Find("GlobalControl").GetComponent <GlobalControl>();

        if (gc.scenes.Count <= 0)//when there is no previous scene
        {
            Debug.Log("There is no previous scene");
            return;
        }
        SceneInfo si    = gc.scenes.Pop(); //the previous scene
        string    sName = si.sceneName;    //gets the previous scene's name

        gc.save();                         //save current data
        gc.sceneInformation = si;          //passes scene information to restore
        SceneManager.LoadScene(sName);
    }
Example #14
0
 void Awake()
 {
     if (Instance == null)
     {
         DontDestroyOnLoad(gameObject);
         Instance  = this;
         musicEasy = GameObject.FindGameObjectWithTag("musicEasy").GetComponent <AudioSource>();
         musicHard = GameObject.FindGameObjectWithTag("musicHard").GetComponent <AudioSource>();
         compsEasy = Resources.LoadAll <GameObject>("Obstacles/easyObstacles");
         compsHard = Resources.LoadAll <GameObject>("Obstacles/hardObstacles");
     }
     else
     {
         Destroy(gameObject);
     }
 }
 void Awake()
 {
     if (Instance == null)
     {
         Debug.Log("Creating new GlobalControl");
         DontDestroyOnLoad(gameObject);
         Instance = this;
     }
     else if (Instance != this)
     {
         Debug.Log("Updating GlobalControl");
         Destroy(gameObject);
     }
     savePath = Application.persistentDataPath + "/saveValues.sheep";
     Load();
 }
    // Start is called before the first frame update

    private void Awake()
    {
        if (Instance == null)
        {
            Camera cam = Camera.main;
            upperBound = cam.transform.position.y + cam.orthographicSize;
            rightBound = cam.transform.position.x + cam.orthographicSize * cam.aspect;
            lowerBound = cam.transform.position.y - cam.orthographicSize;
            leftBound  = cam.transform.position.x - cam.orthographicSize * cam.aspect;
            DontDestroyOnLoad(gameObject);
            Instance = this;
        }
        else
        {
            Destroy(gameObject);
        }
    }
 void Awake()
 {
     if (SceneManager.GetActiveScene().name != "KoniecGry")
     {
         if (Instance == null)
         {
             Player     = GameObject.Find("Player");
             blacksmith = GameObject.Find("BlacksmithInventory");
             DontDestroyOnLoad(gameObject);
             Instance = this;
         }
         else if (Instance != this)
         {
             Destroy(gameObject);
         }
     }
 }
Example #18
0
    void Start()
    {
        spriteRenderer = GetComponent <SpriteRenderer>();
        if (spriteRenderer.sprite == null)
        {
            spriteRenderer.sprite = buttonIn; // set the sprite to sprite1
        }

        pauseGameScript     = FindObjectOfType <PauseGameStatus>();
        buttonActionsScript = FindObjectOfType <ButtonActions>();
        globalControlScript = FindObjectOfType <GlobalControl>();
        gameSaverScript     = FindObjectOfType <GameSaver>();

        audioSource = GetComponent <AudioSource>();

        move = false;
    }
Example #19
0
    void Awake()
    {
        if (instance == null)
        {
            DontDestroyOnLoad(gameObject);
            instance = this;
        }
        else if (instance != this)
        {
            Destroy(gameObject);
        }

        //sessionData.hasDoneValidationByImage = false;
        //sessionData.sessionPaused = false;
        sessionData.selectedScenario = 0;
        sessionData.selectedRoute    = 0;
    }
Example #20
0
 void changeRobotsMotionModel(GlobalControl.motionModels motionModel)
 {
     //Iterate through all the robots and change it
     GameObject[] robots = GameObject.FindGameObjectsWithTag (robotTag);
     for(int i=0;i<robots.Length;i++){
         GameObject g  = robots[i];
         if(g.name!=leaderName){
             Transform t = g.transform;
             GameObject g2;
             switch(motionModel){
                 case GlobalControl.motionModels.DISCRETE:
                     //Destroy object and instantiate a new one
                     Destroy(g);
                     g2 = instantiateRobot(sphere,t);
                     g2.AddComponent<nn_discrete>();
                     break;
                 case GlobalControl.motionModels.KINEMATIC:
                     //Destroy object and instantiate a new one
                     Destroy(g);
                     g2 = instantiateRobot(sphere,t);
                     g2.AddComponent<nn_kinematic>();
                     break;
                 case GlobalControl.motionModels.DYNAMIC:
                     //Destroy object and instantiate a new one
                     Destroy(g);
                     g2 = instantiateRobot(sphere,t);
                     g2.AddComponent<nn_dynamic>();
                     break;
                 case GlobalControl.motionModels.DIFFERENTIAL:{
                     //Destroy object and instantiate a new one
                     Destroy(g);
                     g2 = instantiateRobot(differential,t);
                     g2.AddComponent<nn_differential>();
                     break;
                 }
                 case GlobalControl.motionModels.CAR:{
                     //Destroy object and instantiate a new one
                     Destroy(g);
                     g2 = instantiateRobot(car,t);
                     g2.AddComponent<nn_car>();
                     break;
                 }
             }
         }
     }
 }
    // Update is called once per frame
    void Update()
    {
        //Horizontal movment for the character
        float inputX = GlobalControl.GetHorizontal(num);

        theRigidBody.velocity = new Vector2(inputX * speed, theRigidBody.velocity.y);



        //makes a character jump if they press A
        //want to make a double jump, you can only jup is you have a jump left.
        bool jump = GlobalControl.GetButtonDownA(num);


        if (jump && theRigidBody.transform.position.y < (-3.10) || jump && onFridge)
        {
            theRigidBody.velocity = new Vector2(theRigidBody.velocity.x, jumpPower);
        }
        if (onFridge)
        {
            animator.SetBool("isJumping", false);
        }
        if (transform.position.y < (-3.10) || onFridge)
        {
            animator.SetBool("isJumping", false);
        }
        else
        {
            animator.SetBool("isJumping", true);
        }
        animator.SetFloat("speed", Mathf.Abs(theRigidBody.velocity.x));

        if (theRigidBody.velocity.x < 0)
        {
            sR.flipX = true;
        }
        else
        {
            sR.flipX = false;
        }
        if (theRigidBody.transform.position.x > -7f || theRigidBody.transform.position.y > 0)
        {
            onFridge = false;
        }
    }
Example #22
0
 private void Awake()
 {
     // ------------------------------------------------------------------------
     // make sure that there is only ever one of these gameobjects in existance
     // ------------------------------------------------------------------------
     if (Instance == null)
     {
         DontDestroyOnLoad(gameObject);
         Instance = this;
     }
     else if (Instance != this)
     {
         Destroy(gameObject);
     }
     // ------------------------------------------------------------------------
     // Load the inital JSON file ** moved from the start function and works well now.
     LoadAsJSON();
 }
Example #23
0
    void Awake()
    {
        if (Instance == null)
        {
            DontDestroyOnLoad(gameObject);
            Instance = this;
        }
        else if (Instance != this)
        {
            Destroy(gameObject);
        }

        inviteeName       = "";
        date              = "";
        languageSelected  = 0;
        videoTypeSelected = 0;
        music             = 0;
    }
    // Update is called once per frame
    void Update()
    {
        var x = GlobalControl.GetHorizontal(BossPNum) * 0.05f * speed;

        if (transform.position.x + x > bounds.max.x)
        {
            Debug.Log("Clamping " + transform.position.x + " into " + bounds.max.x);
            x = Mathf.Clamp(x, int.MinValue, 0);
        }
        else if (transform.position.x + x < bounds.min.x)
        {
            x = Mathf.Clamp(x, 0, int.MaxValue);
        }
        transform.position += new Vector3(x, 0, 0);

        if (players.TrueForAll(isDisabled))
        {
            ChangeScene("End_Screen");
            Debug.Log("Game Over");
        }
        frameCt++;
        if (currentObstacle != null)
        {
            currentObstacle.transform.position = transform.position;
            //Debug.Log ("Updating " + Input.GetButton ("X_P1"));
            if (GlobalControl.GetButtonA(BossPNum) || Input.GetKeyDown(KeyCode.Space))
            {
                Debug.Log("Pressed");
                currentObstacle.GetComponent <Obstacle>().setActive(conveyor);
                currentObstacle = null;
                frameCt         = 0;
            }
        }
        else
        {
            if (frameCt > frameDelay)
            {
                currentObstacle = Instantiate(obPreFabs[Random.Range(0, obPreFabs.Length)]).GetComponent <Obstacle>();
                currentObstacle.GetComponent <AffectedByConveyor>().conveyor = conveyor;
                currentObstacle.transform.position = transform.position;
                frameCt = 0;
            }
        }
    }
Example #25
0
 void Awake()
 {
     if (!globalControl)
     {
         //Initialize globalcontrol
         globalControl = this;
         DontDestroyOnLoad(gameObject);
         //Initialize variables on game start
         coins = 0;
         stats = new SpellcastStats();
         stats.InitializeValues(1, 1, 1, 1);
         PauseScript.unlockedShapes   = new bool[] { true, false, false };
         PauseScript.unlockedElements = new bool[] { true, false, false, false, false, false };
     }
     else
     {
         Destroy(gameObject);
     }
 }
Example #26
0
    void Awake()
    {
        Application.targetFrameRate = 144;

        if (Instance == null)
        {
            DontDestroyOnLoad(gameObject);
            Instance = this;
        }
        else if (Instance != this)
        {
            Destroy(gameObject);
        }

        if (TransitionTarget == null)
        {
            TransitionTarget = gameObject.transform;
        }
    }
Example #27
0
    // Start is called before the first frame update
    void Start()
    {
        GlobalControl TotalStats = GlobalControl.Instance;

        if (TotalStats == null)
        {
            return;
        }
        shotsFired     = GameObject.Find("ShotsFired");
        accuracy       = GameObject.Find("Accuracy");
        roomsCompleted = GameObject.Find("RoomsCompleted");
        ItemsPickedUp  = GameObject.Find("ItemsPickedUp");
        EnemiesKilled  = GameObject.Find("EnemiesKilled");
        shotsFired.GetComponent <Text>().text     = "SHOTS FIRED: " + TotalStats.savedPlayerData.totalShots.ToString();
        accuracy.GetComponent <Text>().text       = "Accuracy: " + ((TotalStats.savedPlayerData.bulletsHit / TotalStats.savedPlayerData.totalShots) * 100).ToString() + "%";
        roomsCompleted.GetComponent <Text>().text = "Rooms Completed: " + TotalStats.savedPlayerData.roomsCleared.ToString();
        ItemsPickedUp.GetComponent <Text>().text  = "Items Picked Up: " + TotalStats.savedPlayerData.itemsPickedUp.ToString();
        EnemiesKilled.GetComponent <Text>().text  = "Enemies Killed: " + TotalStats.savedPlayerData.enemiesKilled.ToString();
    }
    // Use this for initialization
    void Start()
    {
        bounds = ConveyerPlayerMovement.OrthographicBounds(camera);
        int pTcount = 0;

        if (PlayerState.playerType == null)
        {
            GlobalControl.AddPlayer(1);
            GlobalControl.AddPlayer(2);
            PlayerState.playerType = new PlayerType[5] {
                PlayerType.APPLE, PlayerType.CHEF, PlayerType.APPLE, PlayerType.CARROT, PlayerType.SAUSAGE
            };
        }
        for (int i = 1; i <= GlobalControl.NumPlayers; i++)
        {
            if (PlayerState.playerType != null && PlayerState.playerType [i] == PlayerType.CHEF)
            {
                BossPNum = i;
                Debug.Log("Boss number is " + i);
            }
            else
            {
                Debug.Log((int)PlayerState.playerType [i]);
                var player = Instantiate(playerFabs [(int)PlayerState.playerType [i]]);
                pTcount++;
                //playerbounds = OrthographicBounds(transform.parent.GetComponentInChildren<Camera> ());
                //TODO: set player based on PlayerState
                player.transform.position += new Vector3(i, 0, 0);
                player.GetComponent <ConveyerPlayerMovement> ().playerNum = i;
                player.GetComponent <ConveyerPlayerMovement> ().bounds    = ConveyerPlayerMovement.OrthographicBounds(camera);
                player.GetComponent <AffectedByConveyor> ().conveyor      = GetComponent <ConveyorController> ();
                players.Add(player);
            }
        }
        //
        //GlobalControl.AddPlayer (2);
        currentObstacle = Instantiate(obPreFabs[Random.Range(0, obPreFabs.Length)]).GetComponent <Obstacle>();
        currentObstacle.GetComponent <AffectedByConveyor> ().conveyor = conveyor;
        currentObstacle.transform.position = new Vector3(0, 7, 0);

        StartCoroutine(GameTimer(60));
    }
Example #29
0
    void Awake()
    {
        if (Instance == null)
        {
            DontDestroyOnLoad(gameObject);
            Instance = this;

            this.turnController  = new TurnController();
            this.roundController = new RoundController();

            CreateStandardPlayers();
        }

        Instance.GetComponentInChildren <LevelLoader>().EndTransition();

        if (Instance != this)
        {
            Destroy(gameObject);
        }
    }
Example #30
0
 // Start is called before the first frame update
 void Start()
 {
     globalControl = FindObjectOfType <GlobalControl>();
     if (globalControl != null)
     {
         colorSelection = globalControl.GetColors();
         if (colorSelection != null)
         {
             SetRowColors(colorSelection);
             SetColColors(colorSelection);
         }
     }
     //save the original positions of all the grid panels so we can reset them when necessary
     SetOriginalPos(gridPanelsRow0, originalPositionsRow0);
     SetOriginalPos(gridPanelsRow1, originalPositionsRow1);
     SetOriginalPos(gridPanelsRow2, originalPositionsRow2);
     SetOriginalPos(gridPanelsCol0, originalPositionsCol0);
     SetOriginalPos(gridPanelsCol1, originalPositionsCol1);
     SetOriginalPos(gridPanelsCol2, originalPositionsCol2);
 }
Example #31
0
    void Awake()
    {
        if (Instance == null)
        {
            DontDestroyOnLoad(gameObject);
            Instance = this;
        }
        else if (Instance != this)
        {
            Destroy(gameObject);
        }

        speed        = 4f;
        jumpProcs    = 1;
        atkDamage    = 10;
        atkLag       = 20;
        maxHealth    = 100;
        health       = 100;
        GravityScale = 3f;
    }
Example #32
0
    void Start()
    {
        socket = GetComponent <SocketIOComponent> ();

        //Get stuff from the global control:
        // - the ip they put in, as well as the username
        GC = GameObject.Find("GlobalControl").GetComponent <GlobalControl>();
        //socket.url = GC.GetIpAddress ();
        username = GC.GetUsername();

        players   = new Dictionary <string, GameObject> ();
        gameState = new Dictionary <string, string> ();

        //Event handler registration
        socket.On("open", OnConnected);
        socket.On("spawn", OnSpawn);
        socket.On("disconnected", OnDisconnected);
        socket.On("tick", OnTick);
        socket.On("leaderboard", OnLeaderboard);
    }
Example #33
0
        private void OkButton_Click(object sender, EventArgs e)
        {
            string[] NewGlobalView    = GlobalControl.GetView();
            string[] NewWorkspaceView = WorkspaceControl.GetView();

            if (NewGlobalView.Any(x => x.Contains("//")) || NewWorkspaceView.Any(x => x.Contains("//")))
            {
                if (MessageBox.Show(this, "Custom views should be relative to the stream root (eg. -/Engine/...).\r\n\r\nFull depot paths (eg. //depot/...) will not match any files.\r\n\r\nAre you sure you want to continue?", "Invalid view", MessageBoxButtons.OKCancel) != System.Windows.Forms.DialogResult.OK)
                {
                    return;
                }
            }

            GlobalView = NewGlobalView;
            GlobalExcludedCategories    = GetExcludedCategories(GlobalControl.CategoriesCheckList, GlobalExcludedCategories);
            WorkspaceView               = NewWorkspaceView;
            WorkspaceExcludedCategories = GetExcludedCategories(WorkspaceControl.CategoriesCheckList, WorkspaceExcludedCategories);

            DialogResult = DialogResult.OK;
        }
    private void Awake()
    {
        if (Instance == null)
        {
            DontDestroyOnLoad(gameObject);
            Instance = this;
            InitWeapons();
        }

        else if (Instance != this)
        {
            Destroy(gameObject);
        }

        if (timeSet == false)
        {
            timer   = timeLimit * 60;
            timeSet = true;
        }
    }
Example #35
0
    // Use this for initialization
    void Start()
    {
        GameObject[] list = GameObject.FindGameObjectsWithTag("Player");
        for (var i = list.Length - 1; i >= 0; i--)
        {
            PlayerControl player = list[i].GetComponent <PlayerControl>();
            if (player != null)
            {
                _player = player;
                break;
            }
        }
        _anim = GetComponent <Animator>();
        GameObject gc = GameObject.Find("GlobalControl");

        if (gc != null)
        {
            _globalControl = gc.GetComponent <GlobalControl>();
        }
    }
Example #36
0
    GameObject instatiateNewRobot(GameObject prefab,GlobalControl.motionModels _motionModel)
    {
        Vector3 currentPosition = currentObject.transform.position;
        Quaternion currentRotation = currentObject.transform.rotation;
        //Remove current object
        DestroyImmediate(currentObject);
        //Create new one
        currentObject = (GameObject)Object.Instantiate(prefab,currentPosition,currentRotation);
        currentObject.name = robotName;
        currentObject.gameObject.SetActive(true);

        //Add control script
        gm = currentObject.gameObject.AddComponent<GlobalMove>();
        gm.changeMotionModel (_motionModel);
        move = currentObject.AddComponent<moveTo> ();
        move.changeMotionModel (_motionModel);

        this.motionModel = _motionModel;
        return currentObject;
    }
    /**********************************************
    * Purpose: Initialize instance of singleton
    *           Ensure it is only instance
    *           and that it will not be destroyed.
    * ********************************************/
    void Awake()
    {
        print("GC awake.");
        if (Instance == null)
        {
            DontDestroyOnLoad(gameObject);
            Instance        = this;
            savedPlayerData = new RestaurantStatistics();
        }
        else if (Instance != this)
        {
            print("Destroying!!!!!!!!");
            Destroy(gameObject);
        }

        //Reset variables that need to be cleared each level
        allCustomersDone = false;
        phase            = 1;
        print(Instance.savedPlayerData.dishPrices ["Ham Sandwich"]);
    }
Example #38
0
    public void OnButtonPress(string type)
    {
        if (type == "start")
        {
            if (MainMenuBtn.confirmNew)
            {
                // Reset all global values and switch to first scene
                GlobalControl.canContinue = true;
                GlobalControl.resetPlayer();
                GlobalControl.resetObjects();
                GlobalControl.respawnAll();

                StartCoroutine(SceneSwitch("Start_"));
            }
            else
            {
                MainMenuBtn.confirmNew = true;
            }
        }
        else if (type == "continue")
        {
            if (GlobalControl.canContinue)
            {
                StartCoroutine(SceneSwitch2(GlobalControl.prevArea));
            }
        }
        else if (type == "controls")
        {
            MainMenuBtn.inControl = true;
        }
        else if (type == "trophy")
        {
            MainMenuBtn.inTrophy = true;
        }
        else if (type == "exit")
        {
            MainMenuBtn.confirmNew = false;
            MainMenuBtn.inControl  = false;
            MainMenuBtn.inTrophy   = false;
        }
    }
Example #39
0
    public void loadEncounter()
    {
        string curName = SceneManager.GetActiveScene().name;

        //saves current scene information
        GlobalControl     gc       = GameObject.Find("GlobalControl").GetComponent <GlobalControl>();
        SceneInfo_dungeon curscene = new SceneInfo_dungeon();

        curscene.pos_x   = pos_x;
        curscene.pos_y   = pos_y;
        curscene.enemies = enemies;

        gc.scenes.Push(curscene);
        SceneInfo_encounter nsi = new SceneInfo_encounter();

        nsi.monsters        = encounter.monsters;
        gc.sceneInformation = nsi;
        gc.save();

        SceneManager.LoadScene("encounter");
    }
Example #40
0
 void changeRobotsMotionModel(GlobalControl.motionModels motionModel)
 {
     //Iterate through all the robots and change it
     GameObject[] robots = GameObject.FindGameObjectsWithTag (robotTag);
     foreach (GameObject g in robots) {
         if(motionModel == GlobalControl.motionModels.DIFFERENTIAL){
             //Destroy object and instantiate a differential robot
             Transform t = g.transform;
             int r_ID = int.Parse(g.name.Substring(g.name.Length-1));
             Destroy(g);
             instatiateNewRobot(differential,t,r_ID,motionModel);
         }else if(motionModel == GlobalControl.motionModels.CAR){
             //Destroy object and instantiate a car
             Transform t = g.transform;
             int r_ID = int.Parse(g.name.Substring(g.name.Length-1));
             Destroy(g);
             instatiateNewRobot(car,t,r_ID,motionModel);
         }else{
             vs_Control c = g.gameObject.GetComponent<vs_Control>();
             c.changeMotionModel(motionModel);
         }
     }
 }
Example #41
0
    GameObject instatiateNewRobot(GameObject prefab,GlobalControl.motionModels motionModel)
    {
        //Get the current object
        GameObject o = GameObject.Find(robotName);
        //Get the position and rotation
        Vector3 currentPosition = o.transform.position;
        Quaternion currentRotation = o.transform.rotation;
        //Remove current object
        Destroy(o);
        //Create new one
        GameObject newO = (GameObject)Object.Instantiate(prefab,currentPosition,currentRotation);
        newO.name = robotName;
        newO.gameObject.SetActive(true);
        objectCamera = GameObject.Find("ObjectCamera");
        mainCamera = GameObject.Find("MainCamera");

        objectCamera.camera.enabled=activeCamera;
        mainCamera.camera.enabled=!activeCamera;

        GlobalControl controlModel = (GlobalControl)newO.gameObject.AddComponent ("GlobalControl");
        controlModel.changeControlModel (motionModel);
        return newO;
    }
Example #42
0
    void demo2()
    {
        //Create leader
        leader = (GameObject)Object.Instantiate (sphere, new Vector3 (0,0.5f,0), Quaternion.identity);
        leader.renderer.material.color = Color.red;
        leader.name = leaderName;
        leader.SetActive (true);
        //Add keyboard controller
        leaderControl = leader.gameObject.AddComponent<GlobalControl> ();
        leaderControl.changeControlModel (GlobalControl.motionModels.KINEMATIC);
        //Add leader script
        leader l = leader.gameObject.AddComponent<leader> ();
        l.distanceEpsilon = 0.01f;
        //Create following robot
        GameObject f = (GameObject)Object.Instantiate (sphere, new Vector3 (10,0.5f,10), Quaternion.identity);
        f.name = robotName;
        f.tag = robotTag;
        f.SetActive (true);
        //Add follower script
        f.gameObject.AddComponent<follower>();

        gtextRobot.text = "Robot motion: Kinematic";
        gtextVS.text = "Leader motion: Kinematic";
        singleFollower = true;
    }
Example #43
0
    // Main function
    public void controlFunction(Transform own, Vector3 target, float minDistance, float bearing, GlobalControl.motionModels motionModel)
    {
        //Check if we consider bearing information. In this case, we want the robot to be at an exact position,
        //so we change the target to be that position, and the minDistance is 0
        Vector3 targetPosition = new Vector3(target.x,target.y,target.z);
        if (bearing != defaultNoBearing) {
            Debug.Log ("USING BEARING");
            Vector3 newTargetPosition = new Vector3(targetPosition.x+minDistance*Mathf.Cos (bearing),targetPosition.y,
                                                    targetPosition.z+minDistance*Mathf.Sin (bearing));
            targetPosition = newTargetPosition;
            minDistance = 0; //We want to be at this exact point.
        }
        float distance = Vector2.Distance (new Vector2(own.transform.position.x,own.transform.position.z),
                                           new Vector2(targetPosition.x,targetPosition.z));
        if(Mathf.Abs(distance-minDistance)>TOLERANCE_DISTANCE){
            Vector3 toRobotVector = targetPosition - own.position;
            float theta = Mathf.Atan2 (toRobotVector.z, toRobotVector.x);
            //Fix theta to avoid discontinuities
            if (Mathf.Abs (theta) > Mathf.PI)
                theta = theta - (2 * Mathf.PI * Mathf.Sign (theta));

            float errorX = (distance - minDistance) * Mathf.Cos (theta);
            float errorZ = (distance - minDistance) * Mathf.Sin (theta);
            switch (motionModel){
                case GlobalControl.motionModels.DISCRETE:{
                    if(Mathf.Abs (distance-minDistance)>1) //Avoid oscillations
                    ((MoveDiscrete)control).applyMotion(threshold(errorX),threshold(errorZ));
                    break;
                }
                case GlobalControl.motionModels.KINEMATIC:{
                    ((MoveKinematic)control).applyMotion (kp * errorX, kp * errorZ);
                    break;
                }
                case GlobalControl.motionModels.DYNAMIC: //We use PD instead of P controller
                    break;
                case GlobalControl.motionModels.DIFFERENTIAL:{
                    float deltaTheta = Mathf.Atan2(own.forward.z,own.forward.x)-Mathf.Atan2(toRobotVector.z,toRobotVector.x);
                    //Fix theta to avoid discontinuities
                    if(Mathf.Abs(deltaTheta) > Mathf.PI)
                        deltaTheta = deltaTheta - (2*Mathf.PI * Mathf.Sign(deltaTheta));

                    float v=0;
                    if(Mathf.Abs(deltaTheta)<0.01f)
                        v = kp*(distance-minDistance);
                    float w = kp_w*deltaTheta;

                    ((MoveDifferential)control).applyMotion(v,w);
                    break;
                }
                case GlobalControl.motionModels.CAR:{
                    float deltaTheta = Mathf.Atan2(own.forward.z,own.forward.x)-Mathf.Atan2(toRobotVector.z,toRobotVector.x);
                    //Fix theta to avoid discontinuities
                    if(Mathf.Abs(deltaTheta) > Mathf.PI)
                        deltaTheta = deltaTheta - (2*Mathf.PI * Mathf.Sign(deltaTheta));

                    float v = kp*(distance-minDistance);
                    float w = kp_w*deltaTheta;

                    ((MoveCar)control).applyMotion(v,w);
                    break;
                }
            }
        }
    }
    //Pseudo-singleton concept from Unity dev tutorial video:
    void Awake()
    {
        Application.targetFrameRate = 144;

        if (Instance == null)
        {
            DontDestroyOnLoad(gameObject);
            Instance = this;
        }
        else if (Instance != this)
        {
            Destroy(gameObject);
        }

        if (TransitionTarget == null)
            TransitionTarget = gameObject.transform;
    }
Example #45
0
 void Start()
 {
     //Create leader
     leader = (GameObject)Object.Instantiate (sphere, new Vector3 (0,0.5f,0), Quaternion.identity);
     leader.renderer.material.color = Color.red;
     leader.tag = robotTag;
     leader.name = leaderName;
     leader.SetActive (true);
     //Add keyboard controller
     leaderControl = leader.gameObject.AddComponent<GlobalControl> ();
     leaderControl.changeControlModel (GlobalControl.motionModels.KINEMATIC);
     //Create N robots around the leader
     for (int i=0; i<N; i++) {
         float theta = 2*Mathf.PI*i/N;
         Vector3 position = leader.transform.position+new Vector3(originalDistance*Mathf.Cos (theta),0.5f,originalDistance*Mathf.Sin (theta));
         GameObject o =(GameObject)Object.Instantiate (sphere, position, Quaternion.identity);
         o.tag = robotTag;
         o.SetActive(true);
         o.gameObject.AddComponent<nn_kinematic>();
     }
     //Create text
     gtextRobot.text = "Robot motion: Kinematic";
     gtextVS.text = "Leader motion: Kinematic";
 }
Example #46
0
 // Binary tree formation
 void demo1()
 {
     //Create leader
     leader = (GameObject)Object.Instantiate (sphere, new Vector3 (0,0.5f,0), Quaternion.identity);
     leader.renderer.material.color = Color.red;
     leader.name = leaderName;
     leader.SetActive (true);
     //Add keyboard controller
     leaderControl = leader.gameObject.AddComponent<GlobalControl> ();
     leaderControl.changeControlModel (GlobalControl.motionModels.KINEMATIC);
     //Add leader script
     leader l = leader.gameObject.AddComponent<leader> ();
     l.distanceEpsilon = 0.01f;
     //Create N robots as a binary tree
     createRobotTree ();
     //Create text
     gtextRobot.text = "Robot motion: Kinematic";
     gtextVS.text = "Leader motion: Kinematic";
     singleFollower = false;
 }
Example #47
0
    Dictionary<string, string> changeRobotsMotionModel(GlobalControl.motionModels motionModel)
    {
        //First, store which robot is following which one
        Dictionary<string,string> relationships = new Dictionary<string,string> ();
        int appendix = 1;
        //Iterate through all the robots and change it
        GameObject[] robots = GameObject.FindGameObjectsWithTag (robotTag);
        for (int i=0; i<robots.Length; i++) {
            GameObject g  = robots[i];
            if(g.name!=leaderName){
                follower f = g.gameObject.GetComponent<follower>();
                string ownName = g.name;
                //Store info in dictionary
                ownName = ownName+appendix.ToString();
                string leadName = f.leader.name;
                if(leadName !=leaderName)
                    leadName = leadName+appendix.ToString();
                relationships.Add(ownName,leadName);
            }
        }

        for(int i=0;i<robots.Length;i++){
            GameObject g  = robots[i];
            if(g.name!=leaderName){
                Transform t = g.transform;
                follower f = g.gameObject.GetComponent<follower>();
                float bearing = f.bearing;
                //Store info in dictionary
                string ownName = g.name+appendix.ToString();
                GameObject g2;
                switch(motionModel){
                    case GlobalControl.motionModels.DISCRETE:
                        //Destroy object and instantiate a new one
                        Destroy(g);
                        g2 = instantiateRobot(sphere,ownName,t,bearing,motionModel);
                        break;
                    case GlobalControl.motionModels.KINEMATIC:
                        //Destroy object and instantiate a new one
                        Destroy(g);
                        g2 = instantiateRobot(sphere,ownName,t,bearing,motionModel);
                        break;
                    case GlobalControl.motionModels.DYNAMIC:
                        //Destroy object and instantiate a new one
                        Destroy(g);
                        g2 = instantiateRobot(sphere,ownName,t,bearing,motionModel);
                        break;
                    case GlobalControl.motionModels.DIFFERENTIAL:{
                        //Destroy object and instantiate a new one
                        Destroy(g);
                        g2 = instantiateRobot(differential,ownName,t,bearing,motionModel);
                        break;
                    }
                    case GlobalControl.motionModels.CAR:{
                        //Destroy object and instantiate a new one
                        Destroy(g);
                        g2 = instantiateRobot(car,ownName,t,bearing,motionModel);
                        break;
                    }
                }
            }
        }
        return relationships;
    }
Example #48
0
 GameObject instantiateRobot(GameObject prefab, string name,Transform t,float bearing,GlobalControl.motionModels motionModel)
 {
     GameObject g2 = (GameObject)Object.Instantiate(prefab,t.position,Quaternion.identity);
     g2.tag = robotTag;
     g2.name = name;
     g2.SetActive(true);
     follower f = g2.gameObject.AddComponent<follower>();
     f.bearing = bearing;
     f.changeMotionModel (motionModel);
     return g2;
 }