void LateUpdate()
        {
            if (_armature == null)
            {
                return;
            }

            _flipX = _armature.flipX;
            _flipY = _armature.flipY;

#if UNITY_5_6_OR_NEWER
            var hasSortingGroup = GetComponent <UnityEngine.Rendering.SortingGroup>() != null;
            if (hasSortingGroup != _hasSortingGroup)
            {
                _hasSortingGroup = hasSortingGroup;

                _UpdateSortingGroup();
            }
#endif
            if (unityBones != null)
            {
                int len = unityBones.Count;
                for (int i = 0; i < len; ++i)
                {
                    UnityBone bone = unityBones[i];
                    if (bone)
                    {
                        bone._Update();
                    }
                }
            }
        }
        public void ShowBones()
        {
            RemoveBones();
            if (bonesRoot == null)
            {
                var bonesContainer = transform.Find("Bones");
                if (bonesContainer == null)
                {
                    GameObject go = new GameObject("Bones");
                    go.transform.SetParent(transform);
                    go.transform.localPosition = Vector3.zero;
                    go.transform.localRotation = Quaternion.identity;
                    go.transform.localScale    = Vector3.one;
                    bonesRoot    = go;
                    go.hideFlags = HideFlags.NotEditable;
                }
                else
                {
                    bonesRoot = bonesContainer.gameObject;
                    bonesContainer.hideFlags = HideFlags.NotEditable;
                }
            }
            if (armature != null)
            {
                unityBones = new List <UnityBone>();
                foreach (Bone bone in armature.GetBones())
                {
                    GameObject go = new GameObject(bone.name);
                    UnityBone  ub = go.AddComponent <UnityBone> ();
                    ub._bone  = bone;
                    ub._proxy = this;
                    unityBones.Add(ub);

                    go.transform.SetParent(bonesRoot.transform);
                }
                foreach (UnityBone bone in unityBones)
                {
                    bone.GetParentGameObject();
                }
                foreach (UnityArmatureComponent child in slotsRoot.GetComponentsInChildren <UnityArmatureComponent>(true))
                {
                    child.ShowBones();
                }
            }
        }
Example #3
0
        void LateUpdate()
        {
            if (_armature == null)
            {
                return;
            }

            flipX = _armature.flipX;
            flipY = _armature.flipY;

                        #if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                                #if UNITY_5_6_OR_NEWER
                if (!isUGUI)
                {
                    _sortingGroup = GetComponent <UnityEngine.Rendering.SortingGroup>();
                    if (_sortingGroup)
                    {
                        sortingMode       = SortingMode.SortByOrder;
                        _sortingLayerName = _sortingGroup.sortingLayerName;
                        _sortingOrder     = _sortingGroup.sortingOrder;
                    }
                }
                                #endif
                foreach (var slot in _armature.GetSlots())
                {
                    var display = slot.display as GameObject;
                    if (display != null)
                    {
                        display.transform.localPosition = new Vector3(display.transform.localPosition.x, display.transform.localPosition.y, -slot._zOrder * (_zSpace + 0.001f));
                        if (!isUGUI && sortingMode == SortingMode.SortByOrder)
                        {
                            UnitySlot us = slot as UnitySlot;
                            if (us.meshRenderer != null)
                            {
                                us.meshRenderer.sortingOrder = slot._zOrder;
                            }
                        }
                    }
                }
            }
                        #endif
            if (zorderIsDirty)
            {
                _sortedSlots = new List <Slot>(_armature.GetSlots());
                _sortedSlots.Sort(delegate(Slot x, Slot y) {
                    return(x._zOrder - y._zOrder);
                });
                for (int i = 0; i < _sortedSlots.Count; ++i)
                {
                    Slot slot    = _sortedSlots[i];
                    var  display = slot.display as GameObject;
                    if (display != null)
                    {
                        display.transform.SetSiblingIndex(i);
                        if (!isUGUI && sortingMode == SortingMode.SortByOrder)
                        {
                            UnitySlot us = slot as UnitySlot;
                            if (us.meshRenderer != null)
                            {
                                us.meshRenderer.sortingOrder = i;
                            }
                        }
                    }
                }
                zorderIsDirty = false;
            }
            if (unityBones != null)
            {
                int len = unityBones.Count;
                for (int i = 0; i < len; ++i)
                {
                    UnityBone bone = unityBones[i];
                    if (bone)
                    {
                        bone._Update();
                    }
                }
            }
        }
Example #4
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.parent != null &&
                mf.transform.parent.parent.GetComponent <UnityArmatureComponent>() != null)
            {
                if (mf.sharedMesh.vertexCount == 4)
                {
                    GUI.Label(rect, textureImg);
                }
                else
                {
                    GUI.Label(rect, textureMesh);
                }
                return;
            }

            UnityBone ubone = go.GetComponent <UnityBone>();

            if (ubone)
            {
                Texture2D icon = textureBone;
                Bone      bone = ubone.bone;
                if (bone != null && bone.ik != null)
                {
                    icon = textureIk;
                }
                GUI.Label(rect, icon);
                return;
            }
        }