Beispiel #1
0
 private void LateUpdate()
 {
     // grab mouse pos for previous position calculations
     m_previousMousePos.Set((short)Input.mousePosition.x, (short)Input.mousePosition.y);
     m_bresenhamCounter = 0;
 }
Beispiel #2
0
        // Update is called once per frame
        void Update()
        {
            if (!isLocalPlayer)
            {
                return;
            }

            if (Input.GetKeyDown(KeyCode.C))
            {
                ClearTextureAlpha(m_localTex);
            }

            m_mousePos.Set((short)Input.mousePosition.x, (short)Input.mousePosition.y);

            if (Input.GetMouseButton(0))
            {
                RaycastHit hit;
                if (Physics.Raycast(m_playerCam.transform.position, m_playerCam.transform.forward, out hit, m_maxDrawDistance, m_DrawableLayerMask))
                {
                    GameObject hitObj = hit.collider.gameObject;

                    m_localChangeMade = m_networkChangeMade = true;

                    // when changing object grab data for drawing on that object
                    if (m_selectedObject != null && m_selectedObject != hitObj)
                    {
                        changeDefaultValues(hitObj);
                        Debug.Log("Select new object");
                    }
                    else if (m_selectedObject == null)
                    {
                        changeDefaultValues(hitObj);
                        Debug.Log("Selected first object");
                    }

                    if (m_writableMaterial && m_localTex)
                    {
                        // find pixel coordinate to affect
                        Vector2 texCoord = hit.textureCoord;

                        m_pixelCoord.x = (short)(m_localTex.width * texCoord.x);
                        m_pixelCoord.y = (short)(m_localTex.height * texCoord.y);

                        // grab previous coordinate if available
                        if (m_networkCoordinates.Count > 1)
                        {
                            m_prevLocalCoord = m_networkCoordinates[m_networkCoordinates.Count - 1];
                        }

                        // reached maximum array size, so send current values
                        if (m_networkCoordinates.Count > m_maxNetworkArraySize)
                        {
                            CmdDrawLines(m_networkCoordinates.ToArray(), m_selectedObject, m_clientDrawSpeed, m_changeDelay, m_defaultBrushRadius);
                            resetLocalValues();
                        }

                        // add coordinate to list if position is different than last coordinate
                        if (m_pixelCoord != m_prevLocalCoord)
                        {
                            m_networkCoordinates.Add(m_pixelCoord);

                            // draw locally
                            drawPoints(m_pixelCoord, m_prevLocalCoord, m_localTex, m_defaultBrushRadius, m_networkCoordinates.Count == 1);
                        }
                    }
                }
            }
            // Release input so send network data to clients immediately
            else if (Input.GetMouseButtonUp(0) && m_networkCoordinates.Count > 0)
            {
                CmdDrawLines(m_networkCoordinates.ToArray(), m_selectedObject, m_clientDrawSpeed, m_changeDelay, m_defaultBrushRadius);
                m_previousMousePos = Vector2Short.zero;
                m_prevLocalCoord   = Vector2Short.zero;

                resetLocalValues();
            }

            // chek locally for applying texture changes
            CheckApplyTexChanges(m_localTex);
        }