Exemple #1
0
    private void setColorOn(int index)
    {
        string color = colorKeys [colorPerPlayer [index]];

        PlayerInfo p = nvs.getPlayer(index);

        if (p != null)
        {
            p.color = color;
        }

        RecolorPlayer.recolorPlayerBody(ed_playerRenderer [index], color);
    }
Exemple #2
0
    void SpawnPlayer(NetworkViewID cartViewIDTransform, NetworkViewID cartViewIDRigidbody, NetworkViewID ballViewID, NetworkViewID characterViewID, int mode, NetworkPlayer player)
    {
        foreach (PlayerInfo newGuy in nvs.players)
        {
            if (newGuy.player == player)
            {
                newGuy.cartViewIDTransform = cartViewIDTransform;
                newGuy.cartGameObject      = NetworkView.Find(cartViewIDTransform).gameObject;
                newGuy.cartViewIDRigidbody = cartViewIDRigidbody;
                // add another NetworkView for the rigidbody
                NetworkView cgr = newGuy.cartGameObject.AddComponent <NetworkView>() as NetworkView;                            // add rigidbody tracking
                cgr.observed               = newGuy.cartGameObject.GetComponent <Rigidbody>();
                cgr.viewID                 = cartViewIDRigidbody;
                cgr.stateSynchronization   = NetworkStateSynchronization.Unreliable;
                newGuy.characterViewID     = characterViewID;
                newGuy.characterGameObject = NetworkView.Find(characterViewID).gameObject;
                newGuy.ballViewID          = ballViewID;
                newGuy.ballGameObject      = NetworkView.Find(ballViewID).gameObject;
                newGuy.currentMode         = mode;
                newGuy.carController       = newGuy.cartGameObject.transform.GetComponent("CarController") as CarController;

                //Move this to a point that is post all object creation but pre level start
                Renderer bodyRenderer = newGuy.characterGameObject.transform.FindChild("body").gameObject.GetComponent <SkinnedMeshRenderer> ();
                RecolorPlayer.recolorPlayerBody(bodyRenderer, newGuy.color);

                // ADD MORE STUFF HERE
                if (newGuy.currentMode == 0)
                {
                    // set them inside the buggy
                    newGuy.characterGameObject.transform.parent        = newGuy.cartGameObject.transform;
                    newGuy.characterGameObject.transform.localPosition = new Vector3(0, 0, 0);
                    newGuy.characterGameObject.transform.localRotation = Quaternion.identity;
                }
                else if (newGuy.currentMode == 1)
                {
                    // set them outside the buggy
                    newGuy.characterGameObject.transform.parent        = newGuy.ballGameObject.transform;
                    newGuy.characterGameObject.transform.localPosition = new Vector3(0, 0, -2);
                    newGuy.characterGameObject.transform.localRotation = Quaternion.identity;
                }
            }
        }
    }
    void createPlayers()
    {
        int numPlayers       = nvs.players.Count;
        ControllerSupport cs = currentView.GetComponent <ControllerSupport>() as ControllerSupport;

        cs.playerObjectList        = new GameObject[numPlayers];
        cs.playerBodyList          = new Renderer[numPlayers];
        cs.playerToControllerIndex = new int[numPlayers];

        GameObject[] playerCams = CameraManager.createSplitScreenCameras(numPlayers);
        GameObject[] ballCams   = CameraManager.createSplitScreenCameras(numPlayers);

        for (int i = 0; i < numPlayers; ++i)
        {
            PlayerInfo player = nvs.players[i] as PlayerInfo;

            GameObject playerContainer = new GameObject(player.name);
            playerContainer.transform.parent = currentView.transform;
            playerContainer.AddComponent <LocalBallMarker> ();
            GameObject playerCamera = playerCams[i];
            playerCamera.transform.parent = playerContainer.transform;
            player.cameraObject           = playerCamera;

            //Create cart for player
            GameObject cartObject = Instantiate(Resources.Load(player.cartModel), new Vector3(0, -100, 0), Quaternion.identity) as GameObject;
            cartObject.name             = "buggy";
            cartObject.transform.parent = playerContainer.transform;
            player.cartGameObject       = cartObject;
            //Create ball for player
            GameObject ballObject = Instantiate(Resources.Load(player.ballModel), new Vector3(0, -100, 0), Quaternion.identity) as GameObject;
            ballObject.name             = "hit_mode_ball";
            ballObject.transform.parent = playerContainer.transform;
            player.ballGameObject       = ballObject;
            //Create character for player
            GameObject characterObject = Instantiate(Resources.Load(player.characterModel)) as GameObject;
            characterObject.name                    = "player_character";
            characterObject.transform.parent        = cartObject.transform;
            characterObject.transform.localPosition = Vector3.zero + new Vector3(0, 0.3f, 0);
            characterObject.transform.localRotation = Quaternion.identity;
            player.characterGameObject              = characterObject;
            //Apply color
            RecolorPlayer.recolorPlayerBody(characterObject.transform.FindChild("body").GetComponent <Renderer>() as Renderer, player.color);
            if (i < 1)          //Only one audiolistener can exist
            {
                characterObject.AddComponent <AudioListener> ();
            }
            //Create camera for hit_ball; remove later
            GameObject hitBallCam = ballCams[i];
            hitBallCam.name = "hit_ball_camera";
            hitBallCam.SetActive(false);
            hitBallCam.transform.parent = ballObject.transform;

            //Add scripts to cart
            (cartObject.transform.GetComponent <CarUserControl>() as CarUserControl).enabled = true;
            Destroy(cartObject.transform.GetComponent <NetworkView>());

            TransferToSwing ts = cartObject.AddComponent <TransferToSwing>() as TransferToSwing;
            ts.ball = ballObject;

            ScriptToggler st = cartObject.AddComponent <ScriptToggler>() as ScriptToggler;
            st.scripts = new List <MonoBehaviour>();
            st.scripts.Add(cartObject.GetComponent <CarController>());
            st.scripts.Add(cartObject.GetComponent <CarUserControl>());
            st.scripts.Add(cartObject.GetComponent <TransferToSwing>());
            st.cameraObject = playerCamera;

            //Add scripts to ball
            InControlSwingMode ics = ballObject.AddComponent <InControlSwingMode>() as InControlSwingMode;
            ics.cameraObject = hitBallCam;
            ics.cart         = cartObject;
            ics.enabled      = false;

            PowerMeter pm = ballObject.AddComponent <PowerMeter>() as PowerMeter;
            pm.m_objectToCircle = ballObject;
            pm.m_markerPrefab   = Instantiate(Resources.Load("powerMeterPrefab")) as GameObject;
            pm.m_swingScript    = ics;
            pm.enabled          = false;

            ScriptToggler stb = ballObject.AddComponent <ScriptToggler>() as ScriptToggler;
            stb.scripts = new List <MonoBehaviour>();
            stb.scripts.Add(ics);
            stb.scripts.Add(pm);
            stb.cameraObject = hitBallCam;


            //controller support
            cs.playerObjectList[i]        = cartObject;
            cs.playerBodyList[i]          = characterObject.transform.FindChild("body").GetComponent <SkinnedMeshRenderer>();
            cs.playerToControllerIndex[i] = -1;                 //dummy value

            FollowPlayerScript fps = (playerCamera.AddComponent <FollowPlayerScript> () as FollowPlayerScript);
            fps.target = cartObject.transform;
        }
        (GameObject.Find("winningPole").gameObject.GetComponent <netWinCollider> () as netWinCollider).initialize();
        nvs.myInfo = nvs.players [0] as PlayerInfo;             //just so some of the network scripts work
        nvs.gameObject.AddComponent <netPause> ();
    }
Exemple #4
0
    // carts for all!
    void BeginGame()
    {
        Vector3 velocity = new Vector3(0, 0, 0);

        //float i = 0;
        //float spacer = 360 / nvs.players.Count;
        foreach (PlayerInfo newGuy in nvs.players)
        {
            // create new buggy for the new guy - his must be done on the server otherwise collisions wont work!
            //Vector3 spawnLocation = transform.position + Quaternion.AngleAxis(spacer * i++, Vector3.up) * new Vector3(10,2,0);
            Vector3 spawnLocation = new Vector3(0, -200, 0);            //start under the map to trigger a reset

            // instantiate the prefabs
            GameObject cartGameObject      = Instantiate(Resources.Load(newGuy.cartModel), spawnLocation, Quaternion.identity) as GameObject;
            GameObject ballGameObject      = Instantiate(Resources.Load(newGuy.ballModel), spawnLocation + new Vector3(3, 0, 0), Quaternion.identity) as GameObject;
            GameObject characterGameObject = Instantiate(Resources.Load(newGuy.characterModel), spawnLocation, Quaternion.identity) as GameObject;
            // set buggy as characters parent
            characterGameObject.transform.parent = cartGameObject.transform;

            // create and set viewIDs
            NetworkViewID cartViewIDTransform = Network.AllocateViewID();                                               // track the transform of the cart
            NetworkView   cgt = cartGameObject.GetComponent("NetworkView") as NetworkView;
            cgt.observed             = cartGameObject.transform;
            cgt.viewID               = cartViewIDTransform;
            cgt.stateSynchronization = NetworkStateSynchronization.Unreliable;
            NetworkViewID cartViewIDRigidbody = Network.AllocateViewID();                                               // track the rigidbody of the cart
            NetworkView   cgr = cartGameObject.AddComponent <NetworkView>() as NetworkView;
            cgr.observed             = cartGameObject.GetComponent <Rigidbody>();
            cgr.viewID               = cartViewIDRigidbody;
            cgr.stateSynchronization = NetworkStateSynchronization.Unreliable;
            NetworkViewID ballViewID = Network.AllocateViewID();
            ballGameObject.GetComponent <NetworkView>().viewID = ballViewID;
            NetworkViewID characterViewID = Network.AllocateViewID();
            characterGameObject.GetComponent <NetworkView>().viewID = characterViewID;

            // edit their PlayerInfo
            newGuy.cartGameObject      = cartGameObject;
            newGuy.cartViewIDTransform = cartViewIDTransform;
            newGuy.cartViewIDRigidbody = cartViewIDRigidbody;
            newGuy.ballGameObject      = ballGameObject;
            newGuy.ballViewID          = ballViewID;
            newGuy.characterGameObject = characterGameObject;
            newGuy.characterViewID     = characterViewID;
            newGuy.currentMode         = 0;     // set them in buggy
            newGuy.carController       = cartGameObject.transform.GetComponent("CarController") as CarController;

            //add details
            //add player colors
            Renderer bodyRenderer = newGuy.characterGameObject.transform.FindChild("body").gameObject.GetComponent <SkinnedMeshRenderer> ();
            RecolorPlayer.recolorPlayerBody(bodyRenderer, newGuy.color);

            // tell everyone else about it
            GetComponent <NetworkView>().RPC("SpawnPrefab", RPCMode.Others, cartViewIDTransform, spawnLocation, velocity, newGuy.cartModel);
            GetComponent <NetworkView>().RPC("SpawnPrefab", RPCMode.Others, ballViewID, spawnLocation, velocity, newGuy.ballModel);
            GetComponent <NetworkView>().RPC("SpawnPrefab", RPCMode.Others, characterViewID, spawnLocation, velocity, newGuy.characterModel);

            // tell all players this is a player and not some random objects
            GetComponent <NetworkView>().RPC("SpawnPlayer", RPCMode.Others, cartViewIDTransform, cartViewIDRigidbody, ballViewID, characterViewID, 0, newGuy.player);

            if (newGuy.player != myInfo.player)
            {
                // tell the player it's theirs
                GetComponent <NetworkView>().RPC("ThisOnesYours", newGuy.player, cartViewIDTransform, ballViewID, characterViewID);
            }
        }
    }