コード例 #1
0
    private void DrawNodeWindow(int id)
    {
        if (GUIUtility.hotControl == 0) //mouseup event outside parent window?
        {
            _handleActive = false;      //make sure handle is deactivated
        }

        float _cornerX = 0f;
        float _cornerY = 0f;

        switch (id) //case which window this is and nab size info
        {
        case 1:
            _cornerX = window1.width;
            _cornerY = window1.height;
            break;

        case 2:
            _cornerX = window2.width;
            _cornerY = window2.height;
            break;
        }

        //begin layout of contents
        GUILayout.BeginArea(new Rect(1, 16, _cornerX - 3, _cornerY - 1));
        GUILayout.BeginHorizontal(EditorStyles.toolbar);
        _nodeOption = GUILayout.Toggle(_nodeOption, "Node Toggle", EditorStyles.toolbarButton);
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();
        GUILayout.EndArea();

        GUILayout.BeginArea(new Rect(1, _cornerY - 16, _cornerX - 3, 14));
        GUILayout.BeginHorizontal(EditorStyles.toolbarTextField, GUILayout.ExpandWidth(true));
        GUILayout.FlexibleSpace();

        //grab corner area based on content reference
        _handleArea = GUILayoutUtility.GetRect(_icon, GUIStyle.none);
        GUI.DrawTexture(new Rect(_handleArea.xMin + 6, _handleArea.yMin - 3, 20, 20), _resizeHandle); //hacky placement
        _action = (Event.current.type == EventType.MouseDown) || (Event.current.type == EventType.MouseDrag);
        if (!_handleActive && _action)
        {
            if (_handleArea.Contains(Event.current.mousePosition, true))
            {
                _handleActive         = true;                                       //active when cursor is in contact area
                GUIUtility.hotControl = GUIUtility.GetControlID(FocusType.Passive); //set handle hot
            }
        }

        EditorGUIUtility.AddCursorRect(_handleArea, MouseCursor.ResizeUpLeft);
        GUILayout.EndHorizontal();
        GUILayout.EndArea();

        //resize window
        if (_handleActive && (Event.current.type == EventType.MouseDrag))
        {
            ResizeNode(id, Event.current.delta.x, Event.current.delta.y);
            Repaint();
            Event.current.Use();
        }

        //enable drag for node
        if (!_handleActive)
        {
            GUI.DragWindow();
        }
    }
コード例 #2
0
ファイル: ActionItemControl.cs プロジェクト: qipa/SkillEditor
    public override void HandleInput(DirectorControlState state, Rect trackPosition)
    {
        CinemaActionWrapper wrapper = base.Wrapper as CinemaActionWrapper;

        if (wrapper == null)
        {
            return;
        }
        if (base.isRenaming)
        {
            return;
        }
        float num  = (wrapper.Firetime * state.Scale.x) + state.Translation.x;
        float num2 = ((wrapper.Firetime + wrapper.Duration) * state.Scale.x) + state.Translation.x;

        ResizeControlPosition(state, trackPosition);
        Rect rect  = new Rect(num, this.controlPosition.y, 5f, this.controlPosition.height);
        Rect rect2 = new Rect(num + 5f, this.controlPosition.y, (num2 - num) - 10f, this.controlPosition.height);
        Rect rect3 = new Rect(num2 - 5f, this.controlPosition.y, 5f, this.controlPosition.height);

        EditorGUIUtility.AddCursorRect(rect, (MouseCursor)3);
        EditorGUIUtility.AddCursorRect(rect2, (MouseCursor)5);
        EditorGUIUtility.AddCursorRect(rect3, (MouseCursor)3);
        base.controlID = GUIUtility.GetControlID(base.Wrapper.Behaviour.GetInstanceID(), (FocusType)2, base.controlPosition);
        int num3 = GUIUtility.GetControlID(base.Wrapper.Behaviour.GetInstanceID(), (FocusType)2, rect);
        int num4 = GUIUtility.GetControlID(base.Wrapper.Behaviour.GetInstanceID(), (FocusType)2, rect2);
        int num5 = GUIUtility.GetControlID(base.Wrapper.Behaviour.GetInstanceID(), (FocusType)2, rect3);

        if (((Event.current.GetTypeForControl(base.controlID) == EventType.MouseDown) && rect2.Contains(Event.current.mousePosition)) && (Event.current.button == 1))
        {
            if (!base.IsSelected)
            {
                GameObject[] objArray = Selection.gameObjects;
                ArrayUtility.Add <GameObject>(ref objArray, base.Wrapper.Behaviour.gameObject);
                Selection.objects        = objArray;
                base.hasSelectionChanged = true;
            }
            this.showContextMenu(base.Wrapper.Behaviour);
            Event.current.Use();
        }
        switch (Event.current.GetTypeForControl(num4))
        {
        case 0:
        {
            if (!rect2.Contains(Event.current.mousePosition) || (Event.current.button != 0))
            {
                goto Label_0471;
            }
            GUIUtility.hotControl = (num4);
            if (!Event.current.control)
            {
                if (!base.IsSelected)
                {
                    Selection.activeInstanceID = (base.Behaviour.GetInstanceID());
                }
                break;
            }
            if (!base.IsSelected)
            {
                GameObject[] objArray3 = Selection.gameObjects;
                ArrayUtility.Add <GameObject>(ref objArray3, base.Wrapper.Behaviour.gameObject);
                Selection.objects        = (objArray3);
                base.hasSelectionChanged = true;
                break;
            }
            GameObject[] objArray2 = Selection.gameObjects;
            ArrayUtility.Remove <GameObject>(ref objArray2, base.Wrapper.Behaviour.gameObject);
            Selection.objects        = (objArray2);
            base.hasSelectionChanged = true;
            break;
        }

        case (EventType)1:
            if (GUIUtility.hotControl == num4)
            {
                mouseDownOffset       = -1f;
                GUIUtility.hotControl = (0);
                if (base.mouseDragActivity)
                {
                    base.TriggerTrackItemUpdateEvent();
                }
                else if (!Event.current.control)
                {
                    Selection.activeInstanceID = (base.Behaviour.GetInstanceID());
                }
                else if (!base.hasSelectionChanged)
                {
                    if (!base.IsSelected)
                    {
                        GameObject[] objArray5 = Selection.gameObjects;
                        ArrayUtility.Add <GameObject>(ref objArray5, base.Wrapper.Behaviour.gameObject);
                        Selection.objects = (objArray5);
                    }
                    else
                    {
                        GameObject[] objArray4 = Selection.gameObjects;
                        ArrayUtility.Remove <GameObject>(ref objArray4, base.Wrapper.Behaviour.gameObject);
                        Selection.objects = (objArray4);
                    }
                }
                base.hasSelectionChanged = false;
            }
            goto Label_0471;

        case (EventType)3:
            if ((GUIUtility.hotControl == num4) && !base.hasSelectionChanged)
            {
                Undo.RecordObject(base.Behaviour, string.Format("Changed {0}", base.Behaviour.name));
                float firetime = (Event.current.mousePosition.x - state.Translation.x) / state.Scale.x;
                firetime = state.SnappedTime(firetime - mouseDownOffset);
                if (!base.mouseDragActivity)
                {
                    base.mouseDragActivity = base.Wrapper.Firetime != firetime;
                }
                base.TriggerRequestTrackItemTranslate(firetime);
            }
            goto Label_0471;

        default:
            goto Label_0471;
        }
        base.mouseDragActivity = false;
        mouseDownOffset        = ((Event.current.mousePosition.x - state.Translation.x) / state.Scale.x) - wrapper.Firetime;
        if (!base.TrackControl.TargetTrack.IsLocked)
        {
            Event.current.Use();
        }
Label_0471:
        switch (Event.current.GetTypeForControl(num3))
        {
        case 0:
            if (rect.Contains(Event.current.mousePosition))
            {
                GUIUtility.hotControl = (num3);
                mouseDownOffset       = ((Event.current.mousePosition.x - state.Translation.x) / state.Scale.x) - wrapper.Firetime;
                if (!base.TrackControl.TargetTrack.IsLocked)
                {
                    Event.current.Use();
                }
            }
            break;

        case (EventType)1:
            if (GUIUtility.hotControl == num3)
            {
                mouseDownOffset       = -1f;
                GUIUtility.hotControl = (0);
                if (this.AlterAction != null)
                {
                    this.AlterAction(this, new ActionItemEventArgs(wrapper.Behaviour, wrapper.Firetime, wrapper.Duration));
                }
            }
            break;

        case (EventType)3:
            if (GUIUtility.hotControl == num3)
            {
                float time = (Event.current.mousePosition.x - state.Translation.x) / state.Scale.x;
                time = state.SnappedTime(time);
                float num8 = 0f;
                float num9 = wrapper.Firetime + wrapper.Duration;
                foreach (CinemaActionWrapper wrapper2 in base.Track.Items)
                {
                    if ((wrapper2 != null) && (wrapper2.Behaviour != base.Wrapper.Behaviour))
                    {
                        float num10 = wrapper2.Firetime + wrapper2.Duration;
                        if (num10 <= base.Wrapper.Firetime)
                        {
                            num8 = Mathf.Max(num8, num10);
                        }
                    }
                }
                time              = Mathf.Max(num8, time);
                time              = Mathf.Min(num9, time);
                wrapper.Duration += base.Wrapper.Firetime - time;
                wrapper.Firetime  = time;
            }
            break;
        }
        switch (Event.current.GetTypeForControl(num5))
        {
        case 0:
            if (rect3.Contains(Event.current.mousePosition))
            {
                GUIUtility.hotControl = (num5);
                mouseDownOffset       = ((Event.current.mousePosition.x - state.Translation.x) / state.Scale.x) - base.Wrapper.Firetime;
                if (!base.TrackControl.TargetTrack.IsLocked)
                {
                    Event.current.Use();
                }
            }
            break;

        case (EventType)1:
            if (GUIUtility.hotControl == num5)
            {
                mouseDownOffset       = -1f;
                GUIUtility.hotControl = (0);
                if (this.AlterAction != null)
                {
                    this.AlterAction(this, new ActionItemEventArgs(wrapper.Behaviour, wrapper.Firetime, wrapper.Duration));
                }
            }
            break;

        case (EventType)3:
            if (GUIUtility.hotControl == num5)
            {
                float num11 = (Event.current.mousePosition.x - state.Translation.x) / state.Scale.x;
                num11 = state.SnappedTime(num11);
                float positiveInfinity = float.PositiveInfinity;
                foreach (CinemaActionWrapper wrapper3 in base.Track.Items)
                {
                    if ((wrapper3 != null) && (wrapper3.Behaviour != base.Wrapper.Behaviour))
                    {
                        float num13 = wrapper.Firetime + wrapper.Duration;
                        if (wrapper3.Firetime >= num13)
                        {
                            positiveInfinity = Mathf.Min(positiveInfinity, wrapper3.Firetime);
                        }
                    }
                }
                num11            = Mathf.Clamp(num11, base.Wrapper.Firetime, positiveInfinity);
                wrapper.Duration = num11 - base.Wrapper.Firetime;
            }
            break;
        }
        if (base.Wrapper.Behaviour.gameObject != null && Selection.activeGameObject != null && Selection.activeGameObject == base.Wrapper.Behaviour.gameObject)
        {
            if ((Event.current.type == (EventType)13) && (Event.current.commandName == "Copy"))
            {
                Event.current.Use();
            }
            if ((Event.current.type == (EventType)14) && (Event.current.commandName == "Copy"))
            {
                DirectorCopyPaste.Copy(base.Wrapper.Behaviour);
                Event.current.Use();
            }
        }
        if (((Event.current.type == (EventType)4) && (Event.current.keyCode == (KeyCode)0x7f)) && (Selection.activeGameObject == base.Wrapper.Behaviour.gameObject))
        {
            base.deleteItem(base.Wrapper.Behaviour);
            Event.current.Use();
        }
    }
コード例 #3
0
        void OnGUI()
        {
            GUILayout.Space(5);
            Event evt       = Event.current;
            bool  hitEnter  = evt.type == EventType.KeyDown && (evt.keyCode == KeyCode.Return || evt.keyCode == KeyCode.KeypadEnter);
            bool  hitEscape = evt.type == EventType.KeyDown && (evt.keyCode == KeyCode.Escape);

            if (hitEscape)
            {
                Close();
                GUIUtility.ExitGUI();
            }
            GUI.SetNextControlName("m_PreferencesName");
            EditorGUI.BeginChangeCheck();
            m_PresetName = EditorGUILayout.TextField(m_PresetName);
            m_PresetName = m_PresetName.TrimEnd();
            if (EditorGUI.EndChangeCheck())
            {
                UpdateCurrentInvalidChars();
            }

            if (!m_DidFocus)
            {
                m_DidFocus = true;
                EditorGUI.FocusTextInControl("m_PreferencesName");
            }

            if (m_CurrentInvalidChars.Length != 0)
            {
                EditorGUILayout.HelpBox(string.Format(s_InvalidCharsFormatString, m_CurrentInvalidChars), MessageType.Warning);
                minSize = new Vector2(k_Width, k_Height + k_HelpBoxHeight);
            }
            else
            {
                minSize = new Vector2(k_Width, k_Height);
            }

            bool canSaveLayout = m_PresetName.Length > 0 && m_CurrentInvalidChars.Length == 0;

            EditorGUI.BeginDisabled(!canSaveLayout);

            if (GUILayout.Button("Save") || hitEnter && canSaveLayout)
            {
                Close();

                if (OverlayPresetManager.Exists(m_Window.GetType(), m_PresetName))
                {
                    if (!EditorUtility.DisplayDialog("Overwrite preset?",
                                                     "Do you want to overwrite '" + m_PresetName + "' preset?",
                                                     "Overwrite", "Cancel"))
                    {
                        GUIUtility.ExitGUI();
                    }
                }

                save(m_PresetName);

                GUIUtility.ExitGUI();
            }
            else
            {
                m_DidFocus = false;
            }

            EditorGUI.EndDisabled();
        }
コード例 #4
0
    static void OnSceneGUI(SceneView sceneView)
    {
        //if (page != PageIndex.BRUSH) return;

        Event   e             = Event.current;
        Vector2 mousePosition = e.mousePosition;

        // View point to world point translation function in my game.
        //this._mousePosition = SceneScreenToWorldPoint(mousePosition);

        // Block SceneView's built-in behavior
        HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive));

        bool HandleMsg = false;

        if (e.isMouse)
        {
            // Debug.Log(e.button.ToString() + ":"+ e.type.ToString());
        }
        if (e.button == 0 && e.type == EventType.MouseDown)
        {
            HandleMsg = false;
            RaycastHit hit;
            Ray        ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);

            int terrainMask = LayerMask.NameToLayer("Terrain");
            int layerIndex  = 0;
            if (targetObject.TouchInTerrain(ray, out layerIndex))
            {
                targetObject.BrushTerrainBegin();

                if ((targetObject.brush.brushType) == TerrainBrush.BrushType.VIEW)
                {
                    targetObject.brush.Targetheight = layerIndex;
                    BrushOpactiy = layerIndex;
                }
                else if ((targetObject.brush.brushType) == TerrainBrush.BrushType.LOCK)
                {
                    targetObject.brush.Targetheight = layerIndex;
                    BrushOpactiy = layerIndex;
                    IsMouseDown  = true;
                }
                else
                {
                    IsMouseDown = true;
                }
            }
        }

        if (e.button == 0 && e.type == EventType.MouseDrag && IsMouseDown)
        {
            HandleMsg = true;
            RaycastHit hit;
            Ray        ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
            targetObject.BrushTerrain(ray);
            IsMouseDrage = true;
        }

        if (e.button == 0 && e.type == EventType.MouseUp)
        {
            IsMouseDown = false;
            if (IsMouseDrage)
            {
                targetObject.BrushTerrainEnd();
                IsMouseDrage = false;
            }
            HandleMsg = true;
        }

        /*if(e.control && e.keyCode == KeyCode.S)
         * {
         *  if(DataFile != null)
         *  {
         *      Debug.Log("Sava data");
         *      targetObject.saveData();
         *      EditorUtility.SetDirty(DataFile.objectReferenceValue);
         *  }
         *
         * }*/
        // ------------------------------
        // Your Custom OnGUI Logic
        // ------------------------------

        if (HandleMsg == true)
        {
            if (Event.current.type == EventType.MouseDown)
            {
                Event.current.Use();
            }
            if (Event.current.type == EventType.MouseMove)
            {
                Event.current.Use();
            }
        }
    }
コード例 #5
0
        void DuringSceneGUI(SceneView sceneView)
        {
            if (polygon.polyEditMode == PolyShape.PolyEditMode.None)
            {
                return;
            }

            if (polygon == null || Tools.current != Tool.None)
            {
                SetPolyEditMode(PolyShape.PolyEditMode.None);
                return;
            }

            if (m_LineMaterial != null)
            {
                m_LineMaterial.SetPass(0);
                Graphics.DrawMeshNow(m_LineMesh, polygon.transform.localToWorldMatrix, 0);
            }

            Event evt = Event.current;

            // used when finishing a loop by clicking the first created point
            if (m_NextMouseUpAdvancesMode && evt.type == EventType.MouseUp)
            {
                evt.Use();

                m_NextMouseUpAdvancesMode = false;

                if (SceneCameraIsAlignedWithPolyUp())
                {
                    SetPolyEditMode(PolyShape.PolyEditMode.Edit);
                }
                else
                {
                    SetPolyEditMode(PolyShape.PolyEditMode.Height);
                }
            }

            if (m_IsModifyingVertices && (
                    evt.type == EventType.MouseUp ||
                    evt.type == EventType.Ignore ||
                    evt.type == EventType.KeyDown ||
                    evt.type == EventType.KeyUp))
            {
                OnFinishVertexMovement();
            }

            DoExistingPointsGUI();

            if (evt.type == EventType.KeyDown)
            {
                HandleKeyEvent(evt);
            }

            if (EditorHandleUtility.SceneViewInUse(evt))
            {
                return;
            }

            m_ControlId = GUIUtility.GetControlID(FocusType.Passive);
            if (evt.type == EventType.Layout)
            {
                HandleUtility.AddDefaultControl(m_ControlId);
            }

            DoPointPlacement();
        }
コード例 #6
0
 public override void Init(IControl parent)
 {
     this.m_Captured         = false;
     this.m_UndoAdded        = false;
     this.m_CapturedHeight   = 0f;
     this.m_CaptureMouseYPos = 0f;
     parent.MouseDown       += delegate(object target, Event evt, TimelineWindow.TimelineState state)
     {
         TimelineTrackGUI timelineTrackGUI = target as TimelineTrackGUI;
         bool             result;
         if (timelineTrackGUI == null)
         {
             result = base.IgnoreEvent();
         }
         else
         {
             Rect rect = RectUtils.Encompass(timelineTrackGUI.headerBounds, timelineTrackGUI.boundingRect);
             rect.set_y(rect.get_yMax() - 5f);
             if (rect.Contains(evt.get_mousePosition()))
             {
                 this.m_Captured         = true;
                 this.m_CapturedHeight   = TimelineWindowViewPrefs.GetInlineCurveHeight(timelineTrackGUI.track);
                 this.m_CaptureMouseYPos = GUIUtility.GUIToScreenPoint(Event.get_current().get_mousePosition()).y;
                 state.captured.Add((IControl)target);
                 this.m_UndoAdded = false;
                 result           = base.ConsumeEvent();
             }
             else
             {
                 result = base.IgnoreEvent();
             }
         }
         return(result);
     };
     parent.MouseDrag += delegate(object target, Event evt, TimelineWindow.TimelineState state)
     {
         bool result;
         if (!this.m_Captured)
         {
             result = base.IgnoreEvent();
         }
         else
         {
             TimelineTrackGUI timelineTrackGUI = target as TimelineTrackGUI;
             if (timelineTrackGUI == null)
             {
                 result = base.IgnoreEvent();
             }
             else
             {
                 if (!this.m_UndoAdded)
                 {
                     TimelineUndo.PushUndo(timelineTrackGUI.track, "Set Track Height");
                     this.m_UndoAdded = true;
                 }
                 float num = this.m_CapturedHeight + (GUIUtility.GUIToScreenPoint(Event.get_current().get_mousePosition()).y - this.m_CaptureMouseYPos);
                 TimelineWindowViewPrefs.SetInlineCurveHeight(timelineTrackGUI.track, Mathf.Max(num, 60f));
                 state.GetWindow().treeView.CalculateRowRects();
                 result = base.ConsumeEvent();
             }
         }
         return(result);
     };
     parent.MouseUp += delegate(object target, Event evt, TimelineWindow.TimelineState state)
     {
         bool result;
         if (!this.m_Captured)
         {
             result = base.IgnoreEvent();
         }
         else
         {
             state.captured.Remove(target as IControl);
             this.m_Captured = false;
             result          = base.ConsumeEvent();
         }
         return(result);
     };
 }
コード例 #7
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        const float textWidthPercent  = 0.3f;
        const float textSpeedPercent  = 0.6f;
        const float textRemovePercent = 0.1f;

        Undo.RecordObject(property.serializedObject.targetObject, "name");

        // Using BeginProperty / EndProperty on the parent property means that
        // prefab override logic works on the entire property.
        EditorGUI.BeginProperty(position, label, property);

        // Draw label
        position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), new GUIContent("Speed lookup table"));

        // Don't make child fields be indented
        var indent = EditorGUI.indentLevel;

        EditorGUI.indentLevel = 0;

        HeightmapSpeedLookupTable propertyLut = (HeightmapSpeedLookupTable)fieldInfo.GetValue(property.serializedObject.targetObject);

        Rect rectNextKeyAdd   = new Rect(position.x + position.width * textWidthPercent, position.y + (propertyLut.Keys.Count) * lineHeight, position.width * (1.0f - textWidthPercent), lineHeight);
        Rect rectNextKeyInput = new Rect(position.x, position.y + (propertyLut.Keys.Count) * lineHeight, position.width * textWidthPercent, lineHeight);

        if (propertyLut.Keys.Count == 0)
        {
            Rect rectObjectInput = new Rect(position.x, position.y + 1 * lineHeight, position.width, lineHeight);

            TextAsset textAsset = (TextAsset)EditorGUI.ObjectField(rectObjectInput, "Speed lookup table json", null, typeof(TextAsset), false);
            if (textAsset != null)
            {
                propertyLut.Overwrite(textAsset.text);
            }
        }

        for (int i = 0; i < propertyLut.Keys.Count; i++)
        {
            Rect rectText      = new Rect(position.x, position.y + i * lineHeight, position.width * textWidthPercent, lineHeight);
            Rect rectSpeed     = new Rect(position.x + position.width * textWidthPercent, position.y + i * lineHeight, position.width * textSpeedPercent, lineHeight);
            Rect rectRemoveKey = new Rect(position.x + position.width * (textWidthPercent + textSpeedPercent), position.y + i * lineHeight, position.width * textRemovePercent, lineHeight);

            EditorGUI.LabelField(rectText, propertyLut.Keys[i].ToString());

            float val = EditorGUI.DelayedFloatField(rectSpeed, propertyLut[propertyLut.Keys[i]]);
            if (val != propertyLut[propertyLut.Keys[i]])
            {
                propertyLut[propertyLut.Keys[i]] = val;
            }

            if (!EditorGUI.Toggle(rectRemoveKey, true))
            {
                propertyLut.Remove(propertyLut.Keys[i]);
            }
        }

        EditorGUI.BeginChangeCheck();
        nextInd = EditorGUI.DelayedIntField(rectNextKeyInput, nextInd);
        if (EditorGUI.EndChangeCheck())
        {
            propertyLut[nextInd] = default;
        }

        EditorGUI.indentLevel = indent;

        EditorGUI.EndProperty();

        property.serializedObject.ApplyModifiedProperties();
    }
コード例 #8
0
        public static KeyCode KeyCodeField(Rect controlRect, KeyCode keyCode)
        {
            var controlID = GUIUtility.GetControlID(FocusType.Keyboard);

            var retVal = keyCode;

            var evt = Event.current;

            switch (evt.GetTypeForControl(controlID))
            {
            case EventType.Repaint:
            {
                var style = GUI.skin.GetStyle("TextField");
                if (style == GUIStyle.none)
                {
                    Debug.Log("GUI Style not found");
                }
                style.Draw(controlRect, new GUIContent(keyCode.ToString()), controlID);
                break;
            }

            case EventType.MouseDown:
            {
                if (controlRect.Contains(Event.current.mousePosition) && Event.current.button == 0 && GUIUtility.hotControl == 0)
                {
                    Debug.Log("mouse down event, control id: " + controlID + ", hot control: " + GUIUtility.hotControl);
                    GUIUtility.hotControl      = controlID;
                    GUIUtility.keyboardControl = controlID;
                    evt.Use();
                }
                break;
            }

            case EventType.MouseUp:
            {
                if (GUIUtility.hotControl == controlID)
                {
                    GUIUtility.hotControl = 0;
                    evt.Use();
                }
                break;
            }

            case EventType.KeyDown:
            {
                Debug.Log("key down, control id: " + controlID + ", hot control: " + GUIUtility.hotControl);
                if (GUIUtility.keyboardControl == controlID)
                {
                    Debug.Log("hotcontrol");
                    retVal = Event.current.keyCode;
                    GUIUtility.hotControl      = 0;
                    GUIUtility.keyboardControl = 0;
                    evt.Use();
                }
                break;
            }

            case EventType.KeyUp:
            {
                break;
            }
            }
            return(retVal);
        }
コード例 #9
0
    void OnSceneGUI()
    {
        var prefabType = PrefabUtility.GetPrefabType(target);

        if (prefabType == PrefabType.Prefab || prefabType == PrefabType.ModelPrefab)
        {
            return;
        }

        var edge = target as EdgeCollider2D;

        if (edge == null)
        {
            return;
        }
        int controlId = GUIUtility.GetControlID(FocusType.Passive);

        if (_isDrawing == true)
        {
            isManipulatingEdge = true;
            if (Event.current.type == EventType.MouseUp)
            {
                if (Event.current.button == 0)  // Left mouse button adds new vertex to the polygon.
                {
                    Utilities.PerformActionAtMouseWorldPosition((p) =>
                    {
                        if (BrushSettingsWindow.SnapToGrid == true)
                        {
                            p = Utilities.SnapToGrid(p, BrushSettingsWindow.GridSize);
                        }
                        if (_currentCreateVertex <= 1)  // Update first two vertices of edge - they are already created so no insert.
                        {
                            edge.UpdateVertexPosition(p, _currentCreateVertex);
                        }
                        else
                        {
                            edge.InsertVertex(p, true);
                        }
                        _currentCreateVertex++;
                        EditorUtility.SetDirty(target);
                    });
                }
                else if (Event.current.button == 1)  // Right mouse button stops drawing and closes the polygon.
                {
                    _isDrawing         = false;
                    isManipulatingEdge = false;
                    edge.UpdateCenter();
                    _currentCreateVertex = 0;
                }
            }
        }

        if (Selection.activeGameObject == edge.gameObject)
        {
            if (Event.current.type == EventType.MouseDown && Event.current.clickCount > 1)
            {
                Utilities.PerformActionAtMouseWorldPosition((p) =>
                {
                    edge.InsertVertex(p);
                    EditorUtility.SetDirty(target);
                });
            }
            if (Event.current.type == EventType.MouseMove && _isDrawing == false && Event.current.type != EventType.MouseDrag)
            {
                // Select vertex
                Utilities.PerformActionAtMouseWorldPosition(p => _selectedVertex = edge.TrySelectVertex(p));
                if (_selectedVertex >= 0)
                {
                    _selectedVertexStartPosition = edge.GetWorldPoint(edge.points[_selectedVertex]);
                    HandleUtility.Repaint();
                }
            }
        }

        if (_selectedVertex != -1 && Event.current.button == 1)
        {
            var deleteOption = new GUIContent();
            deleteOption.text = "Delete Vertex";
            EditorUtility.DisplayCustomMenu(new Rect(Event.current.mousePosition.x, Event.current.mousePosition.y, 0, 0), new GUIContent[] { deleteOption }, -1, (userData, options, selected) =>
            {
                switch (selected)
                {
                case 0:
                    if (edge.DeleteVertex(_selectedVertex) == false)
                    {
                        Undo.DestroyObjectImmediate(edge.gameObject);
                    }
                    break;

                default:
                    break;
                }
            }, null);
        }

        if (Event.current.type == EventType.keyDown && _isPressingKey == false)
        {
            _lastKey       = Event.current.keyCode;
            _isPressingKey = true;
        }
        if (Event.current.type == EventType.keyUp)
        {
            _lastKey       = KeyCode.None;
            _isPressingKey = false;
        }

        // Manipulate polygon vertices
        if (Event.current.type == EventType.MouseDrag && _selectedVertex != -1 && Event.current.button == 0)
        {
            // Update position of the selected vertex
            Utilities.PerformActionAtMouseWorldPosition((p) =>
            {
                if (BrushSettingsWindow.SnapToGrid == true)
                {
                    p = Utilities.SnapToGrid(p, BrushSettingsWindow.GridSize);
                }
                else if (_lastKey == KeyCode.V)     // Snap to vertex.
                {
                    p = Utilities.SnapToVertex(edge, p, 1.0f);
                }
                else if (Event.current.modifiers == EventModifiers.Shift)    // Align with axis when holding shift.
                {
                    p = Utilities.AlignWithAxis(p, _selectedVertexStartPosition);
                }
                else if (Event.current.modifiers == EventModifiers.Control)
                {
                    float xMove = EditorPrefs.GetFloat("MoveSnapX");
                    float yMove = EditorPrefs.GetFloat("MoveSnapY");
                    p           = Utilities.SnapToValues(p, _selectedVertexStartPosition, xMove, yMove);
                }
                edge.UpdateVertexPosition(p, _selectedVertex);
                HandleUtility.Repaint();
            });
        }

        if (Event.current.type == EventType.MouseUp && _selectedVertex != -1)
        {
            _selectedVertex = -1;
        }

        if (_selectedVertex != -1)
        {
            DefaultHandles.Hidden = true;
        }
        else
        {
            DefaultHandles.Hidden = false;
        }

        if ((Event.current.type == EventType.Layout && _isDrawing == true) || _selectedVertex != -1)
        {
            HandleUtility.AddDefaultControl(controlId);
        }
    }
コード例 #10
0
        protected override void OldOnGUI()
        {
            const float space               = 10;
            const float largeSpace          = 20;
            const float standardButtonWidth = 32;
            const float dropdownWidth       = 80;
            const float playPauseStopWidth  = 140;

            InitializeToolIcons();

            bool isOrWillEnterPlaymode = EditorApplication.isPlayingOrWillChangePlaymode;

            GUI.color = isOrWillEnterPlaymode ? HostView.kPlayModeDarken : Color.white;

            if (Event.current.type == EventType.Repaint)
            {
                Styles.appToolbar.Draw(new Rect(0, 0, position.width, position.height), false, false, false, false);
            }

            // Position left aligned controls controls - start from left to right.
            Rect pos = new Rect(0, 0, 0, 0);

            ReserveWidthRight(space, ref pos);

            ReserveWidthRight(standardButtonWidth * s_ShownToolIcons.Length, ref pos);
            DoToolButtons(EditorToolGUI.GetThickArea(pos));

            ReserveWidthRight(largeSpace, ref pos);

            int playModeControlsStart = Mathf.RoundToInt((position.width - playPauseStopWidth) / 2);

            pos.x    += pos.width;
            pos.width = (playModeControlsStart - pos.x) - largeSpace;
            DoToolSettings(EditorToolGUI.GetThickArea(pos));

            // Position centered controls.
            pos = new Rect(playModeControlsStart, 0, 240, 0);

            if (ModeService.HasCapability(ModeCapability.Playbar, true))
            {
                GUILayout.BeginArea(EditorToolGUI.GetThickArea(pos));
                GUILayout.BeginHorizontal();
                {
                    if (!ModeService.Execute("gui_playbar", isOrWillEnterPlaymode))
                    {
                        DoPlayButtons(isOrWillEnterPlaymode);
                    }
                }
                GUILayout.EndHorizontal();
                GUILayout.EndArea();
            }

            // Position right aligned controls controls - start from right to left.
            pos = new Rect(position.width, 0, 0, 0);

            // Right spacing side
            ReserveWidthLeft(space, ref pos);
            ReserveWidthLeft(dropdownWidth, ref pos);
            DoLayoutDropDown(EditorToolGUI.GetThinArea(pos));

            if (ModeService.HasCapability(ModeCapability.Layers, true))
            {
                ReserveWidthLeft(space, ref pos);
                ReserveWidthLeft(dropdownWidth, ref pos);
                DoLayersDropDown(EditorToolGUI.GetThinArea(pos));
            }

            if (Unity.MPE.ProcessService.level == Unity.MPE.ProcessLevel.UMP_MASTER)
            {
                ReserveWidthLeft(space, ref pos);

                ReserveWidthLeft(dropdownWidth, ref pos);
                if (EditorGUI.DropdownButton(EditorToolGUI.GetThinArea(pos), s_AccountContent, FocusType.Passive, Styles.dropdown))
                {
                    ShowUserMenu(EditorToolGUI.GetThinArea(pos));
                }

                ReserveWidthLeft(space, ref pos);

                ReserveWidthLeft(standardButtonWidth, ref pos);
                if (GUI.Button(EditorToolGUI.GetThinArea(pos), s_CloudIcon, Styles.command))
                {
                    UnityConnectServiceCollection.instance.ShowService(HubAccess.kServiceName, true, "cloud_icon"); // Should show hub when it's done
                }
            }

            foreach (SubToolbar subToolbar in s_SubToolbars)
            {
                ReserveWidthLeft(space, ref pos);
                ReserveWidthLeft(subToolbar.Width, ref pos);
                subToolbar.OnGUI(EditorToolGUI.GetThinArea(pos));
            }


            if (ModeService.modeCount > 1 && Unsupported.IsDeveloperBuild())
            {
                EditorGUI.BeginChangeCheck();
                ReserveWidthLeft(space, ref pos);
                ReserveWidthLeft(dropdownWidth, ref pos);
                var selectedModeIndex = EditorGUI.Popup(EditorToolGUI.GetThinArea(pos), ModeService.currentIndex, ModeService.modeNames, Styles.dropdown);
                if (EditorGUI.EndChangeCheck())
                {
                    EditorApplication.delayCall += () => ModeService.ChangeModeByIndex(selectedModeIndex);
                    GUIUtility.ExitGUI();
                }
            }

            EditorGUI.ShowRepaints();
            Highlighter.ControlHighlightGUI(this);
        }
コード例 #11
0
 //copy of CoreLightEditorUtilities
 static float SliderLineHandle(Vector3 position, Vector3 direction, float value)
 {
     return(SliderLineHandle(GUIUtility.GetControlID(FocusType.Passive), position, direction, value, ""));
 }
コード例 #12
0
        internal void OnGUI()
        {
            GUI.Label(new Rect(0, 0, position.width, position.height), GUIContent.none, "grey_border");
            GUILayout.Space(3);

            GUILayout.Label(Styles.header, EditorStyles.boldLabel);
            GUILayout.Space(4);

            GUILayout.BeginHorizontal();
            GUILayout.Label(Styles.nameLabel, GUILayout.Width(90f));
            m_Name = EditorGUILayout.TextField(m_Name);

            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label(Styles.gridLabel, GUILayout.Width(90f));
            EditorGUI.BeginChangeCheck();
            var newLayout = (Grid.CellLayout)EditorGUILayout.EnumPopup(m_Layout);

            if (EditorGUI.EndChangeCheck())
            {
                // Set useful user settings for certain layouts
                switch (newLayout)
                {
                case Grid.CellLayout.Rectangle:
                case Grid.CellLayout.Hexagon:
                {
                    m_CellSizing = GridPalette.CellSizing.Automatic;
                    m_CellSize   = new Vector3(1, 1, 0);
                    break;
                }

                case Grid.CellLayout.Isometric:
                case Grid.CellLayout.IsometricZAsY:
                {
                    m_CellSizing = GridPalette.CellSizing.Manual;
                    m_CellSize   = new Vector3(1, 0.5f, 1);
                    break;
                }
                }
                m_Layout = newLayout;
            }
            GUILayout.EndHorizontal();

            if (m_Layout == GridLayout.CellLayout.Hexagon)
            {
                GUILayout.BeginHorizontal();
                float oldLabelWidth = UnityEditor.EditorGUIUtility.labelWidth;
                EditorGUIUtility.labelWidth = 94;
                m_HexagonLayout             = EditorGUILayout.Popup(Styles.hexagonLabel, m_HexagonLayout, Styles.hexagonSwizzleTypeLabel);
                EditorGUIUtility.labelWidth = oldLabelWidth;
                GUILayout.EndHorizontal();
            }

            GUILayout.BeginHorizontal();
            GUILayout.Label(Styles.sizeLabel, GUILayout.Width(90f));
            m_CellSizing = (GridPalette.CellSizing)EditorGUILayout.EnumPopup(m_CellSizing);
            GUILayout.EndHorizontal();

            using (new EditorGUI.DisabledScope(m_CellSizing == GridPalette.CellSizing.Automatic))
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label(GUIContent.none, GUILayout.Width(90f));
                m_CellSize = EditorGUILayout.Vector3Field(GUIContent.none, m_CellSize);
                GUILayout.EndHorizontal();
            }

            GUILayout.FlexibleSpace();

            // Cancel, Ok
            GUILayout.BeginHorizontal();
            GUILayout.Space(10);
            if (GUILayout.Button(Styles.cancel))
            {
                Close();
            }

            using (new EditorGUI.DisabledScope(!Utils.Paths.IsValidAssetPath(m_Name)))
            {
                if (GUILayout.Button(Styles.ok))
                {
                    // case 1077362: Close window to prevent overlap with OS folder window when saving new palette asset
                    Close();

                    var swizzle = Grid.CellSwizzle.XYZ;
                    if (m_Layout == GridLayout.CellLayout.Hexagon)
                    {
                        swizzle = Styles.hexagonSwizzleTypeValue[m_HexagonLayout];
                    }

                    GameObject go = GridPaletteUtility.CreateNewPaletteNamed(m_Name, m_Layout, m_CellSizing, m_CellSize, swizzle);
                    if (go != null)
                    {
                        m_Owner.palette = go;
                        m_Owner.Repaint();
                    }

                    GUIUtility.ExitGUI();
                }
            }

            GUILayout.Space(10);
            GUILayout.EndHorizontal();
        }
コード例 #13
0
        /// <summary>
        /// Draws the property.
        /// </summary>
        protected override void DrawPropertyLayout(IPropertyValueEntry <TList> entry, GUIContent label)
        {
            var property    = entry.Property;
            var infoContext = property.Context.Get(this, "Context", (ListDrawerConfigInfo)null);
            var info        = infoContext.Value;

            bool isReadOnly = false;

            if (entry.TypeOfValue.IsArray == false)
            {
                for (int i = 0; i < entry.ValueCount; i++)
                {
                    if ((entry.WeakValues[i] as IList <TElement>).IsReadOnly)
                    {
                        isReadOnly = true;
                        break;
                    }
                }
            }

            if (info == null)
            {
                var customListDrawerOptions = property.Info.GetAttribute <ListDrawerSettingsAttribute>() ?? new ListDrawerSettingsAttribute();
                isReadOnly = entry.IsEditable == false || isReadOnly || customListDrawerOptions.IsReadOnlyHasValue && customListDrawerOptions.IsReadOnly;

                info = infoContext.Value = new ListDrawerConfigInfo()
                {
                    StartIndex              = 0,
                    Toggled                 = entry.Context.GetPersistent <bool>(this, "ListDrawerToggled", customListDrawerOptions.ExpandedHasValue ? customListDrawerOptions.Expanded : GeneralDrawerConfig.Instance.OpenListsByDefault),
                    RemoveAt                = -1,
                    label                   = new GUIContent(label == null || string.IsNullOrEmpty(label.text) ? property.ValueEntry.TypeOfValue.GetNiceName() : label.text, label == null ? string.Empty : label.tooltip),
                    ShowAllWhilePageing     = false,
                    EndIndex                = 0,
                    CustomListDrawerOptions = customListDrawerOptions,
                    IsReadOnly              = isReadOnly,
                    Draggable               = !isReadOnly && (!customListDrawerOptions.IsReadOnlyHasValue)
                };

                info.listConfig = GeneralDrawerConfig.Instance;
                info.property   = property;

                if (customListDrawerOptions.DraggableHasValue && !customListDrawerOptions.DraggableItems)
                {
                    info.Draggable = false;
                }

                if (info.CustomListDrawerOptions.OnBeginListElementGUI != null)
                {
                    string     errorMessage;
                    MemberInfo memberInfo = property.ParentType
                                            .FindMember()
                                            .IsMethod()
                                            .IsNamed(info.CustomListDrawerOptions.OnBeginListElementGUI)
                                            .HasParameters <int>()
                                            .ReturnsVoid()
                                            .GetMember <MethodInfo>(out errorMessage);

                    if (memberInfo == null || errorMessage != null)
                    {
                        Debug.LogError(errorMessage ?? "There should really be an error message here.");
                    }
                    else
                    {
                        info.OnBeginListElementGUI = EmitUtilities.CreateWeakInstanceMethodCaller <int>(memberInfo as MethodInfo);
                    }
                }

                if (info.CustomListDrawerOptions.OnEndListElementGUI != null)
                {
                    string     errorMessage;
                    MemberInfo memberInfo = property.ParentType
                                            .FindMember()
                                            .IsMethod()
                                            .IsNamed(info.CustomListDrawerOptions.OnEndListElementGUI)
                                            .HasParameters <int>()
                                            .ReturnsVoid()
                                            .GetMember <MethodInfo>(out errorMessage);

                    if (memberInfo == null || errorMessage != null)
                    {
                        Debug.LogError(errorMessage ?? "There should really be an error message here.");
                    }
                    else
                    {
                        info.OnEndListElementGUI = EmitUtilities.CreateWeakInstanceMethodCaller <int>(memberInfo as MethodInfo);
                    }
                }

                if (info.CustomListDrawerOptions.OnTitleBarGUI != null)
                {
                    string     errorMessage;
                    MemberInfo memberInfo = property.ParentType
                                            .FindMember()
                                            .IsMethod()
                                            .IsNamed(info.CustomListDrawerOptions.OnTitleBarGUI)
                                            .HasNoParameters()
                                            .ReturnsVoid()
                                            .GetMember <MethodInfo>(out errorMessage);

                    if (memberInfo == null || errorMessage != null)
                    {
                        Debug.LogError(errorMessage ?? "There should really be an error message here.");
                    }
                    else
                    {
                        info.OnTitleBarGUI = EmitUtilities.CreateWeakInstanceMethodCaller(memberInfo as MethodInfo);
                    }
                }

                if (info.CustomListDrawerOptions.ListElementLabelName != null)
                {
                    string     errorMessage;
                    MemberInfo memberInfo = typeof(TElement)
                                            .FindMember()
                                            .HasNoParameters()
                                            .IsNamed(info.CustomListDrawerOptions.ListElementLabelName)
                                            .HasReturnType <object>(true)
                                            .GetMember(out errorMessage);

                    if (memberInfo == null || errorMessage != null)
                    {
                        Debug.LogError(errorMessage ?? "There should really be an error message here.");
                    }
                    else
                    {
                        string methodSuffix = memberInfo as MethodInfo == null ? "" : "()";
                        info.GetListElementLabelText = DeepReflection.CreateWeakInstanceValueGetter(typeof(TElement), typeof(object), info.CustomListDrawerOptions.ListElementLabelName + methodSuffix);
                    }
                }

                if (info.CustomListDrawerOptions.CustomAddFunction != null)
                {
                    string     errorMessage;
                    MemberInfo memberInfo = property.ParentType
                                            .FindMember()
                                            .HasNoParameters()
                                            .IsNamed(info.CustomListDrawerOptions.CustomAddFunction)
                                            .IsInstance()
                                            .HasReturnType(typeof(TElement))
                                            .GetMember(out errorMessage);

                    if (memberInfo == null || errorMessage != null)
                    {
                        string errorMessage2;

                        memberInfo = property.ParentType
                                     .FindMember()
                                     .IsMethod()
                                     .HasNoParameters()
                                     .IsNamed(info.CustomListDrawerOptions.CustomAddFunction)
                                     .IsInstance()
                                     .ReturnsVoid()
                                     .GetMember(out errorMessage2);

                        if (memberInfo == null || errorMessage2 != null)
                        {
                            Debug.LogError(errorMessage + " - or - " + errorMessage2);
                        }
                        else
                        {
                            info.GetCustomAddFunctionVoid = EmitUtilities.CreateWeakInstanceMethodCaller(memberInfo as MethodInfo);
                        }
                    }
                    else
                    {
                        string methodSuffix = memberInfo as MethodInfo == null ? "" : "()";
                        info.GetCustomAddFunction = DeepReflection.CreateWeakInstanceValueGetter(
                            property.ParentType,
                            typeof(TElement),
                            info.CustomListDrawerOptions.CustomAddFunction + methodSuffix
                            );
                    }
                }
            }

            info.listConfig = GeneralDrawerConfig.Instance;
            info.property   = property;

            info.ListItemStyle.padding.left  = info.Draggable ? 25 : 7;
            info.ListItemStyle.padding.right = info.IsReadOnly ? 4 : 20;

            if (Event.current.type == EventType.Repaint)
            {
                info.DropZoneTopLeft = GUIUtility.GUIToScreenPoint(new Vector2(0, 0));
            }

            info.ListValueChanger = property.ValueEntry.GetListValueEntryChanger();
            info.Count            = property.Children.Count;
            info.IsEmpty          = property.Children.Count == 0;

            SirenixEditorGUI.BeginIndentedVertical(SirenixGUIStyles.PropertyPadding);
            this.BeginDropZone(info);
            {
                this.DrawToolbar(info);
                if (SirenixEditorGUI.BeginFadeGroup(UniqueDrawerKey.Create(property, this), info.Toggled.Value))
                {
                    GUIHelper.PushLabelWidth(EditorGUIUtility.labelWidth - info.ListItemStyle.padding.left);
                    this.DrawItems(info);
                    GUIHelper.PopLabelWidth();
                }
                SirenixEditorGUI.EndFadeGroup();
            }
            this.EndDropZone(info);
            SirenixEditorGUI.EndIndentedVertical();

            if (info.RemoveAt >= 0 && Event.current.type == EventType.Repaint)
            {
                info.ListValueChanger.RemoveListElementAt(info.RemoveAt, CHANGE_ID);

                info.RemoveAt = -1;
                GUIHelper.RequestRepaint();
            }

            if (info.ObjectPicker != null && info.ObjectPicker.IsReadyToClaim && Event.current.type == EventType.Repaint)
            {
                var value = info.ObjectPicker.ClaimObject();

                if (info.JumpToNextPageOnAdd)
                {
                    info.StartIndex = int.MaxValue;
                }

                object[] values = new object[info.ListValueChanger.ValueCount];

                values[0] = value;
                for (int j = 1; j < values.Length; j++)
                {
                    values[j] = SerializationUtility.CreateCopy(value);
                }

                info.ListValueChanger.AddListElement(values, CHANGE_ID);
            }
        }
コード例 #14
0
    /// <summary>
    /// AddPointモード時の動作
    /// </summary>
    private void AddPointState()
    {
        var e         = Event.current;
        var controlID = GUIUtility.GetControlID(FocusType.Passive);
        var arraySize = _points.arraySize;

        switch (e.GetTypeForControl(controlID))
        {
        case EventType.MouseDown:
            if (e.button != 0)
            {
                return;
            }

            GUIUtility.hotControl = controlID;
            Undo.RecordObject(_bezier, "Add BezierPoint");

            _bezier.AddPoint(HandleUtility.GUIPointToWorldRay(e.mousePosition).origin);
            _focusControl = _bezier.Points.Count - 2;
            _isClick      = true;

            e.Use();
            break;

        case EventType.MouseDrag:
            if (e.button != 0)
            {
                return;
            }

            GUIUtility.hotControl = controlID;
            var mousePoint = (Vector2)HandleUtility.GUIPointToWorldRay(e.mousePosition).origin;
            _points.GetArrayElementAtIndex(arraySize - 3).vector2Value = mousePoint;
            _points.GetArrayElementAtIndex(arraySize - 1).vector2Value = _points.GetArrayElementAtIndex(arraySize - 2).vector2Value * 2 - mousePoint;

            e.Use();
            break;

        case EventType.MouseUp:
            if (e.button != 0)
            {
                return;
            }
            _isClick = false;
            break;

        default: break;
        }

        if (arraySize > 1)
        {
            DrawTangentLine(
                _points.GetArrayElementAtIndex(arraySize - 3).vector2Value,
                _points.GetArrayElementAtIndex(arraySize - 2).vector2Value,
                _points.GetArrayElementAtIndex(arraySize - 1).vector2Value);
        }


        if (_isClick && arraySize > 4)
        {
            DrawTangentLine(
                _points.GetArrayElementAtIndex(arraySize - 6).vector2Value,
                _points.GetArrayElementAtIndex(arraySize - 5).vector2Value,
                _points.GetArrayElementAtIndex(arraySize - 4).vector2Value);
        }
    }
コード例 #15
0
        public void OnGUI()
        {
            base.ClearBackground();
            EditorGUIUtility.ResetGUIState();
            SplitView parent = base.parent as SplitView;

            if ((Event.current.type == EventType.Repaint) && (parent != null))
            {
                View child = this;
                while (parent != null)
                {
                    int controlID = parent.controlID;
                    if ((controlID == GUIUtility.hotControl) || (GUIUtility.hotControl == 0))
                    {
                        int num2 = parent.IndexOfChild(child);
                        if (parent.vertical)
                        {
                            if (num2 != 0)
                            {
                                EditorGUIUtility.AddCursorRect(new Rect(0f, 0f, base.position.width, 5f), MouseCursor.SplitResizeUpDown, controlID);
                            }
                            if (num2 != (parent.children.Length - 1))
                            {
                                EditorGUIUtility.AddCursorRect(new Rect(0f, base.position.height - 5f, base.position.width, 5f), MouseCursor.SplitResizeUpDown, controlID);
                            }
                        }
                        else
                        {
                            if (num2 != 0)
                            {
                                EditorGUIUtility.AddCursorRect(new Rect(0f, 0f, 5f, base.position.height), MouseCursor.SplitResizeLeftRight, controlID);
                            }
                            if (num2 != (parent.children.Length - 1))
                            {
                                EditorGUIUtility.AddCursorRect(new Rect(base.position.width - 5f, 0f, 5f, base.position.height), MouseCursor.SplitResizeLeftRight, controlID);
                            }
                        }
                    }
                    child  = parent;
                    parent = parent.parent as SplitView;
                }
                parent = base.parent as SplitView;
            }
            bool flag = false;

            if (base.window.mainView.GetType() != typeof(MainWindow))
            {
                flag = true;
                if (base.windowPosition.y == 0f)
                {
                    base.background = "dockareaStandalone";
                }
                else
                {
                    base.background = "dockarea";
                }
            }
            else
            {
                base.background = "dockarea";
            }
            if (parent != null)
            {
                Event event2;
                event2 = new Event(Event.current)
                {
                    mousePosition = event2.mousePosition + new Vector2(base.position.x, base.position.y)
                };
                parent.SplitGUI(event2);
                if (event2.type == EventType.Used)
                {
                    Event.current.Use();
                }
            }
            GUIStyle style    = "dockareaoverlay";
            Rect     position = base.background.margin.Remove(new Rect(0f, 0f, base.position.width, base.position.height));

            position.x = base.background.margin.left;
            position.y = base.background.margin.top;
            Rect  windowPosition = base.windowPosition;
            float num3           = 2f;

            if (windowPosition.x == 0f)
            {
                position.x     -= num3;
                position.width += num3;
            }
            if (windowPosition.xMax == base.window.position.width)
            {
                position.width += num3;
            }
            if (windowPosition.yMax == base.window.position.height)
            {
                position.height += !flag ? 2f : 2f;
            }
            GUI.Box(position, GUIContent.none, base.background);
            if (this.tabStyle == null)
            {
                this.tabStyle = "dragtab";
            }
            this.DragTab(new Rect(position.x + 1f, position.y, position.width - 40f, 17f), this.tabStyle);
            this.tabStyle = "dragtab";
            base.ShowGenericMenu();
            base.DoWindowDecorationStart();
            if (this.m_Panes.Count > 0)
            {
                if (this.m_Panes[this.selected] is GameView)
                {
                    GUI.Box(position, GUIContent.none, style);
                }
                BeginOffsetArea(new Rect(position.x + 2f, position.y + 17f, position.width - 4f, (position.height - 17f) - 2f), GUIContent.none, "TabWindowBackground");
                Vector2 vector = GUIUtility.GUIToScreenPoint(Vector2.zero);
                Rect    rect3  = base.borderSize.Remove(base.position);
                rect3.x = vector.x;
                rect3.y = vector.y;
                this.m_Panes[this.selected].m_Pos = rect3;
                EditorGUIUtility.ResetGUIState();
                try
                {
                    base.Invoke("OnGUI");
                }
                catch (TargetInvocationException exception)
                {
                    throw exception.InnerException;
                }
                EditorGUIUtility.ResetGUIState();
                if (((base.actualView != null) && (base.actualView.m_FadeoutTime != 0f)) && ((Event.current != null) && (Event.current.type == EventType.Repaint)))
                {
                    base.actualView.DrawNotification();
                }
                EndOffsetArea();
            }
            base.DoWindowDecorationEnd();
            GUI.Box(position, GUIContent.none, style);
            EditorGUI.ShowRepaints();
            Highlighter.ControlHighlightGUI(this);
        }
コード例 #16
0
        public bool DoGUI(bool hasFocus)
        {
            bool enabled = GUI.enabled;

            if (ASHistoryWindow.ms_Style == null)
            {
                ASHistoryWindow.ms_Style           = new ASHistoryWindow.Constants();
                ASHistoryWindow.ms_Style.entryEven = new GUIStyle(ASHistoryWindow.ms_Style.entryEven);
                ASHistoryWindow.ms_Style.entryEven.padding.left = 3;
                ASHistoryWindow.ms_Style.entryOdd = new GUIStyle(ASHistoryWindow.ms_Style.entryOdd);
                ASHistoryWindow.ms_Style.entryOdd.padding.left = 3;
                ASHistoryWindow.ms_Style.label                    = new GUIStyle(ASHistoryWindow.ms_Style.label);
                ASHistoryWindow.ms_Style.boldLabel                = new GUIStyle(ASHistoryWindow.ms_Style.boldLabel);
                ASHistoryWindow.ms_Style.label.padding.left       = 3;
                ASHistoryWindow.ms_Style.boldLabel.padding.left   = 3;
                ASHistoryWindow.ms_Style.boldLabel.padding.top    = 0;
                ASHistoryWindow.ms_Style.boldLabel.padding.bottom = 0;
                this.DoLocalSelectionChange();
            }
            EditorGUIUtility.SetIconSize(ASHistoryWindow.ms_IconSize);
            if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape)
            {
                this.CancelShowCustomDiff();
                Event.current.Use();
            }
            SplitterGUILayout.BeginHorizontalSplit(this.m_HorSplit, new GUILayoutOption[0]);
            GUILayout.BeginVertical(new GUILayoutOption[0]);
            Rect rect = GUILayoutUtility.GetRect(0f, 0f, new GUILayoutOption[]
            {
                GUILayout.ExpandWidth(true),
                GUILayout.ExpandHeight(true)
            });

            this.m_FileViewWin.DoGUI(this, rect, hasFocus);
            GUILayout.EndVertical();
            GUILayout.BeginVertical(new GUILayoutOption[0]);
            this.WebLikeHistory(hasFocus);
            GUILayout.EndVertical();
            SplitterGUILayout.EndHorizontalSplit();
            if (Event.current.type == EventType.Repaint)
            {
                Handles.color = Color.black;
                Handles.DrawLine(new Vector3((float)(this.m_HorSplit.realSizes[0] - 1), rect.y, 0f), new Vector3((float)(this.m_HorSplit.realSizes[0] - 1), rect.yMax, 0f));
                Handles.DrawLine(new Vector3(0f, rect.yMax, 0f), new Vector3((float)Screen.width, rect.yMax, 0f));
            }
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            GUI.enabled = (this.m_FileViewWin.SelType == ASHistoryFileView.SelectionType.DeletedItems && enabled);
            if (GUILayout.Button(EditorGUIUtility.TextContent("Recover"), ASHistoryWindow.ms_Style.button, new GUILayoutOption[0]))
            {
                this.m_FileViewWin.DoRecover();
            }
            GUILayout.FlexibleSpace();
            if (this.m_InRevisionSelectMode)
            {
                GUI.enabled = enabled;
                GUILayout.Label(EditorGUIUtility.TextContent("Select revision to compare to"), ASHistoryWindow.ms_Style.boldLabel, new GUILayoutOption[0]);
            }
            GUILayout.Space(10f);
            GUI.enabled = (this.IsComparableAssetSelected() && enabled);
            if (GUILayout.Button(EditorGUIUtility.TextContent("Compare to Local Version"), ASHistoryWindow.ms_Style.button, new GUILayoutOption[0]))
            {
                this.DoShowDiff(false, this.ChangeLogSelectionRev, -1);
                GUIUtility.ExitGUI();
            }
            GUI.enabled = (this.ChangeLogSelectionRev > 0 && this.m_ChangeLogSelectionGUID != string.Empty && enabled);
            if (GUILayout.Button(EditorGUIUtility.TextContent("Download Selected File"), ASHistoryWindow.ms_Style.button, new GUILayoutOption[0]))
            {
                this.DownloadFile();
            }
            GUILayout.Space(10f);
            GUI.enabled = (this.ChangeLogSelectionRev > 0 && enabled);
            if (GUILayout.Button((this.ChangeLogSelectionRev <= 0) ? "Revert Entire Project" : ("Revert Entire Project to " + this.ChangeLogSelectionRev), ASHistoryWindow.ms_Style.button, new GUILayoutOption[0]))
            {
                this.DoRevertProject();
            }
            GUI.enabled = enabled;
            GUILayout.EndHorizontal();
            GUILayout.Space(10f);
            if (!this.m_SplittersOk && Event.current.type == EventType.Repaint)
            {
                this.m_SplittersOk = true;
                HandleUtility.Repaint();
            }
            EditorGUIUtility.SetIconSize(Vector2.zero);
            return(true);
        }
コード例 #17
0
        void OnGUI()
        {
            Styles.Init();

            if (m_ConversionReadyState == ConversionReadyState.NoActionRequired ||
                m_ConversionReadyState == ConversionReadyState.ConversionRan)
            {
                if (!string.IsNullOrEmpty(m_ConversionLog))
                {
                    m_ConversionLogScroll = EditorGUILayout.BeginScrollView(m_ConversionLogScroll);
                    GUILayout.Label(m_ConversionLog, EditorStyles.wordWrappedLabel);
                    EditorGUILayout.EndScrollView();
                }
                else
                {
                    GUI.Label(new Rect(0, 0, position.width, position.height), "ProBuilder is up to date!",
                              EditorStyles.centeredGreyMiniLabel);

                    if (Event.current.type == EventType.ContextClick)
                    {
                        var menu = new GenericMenu();
                        menu.AddItem(new GUIContent("Find and replace deprecated Asset IDs"), false, () =>
                        {
                            var log = new StringBuilder();
                            RemapAssetIds(log);
                            Debug.Log(log);
                        });
                        menu.ShowAsContext();
                    }
                }
                return;
            }
            else if ((m_ConversionReadyState & ConversionReadyState.AssetStoreInstallFound) > 0)
            {
                GUILayout.Label("Obsolete Files to Delete", EditorStyles.boldLabel);

                m_AssetTreeRect = GUILayoutUtility.GetRect(position.width, 128, GUILayout.ExpandHeight(true));

                EditorGUI.BeginChangeCheck();

                DrawTreeSettings();

                m_AssetsToDeleteTreeView.OnGUI(m_AssetTreeRect);

                if (EditorGUI.EndChangeCheck())
                {
                    m_ConversionReadyState = GetReadyState();
                }
            }
            else if ((m_ConversionReadyState & ConversionReadyState.DeprecatedAssetIdsFound) > 0)
            {
                var deprecatedIdsRect = GUILayoutUtility.GetRect(position.width, 32, GUILayout.ExpandHeight(true));
                GUI.Label(deprecatedIdsRect, "References to old ProBuilder install found.\n\nProject is ready for conversion.",
                          EditorStyles.centeredGreyMiniLabel);
            }

            if ((m_ConversionReadyState & ConversionReadyState.SerializationError) > 0)
            {
                EditorGUILayout.HelpBox(
                    "Cannot update project with binary or mixed serialization.\n\nPlease swith to ForceText serialization to proceed (you may switch back to ForceBinary or Mixed after the conversion process).",
                    MessageType.Error);

                SerializationMode serializationMode = EditorSettings.serializationMode;

                EditorGUI.BeginChangeCheck();

                serializationMode = (SerializationMode)EditorGUILayout.EnumPopup("Serialization Mode", serializationMode);

                if (EditorGUI.EndChangeCheck())
                {
                    EditorSettings.serializationMode = serializationMode;
                    m_ConversionReadyState           = GetReadyState();
                }
            }

            if ((m_ConversionReadyState & ConversionReadyState.AssetStoreDeleteError) > 0)
            {
                EditorGUILayout.HelpBox(
                    "Cannot update project without removing ProBuilder/Classes and ProBuilder/Editor directories.", MessageType.Error);
            }

            if ((m_ConversionReadyState & ConversionReadyState.AssetStoreDeleteWarning) > 0)
            {
                EditorGUILayout.HelpBox(
                    "Some old ProBuilder files are not marked for deletion. This may cause errors after the conversion process is complete.\n\nTo clear this error use the settings icon to reset the Assets To Delete tree.",
                    MessageType.Warning);
            }

            GUI.enabled =
                (m_ConversionReadyState & (ConversionReadyState.AssetStoreDeleteError | ConversionReadyState.SerializationError)) ==
                ConversionReadyState.Ready;

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Convert to ProBuilder 4", Styles.convertButton))
            {
                DoConversion();
                GUIUtility.ExitGUI();
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            #if UNITY_2018_3_OR_NEWER
            GUILayout.Space(16);
            #endif
            GUI.enabled = true;
        }
コード例 #18
0
        private void DrawParentView(Rect r, ref ASHistoryWindow.GUIHistoryListItem item, int changesetIndex, bool hasFocus)
        {
            ParentViewState assets     = item.assets;
            GUIContent      gUIContent = new GUIContent();
            Texture2D       image      = EditorGUIUtility.FindTexture(EditorResourcesUtility.folderIconName);
            Event           current    = Event.current;

            hasFocus &= (this.m_HistoryControlID == GUIUtility.keyboardControl);
            r.height  = (float)this.m_RowHeight;
            r.y      += 3f;
            int num  = -1;
            int num2 = (item.collapsedItemCount == 0) ? item.totalLineCount : 4;

            num2 += item.startShowingFrom;
            for (int i = 0; i < assets.folders.Length; i++)
            {
                ParentViewFolder parentViewFolder = assets.folders[i];
                gUIContent.text  = parentViewFolder.name;
                gUIContent.image = image;
                num++;
                if (num == num2)
                {
                    break;
                }
                if (num >= item.startShowingFrom)
                {
                    GUIStyle label = ASHistoryWindow.ms_Style.label;
                    if (current.type == EventType.MouseDown && r.Contains(current.mousePosition))
                    {
                        if (this.ChangeLogSelectionRev == this.m_Changesets[changesetIndex].changeset && this.m_ChangeLogSelectionGUID == parentViewFolder.guid && EditorGUI.actionKey)
                        {
                            this.ClearItemSelection();
                        }
                        else
                        {
                            this.ChangeLogSelectionRev         = this.m_Changesets[changesetIndex].changeset;
                            this.m_ChangeLogSelectionGUID      = parentViewFolder.guid;
                            this.m_ChangeLogSelectionAssetName = parentViewFolder.name;
                            this.m_FolderSelected      = true;
                            this.m_AssetSelectionIndex = num;
                        }
                        this.m_ChangesetSelectionIndex = changesetIndex;
                        GUIUtility.keyboardControl     = this.m_HistoryControlID;
                        ((ASMainWindow)this.m_ParentWindow).m_SearchToShow = ASMainWindow.ShowSearchField.HistoryList;
                        if (current.clickCount == 2)
                        {
                            this.ShowAssetsHistory();
                            GUIUtility.ExitGUI();
                        }
                        else if (current.button == 1)
                        {
                            GUIUtility.hotControl = 0;
                            r = new Rect(current.mousePosition.x, current.mousePosition.y, 1f, 1f);
                            EditorUtility.DisplayCustomMenu(r, this.m_DropDownMenuItems, -1, new EditorUtility.SelectMenuItemFunction(this.ContextMenuClick), null);
                        }
                        this.DoScroll();
                        current.Use();
                    }
                    bool flag = this.ChangeLogSelectionRev == this.m_Changesets[changesetIndex].changeset && this.m_ChangeLogSelectionGUID == parentViewFolder.guid;
                    if (item.boldAssets[num] && !flag)
                    {
                        GUI.Label(r, string.Empty, ASHistoryWindow.ms_Style.ping);
                    }
                    if (Event.current.type == EventType.Repaint)
                    {
                        label.Draw(r, gUIContent, false, false, flag, hasFocus);
                        this.DrawBadge(r, parentViewFolder.changeFlags, label, gUIContent, GUIClip.visibleRect.width - 150f);
                    }
                    r.y += (float)this.m_RowHeight;
                }
                ASHistoryWindow.ms_Style.label.padding.left     += 16;
                ASHistoryWindow.ms_Style.boldLabel.padding.left += 16;
                try
                {
                    for (int j = 0; j < parentViewFolder.files.Length; j++)
                    {
                        num++;
                        if (num == num2)
                        {
                            break;
                        }
                        if (num >= item.startShowingFrom)
                        {
                            GUIStyle label = ASHistoryWindow.ms_Style.label;
                            if (current.type == EventType.MouseDown && r.Contains(current.mousePosition))
                            {
                                if (this.ChangeLogSelectionRev == this.m_Changesets[changesetIndex].changeset && this.m_ChangeLogSelectionGUID == parentViewFolder.files[j].guid && EditorGUI.actionKey)
                                {
                                    this.ClearItemSelection();
                                }
                                else
                                {
                                    this.ChangeLogSelectionRev         = this.m_Changesets[changesetIndex].changeset;
                                    this.m_ChangeLogSelectionGUID      = parentViewFolder.files[j].guid;
                                    this.m_ChangeLogSelectionAssetName = parentViewFolder.files[j].name;
                                    this.m_FolderSelected      = false;
                                    this.m_AssetSelectionIndex = num;
                                }
                                this.m_ChangesetSelectionIndex = changesetIndex;
                                GUIUtility.keyboardControl     = this.m_HistoryControlID;
                                ((ASMainWindow)this.m_ParentWindow).m_SearchToShow = ASMainWindow.ShowSearchField.HistoryList;
                                if (current.clickCount == 2)
                                {
                                    if (this.IsComparableAssetSelected() && this.m_SelectedGUID == this.m_ChangeLogSelectionGUID)
                                    {
                                        this.DoShowDiff(false, this.ChangeLogSelectionRev, -1);
                                    }
                                    else
                                    {
                                        this.ShowAssetsHistory();
                                        GUIUtility.ExitGUI();
                                    }
                                }
                                else if (current.button == 1)
                                {
                                    GUIUtility.hotControl = 0;
                                    r = new Rect(current.mousePosition.x, current.mousePosition.y, 1f, 1f);
                                    EditorUtility.DisplayCustomMenu(r, this.m_DropDownMenuItems, -1, new EditorUtility.SelectMenuItemFunction(this.ContextMenuClick), null);
                                }
                                this.DoScroll();
                                current.Use();
                            }
                            gUIContent.text  = parentViewFolder.files[j].name;
                            gUIContent.image = InternalEditorUtility.GetIconForFile(parentViewFolder.files[j].name);
                            bool flag2 = this.ChangeLogSelectionRev == this.m_Changesets[changesetIndex].changeset && this.m_ChangeLogSelectionGUID == parentViewFolder.files[j].guid;
                            if (item.boldAssets[num] && !flag2)
                            {
                                GUI.Label(r, string.Empty, ASHistoryWindow.ms_Style.ping);
                            }
                            if (Event.current.type == EventType.Repaint)
                            {
                                label.Draw(r, gUIContent, false, false, flag2, hasFocus);
                                this.DrawBadge(r, parentViewFolder.files[j].changeFlags, label, gUIContent, GUIClip.visibleRect.width - 150f);
                            }
                            r.y += (float)this.m_RowHeight;
                        }
                    }
                    if (num == num2)
                    {
                        break;
                    }
                }
                finally
                {
                    ASHistoryWindow.ms_Style.label.padding.left     -= 16;
                    ASHistoryWindow.ms_Style.boldLabel.padding.left -= 16;
                }
            }
            if ((num == num2 || num2 >= item.totalLineCount) && item.collapsedItemCount != 0)
            {
                r.x += 19f;
                if (GUI.Button(r, item.collapsedItemCount.ToString() + " more...", ASHistoryWindow.ms_Style.foldout))
                {
                    GUIUtility.keyboardControl = this.m_HistoryControlID;
                    this.UncollapseListItem(ref item);
                }
            }
        }
コード例 #19
0
 protected void RunTestsInPlayer(TestRunnerFilter filter)
 {
     new PlayerLauncher(PlaymodeTestsControllerSettings.CreateRunnerSettings(filter)).Run();
     GUIUtility.ExitGUI();
 }
コード例 #20
0
        private void WebLikeHistory(bool hasFocus)
        {
            if (this.m_Changesets == null)
            {
                this.m_Changesets = new Changeset[0];
            }
            if (this.m_GUIItems == null)
            {
                return;
            }
            this.m_HistoryControlID = GUIUtility.GetControlID(ASHistoryWindow.ms_HistoryControlHash, FocusType.Native);
            this.HandleWebLikeKeyboard();
            Event     current        = Event.current;
            EventType typeForControl = current.GetTypeForControl(this.m_HistoryControlID);

            if (typeForControl == EventType.ValidateCommand)
            {
                current.Use();
                return;
            }
            GUILayout.Space(1f);
            this.m_ScrollPos = GUILayout.BeginScrollView(this.m_ScrollPos, new GUILayoutOption[0]);
            int num = 0;

            GUILayoutUtility.GetRect(1f, (float)(this.m_TotalHeight - 1));
            if ((current.type == EventType.Repaint || current.type == EventType.MouseDown || current.type == EventType.MouseUp) && this.m_GUIItems != null)
            {
                for (int i = 0; i < this.m_Changesets.Length; i++)
                {
                    if (this.m_GUIItems[i].inFilter)
                    {
                        if ((float)(num + this.m_GUIItems[i].height) > GUIClip.visibleRect.y && (float)num < GUIClip.visibleRect.yMax)
                        {
                            float num2 = ASHistoryWindow.ms_Style.descriptionLabel.CalcHeight(this.m_GUIItems[i].colDescription, 3.40282347E+38f);
                            Rect  rect;
                            if (current.type == EventType.Repaint)
                            {
                                if (this.ChangeLogSelectionRev == this.m_Changesets[i].changeset && Event.current.type == EventType.Repaint)
                                {
                                    rect = new Rect(0f, (float)num, GUIClip.visibleRect.width, (float)(this.m_GUIItems[i].height - 10));
                                    ASHistoryWindow.ms_Style.selected.Draw(rect, false, false, false, false);
                                }
                                rect = new Rect(0f, (float)(num + 3), GUIClip.visibleRect.width, (float)this.m_GUIItems[i].height);
                                GUI.Label(rect, this.m_GUIItems[i].colAuthor, ASHistoryWindow.ms_Style.boldLabel);
                                rect = new Rect(GUIClip.visibleRect.width - 160f, (float)(num + 3), 60f, (float)this.m_GUIItems[i].height);
                                GUI.Label(rect, this.m_GUIItems[i].colRevision, ASHistoryWindow.ms_Style.boldLabel);
                                rect.x    += 60f;
                                rect.width = 100f;
                                GUI.Label(rect, this.m_GUIItems[i].colDate, ASHistoryWindow.ms_Style.boldLabel);
                                rect.x      = (float)ASHistoryWindow.ms_Style.boldLabel.margin.left;
                                rect.y     += (float)this.m_RowHeight;
                                rect.width  = GUIClip.visibleRect.width;
                                rect.height = num2;
                                GUI.Label(rect, this.m_GUIItems[i].colDescription, ASHistoryWindow.ms_Style.descriptionLabel);
                                rect.y += num2;
                            }
                            rect = new Rect(0f, (float)num + num2 + (float)this.m_RowHeight, GUIClip.visibleRect.width, (float)this.m_GUIItems[i].height - num2 - (float)this.m_RowHeight);
                            this.DrawParentView(rect, ref this.m_GUIItems[i], i, hasFocus);
                            if (current.type == EventType.MouseDown)
                            {
                                rect = new Rect(0f, (float)num, GUIClip.visibleRect.width, (float)(this.m_GUIItems[i].height - 10));
                                if (rect.Contains(current.mousePosition))
                                {
                                    this.ChangeLogSelectionRev     = this.m_Changesets[i].changeset;
                                    this.m_ChangesetSelectionIndex = i;
                                    GUIUtility.keyboardControl     = this.m_HistoryControlID;
                                    ((ASMainWindow)this.m_ParentWindow).m_SearchToShow = ASMainWindow.ShowSearchField.HistoryList;
                                    if (current.button == 1)
                                    {
                                        GUIUtility.hotControl = 0;
                                        rect = new Rect(current.mousePosition.x, current.mousePosition.y, 1f, 1f);
                                        EditorUtility.DisplayCustomMenu(rect, this.m_DropDownChangesetMenuItems, -1, new EditorUtility.SelectMenuItemFunction(this.ChangesetContextMenuClick), null);
                                        Event.current.Use();
                                    }
                                    this.DoScroll();
                                    current.Use();
                                }
                            }
                        }
                        num += this.m_GUIItems[i].height;
                    }
                }
            }
            else if (this.m_GUIItems == null)
            {
                GUILayout.Label(EditorGUIUtility.TextContent("This item is not yet committed to the Asset Server"), new GUILayoutOption[0]);
            }
            if (Event.current.type == EventType.Repaint)
            {
                this.m_ScrollViewHeight = (int)GUIClip.visibleRect.height;
            }
            GUILayout.EndScrollView();
        }
コード例 #21
0
        private void OnGUI()
        {
            EditorGUIUtility.labelWidth = 150f;
            GUILayout.Label(this.m_HelpString, EditorStyles.wordWrappedLabel, new GUILayoutOption[1]
            {
                GUILayout.ExpandHeight(true)
            });
            this.m_ScrollPosition = EditorGUILayout.BeginVerticalScrollView(this.m_ScrollPosition, false, GUI.skin.verticalScrollbar, (GUIStyle)"OL Box");
            GUIUtility.GetControlID(645789, FocusType.Passive);
            bool flag = this.DrawWizardGUI();

            EditorGUILayout.EndScrollView();
            GUILayout.BeginVertical();
            if (this.m_ErrorString != string.Empty)
            {
                GUILayout.Label(this.m_ErrorString, (GUIStyle)ScriptableWizard.Styles.errorText, new GUILayoutOption[1]
                {
                    GUILayout.MinHeight(32f)
                });
            }
            else
            {
                GUILayout.Label(string.Empty, new GUILayoutOption[1]
                {
                    GUILayout.MinHeight(32f)
                });
            }
            GUILayout.FlexibleSpace();
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            GUI.enabled = this.m_IsValid;
            if (this.m_OtherButton != string.Empty)
            {
                if (GUILayout.Button(this.m_OtherButton, new GUILayoutOption[1]
                {
                    GUILayout.MinWidth(100f)
                }))
                {
                    MethodInfo method = this.GetType().GetMethod("OnWizardOtherButton", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
                    if (method != null)
                    {
                        method.Invoke((object)this, (object[])null);
                        GUIUtility.ExitGUI();
                    }
                    else
                    {
                        Debug.LogError((object)"OnWizardOtherButton has not been implemented in script");
                    }
                }
            }
            if (this.m_CreateButton != string.Empty)
            {
                if (GUILayout.Button(this.m_CreateButton, new GUILayoutOption[1]
                {
                    GUILayout.MinWidth(100f)
                }))
                {
                    MethodInfo method = this.GetType().GetMethod("OnWizardCreate", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
                    if (method != null)
                    {
                        method.Invoke((object)this, (object[])null);
                    }
                    else
                    {
                        Debug.LogError((object)"OnWizardCreate has not been implemented in script");
                    }
                    this.Close();
                    GUIUtility.ExitGUI();
                }
            }
            GUI.enabled = true;
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
            if (!flag)
            {
                return;
            }
            this.InvokeWizardUpdate();
        }
コード例 #22
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && position.Contains(Event.current.mousePosition))
            {
                property.isExpanded = !property.isExpanded;
            }

            if (Event.current.type == EventType.MouseDown && Event.current.button == 1 && position.Contains(Event.current.mousePosition))
            {
                activeProperty = property;
                var context = new GenericMenu();
                context.AddItem(new GUIContent("Save current values"), false, SaveCurrentTransformValues);
                context.AddItem(new GUIContent("Apply to Transform"), false, ApplyToTransform);
                context.ShowAsContext();
            }

            EditorGUI.BeginProperty(position, label, property);

            position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);

            var indent = EditorGUI.indentLevel;

            EditorGUI.indentLevel = 0;

            if (property.isExpanded)
            {
                const int firstLabelWidth  = 50;
                const int secondLabelWidth = 30;
                const int labelsWidth      = firstLabelWidth + secondLabelWidth;
                var       remainingWidth   = position.width - (firstLabelWidth + secondLabelWidth);

                var h = EditorGUIUtility.singleLineHeight;
                EditorGUI.LabelField(new Rect(position.x, position.y, firstLabelWidth, h), "Anchor", new GUIStyle {
                    alignment = TextAnchor.MiddleLeft
                });
                EditorGUI.LabelField(new Rect(position.x + firstLabelWidth, position.y, secondLabelWidth, h), "Min", new GUIStyle {
                    alignment = TextAnchor.MiddleLeft
                });
                EditorGUI.LabelField(new Rect(position.x + firstLabelWidth, position.y + h, secondLabelWidth, h), "Max", new GUIStyle {
                    alignment = TextAnchor.MiddleLeft
                });
                EditorGUI.LabelField(new Rect(position.x, position.y + 2 * h, firstLabelWidth, h), "Offset", new GUIStyle {
                    alignment = TextAnchor.MiddleLeft
                });
                EditorGUI.LabelField(new Rect(position.x + firstLabelWidth, position.y + 2 * h, secondLabelWidth, h), "Min", new GUIStyle {
                    alignment = TextAnchor.MiddleLeft
                });
                EditorGUI.LabelField(new Rect(position.x + firstLabelWidth, position.y + 3 * h, secondLabelWidth, h), "Max", new GUIStyle {
                    alignment = TextAnchor.MiddleLeft
                });

                EditorGUI.PropertyField(new Rect(position.x + labelsWidth, position.y, remainingWidth, position.height), property.FindPropertyRelative("_anchorMin"), GUIContent.none);
                EditorGUI.PropertyField(new Rect(position.x + labelsWidth, position.y + h, remainingWidth, position.height), property.FindPropertyRelative("_anchorMax"), GUIContent.none);
                EditorGUI.PropertyField(new Rect(position.x + labelsWidth, position.y + 2 * h, remainingWidth, position.height), property.FindPropertyRelative("_offsetMin"), GUIContent.none);
                EditorGUI.PropertyField(new Rect(position.x + labelsWidth, position.y + 3 * h, remainingWidth, position.height), property.FindPropertyRelative("_offsetMax"), GUIContent.none);
            }
            else
            {
                EditorGUI.LabelField(position, "<Click for detail>", new GUIStyle {
                    alignment = TextAnchor.MiddleLeft
                });
            }

            EditorGUI.indentLevel = indent;
            EditorGUI.EndProperty();
        }
コード例 #23
0
        private void DragTitleBar(Rect titleBarRect)
        {
            int   id  = GUIUtility.GetControlID(FocusType.Passive);
            Event evt = Event.current;

            switch (evt.GetTypeForControl(id))
            {
            case EventType.Repaint:
                if (m_DraggingNativeTitleBarCaption)
                {
                    m_DraggingNativeTitleBarCaption = false;
                }
                EditorGUIUtility.AddCursorRect(titleBarRect, MouseCursor.Arrow);
                break;

            case EventType.MouseDown:
                // If the mouse is inside the title bar rect, we say that we're the hot control
                if (titleBarRect.Contains(evt.mousePosition) && GUIUtility.hotControl == 0 && evt.button == 0)
                {
                    if (Application.platform == RuntimePlatform.WindowsEditor)
                    {
                        Event.current.Use();
                        m_DraggingNativeTitleBarCaption = true;
                        SendCaptionEvent(m_DraggingNativeTitleBarCaption);
                    }
                    else
                    {
                        GUIUtility.hotControl = id;
                        Event.current.Use();
                        s_LastDragMousePos = evt.mousePosition;
                        startDragDpi       = GUIUtility.pixelsPerPoint;
                        Unsupported.SetAllowCursorLock(false, Unsupported.DisallowCursorLockReasons.SizeMove);
                    }
                }
                break;

            case EventType.MouseUp:
                if (m_DraggingNativeTitleBarCaption)
                {
                    break;
                }

                if (GUIUtility.hotControl == id)
                {
                    GUIUtility.hotControl = 0;
                    Event.current.Use();
                    Unsupported.SetAllowCursorLock(true, Unsupported.DisallowCursorLockReasons.SizeMove);
                }
                break;

            case EventType.MouseDrag:
                if (m_DraggingNativeTitleBarCaption)
                {
                    break;
                }

                if (GUIUtility.hotControl == id)
                {
                    Vector2 mousePos = evt.mousePosition;
                    if (startDragDpi != GUIUtility.pixelsPerPoint)
                    {
                        // We ignore this mouse event when changing screens in multi monitor setups with
                        // different dpi scalings as funky things might/will happen
                        startDragDpi       = GUIUtility.pixelsPerPoint;
                        s_LastDragMousePos = mousePos;
                    }
                    else
                    {
                        Vector2 movement = mousePos - s_LastDragMousePos;

                        float minimumDelta = 1.0f / GUIUtility.pixelsPerPoint;

                        if (Mathf.Abs(movement.x) >= minimumDelta || Mathf.Abs(movement.y) >= minimumDelta)
                        {
                            Rect dragPosition = position;
                            dragPosition.x += movement.x;
                            dragPosition.y += movement.y;
                            position        = dragPosition;

                            GUI.changed = true;
                        }
                    }
                }
                break;
            }
        }
コード例 #24
0
        void OnSceneGUI(SceneView sceneView)
        {
            ProcessInputs();

            if (m_CurrentState == EF_VTXPainterState.Painting || m_CurrentState == EF_VTXPainterState.Sculpting)
            {
                //Raycast into the scene and see if we are hitting anything
                Ray worldRay = HandleUtility.GUIPointToWorldRay(m_MouseData.mousePos);
                if (!Physics.Raycast(worldRay, out m_CurHit, float.MaxValue))
                {
                    m_CurrentGO   = null;
                    m_CurrentMesh = null;
                    return;
                }
                m_CurrentGO = m_CurHit.transform.gameObject;

                //Show the Brush
                if (m_CurHit.transform != null)
                {
                    if (m_CurrentState == EF_VTXPainterState.Painting)
                    {
                        Handles.color = m_BrushData.brushColor;
                    }

                    if (m_CurrentState == EF_VTXPainterState.Sculpting)
                    {
                        Handles.color = Color.red;
                    }
                    Handles.DrawWireDisc(m_CurHit.point, m_CurHit.normal, m_BrushData.falloffSize);
                    Handles.DrawWireDisc(m_CurHit.point, m_CurHit.normal, m_BrushData.brushSize);

                    Handles.color = new Color(Handles.color.r, Handles.color.g, Handles.color.b, m_BrushData.opacity);
                    Handles.DrawSolidDisc(m_CurHit.point, m_CurHit.normal, m_BrushData.brushSize);
                }

                //Get the Mesh only if its different than what is in the current it object
                if (m_CurHit.transform.GetInstanceID() != m_CurrentGO.GetInstanceID())
                {
                    m_CurrentMesh = EF_VertexPainter_Utils.GetMesh(m_CurrentGO);
                }

                //Set Scene View to passive so we can paint without selecting anything
                Tools.current = Tool.None;
                HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive));
            }

            //Handle the Functions of the brush
            if (m_MouseData.leftClickHold)
            {
                EF_VertexPainter_Utils.HandleBrush(m_CurrentGO, m_CurrentMesh, m_CurHit.point, m_BrushData, m_CurrentState);
                if (m_CurrentMesh)
                {
                    EditorUtility.SetDirty(m_CurrentMesh);
                }
                m_WasPainting = true;
            }
            else
            {
                if (m_WasPainting && m_CurrentGO)
                {
                    MeshCollider curCollider = m_CurrentGO.GetComponent <MeshCollider>();
                    if (curCollider)
                    {
                        curCollider.convex = true;
                        curCollider.convex = false;
                    }

                    m_WasPainting = false;
                }
            }


            //Update the Scene View
            sceneView.Repaint();
        }
コード例 #25
0
        private void Buttons()
        {
            bool enabled = GUI.enabled;

            GUI.enabled &= !EditorApplication.isPlayingOrWillChangePlaymode;
            if (Lightmapping.lightingDataAsset && !Lightmapping.lightingDataAsset.isValid)
            {
                EditorGUILayout.HelpBox(Lightmapping.lightingDataAsset.validityErrorMessage, MessageType.Warning);
            }
            EditorGUILayout.Space();
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            GUILayout.FlexibleSpace();
            Rect rect = GUILayoutUtility.GetRect(LightingWindow.Styles.ContinuousBakeLabel, GUIStyle.none);

            EditorGUI.BeginProperty(rect, LightingWindow.Styles.ContinuousBakeLabel, this.m_WorkflowMode);
            bool flag = this.m_WorkflowMode.intValue == 0;

            EditorGUI.BeginChangeCheck();
            flag = GUILayout.Toggle(flag, LightingWindow.Styles.ContinuousBakeLabel, new GUILayoutOption[0]);
            if (EditorGUI.EndChangeCheck())
            {
                this.m_WorkflowMode.intValue = ((!flag) ? 1 : 0);
            }
            EditorGUI.EndProperty();
            using (new EditorGUI.DisabledScope(flag))
            {
                bool flag2 = flag || !Lightmapping.isRunning;
                if (flag2)
                {
                    if (EditorGUI.ButtonWithDropdownList(LightingWindow.Styles.BuildLabel, LightingWindow.s_BakeModeOptions, new GenericMenu.MenuFunction2(this.BakeDropDownCallback), new GUILayoutOption[]
                    {
                        GUILayout.Width(170f)
                    }))
                    {
                        this.DoBake();
                        GUIUtility.ExitGUI();
                    }
                }
                else
                {
                    if (LightmapEditorSettings.lightmapper == LightmapEditorSettings.Lightmapper.PathTracer && this.m_EnabledBakedGI.boolValue && GUILayout.Button("Force Stop", new GUILayoutOption[]
                    {
                        GUILayout.Width(150f)
                    }))
                    {
                        Lightmapping.ForceStop();
                    }
                    if (GUILayout.Button("Cancel", new GUILayoutOption[]
                    {
                        GUILayout.Width(150f)
                    }))
                    {
                        Lightmapping.Cancel();
                        UsabilityAnalytics.Track("/LightMapper/Cancel");
                    }
                }
            }
            GUILayout.EndHorizontal();
            EditorGUILayout.Space();
            GUI.enabled = enabled;
        }
コード例 #26
0
        // Draw the property inside the given rect
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            // Using BeginProperty / EndProperty on the parent property means that
            // prefab override logic works on the entire property.
            EditorGUI.BeginProperty(position, label, property);

            // Draw label
            position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), new GUIContent(property.displayName));

            // Don't make child fields be indented
            var indent = EditorGUI.indentLevel;

            EditorGUI.indentLevel = 0;

            // Caluculate rects
            var spacing       = 5.0f;
            var rectWidth     = Mathf.Round((position.width - spacing) * 0.5f);
            var enumTypeRect  = new Rect(position.x, position.y, rectWidth, position.height);
            var enumValueRect = new Rect(position.x + rectWidth + spacing, position.y, rectWidth, position.height);

            var roleTypeProp  = property.FindPropertyRelative("m_roleTypeFullName");
            var roleValueProp = property.FindPropertyRelative("m_roleValueName");

            var roleTypeName  = roleTypeProp.stringValue;
            var roleValueName = roleValueProp.stringValue;

            // find current role type / type index
            Type roleType;
            var  roleTypeIndex = ViveRoleEnum.ValidViveRoleTable.IndexOf(roleTypeName);

            if (roleTypeIndex < 0)
            {
                // name not found
                roleType      = defaultRoleType;
                roleTypeIndex = defaultRoleTypeIndex;
            }
            else
            {
                roleType = ViveRoleEnum.ValidViveRoleTable.GetValueByIndex(roleTypeIndex);
            }

            // find current role value index
            var roleTypeInfo   = ViveRoleEnum.GetInfo(roleType);
            var roleValueIndex = roleTypeInfo.GetElementIndexByName(roleValueName);

            if (roleValueIndex < 0)
            {
                roleValueIndex = roleTypeInfo.InvalidRoleValueIndex;
            }

            // draw pupup box, get new role type index / value index
            var newRoleTypeIndex  = EditorGUI.Popup(enumTypeRect, roleTypeIndex, roleTypeNames);
            var newRoleValueIndex = EditorGUI.Popup(enumValueRect, roleValueIndex, roleTypeInfo.RoleValueNames);

            // if new role index changed
            var newRoleType     = roleType;
            var newRoleTypeInfo = roleTypeInfo;

            if (newRoleTypeIndex != roleTypeIndex)
            {
                newRoleType              = ViveRoleEnum.ValidViveRoleTable.GetValueByIndex(newRoleTypeIndex);
                newRoleTypeInfo          = ViveRoleEnum.GetInfo(newRoleType);
                roleTypeProp.stringValue = ViveRoleEnum.ValidViveRoleTable.GetKeyByIndex(newRoleTypeIndex);
            }

            if (newRoleTypeIndex != roleTypeIndex || newRoleValueIndex != roleValueIndex)
            {
                if (newRoleValueIndex < 0 || newRoleValueIndex >= newRoleTypeInfo.ElementCount)
                {
                    newRoleValueIndex = newRoleTypeInfo.InvalidRoleValueIndex;
                }

                roleValueProp.stringValue = newRoleTypeInfo.GetNameByElementIndex(newRoleValueIndex);
            }

            property.serializedObject.ApplyModifiedProperties();

            // Set indent back to what it was
            EditorGUI.indentLevel = indent;

            EditorGUI.EndProperty();

            // update target
            if (newRoleTypeIndex != roleTypeIndex || newRoleValueIndex != roleValueIndex)
            {
                var target = GetTarget(fieldInfo, property);
                if (newRoleTypeIndex != roleTypeIndex)
                {
                    target.SetTypeDirty();
                }
                if (newRoleValueIndex != roleValueIndex)
                {
                    target.SetValueDirty();
                }
            }
        }
コード例 #27
0
        public static void PointDrawHandle(Rect dragArea, ref List <Vector3> points, out Matrix4x4 transformation, out ChiselModel modelBeneathCursor, bool releaseOnMouseUp = true, UnitySceneExtensions.SceneHandles.CapFunction capFunction = null)
        {
            var id = GUIUtility.GetControlID(s_PointDrawingHash, FocusType.Keyboard);

            PointDrawing.Do(id, dragArea, ref points, out transformation, out modelBeneathCursor, releaseOnMouseUp, capFunction);
        }
コード例 #28
0
        private void DragTab(Rect pos, GUIStyle tabStyle)
        {
            int   controlID = GUIUtility.GetControlID(FocusType.Passive);
            float tabWidth  = this.GetTabWidth(pos.width);
            Event current   = Event.current;

            if ((s_DragMode != 0) && (GUIUtility.hotControl == 0))
            {
                PaneDragTab.get.Close();
                ResetDragVars();
            }
            EventType typeForControl = current.GetTypeForControl(controlID);

            switch (typeForControl)
            {
            case EventType.MouseDown:
                if (pos.Contains(current.mousePosition) && (GUIUtility.hotControl == 0))
                {
                    int tabAtMousePos = this.GetTabAtMousePos(current.mousePosition, pos);
                    if (tabAtMousePos < this.m_Panes.Count)
                    {
                        switch (current.button)
                        {
                        case 0:
                            if (tabAtMousePos != this.selected)
                            {
                                this.selected = tabAtMousePos;
                            }
                            GUIUtility.hotControl = controlID;
                            s_StartDragPosition   = current.mousePosition;
                            s_DragMode            = 0;
                            current.Use();
                            break;

                        case 2:
                            this.m_Panes[tabAtMousePos].Close();
                            current.Use();
                            break;
                        }
                    }
                }
                goto Label_06B9;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == controlID)
                {
                    Vector2 vector3 = GUIUtility.GUIToScreenPoint(current.mousePosition);
                    if (s_DragMode != 0)
                    {
                        s_DragMode = 0;
                        PaneDragTab.get.Close();
                        EditorApplication.update = (EditorApplication.CallbackFunction)Delegate.Remove(EditorApplication.update, new EditorApplication.CallbackFunction(DockArea.CheckDragWindowExists));
                        if ((s_DropInfo == null) || (s_DropInfo.dropArea == null))
                        {
                            EditorWindow pane = s_DragPane;
                            ResetDragVars();
                            this.RemoveTab(pane);
                            Rect position = pane.position;
                            position.x = vector3.x - (position.width * 0.5f);
                            position.y = vector3.y - (position.height * 0.5f);
                            if (Application.platform == RuntimePlatform.WindowsEditor)
                            {
                                position.y = Mathf.Max(InternalEditorUtility.GetBoundsOfDesktopAtPoint(vector3).y, position.y);
                            }
                            EditorWindow.CreateNewWindowForEditorWindow(pane, false, false);
                            pane.position         = pane.m_Parent.window.FitWindowRectToScreen(position, true, true);
                            GUIUtility.hotControl = 0;
                            GUIUtility.ExitGUI();
                        }
                        else
                        {
                            s_DropInfo.dropArea.PerformDrop(s_DragPane, s_DropInfo, vector3);
                        }
                        ResetDragVars();
                    }
                    GUIUtility.hotControl = 0;
                    current.Use();
                }
                goto Label_06B9;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == controlID)
                {
                    Vector2 vector = current.mousePosition - s_StartDragPosition;
                    current.Use();
                    Rect screenPosition = base.screenPosition;
                    if ((s_DragMode == 0) && (vector.sqrMagnitude > 99f))
                    {
                        s_DragMode       = 1;
                        s_PlaceholderPos = this.selected;
                        s_DragPane       = this.m_Panes[this.selected];
                        if (this.m_Panes.Count != 1)
                        {
                            s_IgnoreDockingForView = null;
                        }
                        else
                        {
                            s_IgnoreDockingForView = this;
                        }
                        s_OriginalDragSource    = this;
                        PaneDragTab.get.content = s_DragPane.titleContent;
                        base.Internal_SetAsActiveWindow();
                        PaneDragTab.get.GrabThumbnail();
                        PaneDragTab.get.Show(new Rect((pos.x + screenPosition.x) + (tabWidth * this.selected), pos.y + screenPosition.y, tabWidth, pos.height), GUIUtility.GUIToScreenPoint(current.mousePosition));
                        EditorApplication.update = (EditorApplication.CallbackFunction)Delegate.Combine(EditorApplication.update, new EditorApplication.CallbackFunction(DockArea.CheckDragWindowExists));
                        GUIUtility.ExitGUI();
                    }
                    if (s_DragMode == 1)
                    {
                        DropInfo          di        = null;
                        ContainerWindow[] windows   = ContainerWindow.windows;
                        Vector2           screenPos = GUIUtility.GUIToScreenPoint(current.mousePosition);
                        ContainerWindow   inFrontOf = null;
                        foreach (ContainerWindow window2 in windows)
                        {
                            foreach (View view in window2.mainView.allChildren)
                            {
                                IDropArea area = view as IDropArea;
                                if (area != null)
                                {
                                    di = area.DragOver(s_DragPane, screenPos);
                                }
                                if (di != null)
                                {
                                    break;
                                }
                            }
                            if (di != null)
                            {
                                inFrontOf = window2;
                                break;
                            }
                        }
                        if (di == null)
                        {
                            di = new DropInfo(null);
                        }
                        if (di.type != DropInfo.Type.Tab)
                        {
                            s_PlaceholderPos = -1;
                        }
                        s_DropInfo = di;
                        if (PaneDragTab.get.m_Window != null)
                        {
                            PaneDragTab.get.SetDropInfo(di, screenPos, inFrontOf);
                        }
                    }
                }
                goto Label_06B9;

            case EventType.Repaint:
            {
                float xMin = pos.xMin;
                int   num8 = 0;
                if (base.actualView == null)
                {
                    Rect  rect5 = new Rect(xMin, pos.yMin, tabWidth, pos.height);
                    float x     = Mathf.Round(rect5.x);
                    Rect  rect6 = new Rect(x, rect5.y, Mathf.Round(rect5.x + rect5.width) - x, rect5.height);
                    tabStyle.Draw(rect6, "Failed to load", false, false, true, false);
                }
                else
                {
                    for (int i = 0; i < this.m_Panes.Count; i++)
                    {
                        if (s_DragPane != this.m_Panes[i])
                        {
                            if (((s_DropInfo != null) && object.ReferenceEquals(s_DropInfo.dropArea, this)) && (s_PlaceholderPos == num8))
                            {
                                xMin += tabWidth;
                            }
                            Rect  rect3 = new Rect(xMin, pos.yMin, tabWidth, pos.height);
                            float num10 = Mathf.Round(rect3.x);
                            Rect  rect4 = new Rect(num10, rect3.y, Mathf.Round(rect3.x + rect3.width) - num10, rect3.height);
                            tabStyle.Draw(rect4, this.m_Panes[i].titleContent, false, false, i == this.selected, base.hasFocus);
                            xMin += tabWidth;
                            num8++;
                        }
                    }
                }
                goto Label_06B9;
            }
            }
            if ((typeForControl == EventType.ContextClick) && (pos.Contains(current.mousePosition) && (GUIUtility.hotControl == 0)))
            {
                int num4 = this.GetTabAtMousePos(current.mousePosition, pos);
                if (num4 < this.m_Panes.Count)
                {
                    base.PopupGenericMenu(this.m_Panes[num4], new Rect(current.mousePosition.x, current.mousePosition.y, 0f, 0f));
                }
            }
Label_06B9:
            this.selected = Mathf.Clamp(this.selected, 0, this.m_Panes.Count - 1);
        }
コード例 #29
0
        //Determines the current and max fuel (not oxidizer) of the active vessel, and the required needle position
        private void fuelStatus()
        {
            /*
             * double current = 0;
             * double max = 0;
             * Vessel active = FlightGlobals.ActiveVessel;
             * if (!stageFuel)     //Global calculation
             * {
             *  foreach (Part p in active.parts)
             *  {
             *      if (active.vesselType == VesselType.EVA)
             *      {
             *          foreach (PartModule PM in p.Modules)
             *          {
             *              if (PM is KerbalEVA)
             *              {
             *                  KerbalEVA eva = PM as KerbalEVA;
             *                  current = eva.Fuel;
             *                  max = eva.FuelCapacity;
             *                  break;
             *              }
             *          }
             *      }
             *      else
             *      {
             *          foreach (PartResource pr in p.Resources)
             *          {
             *              if (pr.resourceName.Equals("LiquidFuel"))
             *              {
             *                  current += pr.amount;
             *                  max += pr.maxAmount;
             *                  break;
             *              }
             *          }
             *      }
             *  }
             * }
             * else
             * {
             *  //Do crazy stage only calculations here
             *  int stage = active.currentStage;
             *  foreach (Part p in active.parts)
             *  {
             *      //Staging.CurrentStage
             *      //if (p.Resources.Contains("LiquidFuel"))
             *      //{
             *      foreach (PartResource pr in p.Resources)
             *      {
             *          if (pr.resourceName.Equals("LiquidFuel"))
             *          {
             *              current += pr.amount;
             *              max += pr.maxAmount;
             *              break;
             *          }
             *      }
             *      //}
             *  }
             * }
             * if (max == 0) max = 1;  //prevents divide by 0
             * //Should check for some kind of "OFF" flag for vessels w/no fuel
             * //print("Found " + electricCharge + "/" + electricMax + " charge.");
             * double percent = current / max;
             */
            double percent = 0;

            if (FlightGlobals.ActiveVessel.vesselType == VesselType.EVA)
            {
                percent = SteamShip.EVAFuelPercent;
            }
            else
            {
                percent = SteamShip.FuelPercent;
            }
            //double percent = SteamShip.liquidFuel / SteamShip.liquidMax;
            //Status light
            if (percent <= fuel_red_cutoff)   //these values are pulled from the config file
            {
                GUI.DrawTextureWithTexCoords(new Rect(60f * Scale, 133f * Scale, 15 * Scale, 15 * Scale), texture, new Rect(0.6775f, 0.3443f, 0.01875f, 0.0214f));
                //GUI.DrawTexture(new Rect(0f, 0f, Resources.fuel_red.width * Scale, Resources.fuel_red .height*Scale), Resources.fuel_red);
            }
            else if (percent <= fuel_yellow_cutoff)
            {
                GUI.DrawTextureWithTexCoords(new Rect(62f * Scale, 134f * Scale, 15 * Scale, 15 * Scale), texture, new Rect(0.615f, 0.3443f, 0.01875f, 0.0214f));
                //GUI.DrawTexture(new Rect(0f, 0f, Resources.fuel_yellow.width * Scale, Resources.fuel_yellow .height*Scale), Resources.fuel_yellow);
            }
            else if (percent <= fuel_green_cutoff)
            {
                GUI.DrawTextureWithTexCoords(new Rect(62f * Scale, 134f * Scale, 15 * Scale, 15 * Scale), texture, new Rect(0.555f, 0.3443f, 0.01875f, 0.0214f));
                //GUI.DrawTexture(new Rect(0f, 0f, Resources.fuel_green.width * Scale, Resources.fuel_green.height*Scale), Resources.fuel_green);
            }
            //There are 72 degrees, split evenly left and right of 50%
            float deg = 72f * (float)percent;

            //The needle starts off pointing up,
            deg -= 36f;
            //150*5 pixel needle
            Vector2 pivotPoint = new Vector2(186f * Scale, 326f * Scale);    //bottom edge of the case

            GUIUtility.RotateAroundPivot(deg, pivotPoint);
            //GUI.DrawTexture(new Rect(179f * Scale, 120f * Scale, Resources.fuel_needle.width * Scale, Resources.fuel_needle.height*Scale), Resources.fuel_needle);
            GUI.DrawTextureWithTexCoords(new Rect(179f * Scale, 120f * Scale, 14f * Scale, 220f * Scale), texture, new Rect(0.805f, 0.0643f, 0.0175f, 0.3143f));
            GUI.matrix = Matrix4x4.identity;    //Reset rotation
        }
    private void LegacyInspectorGUI()
    {
        Undo.RecordObject(target, "Modified Path Terrain");

        EditorGUILayout.HelpBox("This terrain is using legacy data! Legacy support will be removed in future versions. Upgrading will likely result in visual differences.", MessageType.Warning);
        if (GUILayout.Button("Upgrade"))
        {
            for (int i = 0; i < targets.Length; i++)
            {
                Ferr2DT_PathTerrain t = (Ferr2DT_PathTerrain)targets[i];
                if (t.IsLegacy)
                {
                    t.LegacyUpgrade();
                }
            }
            GUIUtility.ExitGUI();
            return;
        }

        // render the material selector!
        EditorGUILayout.LabelField("TERRAIN MATERIAL");

        Ferr.EditorTools.Box(4, () => {
            EditorGUILayout.BeginHorizontal();
            IFerr2DTMaterial material = terrain.TerrainMaterial;
            GUIContent button         = material != null && material.edgeMaterial != null && material.edgeMaterial.mainTexture != null ? new GUIContent(material.edgeMaterial.mainTexture) : new GUIContent("Pick");
            if (GUILayout.Button(button, GUILayout.Width(64f), GUILayout.Height(64f)))
            {
                Ferr2DT_MaterialSelector.Show((mat) => {
                    if (mat != terrain.TerrainMaterial)
                    {
                        SelectMaterial((UnityEngine.Object)mat);
                    }
                });
            }

            UnityEngine.Object obj = EditorGUILayout.ObjectField((UnityEngine.Object)terrain.TerrainMaterial, typeof(Ferr2DT_Material), false, GUILayout.Height(64f));
            if (obj != (UnityEngine.Object)terrain.TerrainMaterial)
            {
                SelectMaterial(obj);
            }
            EditorGUILayout.EndHorizontal();
        });

        showTerrainType = EditorGUILayout.Foldout(showTerrainType, "TERRAIN DATA");
        if (showTerrainType)
        {
            EditorGUI.indentLevel = 2;
            Ferr.EditorTools.Box(4, () => {
                EditorGUILayout.PropertyField(fill, new GUIContent("Fill Type"));
                if (fill.enumValueIndex == (int)Ferr2DT_FillMode.Closed || fill.enumValueIndex == (int)Ferr2DT_FillMode.InvertedClosed || fill.enumValueIndex == (int)Ferr2DT_FillMode.FillOnlyClosed && terrain.GetComponent <Ferr2D_Path>() != null)
                {
                    terrain.GetComponent <Ferr2D_Path>().closed = true;
                }
                if (fill.enumValueIndex != (int)Ferr2DT_FillMode.None && (terrain.TerrainMaterial != null && terrain.TerrainMaterial.fillMaterial == null))
                {
                    fill.enumValueIndex = (int)Ferr2DT_FillMode.None;
                }
                if (fill.enumValueIndex != (int)Ferr2DT_FillMode.None)
                {
                    EditorGUILayout.PropertyField(fillZ, new GUIContent("Fill Z Offset"));
                }
                if (fill.enumValueIndex == (int)Ferr2DT_FillMode.Skirt)
                {
                    EditorGUILayout.PropertyField(fillY, new GUIContent("Skirt Y Value"));
                }
                if (fill.enumValueIndex == (int)Ferr2DT_FillMode.InvertedClosed)
                {
                    EditorGUILayout.PropertyField(invertFillBorder);
                }

                EditorGUILayout.PropertyField(splitCorners);
                EditorGUILayout.PropertyField(smoothPath);
                EditorGUI.indentLevel = 3;
                if (smoothPath.boolValue)
                {
                    EditorGUILayout.PropertyField(splitCount, new GUIContent("Edge Splits"));
                    EditorGUILayout.PropertyField(splitDist, new GUIContent("Fill Split"));
                    if (splitCount.intValue < 1)
                    {
                        splitCount.intValue = 2;
                    }
                }
                else
                {
                    splitCount.intValue  = 0;
                    splitDist.floatValue = 1;
                }
                EditorGUI.indentLevel = 2;

                EditorGUILayout.PropertyField(fillSplit, new GUIContent("Split fill mesh"));
                if (fillSplit.boolValue)
                {
                    EditorGUI.indentLevel = 3;
                    EditorGUILayout.PropertyField(fillSplitDistance, new GUIContent("Split Distance"));
                    EditorGUI.indentLevel = 2;
                }
            });
        }
        EditorGUI.indentLevel = 0;

        showVisuals = EditorGUILayout.Foldout(showVisuals, "VISUALS");

        if (showVisuals)
        {
            EditorGUI.indentLevel = 2;
            Ferr.EditorTools.Box(4, () => {
                // other visual data
                EditorGUILayout.PropertyField(vertexColorType);
                EditorGUI.indentLevel = 3;
                if (!vertexColorType.hasMultipleDifferentValues && vertexColorType.enumValueIndex == (int)Ferr2DT_ColorType.SolidColor)
                {
                    EditorGUILayout.PropertyField(vertexColor);
                }
                else if (!vertexColorType.hasMultipleDifferentValues && vertexColorType.enumValueIndex == (int)Ferr2DT_ColorType.Gradient)
                {
                    EditorGUILayout.PropertyField(vertexGradientAngle);
                    EditorGUILayout.PropertyField(vertexGradient);
                }
                else if (!vertexColorType.hasMultipleDifferentValues && vertexColorType.enumValueIndex == (int)Ferr2DT_ColorType.DistanceGradient)
                {
                    EditorGUILayout.PropertyField(vertexGradientDistance);
                    EditorGUILayout.PropertyField(vertexGradient);
                }
                EditorGUI.indentLevel = 2;

                EditorGUILayout.PropertyField(pixelsPerUnit);
                EditorGUILayout.PropertyField(slantAmount);
                EditorGUILayout.PropertyField(splitMiddle);
                EditorGUILayout.PropertyField(createTangents);
                EditorGUILayout.PropertyField(randomByWorldCoordinates, new GUIContent("Randomize Edge by World Coordinates"));
                EditorGUILayout.PropertyField(uvOffset, new GUIContent("Fill UV Offset"));

                if (!serializedObject.isEditingMultipleObjects)
                {
                    Renderer renderCom     = terrain.GetComponent <Renderer>();
                    string[] sortingLayers = Ferr.LayerUtil.GetSortingLayerNames();
                    if (sortingLayers != null)
                    {
                        string currName = renderCom.sortingLayerName == "" ? "Default" : renderCom.sortingLayerName;
                        int nameID      = EditorGUILayout.Popup("Sorting Layer", Array.IndexOf(sortingLayers, currName), sortingLayers);

                        renderCom.sortingLayerName = sortingLayers[nameID];
                    }
                    else
                    {
                        renderCom.sortingLayerID = EditorGUILayout.IntField("Sorting Layer", renderCom.sortingLayerID);
                    }
                    renderCom.sortingOrder = EditorGUILayout.IntField("Order in Layer", renderCom.sortingOrder);

                    // warn if the shader's aren't likely to work with the settings provided!
                    if (renderCom.sortingOrder != 0 || (renderCom.sortingLayerName != "Default" && renderCom.sortingLayerName != ""))
                    {
                        bool opaque = false;
                        for (int i = 0; i < renderCom.sharedMaterials.Length; ++i)
                        {
                            Material mat = renderCom.sharedMaterials[i];
                            if (mat != null && mat.GetTag("RenderType", false, "") == "Opaque")
                            {
                                opaque = true;
                            }
                        }
                        if (opaque)
                        {
                            EditorGUILayout.HelpBox("Layer properties won't work properly unless your shaders are all 'transparent'!", MessageType.Warning);
                        }
                    }
                }
            });
        }
        EditorGUI.indentLevel = 0;

        showCollider = EditorGUILayout.Foldout(showCollider, "COLLIDER");
        // render collider options
        if (showCollider)
        {
            EditorGUI.indentLevel = 2;
            Ferr.EditorTools.Box(4, () => {
                EditorGUILayout.PropertyField(createCollider);
                if (createCollider.boolValue)
                {
                    EditorGUILayout.PropertyField(sharpCorners);
                    if (sharpCorners.boolValue)
                    {
                        EditorGUI.indentLevel = 3;
                        EditorGUILayout.PropertyField(sharpCornerDistance, new GUIContent("Corner Distance"));
                        EditorGUI.indentLevel = 2;
                    }

                    EditorGUILayout.PropertyField(create3DCollider, new GUIContent("Use 3D Collider"));
                    if (terrain.create3DCollider)
                    {
                        EditorGUI.indentLevel = 3;
                        EditorGUILayout.PropertyField(depth, new GUIContent("Collider Width"));
                        EditorGUILayout.PropertyField(smoothSphereCollisions);
                        EditorGUI.indentLevel = 2;
                        EditorGUILayout.PropertyField(isTrigger);
                        EditorGUILayout.PropertyField(physicsMaterial);
                    }
                    else
                    {
                        EditorGUILayout.PropertyField(useEdgeCollider);
                        EditorGUILayout.PropertyField(usedByEffector);
                        EditorGUILayout.PropertyField(isTrigger);
                        EditorGUILayout.PropertyField(physicsMaterial2D);
                    }

                    if (terrain.fill == Ferr2DT_FillMode.None)
                    {
                        EditorGUILayout.PropertyField(surfaceOffset.GetArrayElementAtIndex((int)Ferr2DT_TerrainDirection.Top), new GUIContent("Thickness Top"));
                        EditorGUILayout.PropertyField(surfaceOffset.GetArrayElementAtIndex((int)Ferr2DT_TerrainDirection.Bottom), new GUIContent("Thickness Bottom"));
                    }
                    else
                    {
                        EditorGUILayout.PropertyField(surfaceOffset.GetArrayElementAtIndex((int)Ferr2DT_TerrainDirection.Top), new GUIContent("Offset Top"));
                        EditorGUILayout.PropertyField(surfaceOffset.GetArrayElementAtIndex((int)Ferr2DT_TerrainDirection.Left), new GUIContent("Offset Left"));
                        EditorGUILayout.PropertyField(surfaceOffset.GetArrayElementAtIndex((int)Ferr2DT_TerrainDirection.Right), new GUIContent("Offset Right"));
                        EditorGUILayout.PropertyField(surfaceOffset.GetArrayElementAtIndex((int)Ferr2DT_TerrainDirection.Bottom), new GUIContent("Offset Bottom"));
                    }

                    //EditorGUI.indentLevel = 0;
                    EditorGUILayout.LabelField("Generate colliders along:");
                    EditorGUILayout.PropertyField(collidersTop, new GUIContent("Top"));
                    EditorGUILayout.PropertyField(collidersLeft, new GUIContent("Left"));
                    EditorGUILayout.PropertyField(collidersRight, new GUIContent("Right"));
                    EditorGUILayout.PropertyField(collidersBottom, new GUIContent("Bottom"));

                    if (!collidersBottom.boolValue || !collidersLeft.boolValue || !collidersRight.boolValue || !collidersTop.boolValue)
                    {
                        EditorGUI.indentLevel = 2;
                        EditorGUILayout.PropertyField(colliderThickness);
                        EditorGUI.indentLevel = 0;
                    }

                    if (GUILayout.Button("Prebuild collider"))
                    {
                        for (int i = 0; i < targets.Length; i++)
                        {
                            Ferr2DT_PathTerrain t = targets[i] as Ferr2DT_PathTerrain;
                            if (t != null)
                            {
                                t.RecreateCollider();
                            }
                        }
                    }
                }
            });
        }
        EditorGUI.indentLevel = 0;

        if (serializedObject.ApplyModifiedProperties() || GUI.changed)
        {
            for (int i = 0; i < targets.Length; i++)
            {
                EditorUtility.SetDirty(targets[i]);
                ((Ferr2DT_PathTerrain)targets[i]).Build(true);
            }

            cachedColliders = terrain.GetColliderVerts();
        }
        if (Event.current.type == EventType.ValidateCommand)
        {
            switch (Event.current.commandName)
            {
            case "UndoRedoPerformed":
                terrain.ForceMaterial(terrain.TerrainMaterial, true);
                terrain.Build(true);
                cachedColliders = terrain.GetColliderVerts();
                break;
            }
        }
    }