/// <summary>
        /// Divides an area into two. Allows you to vertically adjust the area.
        /// </summary>
        public static Rect VerticalDivider(this HUMEditor.Data.Immediate immediate, Event e, Rect divider, ref Rect above, ref Rect below)
        {
            if (divider.Contains(e.mousePosition))
            {
                EditorGUIUtility.AddCursorRect(divider, MouseCursor.ResizeVertical);

                if (e.type == EventType.MouseDown)
                {
                    above = above.Add().Height(e.delta.y);
                    below = above.Add().Height(e.delta.y * -1);
                }
            }

            return(new Rect(divider.x, divider.y + e.delta.y, divider.width, divider.height));
        }
示例#2
0
        public virtual void DrawOperator(Rect area, AttributeData data, bool disabled = false)
        {
            Rect operatorRect = area.Add(18, 0, 0, 0).SetWidth(50);

            EditorGUIUtility.AddCursorRect(operatorRect, MouseCursor.Arrow);
            GUIStyle style = new GUIStyle(EditorStyles.popup);

            style.alignment     = TextAnchor.MiddleRight;
            style.contentOffset = new Vector2(-3, 0);
            style.fontStyle     = FontStyle.Bold;
            List <string> operatorList = new List <string>();

            if (disabled)
            {
                GUI.enabled = false;
                operatorList.Add("=");
                operatorList.Draw(operatorRect, 0, "", style);
                GUI.enabled = true;
                return;
            }
            operatorList = this.operatorOverride;
            if (operatorList == null)
            {
                var operatorCollection = typeof(AttributeType).GetVariable <Dictionary <Type, string[]> >("operators");
                operatorList = operatorCollection[data.GetType()].ToList();
            }
            int operatorIndex = Mathf.Clamp(data.operation, 0, operatorList.Count - 1);

            data.operation = operatorList.Draw(operatorRect, operatorIndex, "", style);
        }
示例#3
0
 protected override void DrawBeforeBackground(IPlatformDrawer platform, Rect boxRect)
 {
     base.DrawBeforeBackground(platform, boxRect);
     if (NodeViewModel.IsFilter && !NodeViewModel.IsCurrentFilter)
     {
         platform.DrawStretchBox(boxRect.Add(new Rect(6, 6, -2, -1)), CachedStyles.NodeBackgroundBorderless, 18);
     }
 }
示例#4
0
        Rect EvaluateFullNodesArea()
        {
            Rect area = _process.nodeToGUIData[_process.nodes[0]].fullArea;

            foreach (IEditorGUINode node in _process.nodes)
            {
                area = area.Add(_process.nodeToGUIData[node].fullArea);
            }
            return(area);
        }
示例#5
0
        public virtual void DrawDirect(Rect area, Rect extraArea, AttributeData data, GUIContent label, bool?drawSpecial = null, bool?drawOperator = null)
        {
            float labelSize = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = this.labelRect.width;
            bool showSpecial = drawSpecial != null && (EditorPref.Get <bool>(data.path + "Advanced") || data.special != 0);

            if (drawOperator != null)
            {
                EditorGUIUtility.labelWidth += 71;
            }
            if (showSpecial)
            {
                EditorGUIUtility.labelWidth += 91;
            }
            if (drawOperator != null)
            {
                this.DrawOperator(extraArea, data, (bool)!drawOperator);
                extraArea = extraArea.Add(51, 0, -51, 0);
            }
            if (showSpecial)
            {
                this.DrawSpecial(extraArea, data);
                area = area.Add(-41, 0, 41, 0);
            }
            if (data is AttributeFloatData)
            {
                AttributeFloatData floatData = (AttributeFloatData)data;
                floatData.Set(floatData.value.Draw(area, label));
            }
            if (data is AttributeIntData)
            {
                AttributeIntData intData = (AttributeIntData)data;
                intData.Set(intData.value.DrawInt(area, label, null, true));
            }
            if (data is AttributeStringData)
            {
                AttributeStringData stringData = (AttributeStringData)data;
                stringData.Set(stringData.value.Draw(area, label));
            }
            if (data is AttributeBoolData)
            {
                AttributeBoolData boolData = (AttributeBoolData)data;
                boolData.Set(boolData.value.Draw(area, label));
            }
            if (data is AttributeVector3Data)
            {
                AttributeVector3Data vector3Data = (AttributeVector3Data)data;
                vector3Data.Set(vector3Data.value.DrawVector3(area, label, true));
            }
            EditorGUIUtility.labelWidth = labelSize;
        }
示例#6
0
        public virtual void DrawSpecial(Rect area, AttributeData data)
        {
            Rect specialRect = area.Add(18, 0, 0, 0).SetWidth(50);

            if (this.attribute.info.mode == AttributeMode.Linked)
            {
                this.attribute.info.linkType = (LinkType)this.attribute.info.linkType.Draw(specialRect);
                return;
            }
            List <string> specialList = this.specialOverride ?? typeof(AttributeType).GetVariable <string[]>("specialList").ToList();

            data.special = specialList.Draw(specialRect, data.special);
        }
示例#7
0
        public override void OnGUI(Rect area, SerializedProperty property, GUIContent label)
        {
            EditorUI.Reset();
            string[]    names     = new string[] { "X", "Y", "Z", "W" };
            List <bool> data      = property.GetObject <ListBool>().value;
            Rect        labelRect = area.SetWidth(EditorGUIUtility.labelWidth);
            Rect        valueRect = area.Add(labelRect.width, 0, -labelRect.width, 0);

            label.ToLabel().DrawLabel(labelRect, null, true);
            for (int index = 0; index < data.Count; ++index)
            {
                data[index] = data[index].Draw(valueRect.AddX((index * 30)).SetWidth(30));
                names[index].ToLabel().DrawLabel(valueRect.Add(14 + (index * 30)));
            }
        }
        /// <summary>
        /// Divides an area into two. Allows you to horizontally adjust the area.
        /// </summary>
        public static Rect HorizontalDivider(this HUMEditor.Data.Immediate immediate, Event e, Rect divider, ref Rect before, ref Rect after)
        {
            if (divider.Contains(e.mousePosition))
            {
                EditorGUIUtility.AddCursorRect(divider, MouseCursor.ResizeHorizontal);

                if (e.type == EventType.MouseDown)
                {
                    before = before.Add().Width(e.delta.x);
                    after  = after.Add().Width(e.delta.x * -1);
                }
            }

            return(new Rect(divider.x + e.delta.x, divider.y, divider.width, divider.height));
        }
示例#9
0
        public Rect GetRect()
        {
            Rect rect = null;

            foreach (PdfTextElement textElement in _textElements)
            {
                Rect elementRect = textElement.GetRect();
                if (rect == null)
                {
                    rect = elementRect;
                }
                rect.Add(elementRect);
            }
            return(rect);
        }
        public void RectExtensions1()
        {
            Rect a = new Rect(1, 2, 3, 4);
            Rect b = new Rect(10, 20, -30, -40);
            Rect c = a.Add(b);

            Assert.AreEqual(11, c.x);
            Assert.AreEqual(22, c.y);
            Assert.AreEqual(-27, c.width);
            Assert.AreEqual(-36, c.height);

            c = b.Subtract(a);
            Assert.AreEqual(9, c.x);
            Assert.AreEqual(18, c.y);
            Assert.AreEqual(-33, c.width);
            Assert.AreEqual(-44, c.height);
        }
示例#11
0
        private void CreateRects(Rect position, GUIContent label)
        {
            backgroundRect        = position;
            backgroundRect.height = GetHeight(position.width, label) - 2;

            if (nest != null && nest.isSpecial)
            {
                iconRect        = backgroundRect;
                iconRect.y     += 4;
                iconRect.x     += 5;
                iconRect.width  = 16;
                iconRect.height = 16;
            }

            typeRect        = nest != null && nest.isSpecial ? backgroundRect.Add().X(iconRect.width + 4).Set().Width(80).Add().Y(3).Add().X(4) : backgroundRect.Set().Width(80).Add().Y(3).Add().X(4);
            typeRect.height = 16;

            if (string.IsNullOrEmpty(nest.name) || string.IsNullOrWhiteSpace(nest.name) || !nest.showLabel)
            {
                typeRect.width = position.width - 44 - 12;
            }

            if (nest.hasOptionalOverride)
            {
                toggleRect       = typeRect;
                toggleRect.width = 16;
                toggleRect.x    += 82;
                toggleRect.y    += 1;
            }

            labelRect        = position;
            labelRect.height = 16;
            labelRect.width  = GUI.skin.label.CalcSize(new GUIContent(label)).x + 6;
            labelRect.x      = typeRect.x + typeRect.width + 18;
            labelRect.y     += 4;

            editRect        = typeRect;
            editRect.x      = position.x + position.width - 44;
            editRect.y     += 1;
            editRect.width  = 40;
            editRect.height = 16;
        }
示例#12
0
        private bool IsRectInRect(Rect dynamicRect,
                                  Vector2 sourceVelocity,
                                  Rect staticRect,
                                  out Vector2 contactPoint,
                                  out Vector2 contactNormal,
                                  out float contactTime,
                                  float elapsedTime)
        {
            contactPoint  = Vector2.Zero;
            contactNormal = Vector2.Zero;
            contactTime   = 0f;

            if (sourceVelocity == Vector2.Zero)
            {
                return(false);
            }

            var expandedStaticRect = staticRect.Add(dynamicRect.Size());

            var centerPoint = dynamicRect.TopLeft() + (dynamicRect.Size() / 2f);
            var ray         = new Ray(centerPoint, sourceVelocity * elapsedTime);

            if (IsRayInRect(ray,
                            expandedStaticRect,
                            out contactPoint,
                            out contactNormal,
                            out contactTime))
            {
                if (contactTime >= 0f && contactTime < 1f)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            return(false);
        }
示例#13
0
        public override void OnGUI(Rect area, SerializedProperty property, GUIContent label)
        {
            EditorUI.Reset();
            Transition     transition    = property.GetObject <Transition>();
            float          durationValue = transition.duration.Get();
            float          delayValue    = transition.delayStart.Get();
            AnimationCurve curveValue    = transition.curve;
            Rect           labelRect     = area.SetWidth(EditorGUIUtility.labelWidth);
            Rect           valueRect     = area.Add(labelRect.width, 0, -labelRect.width, 0);

            label.ToLabel().DrawLabel(labelRect, null, true);
            durationValue = durationValue.Draw(valueRect.SetWidth(35));
            "seconds".ToLabel().DrawLabel(valueRect.AddX(37).SetWidth(50));
            delayValue = delayValue.Draw(valueRect.AddX(90).SetWidth(35));
            "delay".ToLabel().DrawLabel(valueRect.AddX(127).SetWidth(40));
            curveValue = transition.curve.Draw(valueRect.Add(169, 0, -169, 0));
            if (GUI.changed)
            {
                transition.duration.Set(durationValue);
                transition.delayStart.Set(delayValue);
                transition.curve = curveValue;
            }
        }
        static void MakeSafeAreas()
        {
            GameObject[]      gos                  = FindObjectsOfType <GameObject>();
            List <Vector2>    allPositions         = new List <Vector2>();
            List <Vector2>    safeZonePositions    = new List <Vector2>();
            List <Vector3Int> _unexploredPositions = new List <Vector3Int>();

            Vector3Int[]    unexploredPositions = new Vector3Int[0];
            List <SafeArea> safeAreas           = new List <SafeArea>();

            foreach (Vector3Int cellPosition in GameManager.GetSingleton <GameManager>().zonesTilemap.cellBounds.allPositionsWithin)
            {
                _unexploredPositions.Add(cellPosition);
                Vector2 position = GameManager.GetSingleton <GameManager>().zonesTilemap.GetCellCenterWorld(cellPosition);
                if (!ContainsPoint(safeZonePositions, position, .7f) && !ContainsPoint(allPositions, position, .7f))
                {
                    allPositions.Add(position);
                    SafeZone safeZone;
                    if (GetComponent <SafeZone>(gos, position, out safeZone, .7f))
                    {
                        SafeArea safeArea = new GameObject().AddComponent <SafeArea>();
                        safeArea.GetComponent <Transform>().SetParent(GameManager.GetSingleton <World>().piecesParent);
                        safeZone.safeArea = safeArea;
                        List <Vector2> safeAreaPositions = new List <Vector2>();
                        safeAreaPositions.Add(position);
                        List <Vector2> positionsRemaining = new List <Vector2>();
                        List <Vector2> positionsTested    = new List <Vector2>();
                        positionsTested.Add(position);
                        List <DangerArea>   dangerAreas   = new List <DangerArea>();
                        List <ConveyorBelt> conveyorBelts = new List <ConveyorBelt>();
                        ConveyorBelt        conveyorBelt;
                        if (GetComponent <ConveyorBelt>(gos, position, out conveyorBelt, .7f))
                        {
                            conveyorBelts.Add(conveyorBelt);
                        }
                        foreach (Vector2 possibleMove in GameManager.GetSingleton <GameManager>().possibleMoves)
                        {
                            positionsRemaining.Add(position + possibleMove);
                        }
                        do
                        {
                            position = positionsRemaining[0];
                            if (GetComponent <SafeZone>(gos, position, out safeZone, .7f))
                            {
                                safeZone.safeArea = safeArea;
                                foreach (Vector2 possibleMove in GameManager.GetSingleton <GameManager>().possibleMoves)
                                {
                                    Vector2 positionToTest = position + possibleMove;
                                    if (!ContainsPoint(positionsRemaining, positionToTest, .7f) && !ContainsPoint(positionsTested, positionToTest, .7f))
                                    {
                                        positionsRemaining.Add(positionToTest);
                                    }
                                }
                                safeAreaPositions.Add(position);
                            }
                            else
                            {
                                DangerZone dangerZone;
                                if (GetComponent <DangerZone>(gos, position, out dangerZone, .7f))
                                {
                                    DangerArea dangerArea = dangerZone.dangerArea;
                                    dangerAreas.Add(dangerArea);
                                    if (!safeArea.surroundingSafeAreas.Contains(dangerArea.correspondingSafeArea))
                                    {
                                        safeArea.surroundingSafeAreas.Add(dangerArea.correspondingSafeArea);
                                    }
                                    if (!dangerArea.correspondingSafeArea.surroundingSafeAreas.Contains(safeArea))
                                    {
                                        dangerArea.correspondingSafeArea.surroundingSafeAreas.Add(safeArea);
                                    }
                                }
                            }
                            if (GetComponent <ConveyorBelt>(gos, position, out conveyorBelt, .7f))
                            {
                                conveyorBelts.Add(conveyorBelt);
                            }
                            positionsTested.Add(position);
                            allPositions.Add(position);
                            positionsRemaining.RemoveAt(0);
                        } while (positionsRemaining.Count > 0);
                        safeZonePositions.AddRange(safeAreaPositions);
                        safeArea.cameraRect = RectExtensions.FromPoints(safeAreaPositions.ToArray()).Expand(Vector2.one * GameManager.WORLD_SCALE * 4);
                        Rect[] dangerAreaCameraRects = new Rect[dangerAreas.Count];
                        for (int i = 0; i < dangerAreas.Count; i++)
                        {
                            dangerAreaCameraRects[i] = dangerAreas[i].cameraRect;
                        }
                        safeArea.cameraRect    = RectExtensions.Combine(dangerAreaCameraRects.Add(safeArea.cameraRect));
                        safeArea.conveyorBelts = conveyorBelts.ToArray();
                        safeAreas.Add(safeArea);
                    }
                }
            }
            unexploredPositions = _unexploredPositions.ToArray();
            for (int i = 0; i < safeAreas.Count; i++)
            {
                safeAreas[i].unexploredCellPositions = unexploredPositions;
            }
        }
示例#15
0
            private void InitializeMetrics()
            {
                Contract.Requires(_typeface != null, "Typeface cannot be null.");
                Contract.Requires(_mapping != null, "Mapping cannot be null.");
                Contract.Requires(_transform != null, "Transform must be initialized first.");

                ushort glyph = _mapping.Glyph.GetValueOrDefault();

                checked
                {
                    _emHeight   = (ushort)Round(_typeface.Height * _emSize);
                    _emBaseline = (short)Round(_typeface.Baseline * _emSize);
                }

                // System.Diagnostics.Debug.WriteLine("{2}: {0} {1}",
                // _typeface.LeftSideBearings[glyph] * _emSize,
                // _typeface.RightSideBearings[glyph] * _emSize, (char)(int)_mapping.Character);

                if (_antialiasLevel == AntialiasingLevel.None)
                {
                    _emSideBearing = new Int32Thickness(
                        Round(_typeface.LeftSideBearings[glyph] * _emSize),
                        Round(_typeface.TopSideBearings[glyph] * _emSize),
                        Round(_typeface.RightSideBearings[glyph] * _emSize),
                        Round(_typeface.BottomSideBearings[glyph] * _emSize)
                        );
                }
                else
                {
                    _emSideBearing = new Int32Thickness(
                        Floor(_typeface.LeftSideBearings[glyph] * _emSize),
                        Floor(_typeface.TopSideBearings[glyph] * _emSize),
                        Floor(_typeface.RightSideBearings[glyph] * _emSize),
                        Floor(_typeface.BottomSideBearings[glyph] * _emSize)
                        );
                }

                Rect advance            = new Rect(new Size(_typeface.AdvanceWidths[glyph], _typeface.AdvanceHeights[glyph]));
                Rect advanceTransformed = _transform.TransformBounds(advance);

                _emAdvance = new Int32Vector(
                    Round(advanceTransformed.Width * _emSize),
                    Round(advanceTransformed.Height * _emSize)
                    );

                if (!_transform.Value.IsIdentity)
                {
                    Rect boundBox   = _run.ComputeInkBoundingBox();
                    Rect advanceBox = boundBox.Add(_emSideBearing);

                    Rect boundBoxTransformed   = _transform.TransformBounds(boundBox);
                    Rect advanceBoxTransformed = _transform.TransformBounds(advanceBox);

                    Thickness bearingTransformed = boundBox.Subtract(advanceBox);

                    _emSideBearing = new Int32Thickness(
                        Round(bearingTransformed.Left),
                        Round(bearingTransformed.Top),
                        Round(bearingTransformed.Right),
                        Round(bearingTransformed.Bottom)
                        );
                }
            }
示例#16
0
        public override void OnGUI(Rect area, SerializedProperty property, GUIContent label)
        {
            EditorUI.Reset();
            if (!Attribute.ready)
            {
                EditorGUI.ProgressBar(area, AttributeManager.percentLoaded, "Updating");
                return;
            }
            string skin = EditorGUIUtility.isProSkin || EditorPref.Get <bool>("Zios.Theme.Dark", false) ? "Dark" : "Light";

            GUI.skin = File.GetAsset <GUISkin>("Gentleface-" + skin + ".guiskin");
            Rect        labelRect   = area.SetWidth(EditorGUIUtility.labelWidth);
            Rect        valueRect   = area.Add(labelRect.width, 0, -labelRect.width, 0);
            EventTarget eventTarget = property.GetObject <EventTarget>();
            string      eventName   = eventTarget.name;
            GameObject  target      = eventTarget.target.Get();

            label.ToLabel().DrawLabel(labelRect, null, true);
            if (target.IsNull())
            {
                this.targeted = false;
            }
            string targetLabel = this.targeted ? "+" : "-";
            string manualLabel = this.manual ? "M" : "S";
            var    buttonArea  = valueRect.SetWidth(16);

            if (targetLabel.ToLabel().DrawButton(buttonArea))
            {
                this.targeted = !this.targeted;
            }
            if (manualLabel.ToLabel().DrawButton(buttonArea.AddX(18)))
            {
                this.manual = !this.manual;
            }
            valueRect = valueRect.Add(36, 0, -36, 0);
            if (!this.targeted)
            {
                property.FindPropertyRelative("target").Draw(valueRect);
                return;
            }
            if (!this.manual)
            {
                string eventType = eventTarget.mode == EventMode.Listeners ? "Listen" : "Caller";
                bool   hasEvents = eventType == "Listen" ? Events.HasListeners(target) : Events.HasCallers(target);
                if (!hasEvents)
                {
                    string error = "";
                    if (!target.IsNull())
                    {
                        error = "No <b>" + eventType + "</b> events found for target -- " + target.name;
                    }
                    if (target.IsNull())
                    {
                        error = "No global <b>" + eventType + "</b> events exist.";
                    }
                    error.ToLabel().DrawLabel(valueRect, GUI.skin.GetStyle("WarningLabel"));
                    return;
                }
                List <string> events = eventType == "Listen" ? Events.GetEventNames("Listen", target) : Events.GetEventNames("Caller", target);
                events.Sort();
                events = events.OrderBy(item => item.Contains("/")).ToList();
                events.RemoveAll(item => item.StartsWith("@"));
                int  index   = eventName.IsEmpty() ? 0 : events.IndexOf(eventName);
                bool missing = index == -1;
                if (index == -1)
                {
                    events.Insert(0, "[Missing] " + eventName);
                    index = 0;
                }
                index = events.Draw(valueRect, index);
                if (!missing || index != 0)
                {
                    eventTarget.name.Set(events[index]);
                }
                return;
            }
            string name = eventTarget.name.Get().Draw(valueRect);

            eventTarget.name.Set(name);
            if (GUI.changed)
            {
                property.serializedObject.targetObject.DelayEvent("On Validate", 1);
            }
        }
示例#17
0
 public static Rect AddWidth(this Rect current, float value)
 {
     return(current.Add(0, 0, value));
 }
示例#18
0
 public static Rect AddX(this Rect current, float value)
 {
     return(current.Add(value));
 }
示例#19
0
 public static Rect Add(this Rect current, params float[] other)
 {
     return(current.Add(other.ToRect()));
 }
        private static Rect Resizer(HUMEvents.Data.Mouse mouse, Rect handleRect, Rect rect, Vector2 minSize, Vector2 maxSize, HUMEvents_Children.Side side, bool mouseDown, ref bool isUsing)
        {
            var mousePosition  = EditorGUIUtility.GUIToScreenPoint(mouse.e.mousePosition);
            var delta          = HUMEvents.mouseDelta;
            var handleContains = handleRect.Contains(mousePosition);

            if (mouse.Left().Clicked() && handleContains)
            {
                isUsing = true;
                HUMEvents_Children.lastLeftClickPosition = mousePosition;
            }

            if (mouse.Left().Released())
            {
                isUsing = false;
            }

            if (handleContains && !mouseDown)
            {
                if (side == HUMEvents_Children.Side.Bottom || side == HUMEvents_Children.Side.Top)
                {
                    EditorGUIUtility.AddCursorRect(new Rect(mouse.e.mousePosition, new Vector2(34, 34)), MouseCursor.ResizeVertical);
                }
                else
                {
                    EditorGUIUtility.AddCursorRect(new Rect(mouse.e.mousePosition, new Vector2(34, 34)), MouseCursor.ResizeHorizontal);
                }
            }

            if (!mouseDown)
            {
                HUMEvents_Children.lastLeftClickPosition = mousePosition;
            }
            else
            {
                if (isUsing)
                {
                    if (side == HUMEvents_Children.Side.Bottom || side == HUMEvents_Children.Side.Top)
                    {
                        EditorGUIUtility.AddCursorRect(new Rect(mouse.e.mousePosition, new Vector2(34, 34)), MouseCursor.ResizeVertical);
                    }
                    else
                    {
                        EditorGUIUtility.AddCursorRect(new Rect(mouse.e.mousePosition, new Vector2(34, 34)), MouseCursor.ResizeHorizontal);
                    }

                    var yDeltaMax = (mousePosition.y - rect.y) - (rect.yMax - rect.y);
                    var xDeltaMax = (mousePosition.x - rect.x) - (rect.xMax - rect.x);
                    var yDeltaMin = (mousePosition.y - rect.y) - (rect.yMin - rect.y);
                    var xDeltaMin = (mousePosition.x - rect.x) - (rect.xMin - rect.x);

                    if (mouse.e.type == EventType.MouseDrag)
                    {
                        if (side == HUMEvents_Children.Side.Bottom)
                        {
                            if ((rect.height + yDeltaMax < maxSize.y && rect.height + yDeltaMax > minSize.y) ||
                                yDeltaMax > 0)
                            {
                                mouse.e.Use();
                                return(rect.Add().Height(yDeltaMax));
                            }
                        }

                        if (side == HUMEvents_Children.Side.Top)
                        {
                            if ((rect.height + yDeltaMin < maxSize.y && rect.height + yDeltaMin > minSize.y) ||
                                yDeltaMin < 0)
                            {
                                mouse.e.Use();
                                return(rect.Subtract().Height(yDeltaMin).Add().Y(yDeltaMin));
                            }
                        }

                        if (side == HUMEvents_Children.Side.Left)
                        {
                            if ((rect.width + xDeltaMin < maxSize.x && rect.width + xDeltaMin > minSize.x) ||
                                xDeltaMin < 0)
                            {
                                mouse.e.Use();
                                return(rect.Subtract().Width(xDeltaMin).Add().X(xDeltaMin));
                            }
                        }

                        if (side == HUMEvents_Children.Side.Right)
                        {
                            if ((rect.width + xDeltaMax < maxSize.x && rect.width + xDeltaMax > minSize.x) ||
                                xDeltaMax > 0)
                            {
                                mouse.e.Use();
                                return(rect.Add().Width(xDeltaMax));
                            }
                        }

                        mouse.e.Use();
                    }
                }
            }

            return(rect);
        }
示例#21
0
 public static Rect Add(this Rect target, Vector2 source)
 {
     return(target.Add(source.ToSize()));
 }
示例#22
0
    // Use this for initialization
    void Start()
    {
        //Init
        me = this;

        //Needs to be here because of the next request to it in 'CentralBlockWidth' var
        separator1 = (new TextureBorder(new TextureCrop(metalTex, new Rect(0, 0, 15, metalTex.height)).GetTexture())
        {
            leftBorder = 1, rightBorder = 1, topBorder = 0, bottomBorder = 0
        }).GetTexture();

        //Set the blocks' sizes
        //LeftBlockWidth = Mathf.Round((Screen.width - separator1.width * 2) * .3378f); //100 + stoneTex.width * 2;
        //CentralBlockWidth = Mathf.Round((Screen.width - separator1.width * 2) * .3371f);
        //RightBlockWidth = Mathf.Round((Screen.width - separator1.width * 2) * .3251f);

        //CentralBlockWidth = Screen.width - (LeftBlockWidth * 2 + separator1.width);
        //BackgroundWidth = CentralBlockWidth + separator1.width * 2;

        //Load textures
        animBtc = new AnimUtil("Textures/coin");

        //Separators
        separator2 = (new TextureBorder(new TextureCrop(metalTex, new Rect(0, 0, CentralBlockWidth + 2, 15)).GetTexture())
        {
            leftBorder = 0, rightBorder = 0, topBorder = 1, bottomBorder = 1
        }).GetTexture();
        separator3 = (new TextureBorder(new TextureCrop(metalTex, new Rect(0, 0, LeftBlockWidth + 2, 15)).GetTexture())
        {
            leftBorder = 0, rightBorder = 0, topBorder = 1, bottomBorder = 1
        }).GetTexture();

        sep = new Texture2D(1, 1);
        sep.SetPixel(1, 1, new Color(.8f, .8f, .8f));
        sep.Apply();

        //Some rects...
        //LeftBlock = new Rect(0, 0, LeftBlockWidth, Screen.height);
        //RightBlock = new Rect(Screen.width - RightBlockWidth, 50 + separator3.height, RightBlockWidth, Screen.height);

        //Set stone props
        //stonePadd = Screen.width * .03f;
        //stoneWidth = LeftBlockWidth - stonePadd * 2;
        //stoneHeight = stoneTex.height * stoneWidth / stoneTex.width;

        //Load settings
        s_quality    = QualitySettings.GetQualityLevel();
        sr_quality   = new Rect(5, 80, BackgroundWidth - 45, 20);
        s_runInBack  = Application.runInBackground;
        sr_runInBack = new Rect(5, 100, BackgroundWidth - 45, 20);
        sr_padding   = new Rect(LeftBlockWidth + separator1.width, 100 + separator2.height, 0, 0);

        h_Elems.Add(new HoveringElement(sr_quality.Change(-20, RectSides.Top).Change(20, RectSides.Bottom).Add(sr_padding), new Rect(0, 0, 500, 40), "Cambiar la calidad te dará unos FPS más, cámbia esta opción únicamente si tu ordenador es una verdadera patata.", Menu.Settings));
        h_Elems.Add(new HoveringElement(sr_runInBack.Add(sr_padding), new Rect(0, 0, 500, 120), "Esta opción te permitirá seguir ejecutando el juego en segundo plano, es decir, si está opción está marcada y la aplicación del juego pierde el foco el juego seguirá ejecutándose.\nCompruébalo desactivando esta opción y haciendo click en algún lado de la página fuera del cuadro del juego.\nSi tu microprocesador no es muy potente le vendría bien un descanso de vez en cuando, entonces es cuando deberías activar esta opción.", Menu.Settings));

        //Init machines
        transGroups.Add(new Transistors(5)
        {
            mmSize = 100
        });
        transGroups.Add(new Transistors(35)
        {
            mmSize = 166
        });
        transGroups.Add(new Transistors(225)
        {
            mmSize = 333
        });
        transGroups.Add(new Transistors(1180)
        {
            mmSize = 666
        });
        transGroups.Add(new Transistors(3333)
        {
            mmSize = 1000
        });
        transGroups.Add(new Transistors(6250)
        {
            mmSize = 1250
        });
        transGroups.Add(new Transistors(13000)
        {
            mmSize = 1666
        });
        transGroups.Add(new Transistors(43500)
        {
            mmSize = 2857
        });
        transGroups.Add(new Transistors(96000)
        {
            mmSize = 4000
        });
        transGroups.Add(new Transistors(205000)
        {
            mmSize = 5555
        });
        transGroups.Add(new Transistors(435000)
        {
            mmSize = 7692
        });
        transGroups.Add(new Transistors(990000)
        {
            mmSize = 11111
        });
        transGroups.Add(new Transistors(2050000)
        {
            mmSize = 15384
        });
        transGroups.Add(new Transistors(4600000)
        {
            mmSize = 22222
        });
        transGroups.Add(new Transistors(9765000)
        {
            mmSize = 31250
        });
        transGroups.Add(new Transistors(22000000)
        {
            mmSize = 45454
        });
        transGroups.Add(new Transistors(57500000)
        {
            mmSize = 71428
        });
        transGroups.Add(new Transistors(120000000)
        {
            mmSize = 100000
        });
        transGroups.Add(new Transistors(260000000)
        {
            mmSize = 142857
        });
        transGroups.Add(new Transistors(533333333)
        {
            mmSize = 200000
        });
        transGroups.Add(new Transistors(2240000000)
        {
            mmSize = 400000
        });
        transGroups.Add(new Transistors(3666666667)
        {
            mmSize = 500000
        });
        transGroups.Add(new Transistors(15333333333)
        {
            mmSize = 1000000
        });
        transGroups.Add(new Transistors(21160000000)
        {
            mmSize = 1150000
        });
        transGroups.Add(new Transistors(26050000000)
        {
            mmSize = 1250000
        });
        transGroups.Add(new Transistors(30815000000)
        {
            mmSize = 1333333
        });
        transGroups.Add(new Transistors(40500000000)
        {
            mmSize = 1500000
        });
        transGroups.Add(new Transistors(64000000000)
        {
            mmSize = 1850000
        });
        transGroups.Add(new Transistors(10240000000)
        {
            mmSize = 2300000
        });
        transGroups.Add(new Transistors(14600000000)
        {
            mmSize = 2700000
        });
        transGroups.Add(new Transistors(18600000000)
        {
            mmSize = 3000000
        });
        transGroups.Add(new Transistors(43200000000)
        {
            mmSize = 4500000
        });
        transGroups.Add(new Transistors(79200000000)
        {
            mmSize = 6000000
        });
        transGroups.Add(new Transistors(145000000000)
        {
            mmSize = 8000000
        });
        transGroups.Add(new Transistors(233333333333)
        {
            mmSize = 10000000
        });
        transGroups.Add(new Transistors(-1)
        {
            mmSize = -1
        });

        unblockedTrans.Add(transGroups[0]);
    }
        /// <summary>
        /// Gets inertial motion parameters: distance and duration.
        /// </summary>
        /// <param name="hostBounds">The host bounds.</param>
        /// <param name="windowBounds">The window bounds.</param>
        /// <returns>
        /// The inertial motion parameters: distance and duration.
        /// </returns>
        public InertialMotion GetInertialMotionParameters(Rect hostBounds, Rect windowBounds)
        {
            if (mouseTrails.Count < 2)
            {
                return(null);
            }

            var mouseTrailsArray = mouseTrails.ToArray();

            Point    startPosition = mouseTrailsArray[0].Position;
            DateTime startTime     = mouseTrailsArray[0].Timestamp;
            Point    endPosition   = mouseTrailsArray[mouseTrails.Count - 1].Position;
            DateTime endTime       = mouseTrailsArray[mouseTrails.Count - 1].Timestamp;

            double  timeBetweenNowAndLastMove = (DateTime.Now - endTime).TotalMilliseconds;
            Vector2 vector = new Vector2(startPosition, endPosition);

            if (timeBetweenNowAndLastMove < DELAY_BEFORE_MOUSE_UP_IN_MILLISECONDS && !vector.IsZero)
            {
                double time = (endTime - startTime).TotalSeconds;
                time = (time == 0) ? 0.001 : time;

                double distance = vector.Length / pixelsPerMeter;

                double intialVelocity = distance / time;

                double expectedDistance = ((intialVelocity * intialVelocity) / (2 * COEFFICIENT_OF_SLIDING_FRICTION * GRAVITATIONAL_ACCELERATION));
                double expectedTime     = (2 * expectedDistance) / intialVelocity;

                double shiftX = Math.Round(vector.LengthX * expectedDistance / distance);
                double shiftY = Math.Round(vector.LengthY * expectedDistance / distance);

                // New Inertial Motion Vector
                Vector2 imVector       = new Vector2(endPosition, shiftX, shiftY).Round();
                double  expectedLength = imVector.Length;

                Rect bounds = hostBounds.Add(-windowBounds.Width, -windowBounds.Height);

                if (bounds.Contains(endPosition))
                {
                    imVector = EnsureEndPointInBounds(imVector, bounds).Round();
                }
                else if (hostBounds.Contains(endPosition))
                {
                    imVector = EnsureEndPointInBounds(imVector, hostBounds).Round();
                }

                // Reduce expected time if the Inertial Motion Vector was truncated by the bounds
                double realTime = (expectedLength == 0) ? 0 : (expectedTime * imVector.Length / expectedLength);

                var motion = new InertialMotion()
                {
                    Seconds        = realTime,
                    EndPosition    = imVector.End,
                    EasingFunction = new CubicEase()
                    {
                        EasingMode = EasingMode.EaseOut
                    }
                };

                return(motion);
            }

            return(null);
        }
示例#24
0
        public virtual void DrawShaped(Rect area, AttributeData data, GUIContent label, bool?drawSpecial = null, bool?drawOperator = null)
        {
            label.ToLabel().DrawLabel(this.labelRect);
            Rect toggleRect   = area.SetWidth(16);
            bool toggleActive = this.targetMode.ContainsKey(data) ? this.targetMode[data] : !data.referenceID.IsEmpty();

            this.targetMode[data] = toggleActive.Draw(toggleRect, "", this.skin.GetStyle("CheckmarkToggle"));
            if (!this.targetMode[data])
            {
                Rect targetRect = area.Add(18, 0, -18, 0);
                bool ticked     = GUI.changed;
                TargetDrawer.Draw(targetRect, data.target, new GUIContent(""));
                if (this.attribute is AttributeGameObject && !ticked && GUI.changed)
                {
                    data.referenceID   = "";
                    data.referencePath = "";
                    data.reference     = null;
                }
                return;
            }
            List <string> attributeNames = new List <string>();
            List <string> attributeIDs   = new List <string>();
            int           attributeIndex = -1;
            GameObject    targetScope    = data.target.Get();

            if (!targetScope.IsNull() && Attribute.lookup.ContainsKey(targetScope))
            {
                var lookup = Attribute.lookup[targetScope];
                foreach (var item in lookup)
                {
                    if (item.Value.data.Length < 1)
                    {
                        continue;
                    }
                    if (item.Value.info.type != data.GetType())
                    {
                        continue;
                    }
                    bool isSelf = (item.Value.info.id == this.attribute.info.id) || (item.Value.data[0].referenceID == this.attribute.info.id);
                    if (!isSelf)
                    {
                        attributeNames.Add(item.Value.info.path);
                    }
                }
                if (attributeNames.Count != this.attributeNames.AddNew(data).Count)
                {
                    this.attributeNames[data] = attributeNames.Order().OrderBy(item => item.Contains("/")).ToList();
                }
                foreach (string name in this.attributeNames[data])
                {
                    var attribute = lookup.Values.ToList().Find(x => x.info.path == name);
                    if (attribute != null)
                    {
                        attributeIDs.Add(attribute.info.id);
                    }
                }
                if (!data.referenceID.IsEmpty())
                {
                    attributeIndex = attributeIDs.IndexOf(data.referenceID);
                }
            }
            else
            {
                this.attributeNames.Clear();
            }
            if (this.attributeNames.Count > 0)
            {
                Rect line        = area;
                bool showSpecial = drawSpecial != null && (EditorPref.Get <bool>(data.path + "Advanced") || data.special != 0);
                if (attributeIndex == -1)
                {
                    string message = data.referenceID.IsEmpty() ? "[Not Set]" : "[Missing] " + data.referencePath;
                    attributeIndex = 0;
                    this.attributeNames[data].Insert(0, message);
                    attributeIDs.Insert(0, "0");
                }
                if (drawOperator != null)
                {
                    this.DrawOperator(line, data, (bool)!drawOperator);
                    line = line.Add(51, 0, -51, 0);
                }
                if (showSpecial)
                {
                    this.DrawSpecial(line, data);
                    line = line.Add(51, 0, -51, 0);
                }
                Rect attributeRect = line.Add(18, 0, -18, 0);
                int  previousIndex = attributeIndex;
                attributeIndex = this.attributeNames[data].Draw(attributeRect, attributeIndex);
                string name = this.attributeNames[data][attributeIndex];
                string id   = attributeIDs[attributeIndex];
                if (attributeIndex != previousIndex)
                {
                    data.referencePath = name;
                    data.referenceID   = id;
                    data.reference     = Attribute.lookup[targetScope][data.referenceID];
                }
            }
            else
            {
                Rect   warningRect = area.Add(18, 0, -18, 0);
                string targetName  = targetScope.IsNull() ? "Target" : targetScope.ToString().Remove("(UnityEngine.GameObject)").Trim();
                string typeName    = data.GetType().Name.Trim("Attribute", "Data");
                string message     = "<b>" + targetName.Truncate(24) + "</b> has no <b>" + typeName + "</b> attributes.";
                message.ToLabel().DrawLabel(warningRect, this.skin.GetStyle("WarningLabel"));
            }
        }
示例#25
0
        public bool DrawTree(T treeRoot, Rect area)
        {
            var fullArea = area.Add(ScrollPosition);

            if (Event.current.type == EventType.MouseDown)
            {
                if (fullArea.Contains(Event.current.mousePosition))
                {
                    clickedWithin = true;
                    clickPos      = Event.current.mousePosition;
                }
                else
                {
                    clickedWithin = false;
                }
            }

            if (SelectedNode == null)
            {
                selectedNode = treeRoot;
            }

            if (SelectedNode == null) //If it's still null
            {
                return(false);
            }

            int startIndent = EditorGUI.indentLevel;

            ScrollPosition = EditorGUILayout.BeginScrollView(ScrollPosition, false, true);

            if (treeRoot == null || OnNodeDraw == null)
            {
                return(true);
            }

            root  = treeRoot;
            _area = area;



            if (selectedNode.IsFiltered)
            {
                selectedNode = treeRoot;
            }

            if (triggerFilter)
            {
                FilterNodes(treeRoot, filterFunc);

                triggerFilter = false;
                IsDirty       = true;
            }

            IsDirty = false;

            bool    canDropObject = false;
            Vector2 mousePos      = Event.current.mousePosition;

            if (fullArea.Contains(mousePos))
            {
                canDropObject = HandleDragging();
            }


            DrawTree(treeRoot, EditorGUI.indentLevel);

            PostDrawDragHandle(canDropObject);

            ContextHandle();

            KeyboardControl();

            EditorGUILayout.EndScrollView();

            EditorGUI.indentLevel = startIndent;

            if (focusOnSelectedNode)
            {
                ScrollPosition.y    = selectedArea.y;
                focusOnSelectedNode = false;
            }

            return(IsDirty);
        }