Example #1
0
        /**
         * @private
         */
        protected override void _OnClear()
        {
            base._OnClear();

            if (this._meshBuffer != null)
            {
                this._meshBuffer.Dispose();
            }

            this._skewed = false;
            this._proxy  = null;

            this._renderDisplay = null;
            this._uiDisplay     = null;

            this._meshBuffer = null;

            this._meshRenderer = null;
            this._meshFilter   = null;

            this._isIgnoreCombineMesh = false;
            this._isCombineMesh       = false;
            this._sumMeshIndex        = -1;
            this._verticeOrder        = -1;
            this._verticeOffset       = -1;

            this._combineMesh = null;

            this._currentBlendMode = BlendMode.Normal;
            this._isActive         = false;
        }
Example #2
0
        static void HierarchyIconsOnGUI(int instanceId, Rect selectionRect)
        {
            GameObject go = (GameObject)EditorUtility.InstanceIDToObject(instanceId);

            if (!go)
            {
                return;
            }

            Rect rect = new Rect(selectionRect.x - 25f, selectionRect.y + 2, 15f, 15f);

            if (go.GetComponent <UnityArmatureComponent>())
            {
                rect.x = selectionRect.x + selectionRect.width - 15f;
                GUI.Label(rect, textureArmature);
                return;
            }

            UnityUGUIDisplay ugui = go.GetComponent <UnityUGUIDisplay>();

            if (ugui && ugui.sharedMesh)
            {
                if (ugui.sharedMesh.vertexCount == 4)
                {
                    GUI.Label(rect, textureImg);
                }
                else
                {
                    GUI.Label(rect, textureMesh);
                }
                return;
            }

            MeshFilter mf = go.GetComponent <MeshFilter>();

            if (mf && mf.sharedMesh &&
                mf.transform.parent != null &&
                mf.transform.parent.GetComponent <UnityArmatureComponent>() != null)
            {
                if (mf.sharedMesh.vertexCount == 4)
                {
                    GUI.Label(rect, textureImg);
                }
                else
                {
                    GUI.Label(rect, textureMesh);
                }
                return;
            }
        }
        /**
         * @private
         */
        protected override void _OnUpdateDisplay()
        {
            _renderDisplay = (_display != null ? _display : _rawDisplay) as GameObject;

            //
            _proxy = _armature.proxy as UnityArmatureComponent;
            if (_proxy.isUGUI)
            {
                _uiDisplay = _renderDisplay.GetComponent <UnityUGUIDisplay>();
                if (_uiDisplay == null)
                {
                    _uiDisplay = _renderDisplay.AddComponent <UnityUGUIDisplay>();
                    _uiDisplay.raycastTarget = false;
                }
            }
            else
            {
                _renderer = _renderDisplay.GetComponent <MeshRenderer>();
                if (_renderer == null)
                {
                    _renderer = _renderDisplay.AddComponent <MeshRenderer>();
                }
                //
                _meshFilter = _renderDisplay.GetComponent <MeshFilter>();
                if (_meshFilter == null)
                {
                    _meshFilter = _renderDisplay.AddComponent <MeshFilter>();
                }
            }

            //init mesh
            if (_mesh == null)
            {
                _mesh           = new Mesh();
                _mesh.hideFlags = HideFlags.DontSaveInEditor | HideFlags.DontSaveInBuild;
                _mesh.MarkDynamic();
            }
        }
Example #4
0
        /**
         * @private
         */
        protected override void _OnUpdateDisplay()
        {
            _renderDisplay = (_display != null ? _display : _rawDisplay) as GameObject;

            //
            _proxy = _armature.proxy as UnityArmatureComponent;
            if (_proxy.isUGUI)
            {
                _uiDisplay = _renderDisplay.GetComponent <UnityUGUIDisplay>();
                if (_uiDisplay == null)
                {
                    _uiDisplay = _renderDisplay.AddComponent <UnityUGUIDisplay>();
                    _uiDisplay.raycastTarget = false;
                }
            }
            else
            {
                _meshRenderer = _renderDisplay.GetComponent <MeshRenderer>();
                if (_meshRenderer == null)
                {
                    _meshRenderer = _renderDisplay.AddComponent <MeshRenderer>();
                }
                //
                _meshFilter = _renderDisplay.GetComponent <MeshFilter>();
                if (_meshFilter == null && _renderDisplay.GetComponent <TextMesh>() == null)
                {
                    _meshFilter = _renderDisplay.AddComponent <MeshFilter>();
                }
            }

            //init mesh
            if (this._meshBuffer == null)
            {
                this._meshBuffer                 = new MeshBuffer();
                this._meshBuffer.sharedMesh      = MeshBuffer.GenerateMesh();
                this._meshBuffer.sharedMesh.name = this.name;
            }
        }
Example #5
0
        /**
         * @private
         */
        override protected void _updateFrame()
        {
            var isMeshDisplay      = _meshData != null && _display == _meshDisplay;
            var currentTextureData = _textureData as UnityTextureData;

            if (_proxy.isUGUI)
            {
                _uiDisplay = _renderDisplay.GetComponent <UnityUGUIDisplay>();
                if (_uiDisplay == null)
                {
                    _uiDisplay = _renderDisplay.AddComponent <UnityUGUIDisplay>();
                    _uiDisplay.raycastTarget = false;
                }
            }
            else
            {
                _renderer = _renderDisplay.GetComponent <MeshRenderer>();
                if (_renderer == null)
                {
                    _renderer = _renderDisplay.AddComponent <MeshRenderer>();
                }
                _meshFilter = _renderDisplay.GetComponent <MeshFilter>();
                if (_meshFilter == null)
                {
                    _meshFilter = _renderDisplay.AddComponent <MeshFilter>();
                }
            }

            if (_display != null && _displayIndex >= 0 && currentTextureData != null)
            {
                var currentTextureAtlasData = currentTextureData.parent as UnityTextureAtlasData;

                // Update replaced texture atlas.
                if (_armature.replacedTexture != null && _displayData != null && currentTextureAtlasData == _displayData.texture.parent)
                {
                    currentTextureAtlasData = _armature._replaceTextureAtlasData as UnityTextureAtlasData;
                    if (currentTextureAtlasData == null)
                    {
                        currentTextureAtlasData = BaseObject.BorrowObject <UnityTextureAtlasData>();
                        currentTextureAtlasData.CopyFrom(_textureData.parent);
                        if (_proxy.isUGUI)
                        {
                            currentTextureAtlasData.uiTexture = _armature.replacedTexture as Material;
                        }
                        else
                        {
                            currentTextureAtlasData.texture = _armature.replacedTexture as Material;
                        }
                        _armature._replaceTextureAtlasData = currentTextureAtlasData;
                    }

                    currentTextureData = currentTextureAtlasData.GetTexture(currentTextureData.name) as UnityTextureData;
                }

                var currentTextureAtlas = _proxy.isUGUI?currentTextureAtlasData.uiTexture :currentTextureAtlasData.texture;
                if (currentTextureAtlas != null)
                {
                    var textureAtlasWidth  = currentTextureAtlasData.width > 0.0f ? currentTextureAtlasData.width : currentTextureAtlas.mainTexture.width;
                    var textureAtlasHeight = currentTextureAtlasData.height > 0.0f ? currentTextureAtlasData.height : currentTextureAtlas.mainTexture.height;

                    if (_mesh == null)
                    {
                        _mesh           = new Mesh();
                        _mesh.hideFlags = HideFlags.DontSaveInEditor | HideFlags.DontSaveInBuild;
                        _mesh.MarkDynamic();
                    }
                    else
                    {
                        _mesh.Clear();
                        _mesh.uv        = null;
                        _mesh.vertices  = null;
                        _mesh.normals   = null;
                        _mesh.triangles = null;
                        _mesh.colors32  = null;
                    }

                    if (isMeshDisplay) // Mesh.
                    {
                        if (_uvs == null || _uvs.Length != _meshData.uvs.Count / 2)
                        {
                            _uvs = new Vector2[_meshData.uvs.Count / 2];
                        }
                        if (_vertices == null || _vertices.Length != _meshData.vertices.Count / 2)
                        {
                            _vertices  = new Vector3[_meshData.vertices.Count / 2];
                            _vertices2 = new Vector3[_vertices.Length];
                        }

                        for (int i = 0, l = _meshData.uvs.Count; i < l; i += 2)
                        {
                            var iN = i / 2;
                            var u  = _meshData.uvs[i];
                            var v  = _meshData.uvs[i + 1];
                            _uvs[iN] = new Vector2(
                                (currentTextureData.region.x + u * currentTextureData.region.width) / textureAtlasWidth,
                                1.0f - (currentTextureData.region.y + v * currentTextureData.region.height) / textureAtlasHeight
                                );
                            _vertices[iN]  = new Vector3(_meshData.vertices[i], -_meshData.vertices[i + 1], 0.0f);
                            _vertices2[iN] = _vertices[iN];
                        }

                        _mesh.vertices  = _vertices; // Must set vertices before uvs.
                        _mesh.uv        = _uvs;
                        _mesh.triangles = _meshData.vertexIndices.ToArray();
                    }
                    else // Normal texture.
                    {
                        var pivotY = _pivotY - currentTextureData.region.height * _armature.armatureData.scale;

                        if (_vertices == null || _vertices.Length != 4)
                        {
                            _vertices  = new Vector3[4];
                            _vertices2 = new Vector3[4];
                        }

                        for (int i = 0, l = 4; i < l; ++i)
                        {
                            var u = 0.0f;
                            var v = 0.0f;

                            switch (i)
                            {
                            case 0:
                                break;

                            case 1:
                                u = 1.0f;
                                break;

                            case 2:
                                u = 1.0f;
                                v = 1.0f;
                                break;

                            case 3:
                                v = 1.0f;
                                break;

                            default:
                                break;
                            }

                            _helpVector2s[i].x = (currentTextureData.region.x + u * currentTextureData.region.width) / textureAtlasWidth;
                            _helpVector2s[i].y = 1.0f - (currentTextureData.region.y + v * currentTextureData.region.height) / textureAtlasHeight;
                            _vertices[i].x     = (u * currentTextureData.region.width) * 0.01f - _pivotX;
                            _vertices[i].y     = (1.0f - v) * currentTextureData.region.height * 0.01f + pivotY;
                            _vertices[i].z     = 0.0f * 0.01f;
                            _vertices2[i]      = _vertices[i];
                        }

                        _mesh.vertices  = _vertices; // Must set vertices before uvs.
                        _mesh.uv        = _helpVector2s;
                        _mesh.triangles = TRIANGLES;
                    }

                    if (_proxy.isUGUI)
                    {
                        _uiDisplay.material = currentTextureAtlas;
                        _uiDisplay.texture  = currentTextureAtlas.mainTexture;
                        _mesh.RecalculateBounds();
                        _uiDisplay.sharedMesh = _mesh;
                    }
                    else
                    {
                        if (_renderer.enabled)
                        {
                            _mesh.RecalculateBounds();
                        }
                        _meshFilter.sharedMesh   = _mesh;
                        _renderer.sharedMaterial = currentTextureAtlas;
                    }

                    _updateVisible();

                    return;
                }
            }

            _renderDisplay.SetActive(false);
            if (_proxy.isUGUI)
            {
                _uiDisplay.material   = null;
                _uiDisplay.texture    = null;
                _uiDisplay.sharedMesh = null;
            }
            else
            {
                _meshFilter.sharedMesh   = null;
                _renderer.sharedMaterial = null;
            }
            _helpVector3.x = 0.0f;
            _helpVector3.y = 0.0f;
            _helpVector3.z = _renderDisplay.transform.localPosition.z;

            _renderDisplay.transform.localPosition = _helpVector3;
        }
        /**
         * @private
         */
        protected override void _UpdateFrame()
        {
            var meshData           = this._display == this._meshDisplay ? this._meshData : null;
            var currentTextureData = this._textureData as UnityTextureData;

            if (_proxy.isUGUI)
            {
                _uiDisplay = _renderDisplay.GetComponent <UnityUGUIDisplay>();
                if (_uiDisplay == null)
                {
                    _uiDisplay = _renderDisplay.AddComponent <UnityUGUIDisplay>();
                    _uiDisplay.raycastTarget = false;
                }
            }
            else
            {
                _renderer = _renderDisplay.GetComponent <MeshRenderer>();
                if (_renderer == null)
                {
                    _renderer = _renderDisplay.AddComponent <MeshRenderer>();
                }

                _meshFilter = _renderDisplay.GetComponent <MeshFilter>();
                if (_meshFilter == null)
                {
                    _meshFilter = _renderDisplay.AddComponent <MeshFilter>();
                }
            }

            if (this._displayIndex >= 0 && this._display != null && currentTextureData != null)
            {
                if (this._armature.replacedTexture != null && this._rawDisplayDatas.Contains(this._displayData))
                {
                    var currentTextureAtlasData = currentTextureData.parent as UnityTextureAtlasData;
                    if (this._armature._replaceTextureAtlasData == null)
                    {
                        currentTextureAtlasData = BaseObject.BorrowObject <UnityTextureAtlasData>();
                        currentTextureAtlasData.CopyFrom(currentTextureData.parent);

                        if (_proxy.isUGUI)
                        {
                            currentTextureAtlasData.uiTexture = _armature.replacedTexture as Material;
                        }
                        else
                        {
                            currentTextureAtlasData.texture = _armature.replacedTexture as Material;
                        }

                        this._armature._replaceTextureAtlasData = currentTextureAtlasData;
                    }
                    else
                    {
                        currentTextureAtlasData = this._armature._replaceTextureAtlasData as UnityTextureAtlasData;
                    }

                    currentTextureData = currentTextureAtlasData.GetTexture(currentTextureData.name) as UnityTextureData;
                }

                var currentTextureAtlas = _proxy.isUGUI ? currentTextureAtlasData.uiTexture : currentTextureAtlasData.texture;
                if (currentTextureAtlas != null)
                {
                    var textureAtlasWidth  = currentTextureAtlasData.width > 0.0f ? (int)currentTextureAtlasData.width : currentTextureAtlas.mainTexture.width;
                    var textureAtlasHeight = currentTextureAtlasData.height > 0.0f ? (int)currentTextureAtlasData.height : currentTextureAtlas.mainTexture.height;

                    if (_mesh == null)
                    {
                        _mesh           = new Mesh();
                        _mesh.hideFlags = HideFlags.DontSaveInEditor | HideFlags.DontSaveInBuild;
                        _mesh.MarkDynamic();
                    }

                    var meshDisplay = this._mesh;
                    meshDisplay.Clear();
                    meshDisplay.uv        = null;
                    meshDisplay.vertices  = null;
                    meshDisplay.normals   = null;
                    meshDisplay.triangles = null;
                    meshDisplay.colors32  = null;

                    var textureScale = _armature.armatureData.scale * currentTextureData.parent.scale;
                    var sourceX      = currentTextureData.region.x;
                    var sourceY      = currentTextureData.region.y;
                    var sourceWidth  = currentTextureData.region.width;
                    var sourceHeight = currentTextureData.region.height;

                    if (meshData != null)
                    {
                        var data          = meshData.parent.parent.parent;
                        var intArray      = data.intArray;
                        var floatArray    = data.floatArray;
                        var vertexCount   = intArray[meshData.offset + (int)BinaryOffset.MeshVertexCount];
                        var triangleCount = intArray[meshData.offset + (int)BinaryOffset.MeshTriangleCount];
                        int vertexOffset  = intArray[meshData.offset + (int)BinaryOffset.MeshFloatOffset];
                        if (vertexOffset < 0)
                        {
                            vertexOffset += 65536; // Fixed out of bouds bug.
                        }

                        var uvOffset = vertexOffset + vertexCount * 2;

                        if (this._uvs == null || this._uvs.Length != vertexCount)
                        {
                            this._uvs = new Vector2[vertexCount];
                        }

                        if (this._vertices == null || this._vertices.Length != vertexCount)
                        {
                            this._vertices  = new Vector3[vertexCount];
                            this._vertices2 = new Vector3[vertexCount];
                        }

                        int[] triangles = new int[triangleCount * 3];

                        for (int i = 0, iV = vertexOffset, iU = uvOffset, l = vertexCount; i < l; ++i)
                        {
                            this._vertices[i].x = floatArray[iV++] * textureScale;
                            this._vertices[i].y = floatArray[iV++] * textureScale;

                            this._uvs[i].x = (sourceX + floatArray[iU++] * sourceWidth) / textureAtlasWidth;
                            this._uvs[i].y = 1.0f - (sourceY + floatArray[iU++] * sourceHeight) / textureAtlasHeight;

                            this._vertices2[i] = this._vertices[i];
                        }

                        for (int i = 0; i < triangleCount * 3; ++i)
                        {
                            triangles[i] = intArray[meshData.offset + (int)BinaryOffset.MeshVertexIndices + i];
                        }

                        //
                        meshDisplay.vertices  = this._vertices;
                        meshDisplay.uv        = this._uvs;// Must set vertices before uvs.
                        meshDisplay.triangles = triangles;
                    }
                    else
                    {
                        if (_vertices == null || _vertices.Length != 4)
                        {
                            _vertices  = new Vector3[4];
                            _vertices2 = new Vector3[4];
                        }

                        // Normal texture.
                        for (int i = 0, l = 4; i < l; ++i)
                        {
                            var u = 0.0f;
                            var v = 0.0f;

                            switch (i)
                            {
                            case 0:
                                break;

                            case 1:
                                u = 1.0f;
                                break;

                            case 2:
                                u = 1.0f;
                                v = 1.0f;
                                break;

                            case 3:
                                v = 1.0f;
                                break;

                            default:
                                break;
                            }

                            var scaleWidth  = sourceWidth * textureScale;
                            var scaleHeight = sourceHeight * textureScale;
                            var pivotX      = _pivotX;
                            var pivotY      = scaleHeight - _pivotY;

                            if (currentTextureData.rotated)
                            {
                                var temp = scaleWidth;
                                scaleWidth  = scaleHeight;
                                scaleHeight = temp;

                                pivotX = scaleWidth - _pivotX;
                                pivotY = scaleHeight - _pivotY;

                                //uv
                                _helpVector2s[i].x = (sourceX + (1.0f - v) * sourceWidth) / textureAtlasWidth;
                                _helpVector2s[i].y = 1.0f - (sourceY + u * sourceHeight) / textureAtlasHeight;
                            }
                            else
                            {
                                //uv
                                _helpVector2s[i].x = (sourceX + u * sourceWidth) / textureAtlasWidth;
                                _helpVector2s[i].y = 1.0f - (sourceY + v * sourceHeight) / textureAtlasHeight;
                            }

                            //vertices
                            _vertices[i].x = (u * scaleWidth) - pivotX;
                            _vertices[i].y = (1.0f - v) * scaleHeight - pivotY;

                            _vertices[i].z = 0.0f;
                            _vertices2[i]  = _vertices[i];
                        }

                        _mesh.vertices  = _vertices; // Must set vertices before uvs.
                        _mesh.uv        = _helpVector2s;
                        _mesh.triangles = TRIANGLES;
                    }

                    if (_proxy.isUGUI)
                    {
                        _uiDisplay.material = currentTextureAtlas;
                        _uiDisplay.texture  = currentTextureAtlas.mainTexture;
                        _mesh.RecalculateBounds();
                        _uiDisplay.sharedMesh = _mesh;
                    }
                    else
                    {
                        if (_renderer.enabled)
                        {
                            _mesh.RecalculateBounds();
                        }

                        _meshFilter.sharedMesh   = _mesh;
                        _renderer.sharedMaterial = currentTextureAtlas;
                    }

                    this._blendModeDirty = true;
                    this._colorDirty     = true;// Relpace texture will override blendMode and color.
                    this._visibleDirty   = true;
                    return;
                }
            }

            _renderDisplay.SetActive(false);
            if (_proxy.isUGUI)
            {
                _uiDisplay.material   = null;
                _uiDisplay.texture    = null;
                _uiDisplay.sharedMesh = null;
            }
            else
            {
                _meshFilter.sharedMesh   = null;
                _renderer.sharedMaterial = null;
            }

            _helpVector3.x = 0.0f;
            _helpVector3.y = 0.0f;
            _helpVector3.z = _renderDisplay.transform.localPosition.z;

            _renderDisplay.transform.localPosition = _helpVector3;
        }