Пример #1
0
    //----------------------------------------------------------------------------------------------------------------
    // Update is called once per frame

    void Update()
    {
        if (ctunity == null || ctclient == null)
        {
            Debug.Log(name + ", oops no ctunity/ctlient!");
            return;        // async
        }
        if (!ctunity.activePlayer(gameObject))
        {
            return;
        }

        launchInterval = ctclient.getCustom("dt", launchInterval);

        stopWatch += Time.deltaTime;
        if (stopWatch >= launchInterval)
        {
            String missile = ctclient.getCustom("M", Missile);  // optional custom missile
            Ilaunch = ctclient.getCustom("N", Ilaunch);
            Nlaunch = ctclient.getCustom("Nmax", Nlaunch);
            //           Debug.Log(name + ": Nlaunch: " + Nlaunch+", launchInterval: "+launchInterval);

            if (Nlaunch != 0 && Ilaunch >= Nlaunch)
            {
                return;
            }

            ctunity.deployInventory(missile, CTunity.fullName(gameObject) + "/R-" + Ilaunch);
            Ilaunch++;
            ctclient.putCustom("N", Ilaunch);

            stopWatch = 0;
        }
    }
Пример #2
0
    //----------------------------------------------------------------------------------------------------------------
    // Use this for initialization
    void Start()
    {
        replayControl = GameObject.Find("replayControl");
        ctunity       = GameObject.Find("CTunity").GetComponent <CTunity>(); // reference CTgroupstate script
        gameOptions   = GameObject.Find("Setup").gameObject;

        // define menu objects
        myCamera = GameObject.Find("Main Camera").GetComponent <maxCamera>();

        Server   = GameObject.Find("Server");
        Session  = GameObject.Find("Session");
        Player   = GameObject.Find("Player1");
        Deploy   = GameObject.Find("Deploy");
        Login    = GameObject.Find("Login");
        User     = GameObject.Find("User");
        Password = GameObject.Find("Password");

        // setup callbacks

        Button[] buttons = gameObject.GetComponentsInChildren <Button>();
        foreach (Button b in buttons)
        {
            switch (b.name)
            {
            case "Login":
                b.onClick.AddListener(loginButton);
                break;

            case "Quit":
                b.onClick.AddListener(quitButton);
                break;
            }
        }

        Dropdown[] drops = gameObject.GetComponentsInChildren <Dropdown>();
        foreach (Dropdown d in drops)
        {
            switch (d.name)
            {
            case "Session":
                //                    ctunity.Session = d.GetComponent<Dropdown>().options[d.value].text;  // initialize
                // add listener to update session settings
                d.onValueChanged.AddListener(delegate
                {
                    ctunity.Session = d.GetComponent <Dropdown>().options[d.value].text; // set selected session
                    updateSession();
                    myCamera.setTarget(null);                                            // reset cam target to default
                    myCamera.Init();

                    if (playerDrop != null)
                    {
                        ctunity.Player = playerDrop.GetComponent <Dropdown>().options[0].text;
                        ctunity.serverConnect();      // reset player path
                        playerDrop.value = 0;
                    }
                });

                break;

            case "Deploy":
                // add listener to deploy new world
                d.onValueChanged.AddListener(delegate
                                             { if (d.value != 0)
                                               {
                                                   string svalue = d.GetComponent <Dropdown>().options[d.value].text;

                                                   if (svalue.Equals(ctunity.Save))
                                                   {
                                                       ctunity.SnapShot();
                                                       //	StartCoroutine("getInventoryList");         // update list of "World" prefabs
                                                   }
                                                   else if (svalue.Equals(ctunity.Clear))
                                                   {
                                                       ctunity.clearWorld();
                                                   }
                                                   else if (svalue.Equals(ctunity.Load))
                                                   {
                                                       ctunity.clearWorld();
                                                       ctunity.loadWorld();
                                                   }
                                                   else
                                                   {
                                                       ctunity.deployInventory(svalue);
                                                   }

                                                   d.value = 0; // reset to blank
                                               }
                                             });

                break;

            case "Player1":
                playerDrop     = d;
                ctunity.Player = d.GetComponent <Dropdown>().options[d.value].text;         // init?
                //  playerDrop.GetComponent<Button>().onClick.AddListener(onClick);
                d.onValueChanged.AddListener(delegate
                {
                    String player = d.GetComponent <Dropdown>().options[d.value].text;
//                        Debug.Log("onValueChanged, d.value: " + d.value + ", ctunity.Player: " + ctunity.Player + ", player: " + player);
                    if (!player.Equals(ctunity.Player))
                    {
                        updateSession();                      // avoid new player set as child of prior player?
                        ctunity.Player = player;
//                           Debug.Log("new Player: " + player + ", d.value: " + d.value);
                        ctunity.serverConnect();      // reset player path
                    }
                    replayControl.SetActive(ctunity.observerMode());
                });
                break;
            }
        }

        modeSelect();
    }