Inheritance: MonoBehaviour
Example #1
0
    void InitClient(int gridX, int gridY, float offsetX, float offsetY)
    {
        Debug.Log("InitClient");
        playground      = Instantiate <VisualPlayground>(playground_prefab);
        playground.name = "Playground";
        playground.Init(gridX, gridY, offsetX, offsetY);

        character = new VisualJack[2];

        var l1 = Instantiate <VisualJack>(jack_prefab);

        l1.Init(PLAY.ER1, 0, 0, playground.Pos(0, 0));
        Debug.Log("jack 1 pos = " + playground.Pos(0, 0));
        l1.name      = "Jack-1";
        character[0] = l1;

        var l2 = Instantiate <VisualJack>(jack_prefab);

        l2.Init(PLAY.ER2, gridX - 1, 0, playground.Pos(gridX - 1, 0));
        l2.name      = "Jack-2";
        character[1] = l2;

        iAm = PhotonNetwork.isMasterClient ? PLAY.ER1 : PLAY.ER2;

        input         = FindObjectOfType <InputAdapter>();
        input.onTap  += OnTap;
        input.onDrag += OnDrag;

        ui = FindObjectOfType <UIAdapter>();

        photonView.RPC("S_ClientInited", PhotonTargets.MasterClient, (int)iAm);
    }
Example #2
0
        /// <summary>
        /// Construct new instance.
        /// </summary>
        /// <param name="rng">Random number generator to use.</param>
        public GameBuilder(UIAdapter frontEnd, Random rng, IEnumerable <Species> allSpecies)
        {
            _rng        = rng;
            _frontEnd   = frontEnd;
            _allSpecies = allSpecies;

            Logger.Debug("GameFactory constructed.");
        }
 //!
 //! scale currently selected object with joystick input
 //! @param      scale     new scale of object
 //!
 public void scaleSelectionJoystick(Vector3 scale)
 {
     if (currentSelection)
     {
         // lights (scalemode is used for light parameters intensity and range)
         SceneObjectLight scl = currentSelection.GetComponent <SceneObjectLight>();
         if (scl)
         {
             // set light intensity
             scl.setLightIntensity(scl.getLightIntensity() + (scale.z * 0.5f));
             // set gui element
             scl.setLightRange(scl.getLightRange() + (scale.y * 0.5f));
             if (scale.z == 0.0f)
             {
                 UIAdapter.updateRangeSlider(scl.getLightRange());
             }
             else if (scale.y == 0.0f)
             {
                 UIAdapter.updateRangeSlider(scl.getLightIntensity());
             }
         }
         // objects
         else
         {
             if (scale.x == 0 && scale.y == 0)
             {
                 axisLocker = new Vector3(0, 0, 1);
             }
             else if (scale.x == 0 && scale.z == 0)
             {
                 axisLocker = new Vector3(0, 1, 0);
             }
             else if (scale.y == 0 && scale.z == 0)
             {
                 axisLocker = new Vector3(1, 0, 0);
             }
             else if (scale.x != 0 && scale.y != 0 && scale.z != 0)
             {
                 axisLocker = new Vector3(1, 1, 1);
                 scale      = Vector3.one * scale.x;
             }
             if (!currentSelection.transform.parent.transform.GetComponent <Light>())
             {
                 float scaleFactor = (8f * Vector3.Distance(Camera.main.transform.position, currentSelection.position) / VPETSettings.Instance.maxExtend);
                 currentSelection.transform.localScale += Vector3.Scale(scale / currentSelection.transform.parent.lossyScale.x * scaleFactor / VPETSettings.Instance.controllerSpeed, axisLocker) / 100f;
                 if (liveMode)
                 {
                     serverAdapter.SendObjectUpdate(currentSelection.GetComponent <SceneObject>(), ParameterType.SCALE);
                 }
             }
         }
     }
 }
Example #4
0
        /// <summary>
        /// Construct game handler instance.
        /// </summary>
        /// <param name="gameInstance">Injected game logic instance.</param>
        /// <param name="frontEnd">Injected UI.</param>
        /// <param name="timeout">Time to answer a question. Null if no limit.</param>
        public GameHandler(GameInstance gameInstance, UIAdapter frontEnd, TimeSpan?timeout)
        {
            _gameInstance = gameInstance;
            _frontEnd     = frontEnd;
            _timeoutDelay = timeout;

            // Attach event handlers
            QuestionTimeout += OnTimeout;
            QuestionTimeout += frontEnd.OnTimeout;

            AnswerCorrect += frontEnd.OnAnswerCorrect;
            AnswerWrong   += frontEnd.OnAnswerWrong;

            _frontEnd.OnChoice += OnChoiceFromFrontend;
            _frontEnd.OnStart  += OnStarted;
            _frontEnd.OnExit   += OnExit;
        }
        public static BackendInstance GetInstance(UIAdapter ui, Random rng = null)
        {
            Logger.Debug("Creating backend instance.");

            SpeciesFileDescription speciesFileDescription = FileSystemService.GetSpeciesMappings();

            // Map species classes to list of species
            IEnumerable <(SpeciesClass, IList <SpeciesMapping>)> speciesClassMappings =
                speciesFileDescription
                .SpeciesClassMappings
                .Select(classMapping => (
                            SpeciesFactory.GetSpeciesClass(classMapping)
                            , classMapping.SpeciesClassSpeciesMappings))
                .ToList();

            IEnumerable <Species> species
                = speciesClassMappings
                  .AsParallel()
                  .SelectMany(tuple => {
                SpeciesClass parentClass = tuple.Item1;
                IList <SpeciesMapping> speciesMappings = tuple.Item2;

                IEnumerable <Species> childrenSpecies
                    = new List <Species>(speciesMappings.Count);

                childrenSpecies = childrenSpecies
                                  .Concat(speciesMappings.Select(
                                              s => SpeciesFactory.GetSpecies(s, parentClass)));

                return(childrenSpecies);
            }).ToList();

            Random rngToUse = rng ?? new Random();

            BackendInstance instance = new BackendInstance(ui, species, rngToUse);

            Logger.Debug("Species loaded and models created.");

            return(instance);
        }
 internal BackendInstance(UIAdapter ui, IEnumerable <Species> species, Random rng)
 {
     _species = species;
     _ui      = ui;
     _rng     = rng;
 }