Esempio n. 1
0
        // Use this for initialization
        void Start()
        {
                        #if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
            windowHandle = GetActiveWindow();
                        #endif

            if (killSelfWhenThereIsOtherOwn)
            {
                if (it == this.gameObject)
                {
                }
                else if (it == null)
                {
                    it = this;
                }
                else
                {
                    Destroy(this.gameObject);                      // kill yourself!
                    EWUnityExtensions.Log("kill myself");
                    return;
                }
            }
            else
            {
                it = this;
            }

            if (inNames == null || inNames.Length == 0)
            {
                inNames = new string[ControlInput.allControlsList.Count];

                ControlInput[] cis = this.GetComponents <ControlInput> ();
                for (int i = 0; i < cis.Length; i++)
                {
                    ControlInput ci = cis[i];

                    if (ci is ControlInputMulti)
                    {
                        continue;
                    }
                    inNames [i] = ci.controlName;
                }
            }

            DontDestroyOnLoad(transform.gameObject);
            //This is not necessary as it auto connects in the update method
            //StartClientThread ();

            if (autoBootLinker)
            {
                AutoBootLinker();
            }
        }
Esempio n. 2
0
        void Update()
        {
            float curTime = Time.realtimeSinceStartup;

            // check if ControlInputs have to be created (needed for multiinputs which can dynamically grow)

            foreach (CreateQueueEntry entry in createQueue)
            {
                ControlInput parent        = entry.ciParent;
                string       multiId       = entry.multiId;
                string       multiFullName = entry.name;

                if (ControlInputMulti.allMultiControls.ContainsKey(multiFullName) == false)
                {
                    EWUnityExtensions.Log("Create new multi val controlinput child for '" + multiFullName + "'");
                    ControlInputMulti ciChild = this.gameObject.AddComponent <ControlInputMulti> ();
                    ciChild.multiId = multiId;
                    ciChild.RegisterMulti(multiFullName);
                    ciChild.multiParent = parent;
                    ControlInput.MultiInputEntry multiEntry = new ControlInput.MultiInputEntry();
                    multiEntry.multiId      = multiId;
                    multiEntry.name         = multiFullName;
                    multiEntry.controlInput = ciChild;
                    parent.multiInputs.Add(multiEntry);
                    ciChild.SetCurrentValue(entry.initVal);
                }
                else
                {
                    EWUnityExtensions.LogWarning("'" + multiFullName + "' already created!");
                }
            }
            createQueue.Clear();


            // TODO: restart client if closed... look for server (rendevous/zeroconf ? )
            if (IsConnectionLost() && (curTime - timeLastConnectionTry) > cooldownConnectionTry)
            {
                timeLastConnectionTry = curTime;
                EWUnityExtensions.Log("Try to connect to server '" + linker_ip + ":" + linker_tcp_port + "'");
                connectThread = new Thread(ConnectToServer);
                connectThread.Start();
            }

            foreach (var kV in inValues)
            {
                EWUnityExtensions.Log("in Values => " + kV.Key + " -> " + kV.Value);
            }
        }
Esempio n. 3
0
        // Update is called once per frame
        void Update()
        {
            if (IsController)
            {
                //TODO: This should not be hardcoded like this
                //There is no way to check if the input names exist
                //So this was the easiest to avoid error log spamming

                //Check for max controllers
                if (ControllerId < 4)
                {
                    float xRel = Input.GetAxis("Joystick" + (ControllerId + 1) + " X");
                    float yRel = Input.GetAxis("Joystick" + (ControllerId + 1) + " Y");
                    xRel = Mathf.Pow(xRel, 2) * Mathf.Sign(xRel);
                    xRel = Mathf.Sin(xRel);

                    yRel = Mathf.Pow(yRel, 2) * Mathf.Sign(yRel);
                    yRel = Mathf.Sin(yRel);


                    //This registers every button of every controller, but would be much nicer
                    //bool curBtn1State = Input.GetButton("Joystick" + (ControllerId + 1) + " Button1");
                    //bool curBtn2State = Input.GetButton("Joystick" + (ControllerId + 1) + " Button2");

                    //HACK: TODO: This is just so that every button of every controller is registered
                    bool curBtn1State = Input.GetKey((KeyCode)Enum.Parse(typeof(KeyCode), "Joystick" + (ControllerId + 1) + "Button0"));
                    bool curBtn2State = Input.GetKey((KeyCode)Enum.Parse(typeof(KeyCode), "Joystick" + (ControllerId + 1) + "Button1"));


                    ProcessRawDeltaInput(xRel, yRel, curBtn1State, curBtn2State);
                }
            }
            else if (useExerWorld)
            {
                float xRel         = ControlInput.GetCurrentValueMulti("playerMulti_xRel", exerWorldId) - 0.5f;
                float yRel         = ControlInput.GetCurrentValueMulti("playerMulti_yRel", exerWorldId) - 0.5f;
                bool  curBtn1State = ControlInput.GetCurrentValueMulti("playerMulti_btn1", exerWorldId) > 0.5f ? true : false;
                bool  curBtn2State = ControlInput.GetCurrentValueMulti("playerMulti_btn2", exerWorldId) > 0.5f ? true : false;

                ProcessRawDeltaInput(xRel, yRel, curBtn1State, curBtn2State);
            }
            else
            {
                ProcessUnityInput();
            }
        }
Esempio n. 4
0
        // NOTE: only for multi value fields
        public static Dictionary <string, float> GetCurrentMultiValues(string _controlName)
        {
            Dictionary <string, float> multiValDict = new Dictionary <string, float> ();

            try {
                ControlInput ci = allControls[_controlName];
                if (ci.isMultiInput)
                {
                    foreach (MultiInputEntry entry in ci.multiInputs)
                    {
                        multiValDict[entry.multiId] = entry.controlInput.GetCurrentValue();
                    }
                }
            } catch (UnityException e) {
                EWUnityExtensions.LogWarning("Could not find value for control named '" + _controlName + "', Exception: " + e);
            }

            return(multiValDict);
        }
Esempio n. 5
0
 public float GetCurrentControlValue()
 {
     return(ControlInput.GetCurrentValue(controlName));
 }
Esempio n. 6
0
        public void CheckAndCreateCursors()
        {
            //Get Joystick Names
            string[] joyStickNames = Input.GetJoystickNames();
            //Iterate over every element
            for (int i = 0; i < joyStickNames.Length; i++)
            {
                //Unity does not delete entries but clears strings so check if empty
                bool isConnected  = !string.IsNullOrEmpty(joyStickNames[i]);
                var  customCursor = UpdateControllerListing(i, isConnected);
            }

            Dictionary <string, float> mValBtn1 = ControlInput.GetCurrentMultiValues("playerMulti_btn1");
            Dictionary <string, float> mValBtn2 = ControlInput.GetCurrentMultiValues("playerMulti_btn2");
            Dictionary <string, float> mValXRel = ControlInput.GetCurrentMultiValues("playerMulti_xRel");
            Dictionary <string, float> mValYRel = ControlInput.GetCurrentMultiValues("playerMulti_yRel");

            // NOTE: do nothing if there is only one
            if (mValBtn1.Count <= 1 || activateExerWorldSoOrSo)
            {
                return;
            }

            // create new cursor if needed
            foreach (string multiId in mValBtn1.Keys)
            {
                if (CustomCursor.allCursorsDict.ContainsKey(multiId) == false)
                {
                    CreateCustomCursor(multiId);
                }
            }
            foreach (string multiId in mValBtn2.Keys)
            {
                if (CustomCursor.allCursorsDict.ContainsKey(multiId) == false)
                {
                    CreateCustomCursor(multiId);
                }
            }
            foreach (string multiId in mValXRel.Keys)
            {
                if (CustomCursor.allCursorsDict.ContainsKey(multiId) == false)
                {
                    CreateCustomCursor(multiId);
                }
            }
            foreach (string multiId in mValYRel.Keys)
            {
                if (CustomCursor.allCursorsDict.ContainsKey(multiId) == false)
                {
                    CreateCustomCursor(multiId);
                }
            }

            // update values
            // NOTE: will be done by cursor themself

            if (cursors.Count > 1 || activateExerWorldSoOrSo)
            {
                ActivateExerWorldMode();
            }
            else
            {
                DeactivateExerWorldMode();
            }

            // TODO: also deactivate exerworld if the other players leave. check for inactivity
        }