Ejemplo n.º 1
0
        public static void OnGUI(
            ref Rect rect,
            SerializedProperty propertyPath,
            SerializedProperty arrayProperty,
            Object referenceObject,
            HashSet <string> typeStrings,
            float backgroundXMin,
            float headerXOffset = 0
            )
        {
            rect.NextGUIRect();
            if (EditorGUIUtils.DrawHeaderWithFoldout(
                    rect,
                    new GUIContent("Array Property"),
                    propertyPath.isExpanded,
                    backgroundXMin: backgroundXMin,
                    headerXOffset: headerXOffset
                    ))
            {
                propertyPath.isExpanded = !propertyPath.isExpanded;
            }

            if (!propertyPath.isExpanded)
            {
                return;
            }

            SerializedProperty indexing = arrayProperty.FindPropertyRelative("ArrayIndexing");

            rect.NextGUIRect();
            EditorGUI.PropertyField(rect, indexing);

            if (!AssetListConfigurationInspector.ValidateReferenceObjectWithHelpWarningRect(referenceObject, ref rect))
            {
                return;
            }

            switch ((ArrayIndexing)indexing.intValue)
            {
            case ArrayIndexing.First:
                DrawDrawingProperty(ref rect);
                break;

            case ArrayIndexing.ByKey:
                //The property to look for as a key. This is associated with the query.
                SerializedProperty key = arrayProperty.FindPropertyRelative("ArrayPropertyKey");
                bool hasKey            = !string.IsNullOrEmpty(key.stringValue);
                rect.NextGUIRect();
                rect.y += EditorGUIUtility.standardVerticalSpacing;
                EditorGUI.LabelField(rect, hasKey ? keyAndQueryLabel : keyLabel, EditorGUIUtils.CenteredBoldLabel);

                rect.NextGUIRect();
                using (new EditorGUI.DisabledScope(true))
                    EditorGUI.PropertyField(rect, key, GUIContent.none);
                rect.NextGUIRect();
                if (GUI.Button(rect.GetIndentedRect(), hasKey ? modifyArrayKeyLabel : addArrayKeyLabel))
                {
                    //retrieves properties under the first array index for the dropdown
                    DisplayArrayKeyPropertyDropdown(rect, $"{propertyPath.stringValue}.Array.data[0]", arrayProperty, referenceObject);
                }

                //The query into the array. This is associated with the array property key.
                if (!string.IsNullOrEmpty(key.stringValue))
                {
                    rect.NextGUIRect();
                    SerializedProperty arrayQuery = arrayProperty.FindPropertyRelative("ArrayQuery");
                    EditorGUI.PropertyField(rect, arrayQuery, queryLabel);

                    //The property to draw if the query has passed.
                    if (!string.IsNullOrEmpty(arrayQuery.stringValue))
                    {
                        DrawDrawingProperty(ref rect);
                    }
                }

                break;

            case ArrayIndexing.ByIndex:
                rect.NextGUIRect();
                EditorGUI.PropertyField(rect, arrayProperty.FindPropertyRelative("ArrayIndex"));
                DrawDrawingProperty(ref rect);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            void DrawDrawingProperty(ref Rect r)
            {
                r.NextGUIRect();
                r.y += EditorGUIUtility.standardVerticalSpacing;
                EditorGUI.LabelField(r, "Property", EditorGUIUtils.CenteredBoldLabel);
                r.NextGUIRect();
                SerializedProperty arrayPropertyPath = arrayProperty.FindPropertyRelative("ArrayPropertyPath");

                using (new EditorGUI.DisabledScope(true))
                    EditorGUI.PropertyField(r, arrayPropertyPath);
                r.NextGUIRect();
                if (GUI.Button(r.GetIndentedRect(), string.IsNullOrEmpty(arrayPropertyPath.stringValue) ? addDrawingPropertyLabel : modifyDrawingPropertyLabel))
                {
                    DisplayArrayDrawingPropertyDropdown(r, $"{propertyPath.stringValue}.Array.data[0]", arrayProperty, referenceObject, typeStrings);
                }
            }
        }
Ejemplo n.º 2
0
    private static void DrawFaceEditor(ref int face, Atlas atlas, ref Matrix4x4 matrix)
    {
        GUILayout.BeginVertical(GUI.skin.box);
        Texture texture = atlas.GetTexture();
        Rect    rect    = GUILayoutUtility.GetAspectRect((float)texture.width / texture.height);

        GUILayout.EndVertical();

        Matrix4x4 rectMatrix    = Matrix4x4.Scale(new Vector3(rect.width, rect.height, 0)) * matrix;
        Matrix4x4 invRectMatrix = matrix.inverse * Matrix4x4.Scale(new Vector3(1 / rect.width, 1 / rect.height, 0));
        Matrix4x4 invertY       = Matrix4x4.TRS(new Vector2(0, 1), Quaternion.identity, new Vector2(1, -1));

        bool mouseInRect = rect.Contains(Event.current.mousePosition);

        GUI.BeginGroup(rect);
        {
            Vector2 mouse = invRectMatrix.MultiplyPoint(Event.current.mousePosition);             // local mouse [0..1]

            if (Event.current.type == EventType.Repaint)
            {
                Rect texturePosition = Mul(new Rect(0, 0, 1, 1), rectMatrix);
                Rect faceRet         = atlas.ToRect(face);
                faceRet = Mul(faceRet, rectMatrix * invertY);
                GUI.DrawTexture(texturePosition, texture);
                EditorGUIUtils.DrawRect(faceRet, Color.green);
            }

            if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && mouseInRect)
            {
                Vector2 invMouse = invertY.MultiplyPoint(mouse);
                if (invMouse.x >= 0 && invMouse.x <= 1 && invMouse.y >= 0 && invMouse.y <= 1)
                {
                    int posX = Mathf.FloorToInt(invMouse.x * atlas.GetWidth());
                    int posY = Mathf.FloorToInt(invMouse.y * atlas.GetHeight());
                    face = posY * atlas.GetWidth() + posX;

                    GUI.changed = true;
                    Event.current.Use();
                }
            }

            if (Event.current.type == EventType.MouseDrag && Event.current.button == 1 && mouseInRect)
            {
                Vector3 delta = Event.current.delta;
                delta.x /= rect.width;
                delta.y /= rect.height;

                Matrix4x4 offsetMatrix = Matrix4x4.TRS(delta, Quaternion.identity, Vector3.one);
                matrix = offsetMatrix * matrix;

                GUI.changed = true;
                Event.current.Use();
            }

            if (Event.current.type == EventType.ScrollWheel && mouseInRect)
            {
                float s = 0.95f;
                if (Event.current.delta.y < 0)
                {
                    s = 1.0f / s;
                }

                Matrix4x4 offsetMatrix = Matrix4x4.TRS(mouse, Quaternion.identity, Vector3.one);
                matrix *= offsetMatrix;

                Matrix4x4 scaleMatrix = Matrix4x4.Scale(Vector3.one * s);
                matrix *= scaleMatrix;

                offsetMatrix = Matrix4x4.TRS(-mouse, Quaternion.identity, Vector3.one);
                matrix      *= offsetMatrix;

                GUI.changed = true;
                Event.current.Use();
            }
        }
        GUI.EndGroup();
    }
Ejemplo n.º 3
0
    public override void OnInspectorGUI()
    {
        EditorGUIUtils.SetGUIStyles();

        GUILayout.BeginHorizontal();
        EditorGUIUtils.InspectorLogo();
        GUILayout.Label("IMAGE FLOW", EditorGUIUtils.sideLogoIconBoldLabelStyle);

        GUILayout.FlexibleSpace();
        if (GUILayout.Button("▲", EditorGUIUtils.btIconStyle))
        {
            UnityEditorInternal.ComponentUtility.MoveComponentUp(_flow);
        }

        if (GUILayout.Button("▼", EditorGUIUtils.btIconStyle))
        {
            UnityEditorInternal.ComponentUtility.MoveComponentDown(_flow);
        }

        GUILayout.EndHorizontal();

        if (Application.isPlaying)
        {
            GUILayout.Space(8);
            GUILayout.Label("Animation Editor disabled while in play mode", EditorGUIUtils.wordWrapLabelStyle);
            GUILayout.Space(4);
            GUILayout.Label("NOTE: when using DOPlayNext, the sequence is determined by the DOTweenAnimation Components order in the target GameObject's Inspector", EditorGUIUtils.wordWrapLabelStyle);
            GUILayout.Space(10);
            return;
        }

        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();

        EditorGUI.BeginChangeCheck();
        _flow._FlowTex = (Texture2D)EditorGUILayout.ObjectField(_flow._FlowTex, typeof(Texture2D), false,
                                                                GUILayout.Width(180), GUILayout.Height(180));
        if (EditorGUI.EndChangeCheck())
        {
            _flow.ChangeTexture();
        }

        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();

        GUILayout.BeginVertical("Box");

        EditorGUI.BeginChangeCheck();
        _flow._AddColorR = EditorGUILayout.FloatField("+ Color R", _flow._AddColorR);
        _flow._AddColorG = EditorGUILayout.FloatField("+ Color G", _flow._AddColorG);
        _flow._AddColorB = EditorGUILayout.FloatField("+ Color B", _flow._AddColorB);

        _flow._ScrollX = EditorGUILayout.FloatField(" Layer1 ", _flow._ScrollX);
        _flow._ScrollY = EditorGUILayout.FloatField(" Layer2 ", _flow._ScrollY);

        if (EditorGUI.EndChangeCheck())
        {
            _flow.ChangeValue();
        }

        GUILayout.EndVertical();
    }
Ejemplo n.º 4
0
    public override void OnInspectorGUI()
    {
        EditorGUIUtils.SetGUIStyles();

        GUILayout.BeginHorizontal();
        EditorGUIUtils.InspectorLogo();
        GUILayout.Label("IMAGE ALPHA SCALE", EditorGUIUtils.sideLogoIconBoldLabelStyle);

        GUILayout.FlexibleSpace();
        if (GUILayout.Button("▲", EditorGUIUtils.btIconStyle))
        {
            UnityEditorInternal.ComponentUtility.MoveComponentUp(_alphascale);
        }

        if (GUILayout.Button("▼", EditorGUIUtils.btIconStyle))
        {
            UnityEditorInternal.ComponentUtility.MoveComponentDown(_alphascale);
        }

        GUILayout.EndHorizontal();

        if (Application.isPlaying)
        {
            GUILayout.Space(8);
            GUILayout.Label("Animation Editor disabled while in play mode", EditorGUIUtils.wordWrapLabelStyle);
            GUILayout.Space(4);
            GUILayout.Label("NOTE: when using DOPlayNext, the sequence is determined by the DOTweenAnimation Components order in the target GameObject's Inspector", EditorGUIUtils.wordWrapLabelStyle);
            GUILayout.Space(10);
            return;
        }

        GUILayout.BeginVertical("Box");

        EditorGUI.BeginChangeCheck();
        _alphascale._Inside = EditorGUILayout.Slider("Start Inside", _alphascale._Inside, 1, 0);
        _alphascale._Alpha  = EditorGUILayout.Slider("Start Alpha", _alphascale._Alpha, 0, 1);
        if (EditorGUI.EndChangeCheck())
        {
            _alphascale.ChangeValue();
        }

        GUILayout.EndVertical();

        GUILayout.BeginVertical("Box");

        _alphascale.ASeaseType = EditorGUIUtils.FilteredEasePopup(_alphascale.ASeaseType);
        if (_alphascale.ASeaseType == Ease.INTERNAL_Custom)
        {
            _alphascale.AScurve = EditorGUILayout.CurveField("   AlphaScale Curve", _alphascale.AScurve);
        }

        _alphascale.AlphaEaseType = EditorGUIUtils.FilteredEasePopup(_alphascale.AlphaEaseType);
        if (_alphascale.AlphaEaseType == Ease.INTERNAL_Custom)
        {
            _alphascale.AlphaCurve = EditorGUILayout.CurveField("   Alpha Curve", _alphascale.AlphaCurve);
        }

        _alphascale.duration = EditorGUILayout.FloatField("Duration", _alphascale.duration);
        if (_alphascale.duration < 0)
        {
            _alphascale.duration = 0;
        }

        _alphascale.delay = EditorGUILayout.FloatField("Delay", _alphascale.delay);
        if (_alphascale.delay < 0)
        {
            _alphascale.delay = 0;
        }

        _alphascale.loops = EditorGUILayout.IntField(new GUIContent("Loop", "Set to -1 for infinite loops"), _alphascale.loops);
        if (_alphascale.loops < -1)
        {
            _alphascale.loops = -1;
        }
        if (_alphascale.loops > 1 || _alphascale.loops == -1)
        {
            _alphascale.loopType = (LoopType)EditorGUILayout.EnumPopup("   Loop Type", _alphascale.loopType);
        }

        GUIEndValue();

        GUILayout.EndVertical();
    }
Ejemplo n.º 5
0
        private static int SelectionGrid(IList <Block> items, int index)
        {
            Rect rect;
            int  xCount, yCount;

            index = SelectionGrid(items, index, out rect, out xCount, out yCount);
            float itemWidth  = rect.width / xCount;
            float itemHeight = rect.height / yCount;

            GUI.BeginGroup(rect);
            Vector2 mouse     = Event.current.mousePosition;
            int     posX      = Mathf.FloorToInt(mouse.x / itemWidth);
            int     posY      = Mathf.FloorToInt(mouse.y / itemHeight);
            int     realIndex = -1; // номер элемента под курсором

            if (posX >= 0 && posX < xCount && posY >= 0 && posY < yCount)
            {
                realIndex = posY * xCount + posX;
            }

            int dropX = Mathf.Clamp(posX, 0, xCount - 1);
            int dropY = Mathf.Clamp(posY, 0, yCount - 1);

            if (dropY == yCount - 1 && items.Count % xCount != 0)
            {
                dropX = Mathf.Clamp(dropX, 0, items.Count % xCount);
            }
            int dropIndex = dropY * xCount + dropX;   // ближайший элемент к курсору

            if (Event.current.type == EventType.MouseDrag && Event.current.button == 0 && realIndex == index)
            {
                DragAndDrop.PrepareStartDrag();
                DragAndDrop.objectReferences = new Object[0];
                DragAndDrop.paths            = new string[0];
                DragAndDrop.SetGenericData(DRAG_AND_DROP, new Container <int>(index));
                DragAndDrop.StartDrag("DragAndDrop");
                Event.current.Use();
            }

            if (Event.current.type == EventType.DragUpdated)
            {
                Container <int> data = (Container <int>)DragAndDrop.GetGenericData(DRAG_AND_DROP);
                if (data != null)
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Link;
                    Event.current.Use();
                }
            }

            if (Event.current.type == EventType.DragPerform)
            {
                Container <int> oldIndex = (Container <int>)DragAndDrop.GetGenericData(DRAG_AND_DROP);

                if (dropIndex > oldIndex.value)
                {
                    dropIndex--;
                }
                dropIndex = Mathf.Clamp(dropIndex, 0, items.Count - 1);
                Insert(items, dropIndex, oldIndex);

                index = dropIndex;

                DragAndDrop.AcceptDrag();
                DragAndDrop.PrepareStartDrag();
                Event.current.Use();
            }

            if (Event.current.type == EventType.Repaint && DragAndDrop.visualMode == DragAndDropVisualMode.Link)
            {
                Vector2 pos      = new Vector2(2 + dropX * itemWidth, 2 + dropY * itemHeight);
                Rect    lineRect = new Rect(pos.x - 2, pos.y, 2, itemWidth - 2);
                EditorGUIUtils.FillRect(lineRect, Color.red);
            }
            GUI.EndGroup();

            return(index);
        }
Ejemplo n.º 6
0
        //Vector2 srcPos;

        public override void OnInspectorGUI()
        {
            EditorGUIUtils.SetGUIStyles(null);
            EditorGUIUtility.labelWidth = 80f;
            EditorGUIUtils.InspectorLogo();
            GUILayout.Label("Custom Player", EditorGUIUtils.sideLogoIconBoldLabelStyle);

            //VisualManagerPreset preset = this._src.preset;
            //this._src.preset = (VisualManagerPreset)EditorGUILayout.EnumPopup("Preset", this._src.preset, new GUILayoutOption[0]);
            //if (preset != this._src.preset)
            //{
            //    VisualManagerPreset preset2 = this._src.preset;
            //    if (preset2 == VisualManagerPreset.PoolingSystem)
            //    {
            //        this._src.onEnableBehaviour = OnEnableBehaviour.RestartFromSpawnPoint;
            //        this._src.onDisableBehaviour = OnDisableBehaviour.Rewind;
            //    }
            //}

            if (GUILayout.Button("Register"))
            {
                if (Application.isPlaying)
                {
                    return;
                }
                RegisterAll(_src, false);
            }

            if (GUILayout.Button("Register Children"))
            {
                if (Application.isPlaying)
                {
                    return;
                }
                RegisterAll(_src, true);
            }

            GUILayout.Space(6f);
            int to_delete = -1;

            if (_src.AllGroups != null && _src.AllGroups.Length > 0)
            {
                //srcPos = GUILayout.BeginScrollView(srcPos);
                GUILayout.BeginVertical();

                for (int i = 0; i < _src.AllGroups.Length; i++)
                {
                    //GUILayout.BeginArea
                    DOTweenPlayer.DOTGroup dg_item = _src.AllGroups[i];

                    GUILayout.Space(6f);

                    GUILayout.BeginVertical("Button");

                    EditorGUILayout.LabelField("Group ID : " + dg_item.ID);
                    EditorGUILayout.LabelField("Count : " + dg_item.AllComps.Length);

                    OnEnableBehaviour_My  onEnableBehaviour  = dg_item.onEnableBehaviour;
                    OnDisableBehaviour_My onDisableBehaviour = dg_item.onDisableBehaviour;

                    if (GUILayout.Button("X", GUILayout.Width(20)))
                    {
                        to_delete = i;
                    }
                    dg_item.onEnableBehaviour = (OnEnableBehaviour_My)EditorGUILayout.EnumPopup(new GUIContent("On Enable", "Eventual actions to perform when this gameObject is activated"),
                                                                                                dg_item.onEnableBehaviour, new GUILayoutOption[0]);
                    dg_item.onDisableBehaviour = (OnDisableBehaviour_My)EditorGUILayout.EnumPopup(new GUIContent("On Disable", "Eventual actions to perform when this gameObject is deactivated"),
                                                                                                  dg_item.onDisableBehaviour, new GUILayoutOption[0]);

                    GUILayout.Space(6f);

                    if (!Application.isPlaying)
                    {
                        GUILayout.BeginHorizontal();

                        //bool b_autoPlay = false;
                        //bool b_autoKill = false;

                        //for (int k = 0; k < dg_item.AllComps.Length; k++)
                        //{
                        //    if (dg_item.AllComps[k].autoPlay)
                        //    {
                        //        b_autoPlay = true;
                        //        break;
                        //    }
                        //}

                        //for (int k = 0; k < dg_item.AllComps.Length; k++)
                        //{
                        //    if (dg_item.AllComps[k].autoKill)
                        //    {
                        //        b_autoKill = true;
                        //        break;
                        //    }
                        //}

                        //EditorGUI.BeginChangeCheck();
                        //b_autoPlay = DeGUILayout.ToggleButton(b_autoPlay, new GUIContent("AutoPlay", "If selected, the tween will play automatically"));
                        //if (EditorGUI.EndChangeCheck())
                        //{
                        //    ToggleAutoPlay(_src, i, b_autoPlay);
                        //}

                        //EditorGUI.BeginChangeCheck();
                        //b_autoKill = DeGUILayout.ToggleButton(b_autoKill, new GUIContent("AutoKill", "If selected, the tween will be killed when it completes, and won't be reusable"));
                        //if (EditorGUI.EndChangeCheck())
                        //{
                        //    ToggleAutoPlay(_src, i, b_autoPlay);
                        //}


                        if (GUILayout.Button("AutoPlay"))
                        {
                            ToggleAutoPlay(_src, i, true);
                        }
                        if (GUILayout.Button("X AutoPlay"))
                        {
                            ToggleAutoPlay(_src, i, false);
                        }
                        if (GUILayout.Button("AutoKill"))
                        {
                            ToggleAutoKill(_src, i, true);
                        }
                        if (GUILayout.Button("X AutoKill"))
                        {
                            ToggleAutoKill(_src, i, false);
                        }

                        GUILayout.EndHorizontal();
                    }
                    else
                    {
                        GUILayout.BeginHorizontal();
                        if (GUILayout.Button("Play"))
                        {
                            _src.Play(dg_item.ID);
                        }
                        if (GUILayout.Button("Pause"))
                        {
                            _src.Pause(dg_item.ID);
                        }
                        if (GUILayout.Button("Rewind"))
                        {
                            _src.Rewind(dg_item.ID);
                        }
                        if (GUILayout.Button("Restart"))
                        {
                            _src.Restart(dg_item.ID);
                        }
                        GUILayout.EndHorizontal();
                    }
                    GUILayout.EndVertical();

                    if (to_delete != -1)
                    {
                        DeleteGroup(this._src, to_delete);
                        to_delete = -1;
                        break;
                    }
                }
                //GUILayout.EndScrollView();
                GUILayout.EndVertical();
            }

            if (GUI.changed)
            {
                EditorUtility.SetDirty(this._src);
            }
        }
        void OnSceneGUI(SceneView sceneView)
        {
            if (!ShouldDrawBodyPoseUtilityWindow(sceneView))
            {
                return;
            }

            s_LastFoundAnimator = FindHumanAnimatorObj();

            if (s_LastFoundAnimator == null)
            {
                return;
            }

            // We don't want to show the window if the avatar isn't visible.
            // Specifically, we avoid changing the pose of the landmarks rig (Default Body Rig)
            if (!HasDisabledSkinnedMeshRenderer())
            {
                return;
            }

            Handles.BeginGUI();

            var winPos = new Rect(sceneView.position.width - k_WindowWidth - k_WindowOffsetFromEdges,
                                  sceneView.position.height - k_WindowHeight - k_WindowOffsetFromEdges - k_ToolbarHeight,
                                  k_WindowWidth, k_WindowHeight);

            using (new GUILayout.AreaScope(winPos, string.Empty, "Box"))
            {
                GUILayout.Label(k_CreatePoseToolLabel);

                using (new EditorGUI.DisabledScope(!s_LastFoundAnimator.isHuman))
                {
                    using (new GUILayout.HorizontalScope())
                    {
                        m_ExternalBodyData = EditorGUIUtils.ObjectFieldWithControlIdCheck(
                            m_ExternalBodyData, ref m_ObjectSelectorControlId, GUILayout.Width(135),
                            GUILayout.Height(17));

                        using (new EditorGUI.DisabledScope(m_ExternalBodyData == null))
                        {
                            if (GUILayout.Button(k_LoadExternalPose, GUILayout.Width(40), GUILayout.Height(17)))
                            {
                                LoadBodyPose(s_LastFoundAnimator, m_ExternalBodyData);
                            }
                        }
                    }

                    using (new GUILayout.HorizontalScope())
                    {
                        if (GUILayout.Button(k_ResetPoseButton, GUILayout.Width(62)))
                        {
                            LoadBodyPose(s_LastFoundAnimator);
                        }

                        if (GUILayout.Button(k_TPoseButton, GUILayout.Width(62)))
                        {
                            LoadBodyPose(s_LastFoundAnimator, MarsBodySettings.instance.TPoseBodyData, true);
                        }

                        if (GUILayout.Button(k_SaveSelectedPoseButton, GUILayout.Width(65)))
                        {
                            GenerateSerializedDataFromAvatar(s_LastFoundAnimator);
                        }
                    }
                }
            }

            EditorGUIUtils.EatMouseInput(winPos, "BodyPoseUtility");

            Handles.EndGUI();
        }
Ejemplo n.º 8
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (!Initialise(property))
            {
                return;
            }

            Rect originalPosition = position;

            position.height = EditorGUIUtility.singleLineHeight;
            using (new EditorGUI.PropertyScope(position, GUIContent.none, property))
            {
                if (EditorGUIUtils.DrawHeaderWithFoldout(position, label, property.isExpanded, noBoldOrIndent: true))
                {
                    property.isExpanded = !property.isExpanded;
                }
            }

            if (!property.isExpanded)
            {
                return;
            }

            originalPosition.yMin  = position.yMax;
            originalPosition.xMin += 10;
            EditorGUIUtils.DrawOutline(originalPosition, 1);

            position.xMin += 15;             //Indent
            position.xMax -= 4;
            position.y     = position.yMax + EditorGUIUtility.standardVerticalSpacing * 2;

            SerializedProperty values = property.FindPropertyRelative("values");

            values.arraySize = enumNames.Length;
            float contentX     = position.x + EditorGUIUtility.labelWidth;
            float contentWidth = position.width - EditorGUIUtility.labelWidth;

            for (int i = hidesFirstEnum ? 1 : 0; i < enumNames.Length; i++)
            {
                SerializedProperty value = values.GetArrayElementAtIndex(i);
                Rect labelRect           = new Rect(position.x, position.y, EditorGUIUtility.labelWidth - 4, position.height);
                Rect contentRect         = new Rect(contentX, position.y, contentWidth, position.height);
                if (multiLine)
                {
                    Rect r = new Rect(position.x - 5, contentRect.y - 2, position.width + 8, contentRect.height + 2);
                    EditorGUI.DrawRect(r, EditorGUIUtils.HeaderColor);

                    labelRect.xMin += 12;

                    using (new EditorGUI.PropertyScope(r, GUIContent.none, value))
                    {
                        GUI.enabled = false;
                        EditorGUI.Popup(labelRect, i, enumNames);
                        GUI.enabled = true;
                    }

                    EditorGUI.LabelField(labelRect, tooltips[i]);

                    //Foldout
                    value.isExpanded = EditorGUI.Foldout(new Rect(r.x + 15, r.y, r.width, r.height), value.isExpanded, GUIContent.none, true);

                    contentRect.y = labelRect.yMax + EditorGUIUtility.standardVerticalSpacing;
                    if (!value.isExpanded)
                    {
                        EditorGUI.DrawRect(new Rect(r.x, labelRect.yMax, r.width, 1), EditorGUIUtils.SplitterColor);
                        position.y = contentRect.y;
                        continue;
                    }

                    SerializedProperty end = value.GetEndProperty();
                    int  index             = 0;
                    bool enterChildren     = true;
                    while (value.NextVisible(enterChildren) && !SerializedProperty.EqualContents(value, end))
                    {
                        float height = propertyHeights[index++];
                        contentRect.height = height;
                        using (new EditorGUI.PropertyScope(new Rect(position.x, contentRect.y, position.width, contentRect.height), GUIContent.none, value))
                        {
                            float labelRectX = labelRect.x + 15;
                            GUI.Label(new Rect(labelRectX, contentRect.y, contentRect.x - labelRectX - 2, contentRect.height), value.displayName);
                            EditorGUI.PropertyField(contentRect, value, GUIContent.none, false);
                        }

                        contentRect.y += height + EditorGUIUtility.standardVerticalSpacing;
                        enterChildren  = false;
                    }
                }
                else
                {
                    GUI.enabled = false;
                    EditorGUI.Popup(labelRect, i, enumNames);
                    GUI.enabled = true;
                    EditorGUI.LabelField(labelRect, tooltips[i]);

                    Color lastColor = GUI.color;
                    if (value.propertyType == SerializedPropertyType.ObjectReference)
                    {
                        if (value.objectReferenceValue == null)
                        {
                            GUI.color *= new Color(1f, 0.46f, 0.51f);
                        }
                    }

                    using (new EditorGUI.PropertyScope(new Rect(position.x, contentRect.y, position.width, contentRect.height), GUIContent.none, value))
                        EditorGUI.PropertyField(contentRect, value, GUIContent.none);
                    contentRect.y += propertyHeights[0] + EditorGUIUtility.standardVerticalSpacing;
                    GUI.color      = lastColor;
                }

                position.y = contentRect.yMin;
            }
        }
Ejemplo n.º 9
0
        public override void OnInspectorGUI()
        {
            EditorGUIUtils.SetGUIStyles(null);
            int totActiveTweens        = TweenManager.totActiveTweens;
            int num                    = TweenManager.TotalPlayingTweens();
            int value                  = totActiveTweens - num;
            int totActiveDefaultTweens = TweenManager.totActiveDefaultTweens;
            int totActiveLateTweens    = TweenManager.totActiveLateTweens;

            GUILayout.Space(4f);
            GUILayout.Label(this._title, DOTween.isDebugBuild ? EditorGUIUtils.redLabelStyle : EditorGUIUtils.boldLabelStyle);
            GUILayout.Space(6f);
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Documentation"))
            {
                Application.OpenURL("http://dotween.demigiant.com/documentation.php");
            }
            if (GUILayout.Button("Check Updates"))
            {
                Application.OpenURL("http://dotween.demigiant.com/download.php?v=" + DOTween.Version);
            }
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            if (GUILayout.Button(this._showPlayingTweensData ? "Hide Playing Tweens" : "Show Playing Tweens"))
            {
                this._showPlayingTweensData = !this._showPlayingTweensData;
            }
            if (GUILayout.Button(this._showPausedTweensData ? "Hide Paused Tweens" : "Show Paused Tweens"))
            {
                this._showPausedTweensData = !this._showPausedTweensData;
            }
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Play all"))
            {
                DOTween.PlayAll();
            }
            if (GUILayout.Button("Pause all"))
            {
                DOTween.PauseAll();
            }
            if (GUILayout.Button("Kill all"))
            {
                DOTween.KillAll(false);
            }
            GUILayout.EndHorizontal();
            GUILayout.Space(8f);
            this._strBuilder.Length = 0;
            this._strBuilder.Append("Active tweens: ").Append(totActiveTweens).Append(" (")
            .Append(TweenManager.totActiveTweeners)
            .Append("/")
            .Append(TweenManager.totActiveSequences)
            .Append(")")
            .Append("\nDefault/Late tweens: ")
            .Append(totActiveDefaultTweens)
            .Append("/")
            .Append(totActiveLateTweens)
            .Append("\nPlaying tweens: ")
            .Append(num);
            if (this._showPlayingTweensData)
            {
                Tween[] activeTweens = TweenManager._activeTweens;
                foreach (Tween tween in activeTweens)
                {
                    if (tween != null && tween.isPlaying)
                    {
                        this._strBuilder.Append("\n   - [").Append(tween.tweenType).Append("] ")
                        .Append(tween.target);
                    }
                }
            }
            this._strBuilder.Append("\nPaused tweens: ").Append(value);
            if (this._showPausedTweensData)
            {
                Tween[] activeTweens = TweenManager._activeTweens;
                foreach (Tween tween2 in activeTweens)
                {
                    if (tween2 != null && !tween2.isPlaying)
                    {
                        this._strBuilder.Append("\n   - [").Append(tween2.tweenType).Append("] ")
                        .Append(tween2.target);
                    }
                }
            }
            this._strBuilder.Append("\nPooled tweens: ").Append(TweenManager.TotalPooledTweens()).Append(" (")
            .Append(TweenManager.totPooledTweeners)
            .Append("/")
            .Append(TweenManager.totPooledSequences)
            .Append(")");
            GUILayout.Label(this._strBuilder.ToString());
            GUILayout.Space(8f);
            this._strBuilder.Remove(0, this._strBuilder.Length);
            this._strBuilder.Append("Tweens Capacity: ").Append(TweenManager.maxTweeners).Append("/")
            .Append(TweenManager.maxSequences)
            .Append("\nMax Simultaneous Active Tweens: ")
            .Append(DOTween.maxActiveTweenersReached)
            .Append("/")
            .Append(DOTween.maxActiveSequencesReached);
            GUILayout.Label(this._strBuilder.ToString());
            GUILayout.Space(8f);
            this._strBuilder.Remove(0, this._strBuilder.Length);
            this._strBuilder.Append("SETTINGS ▼");
            this._strBuilder.Append("\nSafe Mode: ").Append(DOTween.useSafeMode ? "ON" : "OFF");
            this._strBuilder.Append("\nLog Behaviour: ").Append(DOTween.logBehaviour);
            this._strBuilder.Append("\nShow Unity Editor Report: ").Append(DOTween.showUnityEditorReport);
            this._strBuilder.Append("\nTimeScale (Unity/DOTween): ").Append(Time.timeScale).Append("/")
            .Append(DOTween.timeScale);
            GUILayout.Label(this._strBuilder.ToString());
            GUILayout.Label("NOTE: DOTween's TimeScale is not the same as Unity's Time.timeScale: it is actually multiplied by it except for tweens that are set to update independently", EditorGUIUtils.wordWrapItalicLabelStyle);
            GUILayout.Space(8f);
            this._strBuilder.Remove(0, this._strBuilder.Length);
            this._strBuilder.Append("DEFAULTS ▼");
            this._strBuilder.Append("\ndefaultRecyclable: ").Append(DOTween.defaultRecyclable);
            this._strBuilder.Append("\ndefaultUpdateType: ").Append(DOTween.defaultUpdateType);
            this._strBuilder.Append("\ndefaultTSIndependent: ").Append(DOTween.defaultTimeScaleIndependent);
            this._strBuilder.Append("\ndefaultAutoKill: ").Append(DOTween.defaultAutoKill);
            this._strBuilder.Append("\ndefaultAutoPlay: ").Append(DOTween.defaultAutoPlay);
            this._strBuilder.Append("\ndefaultEaseType: ").Append(DOTween.defaultEaseType);
            this._strBuilder.Append("\ndefaultLoopType: ").Append(DOTween.defaultLoopType);
            GUILayout.Label(this._strBuilder.ToString());
            GUILayout.Space(10f);
        }
Ejemplo n.º 10
0
        protected override void AddComponentMenuButton()
        {
            var componentTabSelection = MarsInspectorSharedSettings.Instance.ComponentTabSelection;

            // Skip this button in the case of Forces, because they have their more complex button already and this button is redundant.
            if (componentTabSelection == k_ForcesTab)
            {
                return;
            }

            var tabIsAllOrSettings = componentTabSelection == k_AllTabs || componentTabSelection == k_SettingsTab;

            var addComponentText = "Add MARS Component...";

            if (!tabIsAllOrSettings)
            {
                switch (componentTabSelection)
                {
                case k_ConditionsTab:
                    addComponentText = "Add Condition...";
                    break;

                case k_ActionsTab:
                    addComponentText = "Add Action...";
                    break;

                case k_ForcesTab:
                    addComponentText = "Add Force...";
                    break;
                }
            }

            if (GUILayout.Button(addComponentText, EditorStyles.miniButton))
            {
                var menu    = new GenericMenu();
                var isGroup = (m_BaseEditor.target is ProxyGroup);

                foreach (var kvp in k_ComponentTypes)
                {
                    var type = kvp.Key;

                    if (isGroup && !(type.IsSubclassOf(typeof(Relation))))
                    {
                        continue;
                    }

                    if (!CanDrawSelectedOption(null, type, true))
                    {
                        continue;
                    }

                    // Check if this component cannot be added because another of its exclusive siblings is added
                    m_ConflictingBehaviors.Clear();
                    var componentClash = HasComponentClash(type, m_ComponentList, false, m_ConflictingBehaviors);

                    if (!componentClash)
                    {
                        componentClash = HasRequirementClash(type, m_ComponentList);
                    }
                    else if (m_ConflictingBehaviors.Count > 0)
                    {
                        m_ConflictingBehaviors.RemoveAll(alternate => HasRequirementClash(alternate.GetType(), m_ComponentList));
                    }

                    var menuItem = EditorGUIUtils.GetContent(kvp.Value.menuItem);

                    if (!tabIsAllOrSettings)
                    {
                        var modifiedMenuItem = new GUIContent(menuItem);
                        var text             = modifiedMenuItem.text;
                        // If we're in a filtered tab, don't show the first-layer menu (Conditions, Actions, Forces),
                        // because it would be redundant with the tab itself.
                        modifiedMenuItem.text = text.Substring(text.IndexOf("/", StringComparison.Ordinal) + 1);
                        menuItem = modifiedMenuItem;
                    }

                    if (!componentClash)
                    {
                        menu.AddItem(menuItem, false, () => AddComponent(type));
                    }
                    else if (m_ConflictingBehaviors.Count > 0)
                    {
                        var conflictingComponent = m_ConflictingBehaviors[0];

                        var conflictingTypeName = conflictingComponent.GetType().Name;
                        if (k_ComponentTypes.ContainsKey(conflictingComponent.GetType()))
                        {
                            conflictingTypeName = k_ComponentTypes[conflictingComponent.GetType()].menuItem;
                            if (conflictingTypeName.Contains("/"))
                            {
                                conflictingTypeName = conflictingTypeName.Substring(conflictingTypeName.IndexOf("/", StringComparison.Ordinal) + 1);
                            }
                        }

                        var insertText   = $"Replace/{conflictingTypeName} with";
                        var menuItemText = menuItem.text;
                        if (menuItemText.Contains("/"))
                        {
                            var lastIndex = menuItemText.IndexOf("/", StringComparison.Ordinal);
                            menuItemText = menuItemText.Insert(lastIndex, "/" + insertText);
                        }
                        else
                        {
                            menuItemText = insertText + "/" + menuItemText;
                        }

                        menu.AddItem(new GUIContent(menuItemText), false, () =>
                        {
                            Undo.DestroyObjectImmediate(conflictingComponent);
                            AddComponent(type);
                        });
                    }
                }

                menu.ShowAsContext();
            }
        }
Ejemplo n.º 11
0
    public override void OnInspectorGUI()
    {
        EditorGUIUtils.SetGUIStyles();

        GUILayout.BeginHorizontal();
        GUILayout.Label("IMAGE EDGE FADE", EditorGUIUtils.sideLogoIconBoldLabelStyle);

        GUILayout.FlexibleSpace();
        if (GUILayout.Button("▲", EditorGUIUtils.btIconStyle))
        {
            UnityEditorInternal.ComponentUtility.MoveComponentUp(_edgeFade);
        }

        if (GUILayout.Button("▼", EditorGUIUtils.btIconStyle))
        {
            UnityEditorInternal.ComponentUtility.MoveComponentDown(_edgeFade);
        }
        GUILayout.EndHorizontal();


        GUILayout.BeginVertical("Box");

        EditorGUI.BeginChangeCheck();
        _edgeFade._Offset    = EditorGUILayout.Slider("Offset", _edgeFade._Offset, 0f, 1f);
        _edgeFade._Alpha     = EditorGUILayout.Slider("Alpha", _edgeFade._Alpha, 0f, 1f);
        _edgeFade._ClipLeft  = EditorGUILayout.Slider("Clip Left", _edgeFade._ClipLeft, 0f, 1f);
        _edgeFade._ClipRight = EditorGUILayout.Slider("Clip Right", _edgeFade._ClipRight, 0f, 1f);
        _edgeFade._ClipUp    = EditorGUILayout.Slider("Clip Up", _edgeFade._ClipUp, 0f, 1f);
        _edgeFade._ClipDown  = EditorGUILayout.Slider("Clip Down", _edgeFade._ClipDown, 0f, 1f);
        if (EditorGUI.EndChangeCheck())
        {
            _edgeFade.ChangeValue();
        }

        GUILayout.EndVertical();

        GUILayout.BeginVertical("Box");

        _edgeFade.cLeftEaseType = EditorGUIUtils.FilteredEasePopup(_edgeFade.cLeftEaseType);
        if (_edgeFade.cLeftEaseType == Ease.INTERNAL_Custom)
        {
            _edgeFade.cLeftCurve = EditorGUILayout.CurveField(" Clip Left Curve", _edgeFade.cLeftCurve);
        }

        _edgeFade.cLeftDuration = EditorGUILayout.FloatField("Clip Left Duration", _edgeFade.cLeftDuration);
        if (_edgeFade.cLeftDuration < 0)
        {
            _edgeFade.cLeftDuration = 0;
        }

        _edgeFade.cLeftDelay = EditorGUILayout.FloatField("Clip Left Delay", _edgeFade.cLeftDelay);
        if (_edgeFade.cLeftDelay < 0)
        {
            _edgeFade.cLeftDelay = 0;
        }

        _edgeFade.cLeftLoops = EditorGUILayout.IntField(new GUIContent("Loop", "Set to -1 for infinite loops"), _edgeFade.cLeftLoops);
        if (_edgeFade.cLeftLoops < -1)
        {
            _edgeFade.cLeftLoops = -1;
        }
        if (_edgeFade.cLeftLoops > 1 || _edgeFade.cLeftLoops == -1)
        {
            _edgeFade.cLeftLoopType = (LoopType)EditorGUILayout.EnumPopup(" Clip Loop Type", _edgeFade.cLeftLoopType);
        }

        _edgeFade.cLeftEndValue = EditorGUILayout.FloatField("Clip Left End Value", _edgeFade.cLeftEndValue);

        GUILayout.EndVertical();

        GUILayout.BeginVertical("Box");

        _edgeFade.cRightEaseType = EditorGUIUtils.FilteredEasePopup(_edgeFade.cRightEaseType);
        if (_edgeFade.cRightEaseType == Ease.INTERNAL_Custom)
        {
            _edgeFade.cRightCurve = EditorGUILayout.CurveField(" Clip Right Curve", _edgeFade.cRightCurve);
        }

        _edgeFade.cRightDuration = EditorGUILayout.FloatField("Clip Right Duration", _edgeFade.cRightDuration);
        if (_edgeFade.cRightDuration < 0)
        {
            _edgeFade.cRightDuration = 0;
        }

        _edgeFade.cRightDelay = EditorGUILayout.FloatField("Clip Right Delay", _edgeFade.cRightDelay);
        if (_edgeFade.cRightDelay < 0)
        {
            _edgeFade.cRightDelay = 0;
        }

        _edgeFade.cRightLoops = EditorGUILayout.IntField(new GUIContent("Loop", "Set to -1 for infinite loops"), _edgeFade.cRightLoops);
        if (_edgeFade.cRightLoops < -1)
        {
            _edgeFade.cRightLoops = -1;
        }
        if (_edgeFade.cRightLoops > 1 || _edgeFade.cRightLoops == -1)
        {
            _edgeFade.cRightLoopType = (LoopType)EditorGUILayout.EnumPopup(" Clip Loop Type", _edgeFade.cRightLoopType);
        }

        _edgeFade.cRightEndValue = EditorGUILayout.FloatField("Clip Right End Value", _edgeFade.cRightEndValue);

        GUILayout.EndVertical();
    }
Ejemplo n.º 12
0
    public override void OnInspectorGUI()
    {
        EditorGUIUtils.SetGUIStyles();

        GUILayout.BeginHorizontal();
        EditorGUIUtils.InspectorLogo();
        GUILayout.Label("IMAGE CLIPPING", EditorGUIUtils.sideLogoIconBoldLabelStyle);

        GUILayout.FlexibleSpace();
        if (GUILayout.Button("▲", EditorGUIUtils.btIconStyle))
        {
            UnityEditorInternal.ComponentUtility.MoveComponentUp(_clipping);
        }

        if (GUILayout.Button("▼", EditorGUIUtils.btIconStyle))
        {
            UnityEditorInternal.ComponentUtility.MoveComponentDown(_clipping);
        }

        GUILayout.EndHorizontal();

        if (Application.isPlaying)
        {
            GUILayout.Space(8);
            GUILayout.Label("Animation Editor disabled while in play mode", EditorGUIUtils.wordWrapLabelStyle);
            GUILayout.Space(4);
            GUILayout.Label("NOTE: when using DOPlayNext, the sequence is determined by the DOTweenAnimation Components order in the target GameObject's Inspector", EditorGUIUtils.wordWrapLabelStyle);
            GUILayout.Space(10);
            return;
        }

        GUILayout.BeginVertical("Box");

        EditorGUI.BeginChangeCheck();
        _clipping._ClipLeft  = EditorGUILayout.Slider("Start Clip Left", _clipping._ClipLeft, 0, 1);
        _clipping._ClipRight = EditorGUILayout.Slider("Start Clip Right", _clipping._ClipRight, 0, 1);
        _clipping._ClipUp    = EditorGUILayout.Slider("Start Clip Up", _clipping._ClipUp, 0, 1);
        _clipping._ClipDown  = EditorGUILayout.Slider("Start Clip Down", _clipping._ClipDown, 0, 1);

        if (EditorGUI.EndChangeCheck())
        {
            _clipping.ChangeValue();
        }

        GUILayout.EndVertical();

        GUILayout.BeginVertical("Box");

        _clipping.ClipRightEaseType = EditorGUIUtils.FilteredEasePopup(_clipping.ClipRightEaseType);
        if (_clipping.ClipRightEaseType == Ease.INTERNAL_Custom)
        {
            _clipping.ClipRightCurve = EditorGUILayout.CurveField(" Right Clipping Curve", _clipping.ClipRightCurve);
        }

        _clipping.ClipRightDuration = EditorGUILayout.FloatField(" Right Clipping Duration", _clipping.ClipRightDuration);
        if (_clipping.ClipRightDuration < 0)
        {
            _clipping.ClipRightDuration = 0;
        }

        _clipping.ClipRightDelay = EditorGUILayout.FloatField(" Right Clipping Delay", _clipping.ClipRightDelay);
        if (_clipping.ClipRightDelay < 0)
        {
            _clipping.ClipRightDelay = 0;
        }

        _clipping.ClipRightLoop = EditorGUILayout.IntField(new GUIContent("Loop", "Set to -1 for infinite loops"), _clipping.ClipRightLoop);
        if (_clipping.ClipRightLoop < -1)
        {
            _clipping.ClipRightLoop = -1;
        }
        if (_clipping.ClipRightLoop > 1 || _clipping.ClipRightLoop == -1)
        {
            _clipping.ClipRightLoopType = (LoopType)EditorGUILayout.EnumPopup(" Loop Type", _clipping.ClipRightLoopType);
        }

        _clipping.ClipLeftEaseType = EditorGUIUtils.FilteredEasePopup(_clipping.ClipLeftEaseType);
        if (_clipping.ClipLeftEaseType == Ease.INTERNAL_Custom)
        {
            _clipping.ClipLeftCurve = EditorGUILayout.CurveField(" Left Clipping Curve", _clipping.ClipLeftCurve);
        }

        _clipping.ClipLeftDuration = EditorGUILayout.FloatField(" Left Clipping Duration", _clipping.ClipLeftDuration);
        if (_clipping.ClipLeftDuration < 0)
        {
            _clipping.ClipLeftDuration = 0;
        }

        _clipping.ClipLeftDelay = EditorGUILayout.FloatField(" Left Clipping Delay", _clipping.ClipLeftDelay);
        if (_clipping.ClipLeftDelay < 0)
        {
            _clipping.ClipLeftDelay = 0;
        }

        _clipping.ClipLeftLoop = EditorGUILayout.IntField(new GUIContent("Loop", "Set to -1 for infinite loops"), _clipping.ClipLeftLoop);
        if (_clipping.ClipLeftLoop < -1)
        {
            _clipping.ClipLeftLoop = -1;
        }
        if (_clipping.ClipLeftLoop > 1 || _clipping.ClipLeftLoop == -1)
        {
            _clipping.ClipLeftLoopType = (LoopType)EditorGUILayout.EnumPopup(" Loop Type", _clipping.ClipLeftLoopType);
        }

        EditorGUILayout.BeginVertical("Box");

        GUIEndValue();

        EditorGUILayout.EndVertical();

        GUILayout.EndVertical();
    }
Ejemplo n.º 13
0
        override public void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            GUILayout.Space(3);
            EditorGUIUtils.SetGUIStyles();

            bool playMode = Application.isPlaying;

            _runtimeEditMode = _runtimeEditMode && playMode;

            GUILayout.BeginHorizontal();
            EditorGUIUtils.InspectorLogo();
            GUILayout.Label(_src.animationType.ToString() + (string.IsNullOrEmpty(_src.id) ? "" : " [" + _src.id + "]"), EditorGUIUtils.sideLogoIconBoldLabelStyle);
            // Up-down buttons
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("▲", DeGUI.styles.button.toolIco))
            {
                UnityEditorInternal.ComponentUtility.MoveComponentUp(_src);
            }
            if (GUILayout.Button("▼", DeGUI.styles.button.toolIco))
            {
                UnityEditorInternal.ComponentUtility.MoveComponentDown(_src);
            }
            GUILayout.EndHorizontal();

            if (playMode)
            {
                if (_runtimeEditMode)
                {
                }
                else
                {
                    GUILayout.Space(8);
                    GUILayout.Label("Animation Editor disabled while in play mode", EditorGUIUtils.wordWrapLabelStyle);
                    if (!_src.isActive)
                    {
                        GUILayout.Label("This animation has been toggled as inactive and won't be generated", EditorGUIUtils.wordWrapLabelStyle);
                        GUI.enabled = false;
                    }
                    if (GUILayout.Button(new GUIContent("Activate Edit Mode", "Switches to Runtime Edit Mode, where you can change animations values and restart them")))
                    {
                        _runtimeEditMode = true;
                    }
                    GUILayout.Label("NOTE: when using DOPlayNext, the sequence is determined by the DOTweenAnimation Components order in the target GameObject's Inspector", EditorGUIUtils.wordWrapLabelStyle);
                    GUILayout.Space(10);
                    if (!_runtimeEditMode)
                    {
                        return;
                    }
                }
            }

            Undo.RecordObject(_src, "DOTween Animation");

//            _src.isValid = Validate(); // Moved down

            EditorGUIUtility.labelWidth = 120;

            if (playMode)
            {
                GUILayout.Space(4);
                DeGUILayout.Toolbar("Edit Mode Commands");
                DeGUILayout.BeginVBox(DeGUI.styles.box.stickyTop);
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("TogglePause"))
                {
                    _src.tween.TogglePause();
                }
                if (GUILayout.Button("Rewind"))
                {
                    _src.tween.Rewind();
                }
                if (GUILayout.Button("Restart"))
                {
                    _src.tween.Restart();
                }
                GUILayout.EndHorizontal();
                if (GUILayout.Button("Commit changes and restart"))
                {
                    _src.tween.Rewind();
                    _src.tween.Kill();
                    if (_src.isValid)
                    {
                        _src.CreateTween();
                        _src.tween.Play();
                    }
                }
                GUILayout.Label("To apply your changes when exiting Play mode, use the Component's upper right menu and choose \"Copy Component\", then \"Paste Component Values\" after exiting Play mode", DeGUI.styles.label.wordwrap);
                DeGUILayout.EndVBox();
            }
            else
            {
                bool hasManager = _src.GetComponent <DOTweenVisualManager>() != null;
                if (!hasManager)
                {
                    if (GUILayout.Button(new GUIContent("Add Manager", "Adds a manager component which allows you to choose additional options for this gameObject")))
                    {
                        _src.gameObject.AddComponent <DOTweenVisualManager>();
                    }
                }
            }

            GUILayout.BeginHorizontal();
            DOTweenAnimationType prevAnimType = _src.animationType;

//                _src.animationType = (DOTweenAnimationType)EditorGUILayout.EnumPopup(_src.animationType, EditorGUIUtils.popupButton);
            _src.isActive      = EditorGUILayout.Toggle(new GUIContent("", "If unchecked, this animation will not be created"), _src.isActive, GUILayout.Width(16));
            GUI.enabled        = _src.isActive;
            _src.animationType = AnimationToDOTweenAnimationType(_AnimationType[EditorGUILayout.Popup(DOTweenAnimationTypeToPopupId(_src.animationType), _AnimationType)]);
            _src.autoPlay      = DeGUILayout.ToggleButton(_src.autoPlay, new GUIContent("AutoPlay", "If selected, the tween will play automatically"));
            _src.autoKill      = DeGUILayout.ToggleButton(_src.autoKill, new GUIContent("AutoKill", "If selected, the tween will be killed when it completes, and won't be reusable"));
            GUILayout.EndHorizontal();
            if (prevAnimType != _src.animationType)
            {
                // Set default optional values based on animation type
                switch (_src.animationType)
                {
                case DOTweenAnimationType.Move:
                case DOTweenAnimationType.LocalMove:
                case DOTweenAnimationType.Rotate:
                case DOTweenAnimationType.LocalRotate:
                case DOTweenAnimationType.Scale:
                    _src.endValueV3    = Vector3.zero;
                    _src.endValueFloat = 0;
                    _src.optionalBool0 = _src.animationType == DOTweenAnimationType.Scale;
                    break;

                case DOTweenAnimationType.Color:
                case DOTweenAnimationType.Fade:
                    _src.endValueFloat = 0;
                    break;

                case DOTweenAnimationType.Text:
                    _src.optionalBool0 = true;
                    break;

                case DOTweenAnimationType.PunchPosition:
                case DOTweenAnimationType.PunchRotation:
                case DOTweenAnimationType.PunchScale:
                    _src.endValueV3     = _src.animationType == DOTweenAnimationType.PunchRotation ? new Vector3(0, 180, 0) : Vector3.one;
                    _src.optionalFloat0 = 1;
                    _src.optionalInt0   = 10;
                    _src.optionalBool0  = false;
                    break;

                case DOTweenAnimationType.ShakePosition:
                case DOTweenAnimationType.ShakeRotation:
                case DOTweenAnimationType.ShakeScale:
                    _src.endValueV3     = _src.animationType == DOTweenAnimationType.ShakeRotation ? new Vector3(90, 90, 90) : Vector3.one;
                    _src.optionalInt0   = 10;
                    _src.optionalFloat0 = 90;
                    _src.optionalBool0  = false;
                    break;

                case DOTweenAnimationType.CameraAspect:
                case DOTweenAnimationType.CameraFieldOfView:
                case DOTweenAnimationType.CameraOrthoSize:
                    _src.endValueFloat = 0;
                    break;

                case DOTweenAnimationType.CameraPixelRect:
                case DOTweenAnimationType.CameraRect:
                    _src.endValueRect = new Rect(0, 0, 0, 0);
                    break;
                }
            }
            if (_src.animationType == DOTweenAnimationType.None)
            {
                _src.isValid = false;
                if (GUI.changed)
                {
                    EditorUtility.SetDirty(_src);
                }
                return;
            }

            if (prevAnimType != _src.animationType || ComponentsChanged())
            {
                _src.isValid = Validate();
            }

            if (!_src.isValid)
            {
                GUI.color = Color.red;
                GUILayout.BeginVertical(GUI.skin.box);
                GUILayout.Label("No valid Component was found for the selected animation", EditorGUIUtils.wordWrapLabelStyle);
                GUILayout.EndVertical();
                GUI.color = Color.white;
                if (GUI.changed)
                {
                    EditorUtility.SetDirty(_src);
                }
                return;
            }

            _src.duration = EditorGUILayout.FloatField("Duration", _src.duration);
            if (_src.duration < 0)
            {
                _src.duration = 0;
            }
            _src.delay = EditorGUILayout.FloatField("Delay", _src.delay);
            if (_src.delay < 0)
            {
                _src.delay = 0;
            }
            _src.isIndependentUpdate = EditorGUILayout.Toggle("Ignore TimeScale", _src.isIndependentUpdate);
            _src.easeType            = EditorGUIUtils.FilteredEasePopup(_src.easeType);
            if (_src.easeType == Ease.INTERNAL_Custom)
            {
                _src.easeCurve = EditorGUILayout.CurveField("   Ease Curve", _src.easeCurve);
            }
            _src.loops = EditorGUILayout.IntField(new GUIContent("Loops", "Set to -1 for infinite loops"), _src.loops);
            if (_src.loops < -1)
            {
                _src.loops = -1;
            }
            if (_src.loops > 1 || _src.loops == -1)
            {
                _src.loopType = (LoopType)EditorGUILayout.EnumPopup("   Loop Type", _src.loopType);
            }
            _src.id = EditorGUILayout.TextField("ID", _src.id);

            bool canBeRelative = true;

            // End value and eventual specific options
            switch (_src.animationType)
            {
            case DOTweenAnimationType.Move:
            case DOTweenAnimationType.LocalMove:
                GUIEndValueV3();
                _src.optionalBool0 = EditorGUILayout.Toggle("    Snapping", _src.optionalBool0);
                break;

            case DOTweenAnimationType.Rotate:
            case DOTweenAnimationType.LocalRotate:
                if (_src.GetComponent <Rigidbody2D>())
                {
                    GUIEndValueFloat();
                }
                else
                {
                    GUIEndValueV3();
                    _src.optionalRotationMode = (RotateMode)EditorGUILayout.EnumPopup("    Rotation Mode", _src.optionalRotationMode);
                }
                break;

            case DOTweenAnimationType.Scale:
                if (_src.optionalBool0)
                {
                    GUIEndValueFloat();
                }
                else
                {
                    GUIEndValueV3();
                }
                _src.optionalBool0 = EditorGUILayout.Toggle("Uniform Scale", _src.optionalBool0);
                break;

            case DOTweenAnimationType.Color:
                GUIEndValueColor();
                canBeRelative = false;
                break;

            case DOTweenAnimationType.Fade:
                GUIEndValueFloat();
                if (_src.endValueFloat < 0)
                {
                    _src.endValueFloat = 0;
                }
                if (_src.endValueFloat > 1)
                {
                    _src.endValueFloat = 1;
                }
                canBeRelative = false;
                break;

            case DOTweenAnimationType.Text:
                GUIEndValueString();
                _src.optionalBool0        = EditorGUILayout.Toggle("Rich Text Enabled", _src.optionalBool0);
                _src.optionalScrambleMode = (ScrambleMode)EditorGUILayout.EnumPopup("Scramble Mode", _src.optionalScrambleMode);
                _src.optionalString       = EditorGUILayout.TextField(new GUIContent("Custom Scramble", "Custom characters to use in case of ScrambleMode.Custom"), _src.optionalString);
                break;

            case DOTweenAnimationType.PunchPosition:
            case DOTweenAnimationType.PunchRotation:
            case DOTweenAnimationType.PunchScale:
                GUIEndValueV3();
                canBeRelative       = false;
                _src.optionalInt0   = EditorGUILayout.IntSlider(new GUIContent("    Vibrato", "How much will the punch vibrate"), _src.optionalInt0, 1, 50);
                _src.optionalFloat0 = EditorGUILayout.Slider(new GUIContent("    Elasticity", "How much the vector will go beyond the starting position when bouncing backwards"), _src.optionalFloat0, 0, 1);
                if (_src.animationType == DOTweenAnimationType.PunchPosition)
                {
                    _src.optionalBool0 = EditorGUILayout.Toggle("    Snapping", _src.optionalBool0);
                }
                break;

            case DOTweenAnimationType.ShakePosition:
            case DOTweenAnimationType.ShakeRotation:
            case DOTweenAnimationType.ShakeScale:
                GUIEndValueV3();
                canBeRelative       = false;
                _src.optionalInt0   = EditorGUILayout.IntSlider(new GUIContent("    Vibrato", "How much will the shake vibrate"), _src.optionalInt0, 1, 50);
                _src.optionalFloat0 = EditorGUILayout.Slider(new GUIContent("    Randomness", "The shake randomness"), _src.optionalFloat0, 0, 90);
                if (_src.animationType == DOTweenAnimationType.ShakePosition)
                {
                    _src.optionalBool0 = EditorGUILayout.Toggle("    Snapping", _src.optionalBool0);
                }
                break;

            case DOTweenAnimationType.CameraAspect:
            case DOTweenAnimationType.CameraFieldOfView:
            case DOTweenAnimationType.CameraOrthoSize:
                GUIEndValueFloat();
                canBeRelative = false;
                break;

            case DOTweenAnimationType.CameraBackgroundColor:
                GUIEndValueColor();
                canBeRelative = false;
                break;

            case DOTweenAnimationType.CameraPixelRect:
            case DOTweenAnimationType.CameraRect:
                GUIEndValueRect();
                canBeRelative = false;
                break;
            }

            // Final settings
            if (canBeRelative)
            {
                _src.isRelative = EditorGUILayout.Toggle("    Relative", _src.isRelative);
            }

            // Events
            AnimationInspectorGUI.AnimationEvents(this, _src);

            if (GUI.changed)
            {
                EditorUtility.SetDirty(_src);
            }
        }
Ejemplo n.º 14
0
    public override void OnInspectorGUI()
    {
        EditorGUIUtils.SetGUIStyles();

        GUILayout.BeginHorizontal();
        EditorGUIUtils.InspectorLogo();
        GUILayout.Label("IMAGE SMOKE", EditorGUIUtils.sideLogoIconBoldLabelStyle);

        GUILayout.FlexibleSpace();
        if (GUILayout.Button("▲", EditorGUIUtils.btIconStyle))
        {
            UnityEditorInternal.ComponentUtility.MoveComponentUp(_smoke);
        }

        if (GUILayout.Button("▼", EditorGUIUtils.btIconStyle))
        {
            UnityEditorInternal.ComponentUtility.MoveComponentDown(_smoke);
        }
        GUILayout.EndHorizontal();

        if (Application.isPlaying)
        {
            GUILayout.Space(8);
            GUILayout.Label("Animation Editor disabled while in play mode", EditorGUIUtils.wordWrapLabelStyle);
            GUILayout.Space(4);
            GUILayout.Label("NOTE: when using DOPlayNext, the sequence is determined by the DOTweenAnimation Components order in the target GameObject's Inspector", EditorGUIUtils.wordWrapLabelStyle);
            GUILayout.Space(10);
            return;
        }

        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();

        EditorGUI.BeginChangeCheck();

        _smoke.SmokeTex = (Texture2D)EditorGUILayout.ObjectField(_smoke.SmokeTex, typeof(Texture2D), false,
                                                                 GUILayout.Width(180), GUILayout.Height(180));
        if (EditorGUI.EndChangeCheck())
        {
            _smoke.ChangeTexture();
        }

        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();

        GUILayout.BeginVertical("Box");

        EditorGUI.BeginChangeCheck();
        _smoke._Value2      = EditorGUILayout.Slider("Start Smoke Value", _smoke._Value2, 0, 1);
        _smoke._SmokeColor1 = EditorGUILayout.ColorField("Smoke Color", _smoke._SmokeColor1);
        _smoke._SmokeColor2 = EditorGUILayout.ColorField("Smoke Color2", _smoke._SmokeColor2);

        if (EditorGUI.EndChangeCheck())
        {
            _smoke.ChangeScroll();
        }

        GUILayout.EndVertical();


        GUILayout.BeginVertical("Box");
        _smoke.SmokeEaseType = EditorGUIUtils.FilteredEasePopup(_smoke.SmokeEaseType);
        if (_smoke.SmokeEaseType == Ease.INTERNAL_Custom)
        {
            _smoke.SmokeSpdCurve = EditorGUILayout.CurveField("   Smoke Value Curve", _smoke.SmokeSpdCurve);
        }

        _smoke.duration = EditorGUILayout.FloatField("Duration", _smoke.duration);
        if (_smoke.duration < 0)
        {
            _smoke.duration = 0;
        }

        _smoke.delay = EditorGUILayout.FloatField("Delay", _smoke.delay);
        if (_smoke.delay < 0)
        {
            _smoke.delay = 0;
        }

        _smoke.loops = EditorGUILayout.IntField(new GUIContent("Loop", "Set to -1 for infinite loops"), _smoke.loops);
        if (_smoke.loops < -1)
        {
            _smoke.loops = -1;
        }
        if (_smoke.loops > 1 || _smoke.loops == -1)
        {
            _smoke.loopType = (LoopType)EditorGUILayout.EnumPopup("   Loop Type", _smoke.loopType);
        }

        GUIEndValue();

        GUILayout.EndVertical();
    }
Ejemplo n.º 15
0
        private void DrawInit()
        {
            GUILayout.BeginHorizontal();
            GUILayout.Label("当前版本号", GUILayout.Width(100));
            GUILayout.Label(mPackageVersion.Version, GUILayout.Width(100));
            GUILayout.EndHorizontal();


            GUILayout.BeginHorizontal();
            GUILayout.Label("发布版本号", GUILayout.Width(100));
            mVersionText = GUILayout.TextField(mVersionText, GUILayout.Width(100));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("类型", GUILayout.Width(100));

            mPackageVersion.Type = (PackageType)EditorGUILayout.EnumPopup(mPackageVersion.Type);

            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("权限", GUILayout.Width(100));

            mPackageVersion.AccessRight = (PackageAccessRight)EditorGUILayout.EnumPopup(mPackageVersion.AccessRight);
            GUILayout.EndHorizontal();

            GUILayout.Label("发布说明:", GUILayout.Width(150));
            mReleaseNote = GUILayout.TextArea(mReleaseNote, GUILayout.Width(250), GUILayout.Height(300));

            GUILayout.BeginHorizontal();
            GUILayout.Label("文档地址:", GUILayout.Width(52));
            mPackageVersion.DocUrl = GUILayout.TextField(mPackageVersion.DocUrl, GUILayout.Width(150));
            if (GUILayout.Button("Paste"))
            {
                mPackageVersion.DocUrl = GUIUtility.systemCopyBuffer;
            }
            GUILayout.EndHorizontal();

            if (User.Token.Value.IsNullOrEmpty())
            {
                User.Username.Value = EditorGUIUtils.GUILabelAndTextField("username:"******"password:"******"登录"))
                {
                    GetTokenAction.DoGetToken(User.Username.Value, User.Password.Value, token =>
                    {
                        User.Token.Value = token;
                        User.Save();
                    });
                }

                if (!inRegisterView && GUILayout.Button("注册"))
                {
                    inRegisterView = true;
                }

                if (inRegisterView)
                {
                    if (GUILayout.Button("注册"))
                    {
                    }

                    if (GUILayout.Button("返回注册"))
                    {
                        inRegisterView = false;
                    }
                }
            }
            else
            {
                if (GUILayout.Button("注销"))
                {
                    User.Clear();
                }
            }

            if (User.Token.Value.IsNotNullAndEmpty())
            {
                var clicked     = false;
                var deleteLocal = false;

                if (GUILayout.Button("发布"))
                {
                    clicked = true;
                }

                if (GUILayout.Button("发布并删除本地"))
                {
                    clicked     = true;
                    deleteLocal = true;
                }

                if (clicked)
                {
                    User.Save();

                    if (mReleaseNote.Length < 2)
                    {
                        ShowErrorMsg("请输入版本修改说明");
                        return;
                    }

                    if (!IsVersionValide(mVersionText))
                    {
                        ShowErrorMsg("请输入正确的版本号");
                        return;
                    }

                    mPackageVersion.Version = mVersionText;
                    mPackageVersion.Readme  = new ReleaseItem(mVersionText, mReleaseNote, User.Username.Value,
                                                              DateTime.Now);

                    mPackageVersion.Save();

                    AssetDatabase.Refresh();

                    noticeMessage = "插件导出中,请稍后...";

                    Observable.NextFrame().Subscribe(_ =>
                    {
                        noticeMessage  = "插件上传中,请稍后...";
                        mUploadResult  = null;
                        mGenerateState = STATE_GENERATE_UPLOADING;
                        UploadPackage.DoUpload(mPackageVersion, () =>
                        {
                            if (deleteLocal)
                            {
                                Directory.Delete(mPackageVersion.InstallPath, true);
                                AssetDatabase.Refresh();
                            }

                            mUploadResult = "上传成功";
                            GotoComplete();
                        });
                    });
                }
            }
        }
Ejemplo n.º 16
0
    public override void OnInspectorGUI()
    {
        EditorGUIUtility.LookLikeControls();

        Mode oldMode = mode;

        mode = (Mode)EditorGUIUtils.Toolbar(mode);
        EditorGUILayout.Separator();
        if (mode != oldMode)
        {
            EditorGUIUtility.keyboardControl = 0;
        }

        if (mode == Mode.AtlasSet)
        {
            DrawAtlasesList(blockSet);
            if (blockSet.GetAtlas(selectedAtlas) != null)
            {
                DrawAtlasEditor(blockSet.GetAtlas(selectedAtlas));
            }
        }
        if (mode == Mode.BlockSet)
        {
            DrawBlockSet(blockSet);
            EditorGUILayout.Separator();

            if (selectedBlock < blockSet.GetBlockCount() && blockSet.GetBlock(selectedBlock) != null)
            {
                BlockEditor.DrawBlockEditor(blockSet.GetBlock(selectedBlock), blockSet);
            }
            if (selectedBlock >= blockSet.GetBlockCount() && blockSet.GetItem(selectedBlock - blockSet.GetBlockCount()) != null)
            {
                BlockEditor.DrawItemEditor(blockSet.GetItem(selectedBlock - blockSet.GetBlockCount()), blockSet);
            }
        }
        if (mode == Mode.XML)
        {
            if (oldMode != mode)
            {
                xml = blockSet.GetData();
            }

            xmlScrollPosition = GUILayout.BeginScrollView(xmlScrollPosition);
            GUIStyle style = new GUIStyle(GUI.skin.box);
            style.alignment = TextAnchor.UpperLeft;
            xml             = EditorGUILayout.TextArea(xml, GUILayout.ExpandWidth(true));
            blockSet.SetData(xml);
            GUILayout.EndScrollView();

            if (GUILayout.Button("Import"))
            {
                BlockSetImport.Import(blockSet, blockSet.GetData());
                GUI.changed = true;
            }
        }

        if (GUI.changed)
        {
            string data = BlockSetExport.Export(blockSet);
            blockSet.SetData(data);
            EditorUtility.SetDirty(blockSet);
        }
    }
Ejemplo n.º 17
0
        /// <summary>
        /// Draws the component editors in an inspector.
        /// </summary>
        public void OnGUI()
        {
            if (m_ComponentList == null)
            {
                return;
            }

            if (m_ComponentList.isDirty)
            {
                RefreshEditors();
                m_ComponentList.isDirty = false;
            }

            var isEditable = !UnityEditor.VersionControl.Provider.isActive ||
                             AssetDatabase.IsOpenForEdit(m_ComponentList.self, StatusQueryOptions.UseCachedIfPossible);

            if (!targetRequiresProxyMenu)
            {
                m_MarsInspectorSharedSettings.ComponentTabSelection = 0;
            }

            using (new EditorGUI.DisabledScope(!isEditable))
            {
                EditorGUILayout.LabelField(EditorGUIUtils.GetContent("Components"), EditorStyles.boldLabel);

                var availableWidth         = EditorGUIUtility.currentViewWidth;
                var isWideEnoughForAllTabs = availableWidth > k_MinWidthForAllTabs;
                if (isWideEnoughForAllTabs && targetRequiresProxyMenu)
                {
                    m_MarsInspectorSharedSettings.ComponentTabSelection
                        = GUILayout.Toolbar(m_MarsInspectorSharedSettings.ComponentTabSelection, k_ProxyComponentsStrings);
                }
                else if (targetRequiresProxyMenu)
                {
                    var tabIndex   = m_MarsInspectorSharedSettings.ComponentTabSelection;
                    var shortIndex = (tabIndex == 0) ? 0 : 1;
                    k_ProxyFilterStrings[1] = ((tabIndex == 0) ? k_ProxyFilter : k_ProxyComponentsStrings[tabIndex]) + k_DownArrowPostFix;
                    using (var check = new EditorGUI.ChangeCheckScope())
                    {
                        var selectedShortIndex = GUILayout.Toolbar(shortIndex, k_ProxyFilterStrings);
                        if (shortIndex != selectedShortIndex)
                        {
                            if (selectedShortIndex == 0)
                            {
                                m_MarsInspectorSharedSettings.ComponentTabSelection = 0;
                            }
                            else
                            {
                                ComponentFilterContextMenu();
                            }
                        }
                        else if (check.changed)
                        {
                            ComponentFilterContextMenu();
                        }
                    }
                }

                if (targetRequiresProxyMenu && (MarsInspectorSharedSettings.Instance.ComponentTabSelection == k_ForcesTab))
                {
                    Forces.EditorExtensions.ForcesMenuItemsRegions.DrawForcesInInspectorForMainProxy(m_BaseEditor.target);
                }

                // Override list
                for (var i = 0; i < m_Editors.Count; i++)
                {
                    var editor = m_Editors[i];

                    if (editor.activeProperty.serializedObject.targetObject == null)
                    {
                        continue;
                    }

                    if (CanDrawSelectedOption(editor.target))
                    {
                        var title = string.Format("{0}|{1}", editor.GetDisplayTitle(), editor.GetToolTip());
                        var id    = i; // Needed for closure capture below

                        EditorGUIUtils.DrawSplitter();
                        var displayContent = EditorGUIUtils.DrawHeader(
                            title,
                            editor.baseProperty,
                            editor.activeProperty,
                            () => ResetComponent(editor.target.GetType(), id),
                            () => RemoveComponent(id),
                            () => CopyComponent(id),
                            () => PasteComponent(id),
                            CanPasteComponent(id),
                            editor.HasDisplayProperties()
                            );

                        if (displayContent)
                        {
                            if (beforeDrawComponentInspector != null)
                            {
                                beforeDrawComponentInspector(editor);
                            }

                            using (new EditorGUI.DisabledScope(!editor.activeProperty.boolValue))
                            {
                                editor.OnInternalInspectorGUI();
                            }

                            if (afterDrawComponentInspector != null)
                            {
                                afterDrawComponentInspector(editor);
                            }
                        }
                    }
                }

                if (targetRequiresProxyMenu || (m_BaseEditor.target is ProxyGroup))
                {
                    if (m_Editors.Count > 0)
                    {
                        EditorGUIUtils.DrawSplitter();
                        EditorGUILayout.Space();
                    }
                    AddComponentMenuButton();
                    EditorGUILayout.Space();
                }
            }
        }
        override public void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            GUILayout.Space(3);
            EditorGUIUtils.SetGUIStyles();

            bool playMode = Application.isPlaying;

            _runtimeEditMode = _runtimeEditMode && playMode;

            GUILayout.BeginHorizontal();
            EditorGUIUtils.InspectorLogo();
            GUILayout.Label(_src.animationType.ToString() + (string.IsNullOrEmpty(_src.id) ? "" : " [" + _src.id + "]"), EditorGUIUtils.sideLogoIconBoldLabelStyle);
            // Up-down buttons
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("▲", DeGUI.styles.button.toolIco))
            {
                UnityEditorInternal.ComponentUtility.MoveComponentUp(_src);
            }
            if (GUILayout.Button("▼", DeGUI.styles.button.toolIco))
            {
                UnityEditorInternal.ComponentUtility.MoveComponentDown(_src);
            }
            GUILayout.EndHorizontal();

            if (playMode)
            {
                if (_runtimeEditMode)
                {
                }
                else
                {
                    GUILayout.Space(8);
                    GUILayout.Label("Animation Editor disabled while in play mode", EditorGUIUtils.wordWrapLabelStyle);
                    if (!_src.isActive)
                    {
                        GUILayout.Label("This animation has been toggled as inactive and won't be generated", EditorGUIUtils.wordWrapLabelStyle);
                        GUI.enabled = false;
                    }
                    if (GUILayout.Button(new GUIContent("Activate Edit Mode", "Switches to Runtime Edit Mode, where you can change animations values and restart them")))
                    {
                        _runtimeEditMode = true;
                    }
                    GUILayout.Label("NOTE: when using DOPlayNext, the sequence is determined by the DOTweenAnimation Components order in the target GameObject's Inspector", EditorGUIUtils.wordWrapLabelStyle);
                    GUILayout.Space(10);
                    if (!_runtimeEditMode)
                    {
                        return;
                    }
                }
            }

            Undo.RecordObject(_src, "DOTween Animation");

//            _src.isValid = Validate(); // Moved down

            EditorGUIUtility.labelWidth = 110;

            if (playMode)
            {
                GUILayout.Space(4);
                DeGUILayout.Toolbar("Edit Mode Commands");
                DeGUILayout.BeginVBox(DeGUI.styles.box.stickyTop);
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("TogglePause"))
                {
                    _src.tween.TogglePause();
                }
                if (GUILayout.Button("Rewind"))
                {
                    _src.tween.Rewind();
                }
                if (GUILayout.Button("Restart"))
                {
                    _src.tween.Restart();
                }
                GUILayout.EndHorizontal();
                if (GUILayout.Button("Commit changes and restart"))
                {
                    _src.tween.Rewind();
                    _src.tween.Kill();
                    if (_src.isValid)
                    {
                        _src.CreateTween();
                        _src.tween.Play();
                    }
                }
                GUILayout.Label("To apply your changes when exiting Play mode, use the Component's upper right menu and choose \"Copy Component\", then \"Paste Component Values\" after exiting Play mode", DeGUI.styles.label.wordwrap);
                DeGUILayout.EndVBox();
            }
            else
            {
                bool hasManager = _src.GetComponent <DOTweenVisualManager>() != null;
                if (!hasManager)
                {
                    if (GUILayout.Button(new GUIContent("Add Manager", "Adds a manager component which allows you to choose additional options for this gameObject")))
                    {
                        _src.gameObject.AddComponent <DOTweenVisualManager>();
                    }
                }
            }

            // Choose target
            GUILayout.BeginHorizontal();
            _src.isActive = EditorGUILayout.Toggle(new GUIContent("", "If unchecked, this animation will not be created"), _src.isActive, GUILayout.Width(14));
            EditorGUI.BeginChangeCheck();
            EditorGUI.BeginChangeCheck();
            _src.targetIsSelf = DeGUILayout.ToggleButton(
                _src.targetIsSelf, _src.targetIsSelf ? _GuiC_selfTarget_true : _GuiC_selfTarget_false,
                new Color(1f, 0.78f, 0f), DeGUI.colors.bg.toggleOn, new Color(0.33f, 0.14f, 0.02f), DeGUI.colors.content.toggleOn,
                null, GUILayout.Width(47)
                );
            bool innerChanged = EditorGUI.EndChangeCheck();

            if (innerChanged)
            {
                _src.targetGO = null;
                GUI.changed   = true;
            }
            if (_src.targetIsSelf)
            {
                GUILayout.Label(_GuiC_selfTarget_true.tooltip);
            }
            else
            {
                using (new DeGUI.ColorScope(null, null, _src.targetGO == null ? Color.red : Color.white)) {
                    _src.targetGO = (GameObject)EditorGUILayout.ObjectField(_src.targetGO, typeof(GameObject), true);
                }
                _src.tweenTargetIsTargetGO = DeGUILayout.ToggleButton(
                    _src.tweenTargetIsTargetGO, _src.tweenTargetIsTargetGO ? _GuiC_tweenTargetIsTargetGO_true : _GuiC_tweenTargetIsTargetGO_false,
                    GUILayout.Width(131)
                    );
            }
            bool check = EditorGUI.EndChangeCheck();

            if (check)
            {
                _refreshRequired = true;
            }
            GUILayout.EndHorizontal();

            GameObject targetGO = _src.targetIsSelf ? _src.gameObject : _src.targetGO;

            if (targetGO == null)
            {
                // Uses external target gameObject but it's not set
                if (_src.targetGO != null || _src.target != null)
                {
                    _src.targetGO = null;
                    _src.target   = null;
                    GUI.changed   = true;
                }
            }
            else
            {
                GUILayout.BeginHorizontal();
                DOTweenAnimationType prevAnimType = _src.animationType;
//                _src.animationType = (DOTweenAnimationType)EditorGUILayout.EnumPopup(_src.animationType, EditorGUIUtils.popupButton);
                GUI.enabled        = _src.isActive;
                _src.animationType = AnimationToDOTweenAnimationType(_AnimationType[EditorGUILayout.Popup(DOTweenAnimationTypeToPopupId(_src.animationType), _AnimationType)]);
                _src.autoPlay      = DeGUILayout.ToggleButton(_src.autoPlay, new GUIContent("AutoPlay", "If selected, the tween will play automatically"));
                _src.autoKill      = DeGUILayout.ToggleButton(_src.autoKill, new GUIContent("AutoKill", "If selected, the tween will be killed when it completes, and won't be reusable"));
                GUILayout.EndHorizontal();
                if (prevAnimType != _src.animationType)
                {
                    // Set default optional values based on animation type
                    _src.endValueTransform = null;
                    _src.useTargetAsV3     = false;
                    switch (_src.animationType)
                    {
                    case DOTweenAnimationType.Move:
                    case DOTweenAnimationType.LocalMove:
                    case DOTweenAnimationType.Rotate:
                    case DOTweenAnimationType.LocalRotate:
                    case DOTweenAnimationType.Scale:
                        _src.endValueV3    = Vector3.zero;
                        _src.endValueFloat = 0;
                        _src.optionalBool0 = _src.animationType == DOTweenAnimationType.Scale;
                        break;

                    case DOTweenAnimationType.UIWidthHeight:
                        _src.endValueV3    = Vector3.zero;
                        _src.endValueFloat = 0;
                        _src.optionalBool0 = _src.animationType == DOTweenAnimationType.UIWidthHeight;
                        break;

                    case DOTweenAnimationType.Color:
                    case DOTweenAnimationType.Fade:
                        _isLightSrc        = targetGO.GetComponent <Light>() != null;
                        _src.endValueFloat = 0;
                        break;

                    case DOTweenAnimationType.Text:
                        _src.optionalBool0 = true;
                        break;

                    case DOTweenAnimationType.PunchPosition:
                    case DOTweenAnimationType.PunchRotation:
                    case DOTweenAnimationType.PunchScale:
                        _src.endValueV3     = _src.animationType == DOTweenAnimationType.PunchRotation ? new Vector3(0, 180, 0) : Vector3.one;
                        _src.optionalFloat0 = 1;
                        _src.optionalInt0   = 10;
                        _src.optionalBool0  = false;
                        break;

                    case DOTweenAnimationType.ShakePosition:
                    case DOTweenAnimationType.ShakeRotation:
                    case DOTweenAnimationType.ShakeScale:
                        _src.endValueV3     = _src.animationType == DOTweenAnimationType.ShakeRotation ? new Vector3(90, 90, 90) : Vector3.one;
                        _src.optionalInt0   = 10;
                        _src.optionalFloat0 = 90;
                        _src.optionalBool0  = false;
                        break;

                    case DOTweenAnimationType.CameraAspect:
                    case DOTweenAnimationType.CameraFieldOfView:
                    case DOTweenAnimationType.CameraOrthoSize:
                        _src.endValueFloat = 0;
                        break;

                    case DOTweenAnimationType.CameraPixelRect:
                    case DOTweenAnimationType.CameraRect:
                        _src.endValueRect = new Rect(0, 0, 0, 0);
                        break;
                    }
                }
                if (_src.animationType == DOTweenAnimationType.None)
                {
                    _src.isValid = false;
                    if (GUI.changed)
                    {
                        EditorUtility.SetDirty(_src);
                    }
                    return;
                }

                if (_refreshRequired || prevAnimType != _src.animationType || ComponentsChanged())
                {
                    _refreshRequired = false;
                    _src.isValid     = Validate(targetGO);
                    // See if we need to choose between multiple targets
#if true // UI_MARKER
                    if (_src.animationType == DOTweenAnimationType.Fade && targetGO.GetComponent <CanvasGroup>() != null && targetGO.GetComponent <Image>() != null)
                    {
                        _chooseTargetMode = ChooseTargetMode.BetweenCanvasGroupAndImage;
                        // Reassign target and forcedTargetType if lost
                        if (_src.forcedTargetType == TargetType.Unset)
                        {
                            _src.forcedTargetType = _src.targetType;
                        }
                        switch (_src.forcedTargetType)
                        {
                        case TargetType.CanvasGroup:
                            _src.target = targetGO.GetComponent <CanvasGroup>();
                            break;

                        case TargetType.Image:
                            _src.target = targetGO.GetComponent <Image>();
                            break;
                        }
                    }
                    else
                    {
#endif
                    _chooseTargetMode     = ChooseTargetMode.None;
                    _src.forcedTargetType = TargetType.Unset;
#if true // UI_MARKER
                }
#endif
                }

                if (!_src.isValid)
                {
                    GUI.color = Color.red;
                    GUILayout.BeginVertical(GUI.skin.box);
                    GUILayout.Label("No valid Component was found for the selected animation", EditorGUIUtils.wordWrapLabelStyle);
                    GUILayout.EndVertical();
                    GUI.color = Color.white;
                    if (GUI.changed)
                    {
                        EditorUtility.SetDirty(_src);
                    }
                    return;
                }

#if true // UI_MARKER
                // Special cases in which multiple target types could be used (set after validation)
                if (_chooseTargetMode == ChooseTargetMode.BetweenCanvasGroupAndImage && _src.forcedTargetType != TargetType.Unset)
                {
                    FadeTargetType fadeTargetType = (FadeTargetType)Enum.Parse(typeof(FadeTargetType), _src.forcedTargetType.ToString());
                    TargetType     prevTargetType = _src.forcedTargetType;
                    _src.forcedTargetType = (TargetType)Enum.Parse(typeof(TargetType), EditorGUILayout.EnumPopup(_src.animationType + " Target", fadeTargetType).ToString());
                    if (_src.forcedTargetType != prevTargetType)
                    {
                        // Target type change > assign correct target
                        switch (_src.forcedTargetType)
                        {
                        case TargetType.CanvasGroup:
                            _src.target = targetGO.GetComponent <CanvasGroup>();
                            break;

                        case TargetType.Image:
                            _src.target = targetGO.GetComponent <Image>();
                            break;
                        }
                    }
                }
#endif

                GUILayout.BeginHorizontal();
                _src.duration = EditorGUILayout.FloatField("Duration", _src.duration);
                if (_src.duration < 0)
                {
                    _src.duration = 0;
                }
                _src.isSpeedBased = DeGUILayout.ToggleButton(_src.isSpeedBased, new GUIContent("SpeedBased", "If selected, the duration will count as units/degree x second"), DeGUI.styles.button.tool, GUILayout.Width(75));
                GUILayout.EndHorizontal();
                _src.delay = EditorGUILayout.FloatField("Delay", _src.delay);
                if (_src.delay < 0)
                {
                    _src.delay = 0;
                }
                _src.isIndependentUpdate = EditorGUILayout.Toggle("Ignore TimeScale", _src.isIndependentUpdate);
                _src.easeType            = EditorGUIUtils.FilteredEasePopup(_src.easeType);
                if (_src.easeType == Ease.INTERNAL_Custom)
                {
                    _src.easeCurve = EditorGUILayout.CurveField("   Ease Curve", _src.easeCurve);
                }
                _src.loops = EditorGUILayout.IntField(new GUIContent("Loops", "Set to -1 for infinite loops"), _src.loops);
                if (_src.loops < -1)
                {
                    _src.loops = -1;
                }
                if (_src.loops > 1 || _src.loops == -1)
                {
                    _src.loopType = (LoopType)EditorGUILayout.EnumPopup("   Loop Type", _src.loopType);
                }
                _src.id = EditorGUILayout.TextField("ID", _src.id);

                bool canBeRelative = true;
                // End value and eventual specific options
                switch (_src.animationType)
                {
                case DOTweenAnimationType.Move:
                case DOTweenAnimationType.LocalMove:
                    GUIEndValueV3(targetGO, _src.animationType == DOTweenAnimationType.Move);
                    _src.optionalBool0 = EditorGUILayout.Toggle("    Snapping", _src.optionalBool0);
                    canBeRelative      = !_src.useTargetAsV3;
                    break;

                case DOTweenAnimationType.Rotate:
                case DOTweenAnimationType.LocalRotate:
                    bool isRigidbody2D = DOTweenModuleUtils.Physics.HasRigidbody2D(_src);
                    if (isRigidbody2D)
                    {
                        GUIEndValueFloat();
                    }
                    else
                    {
                        GUIEndValueV3(targetGO);
                        _src.optionalRotationMode = (RotateMode)EditorGUILayout.EnumPopup("    Rotation Mode", _src.optionalRotationMode);
                    }
                    break;

                case DOTweenAnimationType.Scale:
                    if (_src.optionalBool0)
                    {
                        GUIEndValueFloat();
                    }
                    else
                    {
                        GUIEndValueV3(targetGO);
                    }
                    _src.optionalBool0 = EditorGUILayout.Toggle("Uniform Scale", _src.optionalBool0);
                    break;

                case DOTweenAnimationType.UIWidthHeight:
                    if (_src.optionalBool0)
                    {
                        GUIEndValueFloat();
                    }
                    else
                    {
                        GUIEndValueV2();
                    }
                    _src.optionalBool0 = EditorGUILayout.Toggle("Uniform Scale", _src.optionalBool0);
                    break;

                case DOTweenAnimationType.Color:
                    GUIEndValueColor();
                    canBeRelative = false;
                    break;

                case DOTweenAnimationType.Fade:
                    GUIEndValueFloat();
                    if (_src.endValueFloat < 0)
                    {
                        _src.endValueFloat = 0;
                    }
                    if (!_isLightSrc && _src.endValueFloat > 1)
                    {
                        _src.endValueFloat = 1;
                    }
                    canBeRelative = false;
                    break;

                case DOTweenAnimationType.Text:
                    GUIEndValueString();
                    _src.optionalBool0        = EditorGUILayout.Toggle("Rich Text Enabled", _src.optionalBool0);
                    _src.optionalScrambleMode = (ScrambleMode)EditorGUILayout.EnumPopup("Scramble Mode", _src.optionalScrambleMode);
                    _src.optionalString       = EditorGUILayout.TextField(new GUIContent("Custom Scramble", "Custom characters to use in case of ScrambleMode.Custom"), _src.optionalString);
                    break;

                case DOTweenAnimationType.PunchPosition:
                case DOTweenAnimationType.PunchRotation:
                case DOTweenAnimationType.PunchScale:
                    GUIEndValueV3(targetGO);
                    canBeRelative       = false;
                    _src.optionalInt0   = EditorGUILayout.IntSlider(new GUIContent("    Vibrato", "How much will the punch vibrate"), _src.optionalInt0, 1, 50);
                    _src.optionalFloat0 = EditorGUILayout.Slider(new GUIContent("    Elasticity", "How much the vector will go beyond the starting position when bouncing backwards"), _src.optionalFloat0, 0, 1);
                    if (_src.animationType == DOTweenAnimationType.PunchPosition)
                    {
                        _src.optionalBool0 = EditorGUILayout.Toggle("    Snapping", _src.optionalBool0);
                    }
                    break;

                case DOTweenAnimationType.ShakePosition:
                case DOTweenAnimationType.ShakeRotation:
                case DOTweenAnimationType.ShakeScale:
                    GUIEndValueV3(targetGO);
                    canBeRelative       = false;
                    _src.optionalInt0   = EditorGUILayout.IntSlider(new GUIContent("    Vibrato", "How much will the shake vibrate"), _src.optionalInt0, 1, 50);
                    _src.optionalFloat0 = EditorGUILayout.Slider(new GUIContent("    Randomness", "The shake randomness"), _src.optionalFloat0, 0, 90);
                    if (_src.animationType == DOTweenAnimationType.ShakePosition)
                    {
                        _src.optionalBool0 = EditorGUILayout.Toggle("    Snapping", _src.optionalBool0);
                    }
                    break;

                case DOTweenAnimationType.CameraAspect:
                case DOTweenAnimationType.CameraFieldOfView:
                case DOTweenAnimationType.CameraOrthoSize:
                    GUIEndValueFloat();
                    canBeRelative = false;
                    break;

                case DOTweenAnimationType.CameraBackgroundColor:
                    GUIEndValueColor();
                    canBeRelative = false;
                    break;

                case DOTweenAnimationType.CameraPixelRect:
                case DOTweenAnimationType.CameraRect:
                    GUIEndValueRect();
                    canBeRelative = false;
                    break;
                }

                // Final settings
                if (canBeRelative)
                {
                    _src.isRelative = EditorGUILayout.Toggle("    Relative", _src.isRelative);
                }

                // Events
                AnimationInspectorGUI.AnimationEvents(this, _src);
            }

            if (GUI.changed)
            {
                EditorUtility.SetDirty(_src);
            }
        }
Ejemplo n.º 19
0
        protected override void OnHeaderGUI()
        {
            base.OnHeaderGUI();
            if (selectContent == null)
            {
                Debug.LogWarning($"base.OnEnable was not called for {GetType().Name}, a class inheriting from {nameof(ScriptableObjectInspector)}.");
                return;
            }

            Event e = Event.current;

            Rect position  = GUILayoutUtility.GetLastRect();
            Rect titleRect = position;

            titleRect.xMin += 40;
            titleRect.xMax -= 55;
            titleRect.yMax -= 25;
            if (e.isMouse && e.type == EventType.MouseDown && titleRect.Contains(e.mousePosition))
            {
                DragAndDrop.objectReferences = targets;
                DragAndDrop.visualMode       = DragAndDropVisualMode.Link;
                DragAndDrop.StartDrag("Drag SO");
            }

            position.y      = position.yMax - 21;
            position.height = 15;
            position.xMin  += 46;
            position.xMax  -= 55;

            Rect  selectPosition = position;
            float searchWidth    = EditorStyles.miniButton.CalcSize(searchContent).x;

            if (searchForMoreContent != null)
            {
                searchWidth += 15;
            }
            selectPosition.width = Mathf.Min(position.width / 2f, position.width - searchWidth);


            //Selectively use a small version of the search button when the large version forces the Select button to be too small.
            GUIContent searchContentToUse = searchContent;

            if (selectPosition.width < 60)
            {
                selectPosition.width = 60;
                searchContentToUse   = searchContentSmall;
            }

            //Draw the Select button
            if (GUI.Button(selectPosition, selectContent, EditorStyles.miniButtonLeft))
            {
                Selection.activeObject = target;
                EditorGUIUtility.PingObject(target);
            }

            //Draw the Search button
            Rect searchPosition = position;

            searchPosition.xMin = selectPosition.xMax;
            if (searchForMoreContent == null)
            {
                if (GUI.Button(searchPosition, searchContentToUse, EditorStyles.miniButtonRight))
                {
                    EditorGUIUtils.SetProjectBrowserSearch($"t:{target.GetType().FullName}");
                }
            }
            else
            {
                Rect searchPositionWhole = searchPosition;
                searchPosition.width -= 15;
                if (GUI.Button(searchPosition, searchContentToUse, EditorStyles.miniButtonMid))
                {
                    EditorGUIUtils.SetProjectBrowserSearch($"t:{target.GetType().FullName}");
                }
                searchPosition.x     = searchPosition.xMax - 1;
                searchPosition.width = 15;
                if (EditorGUI.DropdownButton(searchPosition, GUIContent.none, FocusType.Keyboard, EditorStyles.miniButtonRight))
                {
                    GenericMenu menu = new GenericMenu();
                    for (var i = 0; i < searchForMoreContent.Count; i++)
                    {
                        int        iLocal  = i;
                        GUIContent content = searchForMoreContent[i];
                        menu.AddItem(content, false, () => EditorGUIUtils.SetProjectBrowserSearch($"t:{moreContentTypeNames[iLocal]}"));
                    }

                    searchPositionWhole.yMax += 3;
                    menu.DropDown(searchPositionWhole);
                }

                if (e.type == EventType.Repaint)
                {
                    searchPosition.x += 1;
                    searchPosition.y += 3;
                    GUIStyle.none.Draw(searchPosition, DropdownIcon, false, false, false, false);
                }
            }
        }