Beispiel #1
0
        void Init()
        {
            if (id == -1)
            {
                id = EditorGUIExtra.GetPermanentControlID();
            }

            if (m_TimeArea == null)
            {
                m_TimeArea = new TimeArea(false);
                m_TimeArea.hRangeLocked    = false;
                m_TimeArea.vRangeLocked    = false;
                m_TimeArea.hSlider         = false;
                m_TimeArea.vSlider         = false;
                m_TimeArea.margin          = 10f;
                m_TimeArea.scaleWithWindow = true;
                m_TimeArea.hTicks.SetTickModulosForFrameRate(30f);
                m_TimeArea.OnEnable();
            }

            if (styles == null)
            {
                styles = new Timeline.Styles();
            }
        }
Beispiel #2
0
        private void SliderGUI()
        {
            if (!this.m_HSlider && !this.m_VSlider)
            {
                return;
            }
            Bounds  drawingBounds          = this.drawingBounds;
            Rect    shownAreaInsideMargins = this.shownAreaInsideMargins;
            float   num  = this.styles.sliderWidth - this.styles.visualSliderWidth;
            float   num2 = (!this.vSlider || !this.hSlider) ? 0f : num;
            Vector2 a    = this.m_Scale;

            if (this.m_HSlider)
            {
                Rect  position = new Rect(this.drawRect.x + 1f, this.drawRect.yMax - num, this.drawRect.width - num2, this.styles.sliderWidth);
                float width    = shownAreaInsideMargins.width;
                float xMin     = shownAreaInsideMargins.xMin;
                EditorGUIExtra.MinMaxScroller(position, this.horizontalScrollbarID, ref xMin, ref width, drawingBounds.min.x, drawingBounds.max.x, float.NegativeInfinity, float.PositiveInfinity, this.styles.horizontalScrollbar, this.styles.horizontalMinMaxScrollbarThumb, this.styles.horizontalScrollbarLeftButton, this.styles.horizontalScrollbarRightButton, true);
                float num3 = xMin;
                float num4 = xMin + width;
                if (num3 > shownAreaInsideMargins.xMin)
                {
                    num3 = Mathf.Min(num3, num4 - this.m_HScaleMin);
                }
                if (num4 < shownAreaInsideMargins.xMax)
                {
                    num4 = Mathf.Max(num4, num3 + this.m_HScaleMin);
                }
                this.SetShownHRangeInsideMargins(num3, num4);
            }
            if (this.m_VSlider)
            {
                Rect  position2 = new Rect(this.drawRect.xMax - num, this.drawRect.y, this.styles.sliderWidth, this.drawRect.height - num2);
                float height    = shownAreaInsideMargins.height;
                float num5      = -shownAreaInsideMargins.yMax;
                EditorGUIExtra.MinMaxScroller(position2, this.verticalScrollbarID, ref num5, ref height, -drawingBounds.max.y, -drawingBounds.min.y, float.NegativeInfinity, float.PositiveInfinity, this.styles.verticalScrollbar, this.styles.verticalMinMaxScrollbarThumb, this.styles.verticalScrollbarUpButton, this.styles.verticalScrollbarDownButton, false);
                float num3 = -(num5 + height);
                float num4 = -num5;
                if (num3 > shownAreaInsideMargins.yMin)
                {
                    num3 = Mathf.Min(num3, num4 - this.m_VScaleMin);
                }
                if (num4 < shownAreaInsideMargins.yMax)
                {
                    num4 = Mathf.Max(num4, num3 + this.m_VScaleMin);
                }
                this.SetShownVRangeInsideMargins(num3, num4);
            }
            if (this.uniformScale)
            {
                float num6 = this.drawRect.width / this.drawRect.height;
                a -= this.m_Scale;
                Vector2 b = new Vector2(-a.y * num6, -a.x / num6);
                this.m_Scale        -= b;
                this.m_Translation.x = this.m_Translation.x - a.y / 2f;
                this.m_Translation.y = this.m_Translation.y - a.x / 2f;
                this.EnforceScaleAndRange();
            }
        }
Beispiel #3
0
        public override void OnInspectorGUI()
        {
#if UNITY_5_5_OR_NEWER
#else
            EditorUtility.SetSelectedWireframeHidden(m_SpriteMeshInstance.cachedRenderer, !m_SpriteMeshInstance.cachedSkinnedRenderer);
#endif

            EditorGUI.BeginChangeCheck();

            serializedObject.Update();

            EditorGUILayout.PropertyField(m_SpriteMeshProperty);

            serializedObject.ApplyModifiedProperties();

            if (EditorGUI.EndChangeCheck())
            {
                UpdateSpriteMeshData();
                UpdateRenderers();
                SetupBoneList();
            }

            serializedObject.Update();

            EditorGUILayout.PropertyField(m_ColorProperty);

            if (m_MaterialsProperty.arraySize == 0)
            {
                m_MaterialsProperty.InsertArrayElementAtIndex(0);
            }
            EditorGUILayout.PropertyField(m_MaterialsProperty.GetArrayElementAtIndex(0), new GUIContent("Material"), true, new GUILayoutOption[0]);

            EditorGUILayout.Space();

            EditorGUIExtra.SortingLayerField(new GUIContent("Sorting Layer"), m_SortingLayerID, EditorStyles.popup, EditorStyles.label);
            EditorGUILayout.PropertyField(m_SortingOrder, new GUIContent("Order in Layer"));

            EditorGUILayout.Space();

            if (!HasBindPoses())
            {
                List <Bone2D> bones = new List <Bone2D>();

                EditorGUI.BeginChangeCheck();

                Transform root = EditorGUILayout.ObjectField("Set bones", null, typeof(Transform), true) as Transform;

                if (EditorGUI.EndChangeCheck())
                {
                    if (root)
                    {
                        root.GetComponentsInChildren <Bone2D>(bones);
                    }

                    Undo.RegisterCompleteObjectUndo(m_SpriteMeshInstance, "set bones");

                    m_BoneTransformsProperty.arraySize = bones.Count;

                    for (int i = 0; i < bones.Count; ++i)
                    {
                        m_BoneTransformsProperty.GetArrayElementAtIndex(i).objectReferenceValue = bones[i].transform;
                    }

                    UpdateRenderers();
                }
            }

            EditorGUI.BeginChangeCheck();

            if (mBoneList != null)
            {
                mBoneList.DoLayoutList();
            }

            serializedObject.ApplyModifiedProperties();

            if (EditorGUI.EndChangeCheck())
            {
                UpdateRenderers();
            }

            if (m_SpriteMeshInstance.spriteMesh)
            {
                if (SpriteMeshUtils.HasNullBones(m_SpriteMeshInstance))
                {
                    EditorGUILayout.HelpBox("Warning:\nBone list contains null references.", MessageType.Warning);
                }

                if (m_SpriteMeshInstance.spriteMesh.sharedMesh.bindposes.Length != m_SpriteMeshInstance.bones.Count)
                {
                    EditorGUILayout.HelpBox("Warning:\nNumber of SpriteMesh Bind Poses and number of Bones does not match.", MessageType.Warning);
                }
            }
        }
        void DoVerticesInspector()
        {
            if (spriteMeshCache.selection.Count > 0)
            {
                string[] names = spriteMeshCache.GetBoneNames("Unassigned");

                BoneWeight boneWeight = BoneWeight.Create();

                EditorGUI.BeginChangeCheck();

                bool mixedBoneIndex0 = false;
                bool mixedBoneIndex1 = false;
                bool mixedBoneIndex2 = false;
                bool mixedBoneIndex3 = false;
                bool changedIndex0   = false;
                bool changedIndex1   = false;
                bool changedIndex2   = false;
                bool changedIndex3   = false;
                bool mixedWeight     = false;

                if (spriteMeshCache.multiselection)
                {
                    mixedWeight = true;

                    int boneIndex = -1;
                    mixedBoneIndex0 = IsMixedBoneIndex(0, out boneIndex);
                    if (!mixedBoneIndex0)
                    {
                        boneWeight.boneIndex0 = boneIndex;
                    }
                    mixedBoneIndex1 = IsMixedBoneIndex(1, out boneIndex);
                    if (!mixedBoneIndex1)
                    {
                        boneWeight.boneIndex1 = boneIndex;
                    }
                    mixedBoneIndex2 = IsMixedBoneIndex(2, out boneIndex);
                    if (!mixedBoneIndex2)
                    {
                        boneWeight.boneIndex2 = boneIndex;
                    }
                    mixedBoneIndex3 = IsMixedBoneIndex(3, out boneIndex);
                    if (!mixedBoneIndex3)
                    {
                        boneWeight.boneIndex3 = boneIndex;
                    }
                }
                else
                {
                    boneWeight = spriteMeshCache.GetBoneWeight(spriteMeshCache.selectedNode);
                }

                EditorGUI.BeginChangeCheck();

                EditorGUI.BeginChangeCheck();
                boneWeight    = EditorGUIExtra.Weight(boneWeight, 0, names, mixedBoneIndex0, mixedWeight);
                changedIndex0 = EditorGUI.EndChangeCheck();

                EditorGUI.BeginChangeCheck();
                boneWeight    = EditorGUIExtra.Weight(boneWeight, 1, names, mixedBoneIndex1, mixedWeight);
                changedIndex1 = EditorGUI.EndChangeCheck();

                EditorGUI.BeginChangeCheck();
                boneWeight    = EditorGUIExtra.Weight(boneWeight, 2, names, mixedBoneIndex2, mixedWeight);
                changedIndex2 = EditorGUI.EndChangeCheck();

                EditorGUI.BeginChangeCheck();
                boneWeight    = EditorGUIExtra.Weight(boneWeight, 3, names, mixedBoneIndex3, mixedWeight);
                changedIndex3 = EditorGUI.EndChangeCheck();

                if (EditorGUI.EndChangeCheck())
                {
                    spriteMeshCache.RegisterUndo("modify weights");

                    if (spriteMeshCache.multiselection)
                    {
                        List <Node> selectedNodes = spriteMeshCache.selectedNodes;

                        foreach (Node node in selectedNodes)
                        {
                            BoneWeight l_boneWeight = spriteMeshCache.GetBoneWeight(node);

                            if (!mixedBoneIndex0 || changedIndex0)
                            {
                                l_boneWeight.SetWeight(0, boneWeight.boneIndex0, l_boneWeight.weight0);
                            }
                            if (!mixedBoneIndex1 || changedIndex1)
                            {
                                l_boneWeight.SetWeight(1, boneWeight.boneIndex1, l_boneWeight.weight1);
                            }
                            if (!mixedBoneIndex2 || changedIndex2)
                            {
                                l_boneWeight.SetWeight(2, boneWeight.boneIndex2, l_boneWeight.weight2);
                            }
                            if (!mixedBoneIndex3 || changedIndex3)
                            {
                                l_boneWeight.SetWeight(3, boneWeight.boneIndex3, l_boneWeight.weight3);
                            }

                            spriteMeshCache.SetBoneWeight(node, l_boneWeight);
                        }
                    }
                    else
                    {
                        spriteMeshCache.SetBoneWeight(spriteMeshCache.selectedNode, boneWeight);
                    }
                }

                EditorGUI.showMixedValue = false;
            }
        }