Example #1
0
        public void AllocateWidthFlat_WithoutLine()
        {
            int          width        = 512;
            int          heigth       = 512;
            Rect         originalRect = new Rect(0, 0, width, heigth);
            PropertyRect propertyRect = new PropertyRect(originalRect);

            Assert.Throws <InvalidOperationException>(() => propertyRect.AllocateWidthFlat(10));
        }
Example #2
0
        public void AllocateLine_Zero()
        {
            int          width        = 512;
            int          heigth       = 512;
            Rect         originalRect = new Rect(0, 0, width, heigth);
            PropertyRect propertyRect = new PropertyRect(originalRect);

            Assert.Throws <ArgumentOutOfRangeException>(() => propertyRect.AllocateLine(0));
        }
Example #3
0
        public void AllocateWidthWithAscesorFlat_Minus()
        {
            int          width        = 512;
            int          heigth       = 512;
            Rect         originalRect = new Rect(0, 0, width, heigth);
            PropertyRect propertyRect = new PropertyRect(originalRect);

            propertyRect.AllocateLine();
            Assert.Throws <ArgumentOutOfRangeException>(() => propertyRect.AllocateWidthWithAscesorFlat(-1));
        }
Example #4
0
        public void AllocateWidthPrecent_OverOne()
        {
            int          width        = 512;
            int          heigth       = 512;
            Rect         originalRect = new Rect(0, 0, width, heigth);
            PropertyRect propertyRect = new PropertyRect(originalRect);

            propertyRect.AllocateLine();
            Assert.Throws <ArgumentOutOfRangeException>(() => propertyRect.AllocateWidthPrecent(1.1f));
        }
Example #5
0
        public void AllocateLine_Default()
        {
            int          width        = 512;
            int          heigth       = 512;
            Rect         originalRect = new Rect(0, 0, width, heigth);
            PropertyRect propertyRect = new PropertyRect(originalRect);
            var          line         = propertyRect.AllocateLine();

            Assert.AreEqual(line.height, EditorGUIUtility.singleLineHeight);
            Assert.AreEqual(line.y, 0);
            Assert.AreEqual(line.width, width);
        }
Example #6
0
        public void AllocateWidthFlat()
        {
            int          width        = 512;
            int          heigth       = 512;
            Rect         originalRect = new Rect(0, 0, width, heigth);
            PropertyRect propertyRect = new PropertyRect(originalRect);

            propertyRect.AllocateLine();
            var rect = propertyRect.AllocateWidthFlat(10);

            Assert.AreEqual(rect.height, EditorGUIUtility.singleLineHeight);
            Assert.AreEqual(rect.width, 10);
        }
Example #7
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            PropertyRect propertyRect = new PropertyRect(position);

            EditorGUI.BeginProperty(position, label, property);

            GUIDrawers.DrawFieldWithLabelPercentage(ref propertyRect, property.FindPropertyRelative(nameof(ComponentField.accessType)), labelWidth: 100, labelWidthPercentage: 0.3f);
            propertyRect.AllocateWidthPrecent(0.05f);
            GUIDrawers.DrawFieldWithLabelPercentage(ref propertyRect, property.FindPropertyRelative(nameof(ComponentField.type)), false, labelWidth: 50, labelWidthPercentage: 0.65f);

            GUIDrawers.DrawFieldWithLabel(ref propertyRect, property.FindPropertyRelative(nameof(ComponentField.name)), labelWidth: 100);

            EditorGUI.EndProperty();
        }
Example #8
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);

            // Draw label
            position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), EmptyContent);
            var propertyRect = new PropertyRect(position);
            var indent       = EditorGUI.indentLevel;

            EditorGUI.indentLevel = Math.Max(0, indent - 1);

            var usageProp  = property.FindPropertyRelative("_usageType");
            var accessProp = property.FindPropertyRelative("_accessType");
            var typeProp   = property.FindPropertyRelative("_componentTypeReference");

            propertyRect.AllocateLine();

            EditorGUI.PropertyField(propertyRect.AllocateWidthFlat(50), usageProp, EmptyContent);

            if (((ComponentLinkUsageType)usageProp.GetPropertyValue()) == ComponentLinkUsageType.All)
            {
                EditorGUI.PropertyField(propertyRect.AllocateWidthFlat(40), accessProp, EmptyContent);
            }

            EditorGUI.PropertyField(propertyRect.AllocateRestOfLine(), typeProp, EmptyContent);

            // New custom component
            if (!HasSettedType(property))
            {
                propertyRect.AllocateLine();
                var nameProp = property.FindPropertyRelative("_componentName");
                EditorGUI.PropertyField(propertyRect.AllocateWidthWithAscesorFlat(25), nameProp, EmptyContent);
                using (new GUIEnabledScope(!string.IsNullOrWhiteSpace(nameProp.stringValue)))
                {
                    if (GUI.Button(propertyRect.AllocateRestOfLine(), PlusContent))
                    {
                        ShowCreateComponentWindow(property);
                    }
                }
            }

            EditorGUI.indentLevel = indent;
            EditorGUI.EndProperty();
        }
Example #9
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);

            var wasChanged = GUI.changed;

            GUI.changed = false;

            PropertyRect propertyRect = new PropertyRect(position);

            // Draw name
            var nameProp = property.FindPropertyRelative("_name");

            EditorGUI.PropertyField(propertyRect.AllocateLine(), nameProp);

            // Draw array
            var componentsProp = property.FindPropertyRelative("_components");

            s_cache.Clear();
            GUIDrawers.DrawArray(ref propertyRect, componentsProp, s_cache);

            // Draw additional settings
            propertyRect.AllocateLine();
            var parallelScheduling = property.FindPropertyRelative("_parallelSchedule");

            EditorGUI.LabelField(propertyRect.AllocateWidthFlat(105), s_parallelContent);
            EditorGUI.PropertyField(propertyRect.AllocateWidthFlat(25), parallelScheduling, EmptyContent);
            var structuralChanges = property.FindPropertyRelative("_hasStructuralChanges");

            EditorGUI.LabelField(propertyRect.AllocateWidthFlat(115), s_structuralChangesContent);
            EditorGUI.PropertyField(propertyRect.AllocateWidthFlat(25), structuralChanges, EmptyContent);

            propertyRect.AllocateLine();
            var queryField = property.FindPropertyRelative("_queryField");

            EditorGUI.LabelField(propertyRect.AllocateWidthFlat(75), s_queryFieldContent);
            EditorGUI.PropertyField(propertyRect.AllocateRestOfLine(), queryField, EmptyContent);

            propertyRect.AllocateLine();
            var sharedFilter = property.FindPropertyRelative("_sharedFilter").GetPropertyValue <SharedComponentFilter>();

            EditorGUI.LabelField(propertyRect.AllocateWidthFlat(75), s_sharedFilterContent);

            if (sharedFilter.IsValid)
            {
                EditorGUI.LabelField(propertyRect.AllocateWidthWithAscesorFlat(25), sharedFilter.FilterName, s_BoldLabelStyle);
            }
            else
            {
                EditorGUI.LabelField(propertyRect.AllocateWidthWithAscesorFlat(25), EmptyContent);
            }

            if (!sharedFilter.IsValid && GUI.Button(propertyRect.AllocateRestOfLine(), PlusContent))
            {
                SharedComponentFilterWindow.ShowWindow((name, declaration) =>
                {
                    property.serializedObject.ApplyModifiedProperties();
                    sharedFilter.FilterName           = name;
                    sharedFilter.ComponentDeclaration = declaration;
                    property.serializedObject.Update();
                });
            }
            else if (sharedFilter.IsValid && GUI.Button(propertyRect.AllocateRestOfLine(), MinusContent))
            {
                sharedFilter.Invalid();
            }

            EditorGUI.EndProperty();

            if (GUI.changed)
            {
                // We can have some structural changes so we need to sync with Unity serialized side
                property.serializedObject.ApplyModifiedProperties();
                SystemLambdaAction systemLambdaAction = property.GetPropertyValue() as SystemLambdaAction;
                systemLambdaAction?.PropertiesChanged(s_cache);
                property.serializedObject.Update();
            }

            GUI.changed |= wasChanged;
        }
Example #10
0
    private void Update()
    {
        #region This is old and horrible and fugly BUT it works.

        if ((Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.LeftApple)) && Input.GetKeyDown(KeyCode.Z))
        {
            ActionManager.Undo();
        }

        if (Input.GetMouseButtonUp(0))
        {
            _entitySpawned = false;
            _movingEntity  = false;
            _posSelected   = false;

            if (_entity != null && _entitySelected)
            {
                Editor.Log("Adding a new move action to the stack");
                ActionManager.ActionStack.Push(new MoveAction {
                    Entity = _entity, Movement = _entity.transform.position - _startingPos
                });
            }
        }

        if (IsIngame)
        {
            if (Input.GetKeyDown(KeyCode.Escape))
            {
                IsIngame = false;
            }
        }
        else if (Input.GetMouseButton(2) && _mouseScreenPos != Vector3.zero)
        {
            Screen.showCursor = false;
            _movementRequest  = (_mouseScreenPos - Input.mousePosition) / 4;
        }
        else
        {
            Screen.showCursor = true;
            _movementRequest  = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), Input.GetAxis("ScrollWheel") * 1.5f);
        }

        _mouseScreenPos = Input.mousePosition;
        _movementDelta  = new Vector3();

        transform.position = Vector3.Lerp(transform.position, transform.position + _movementRequest, 0.5f);

        RaycastHit mouseHitInfo;
        if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out mouseHitInfo, 100, ~_planeLayer))
        {
            _mousePos = new Vector3(
                _snapToGrid ? (float)Math.Round(mouseHitInfo.point.x * 2, MidpointRounding.AwayFromZero) / 2 : mouseHitInfo.point.x,
                _snapToGrid ? (float)Math.Round(mouseHitInfo.point.y * 2, MidpointRounding.AwayFromZero) / 2 : mouseHitInfo.point.y,
                0);

            _movementDelta = _mousePos - _mousePosPrev;
            _mousePosPrev  = _mousePos;
        }

        RaycastHit entityHitInfo;
        Entity     rayEntity;

        if (!Input.GetMouseButton(0))
        {
            _entitySelected = false;
        }

        _movingEntity = Input.GetMouseButton(0) && _entitySelected;

        var screenMousePos = new Vector3(Input.mousePosition.x, Screen.height - Input.mousePosition.y, Input.mousePosition.z);

        var rayResult = Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out entityHitInfo, 100, ~_planeLayer) && !_movingEntity &&
                        !EntityRect.Contains(screenMousePos) && !PropertyRect.Contains(screenMousePos) && !MenuManager.MouseOverGui;

        if (rayResult)
        {
            if (entityHitInfo.collider.TryGetComponent(out rayEntity) && Input.GetMouseButton(0))
            {
                _entitySelected = true;
                _entity         = Entity.SelectedEntity = rayEntity;

                if (!_posSelected)
                {
                    _posSelected = true;
                    _startingPos = _entity.transform.position;
                }
            }
        }
        #endregion

        var hasEntity = _entity != null;

        //Should probably add some more editor states one day...
        switch (State)
        {
        case EditorState.Edit:
        {
            if (hasEntity && !MenuManager.MouseOverGui)
            {
                if ((Input.GetKey(KeyCode.LeftApple) || Input.GetKey(KeyCode.LeftControl)) && Input.GetKeyDown(KeyCode.C))
                {
                    _entity = Entity.Create <Entity>(_mousePos, _entity.transform.rotation.eulerAngles, _entity.transform.localScale, _entity.GetType());
                }
                else if (Input.GetKeyDown(KeyCode.Delete) || Input.GetKeyDown(KeyCode.Backspace))
                {
                    Entity.Destroy(_entity.gameObject);
                }

                if (_movingEntity)
                {
                    _entity.transform.position = _entity.transform.position + _movementDelta;
                }

                if (Input.GetMouseButtonUp(0))
                {
                    _entitySpawned = false;
                    _movingEntity  = false;
                }
            }
        }
        break;
        }

        if (State != _previousEditorState)
        {
            _entitySpawned        = true;
            Entity.SelectedEntity = null;
        }

        _previousEditorState = State;
    }