Example #1
0
 internal static void ControlHighlightGUI(GUIView self)
 {
     if (!(Highlighter.s_View == null) && !(self.window != Highlighter.s_View.window))
     {
         if (Highlighter.activeVisible && !Highlighter.searching)
         {
             if (Event.current.type == EventType.ExecuteCommand && Event.current.commandName == "HandleControlHighlight")
             {
                 if (self.screenPosition.Overlaps(Highlighter.s_RepaintRegion))
                 {
                     self.Repaint();
                 }
             }
             else if (Event.current.type == EventType.Repaint)
             {
                 Rect rect = GUIUtility.ScreenToGUIRect(Highlighter.activeRect);
                 rect = Highlighter.highlightStyle.padding.Add(rect);
                 float num  = (Mathf.Cos(Highlighter.s_HighlightElapsedTime * 3.14159274f * 2f * 0.45f) + 1f) * 0.5f;
                 float num2 = Mathf.Min(1f, 0.01f + Highlighter.s_HighlightElapsedTime / 0.33f);
                 num2 += Mathf.Sin(num2 * 3.14159274f) * 0.5f;
                 Vector2   b      = new Vector2((rect.width + 5f) / rect.width - 1f, (rect.height + 5f) / rect.height - 1f) * num;
                 Vector2   scale  = (Vector2.one + b) * num2;
                 Matrix4x4 matrix = GUI.matrix;
                 Color     color  = GUI.color;
                 GUI.color = new Color(1f, 1f, 1f, Mathf.Clamp01(0.8f * num2 - 0.3f * num));
                 GUIUtility.ScaleAroundPivot(scale, rect.center);
                 Highlighter.highlightStyle.Draw(rect, false, false, false, false);
                 GUI.color  = color;
                 GUI.matrix = matrix;
             }
         }
     }
 }
Example #2
0
 internal static void ControlHighlightGUI(GUIView self)
 {
     if (((s_View != null) && (self.window == s_View.window)) && (activeVisible && !searching))
     {
         if ((Event.current.type == EventType.ExecuteCommand) && (Event.current.commandName == "HandleControlHighlight"))
         {
             if (self.screenPosition.Overlaps(s_RepaintRegion))
             {
                 self.Repaint();
             }
         }
         else if (Event.current.type == EventType.Repaint)
         {
             Rect rect = GUIUtility.ScreenToGUIRect(activeRect);
             rect = highlightStyle.padding.Add(rect);
             float num  = (Mathf.Cos(((s_HighlightElapsedTime * 3.141593f) * 2f) * 0.45f) + 1f) * 0.5f;
             float num2 = Mathf.Min((float)1f, (float)(0.01f + (s_HighlightElapsedTime / 0.33f)));
             num2 += Mathf.Sin(num2 * 3.141593f) * 0.5f;
             Vector2   vector = (Vector2)(new Vector2(((rect.width + 5f) / rect.width) - 1f, ((rect.height + 5f) / rect.height) - 1f) * num);
             Vector2   scale  = (Vector2)((Vector2.one + vector) * num2);
             Matrix4x4 matrix = GUI.matrix;
             Color     color  = GUI.color;
             GUI.color = new Color(1f, 1f, 1f, 0.8f - (0.3f * num));
             GUIUtility.ScaleAroundPivot(scale, rect.center);
             highlightStyle.Draw(rect, false, false, false, false);
             GUI.color  = color;
             GUI.matrix = matrix;
         }
     }
 }
Example #3
0
 internal static void ControlHighlightGUI(GUIView self)
 {
     if ((Object)Highlighter.s_View == (Object)null || (Object)self.window != (Object)Highlighter.s_View.window || (!Highlighter.activeVisible || Highlighter.searching))
     {
         return;
     }
     if (Event.current.type == EventType.ExecuteCommand && Event.current.commandName == "HandleControlHighlight")
     {
         if (!self.screenPosition.Overlaps(Highlighter.s_RepaintRegion))
         {
             return;
         }
         self.Repaint();
     }
     else
     {
         if (Event.current.type != EventType.Repaint)
         {
             return;
         }
         Rect      position = Highlighter.highlightStyle.padding.Add(GUIUtility.ScreenToGUIRect(Highlighter.activeRect));
         float     num1     = (float)(((double)Mathf.Cos((float)((double)Highlighter.s_HighlightElapsedTime * 3.14159274101257 * 2.0 * 0.449999988079071)) + 1.0) * 0.5);
         float     num2     = Mathf.Min(1f, (float)(0.00999999977648258 + (double)Highlighter.s_HighlightElapsedTime / 0.330000013113022));
         float     num3     = num2 + Mathf.Sin(num2 * 3.141593f) * 0.5f;
         Vector2   scale    = (Vector2.one + new Vector2((float)(((double)position.width + 5.0) / (double)position.width - 1.0), (float)(((double)position.height + 5.0) / (double)position.height - 1.0)) * num1) * num3;
         Matrix4x4 matrix   = GUI.matrix;
         Color     color    = GUI.color;
         GUI.color = new Color(1f, 1f, 1f, (float)(0.800000011920929 - 0.300000011920929 * (double)num1));
         GUIUtility.ScaleAroundPivot(scale, position.center);
         Highlighter.highlightStyle.Draw(position, false, false, false, false);
         GUI.color  = color;
         GUI.matrix = matrix;
     }
 }
Example #4
0
        public static void Open(GameObject[] targets, Rect activatorPosition, GenericMenu.MenuFunction rename = null)
        {
            var menu = new GenericMenu();

            menu.allowDuplicateNames = true;
            Fill(targets, menu, activatorPosition, rename);
            menu.DropDown(GUIUtility.ScreenToGUIRect(activatorPosition));
        }
Example #5
0
        private static void ControlHighlightGUI()
        {
            if (!activeVisible || searching)
            {
                return;
            }

            if (Event.current.type == EventType.ExecuteCommand && Event.current.commandName == "HandleControlHighlight")
            {
                if (s_View.screenPosition.Overlaps(s_RepaintRegion))
                {
                    s_View.Repaint();
                }
                return;
            }

            if (Event.current.type != EventType.Repaint)
            {
                return;
            }

            Rect localRect = GUIUtility.ScreenToGUIRect(activeRect);

            localRect = highlightStyle.padding.Add(localRect);

            // Animation calculations

            // Value pulses between 0 and 1
            float pulseValue = (Mathf.Cos(s_HighlightElapsedTime * Mathf.PI * 2 * kPulseSpeed) + 1) * 0.5f;

            // Value expands from 0.01 to 1 and stays at 1
            float popupScale = Mathf.Min(1, 0.01f + s_HighlightElapsedTime / kPopupDuration);

            // Value goes from 0.01 towards 1, overshoots a bit, and ends at 1.
            popupScale = popupScale + Mathf.Sin(popupScale * Mathf.PI) * 0.5f;

            // Scale calculations
            Vector2 pulseScaleAddition = new Vector2(
                (localRect.width + kExpansionMovementSize) / localRect.width - 1.0f,
                (localRect.height + kExpansionMovementSize) / localRect.height - 1.0f
                ) * pulseValue;
            Vector2 scale = (Vector2.one + pulseScaleAddition) * popupScale;

            // Cache old values
            Matrix4x4 oldMatrix = GUI.matrix;
            Color     oldColor  = GUI.color;

            // Set pulsing values
            GUI.color = new Color(1, 1, 1, Mathf.Clamp01(0.8f * popupScale - 0.3f * pulseValue));
            GUIUtility.ScaleAroundPivot(scale, localRect.center);

            // Draw highlight
            highlightStyle.Draw(localRect, false, false, false, false);

            // Reset to old values
            GUI.color  = oldColor;
            GUI.matrix = oldMatrix;
        }
Example #6
0
        private void OnGUI()
        {
            if (!_mouseOver)
            {
                return;
            }

            GUI.skin = HighLogic.Skin;

            Orbit    orbit    = _hitOrbit;
            Vector3d deltaPos = orbit.getPositionAtUT(_hitUT) - orbit.referenceBody.position;
            double   altitude = deltaPos.magnitude - orbit.referenceBody.Radius;
            double   speed    = orbit.getOrbitalSpeedAt(orbit.getObtAtUT(_hitUT));

            string labelText = "";

            if (HighLogic.CurrentGame.Parameters.CustomParams <ABCORSSettings>().showTime)
            {
                labelText += "T: " + KSPUtil.PrintTime((int)(Planetarium.GetUniversalTime() - _hitUT), 5, true) + "\n";
            }
            if (HighLogic.CurrentGame.Parameters.CustomParams <ABCORSSettings>().showAltitude)
            {
                labelText += "Alt: " + altitude.ToString("N0", CultureInfo.CurrentCulture) + "m\n";
            }
            if (HighLogic.CurrentGame.Parameters.CustomParams <ABCORSSettings>().showSpeed)
            {
                labelText += "Vel: " + speed.ToString("N0", CultureInfo.CurrentCulture) + "m/s\n";
            }
            if (HighLogic.CurrentGame.Parameters.CustomParams <ABCORSSettings>().showAngleToPrograde&& orbit.referenceBody.orbit != null)
            {
                Vector3d bodyVel        = orbit.referenceBody.orbit.getOrbitalVelocityAtUT(_hitUT);
                Vector3d shipPos        = orbit.getRelativePositionAtUT(_hitUT);
                double   angle          = Vector3d.Angle(shipPos, bodyVel);
                Vector3d rotatedBodyVel = QuaternionD.AngleAxis(90.0, Vector3d.forward) * bodyVel;
                if (Vector3d.Dot(rotatedBodyVel, shipPos) > 0)
                {
                    angle = 360 - angle;
                }

                labelText += "\u03B1P: " + angle.ToString("N1", CultureInfo.CurrentCulture) + "\u00B0\n";
            }

            GUILayout.BeginArea(GUIUtility.ScreenToGUIRect(_popup));
            GUIStyle labelStyle = new GUIStyle(GUI.skin.GetStyle("Label"));

            if (_isTarget)
            {
                labelStyle.normal.textColor = Color.cyan;
            }
            GUILayout.Label(labelText, labelStyle);
            GUILayout.EndArea();
        }
Example #7
0
        public static void CalculateFrameTransform(Rect rectToFit, Rect clientRect, int border, out Vector3 frameTranslation, out Vector3 frameScaling)
        {
            // bring slightly smaller screen rect into GUI space
            var screenRect = new Rect
            {
                xMin = border,
                xMax = clientRect.width - border,
                yMin = border,
                yMax = clientRect.height - border
            };

            Matrix4x4 m = GUI.matrix;

            GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, Vector3.one);
            Rect identity = GUIUtility.ScreenToGUIRect(screenRect);

            // measure zoom level necessary to fit the canvas rect into the screen rect
            float zoomLevel = Math.Min(identity.width / rectToFit.width, identity.height / rectToFit.height);

            // clamp
            zoomLevel = Mathf.Clamp(zoomLevel, ContentZoomer.DefaultMinScale, 1.0f);

            var transform = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(zoomLevel, zoomLevel, 1.0f));

            var edge   = new Vector2(clientRect.width, clientRect.height);
            var origin = new Vector2(0, 0);

            var r = new Rect
            {
                min = origin,
                max = edge
            };

            var parentScale = new Vector3(transform.GetColumn(0).magnitude,
                                          transform.GetColumn(1).magnitude,
                                          transform.GetColumn(2).magnitude);
            Vector2 offset = r.center - (rectToFit.center * parentScale.x);

            // Update output values before leaving
            frameTranslation = new Vector3(offset.x, offset.y, 0.0f);
            frameScaling     = parentScale;

            GUI.matrix = m;
        }
        public void End(SceneView sceneView)
        {
            duringSceneGUI?.Invoke(sceneView);

            windows.Sort();

            if (windows.Count > 0 && Event.current.type != EventType.Used)
            {
                Handles.BeginGUI();

                Rect windowRect = GUIUtility.ScreenToGUIRect(sceneView.position);
                windowRect.y += 19;

                GUILayout.BeginArea(windowRect);
                WindowTrampoline(sceneView);
                GUILayout.EndArea();

                Handles.EndGUI();
            }
        }
Example #9
0
        /*
         *      public static void HandleAreaOffset()
         *      {
         *              HandleAreaOffset(Vector2.zero);
         *      }
         *
         *      public static void HandleAreaOffset(Vector2 scrollPos)
         *      {
         *              if (currentState == null)
         *                      return;
         *
         *              if (currentState.currentToolTip == null)
         *                      return;
         *
         *              var rect = GUILayoutUtility.GetLastRect();
         *
         *              currentState.rectOffset.x += rect.x - scrollPos.x;
         *              currentState.rectOffset.y += rect.y - scrollPos.y;
         *      }*/

        static void UpdateToolTip(bool getLastRect = false, bool goUp = false)
        {
            if (currentState == null)
            {
                return;
            }


            if (currentState.prevToolTip != currentState.currentToolTip)
            {
                currentState.prevToolTip            = currentState.currentToolTip;
                currentState.tooltipTimer           = Time.realtimeSinceStartup;
                currentState.currentToolTipTitle    = null;
                currentState.currentToolTipContents = null;
                currentState.currentToolTipKeyCodes = null;
            }

            if (currentState.currentToolTip == null)
            {
                return;
            }

            //if ((Time.realtimeSinceStartup - currentState.tooltipTimer) < TooltipWaitTime)
            //	return;

            var titleStyle    = GUIStyleUtility.toolTipTitleStyle;
            var contentsStyle = GUIStyleUtility.toolTipContentsStyle;
            var keycodesStyle = GUIStyleUtility.toolTipKeycodesStyle;

            if (currentState.currentToolTipTitle == null)
            {
                var currentToolTipTitleString    = currentState.currentToolTip.TitleString();
                var currentToolTipContentsString = currentState.currentToolTip.ContentsString();
                var currentToolTipKeyCodesString = currentState.currentToolTip.KeyString();

                currentState.currentToolTipTitle    = new GUIContent(currentToolTipTitleString);
                currentState.currentToolTipContents = new GUIContent(currentToolTipContentsString);
                if (string.IsNullOrEmpty(currentToolTipKeyCodesString))
                {
                    currentState.currentToolTipKeyCodes = null;
                }
                else
                {
                    currentState.currentToolTipKeyCodes = new GUIContent(currentToolTipKeyCodesString);
                }

                var currentToolTipTitleSize    = titleStyle.CalcSize(currentState.currentToolTipTitle);
                var currentToolTipContentsSize = contentsStyle.CalcSize(currentState.currentToolTipContents);
                var currentToolTipKeyCodesSize = currentState.currentToolTipKeyCodes != null?keycodesStyle.CalcSize(currentState.currentToolTipKeyCodes) : Vector2.zero;


                var currentArea = getLastRect ? GUILayoutUtility.GetLastRect() : currentState.maxArea;
                //currentArea.y += 100;

                Vector2 size = currentToolTipTitleSize;
                size.x = Mathf.Max(currentToolTipTitleSize.x, currentToolTipContentsSize.x, currentToolTipKeyCodesSize.x);
                size.y = currentToolTipTitleSize.y + currentToolTipContentsSize.y + currentToolTipKeyCodesSize.y;
                currentState.currentToolTipArea = GUIUtility.ScreenToGUIRect(currentState.tooltipArea);
                //currentState.currentToolTipArea.x += currentState.rectOffset.x;
                //currentState.currentToolTipArea.y += currentState.rectOffset.y;
                //currentToolTipArea.x = (currentToolTipArea.x + currentToolTipArea.width) - size.x;
                currentState.currentToolTipArea.width = size.x;

                if (currentState.currentToolTipArea.xMax > currentArea.xMax)
                {
                    currentState.currentToolTipArea.xMin -= currentState.currentToolTipArea.xMax - currentArea.xMax;
                }
                if (currentState.currentToolTipArea.xMin < 0)
                {
                    currentState.currentToolTipArea.xMin  = 0;
                    currentState.currentToolTipArea.width = currentArea.xMax;
                }

                var currentToolTipTitleHeight    = titleStyle.CalcHeight(currentState.currentToolTipTitle, currentState.currentToolTipArea.width);
                var currentToolTipContentsHeight = contentsStyle.CalcHeight(currentState.currentToolTipContents, currentState.currentToolTipArea.width);
                var currentToolTipKeyCodesHeight = (currentState.currentToolTipKeyCodes != null ? keycodesStyle.CalcHeight(currentState.currentToolTipKeyCodes, currentState.currentToolTipArea.width) : 0);

                currentState.currentToolTipArea.height = currentToolTipTitleHeight + currentToolTipContentsHeight + currentToolTipKeyCodesHeight + 4;

                if (goUp)
                {
                    if (currentState.currentToolTipArea.y - currentState.tooltipArea.height < 0)
                    {
                        currentState.currentToolTipArea.y += currentState.tooltipArea.height;
                    }
                    else
                    {
                        currentState.currentToolTipArea.y -= currentState.currentToolTipArea.height;
                    }
                }
                else
                {
                    if (currentState.currentToolTipArea.yMax + currentState.tooltipArea.height < currentArea.yMax)
                    {
                        currentState.currentToolTipArea.y += currentState.tooltipArea.height;
                    }
                    else
                    {
                        currentState.currentToolTipArea.y -= currentState.currentToolTipArea.height;
                    }
                }
                if (currentState.currentToolTipArea.y < 0)
                {
                    currentState.currentToolTipArea.y = 0;
                }


                currentState.currentToolTipTitleArea.x     = currentState.currentToolTipArea.x;
                currentState.currentToolTipTitleArea.width = currentState.currentToolTipArea.width;

                currentState.currentToolTipContentsArea.x     = currentState.currentToolTipArea.x;
                currentState.currentToolTipContentsArea.width = currentState.currentToolTipArea.width;

                currentState.currentToolTipKeyCodesArea.x     = currentState.currentToolTipArea.x;
                currentState.currentToolTipKeyCodesArea.width = currentState.currentToolTipArea.width;

                currentState.currentToolTipTitleArea.height    = currentToolTipTitleHeight;
                currentState.currentToolTipContentsArea.height = currentToolTipContentsHeight;
                currentState.currentToolTipKeyCodesArea.height = currentToolTipKeyCodesHeight;

                currentState.currentToolTipTitleArea.y    = currentState.currentToolTipArea.y;
                currentState.currentToolTipContentsArea.y = currentState.currentToolTipTitleArea.y + currentState.currentToolTipTitleArea.height;
                currentState.currentToolTipKeyCodesArea.y = currentState.currentToolTipContentsArea.y + currentState.currentToolTipContentsArea.height;

                if (currentState.currentToolTipKeyCodes != null)
                {
                    currentState.currentToolTipKeyCodesArea.height += 4;
                }
                else
                {
                    currentState.currentToolTipContentsArea.height += 4;
                }
            }
        }
Example #10
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Mouse0))
        {
            if ((IsCraftArbre | IsCraftFleur | IsCraftRoche) && (rect.Contains(new Vector2(Input.mousePosition.x, -Input.mousePosition.y + 530))) == true) // si un des menus est ouvert et qu'on clique dedans, on ne crée pas de raycast
                                                                                                                                                           //( pour éviter que le personnage ne selectionne un objet derriere le menu)
            {
            }

            else
            {
                RaycastHit hit;
                Ray        ray = camera.ScreenPointToRay(Input.mousePosition);
                if (Physics.Raycast(ray, out hit))                                           // on verifie si le raycast a touché un gameobject
                {
                    mP   = new Vector2(Input.mousePosition.x, -Input.mousePosition.y + 530); // on prend les coordonnées du clic pour créer le menu où on clic
                    rect = GUIUtility.ScreenToGUIRect(new Rect(mP.x, mP.y, 150, 250));       // on crée le rectangle du menus pour vérifier avec le contains

                    if (hit.collider.CompareTag("Arbre"))                                    // si on touche un arbre :
                    {
                        if (IsCraftArbre == false)                                           // si un autre menu est ouvert alors qu'on a cliqué sur l'arbre, on le ferme
                        {
                            cible        = hit;
                            R            = ray;
                            IsCraftFleur = false;
                            IsCraftRoche = false;
                            IsCraftArbre = true;
                        }
                        else
                        {
                            IsCraftArbre = false;
                            IsCraftArbre = true;
                        }
                    }
                    if (hit.collider.CompareTag("Untagged") || (hit.collider.CompareTag("Arbre") == false && hit.collider.CompareTag("Roche1") == false && hit.collider.CompareTag("Roche2") == false && hit.collider.CompareTag("Roche3") == false && hit.collider.CompareTag("Fleurs") == false))
                    {
                        IsCraftArbre = false;
                        IsCraftFleur = false;
                        IsCraftRoche = false;
                    }

                    if (hit.collider.CompareTag("Bois")) // si on clic sur une buche et qu'on a assez de place dans l'inventaire, on la récupère
                    {
                        if (NbrPlace(bois) > 0)          // a changer lorsque l'inventaire sera fonctionnelle
                        {
                            Destroy(hit.transform.gameObject);
                            AjouterInventaire(bois, 1); // à changer lorsque l'inventaire sera terminé
                        }
                    }

                    if ((hit.collider.CompareTag("Roche1")) || (hit.collider.CompareTag("Roche2")) || (hit.collider.CompareTag("Roche3"))) //pareil avec les roches
                    {
                        if (IsCraftRoche == false)
                        {
                            cible        = hit;
                            R            = ray;
                            IsCraftArbre = false;
                            IsCraftFleur = false;
                            IsCraftRoche = true;
                        }
                        else
                        {
                            IsCraftRoche = false;
                            IsCraftRoche = true;
                        }
                    }

                    if (hit.collider.CompareTag("Pierre")) // pareil que les buches
                    {
                        if (NbrPlace(pierre) > 0)
                        {
                            Destroy(hit.transform.gameObject);
                            AjouterInventaire(pierre, 1); // a changer plus tard selon le fonctionnement de l'inventaire
                        }
                    }

                    if (hit.collider.CompareTag("Fleurs")) //same
                    {
                        if (IsCraftFleur == false)
                        {
                            cible        = hit;
                            R            = ray;
                            IsCraftArbre = false;
                            IsCraftRoche = false;
                            IsCraftFleur = true;
                        }
                        else
                        {
                            IsCraftFleur = false;
                            IsCraftFleur = true;
                        }
                    }

                    if (hit.collider.CompareTag("FleursDrop"))//same
                    {
                        if (NbrPlace(fleursdrop) > 0)
                        {
                            Destroy(hit.transform.gameObject);
                            AjouterInventaire(fleursdrop, 3); // à changer plus tard selon le fonctionnement de l'inventaire
                        }
                    }
                }
            }
        }
    }
Example #11
0
        internal bool OnGUI(Rect position, SerializedProperty property, GUIContent label, bool includeChildren, Rect visibleArea)
        {
            TestInvalidateCache();

            float oldLabelWidth, oldFieldWidth;

            float propHeight = position.height;

            position.height = 0;
            if (m_DecoratorDrawers != null && !isCurrentlyNested)
            {
                foreach (DecoratorDrawer decorator in m_DecoratorDrawers)
                {
                    position.height = decorator.GetHeight();

                    oldLabelWidth = EditorGUIUtility.labelWidth;
                    oldFieldWidth = EditorGUIUtility.fieldWidth;
                    decorator.OnGUI(position);
                    EditorGUIUtility.labelWidth = oldLabelWidth;
                    EditorGUIUtility.fieldWidth = oldFieldWidth;

                    position.y += position.height;
                    propHeight -= position.height;
                }
            }

            position.height = propHeight;
            if (propertyDrawer != null)
            {
                // Remember widths
                oldLabelWidth = EditorGUIUtility.labelWidth;
                oldFieldWidth = EditorGUIUtility.fieldWidth;
                // Draw with custom drawer - retrieve it BEFORE increasing nesting.
                PropertyDrawer drawer = propertyDrawer;

                using (var nestingContext = IncrementNestingContext())
                {
                    drawer.OnGUISafe(position, property.Copy(), label ?? EditorGUIUtility.TempContent(property.localizedDisplayName, tooltip));
                }

                // Restore widths
                EditorGUIUtility.labelWidth = oldLabelWidth;
                EditorGUIUtility.fieldWidth = oldFieldWidth;

                return(false);
            }
            else
            {
                if (!includeChildren)
                {
                    return(EditorGUI.DefaultPropertyField(position, property, label));
                }

                if (UseReorderabelListControl(property))
                {
                    ReorderableListWrapper reorderableList;
                    string key = ReorderableListWrapper.GetPropertyIdentifier(property);

                    if (!s_reorderableLists.TryGetValue(key, out reorderableList))
                    {
                        // Manual layout controls don't call GetHeight() method so we need to have a way to initialized list as we prepare to render it here
                        reorderableList         = new ReorderableListWrapper(property, label, true);
                        s_reorderableLists[key] = reorderableList;
                    }

                    // Calculate visibility rect specifically for reorderable list as when applied for the whole serialized object,
                    // it causes collapsed out of sight array elements appear thus messing up scroll-bar experience
                    var screenPos = GUIUtility.GUIToScreenPoint(position.position);

                    screenPos.y = Mathf.Clamp(screenPos.y,
                                              GUIView.current?.screenPosition.yMin ?? 0,
                                              GUIView.current?.screenPosition.yMax ?? Screen.height);

                    Rect listVisibility = new Rect(screenPos.x, screenPos.y,
                                                   GUIView.current?.screenPosition.width ?? Screen.width,
                                                   GUIView.current?.screenPosition.height ?? Screen.height);

                    listVisibility = GUIUtility.ScreenToGUIRect(listVisibility);

                    reorderableList.Property = property;
                    reorderableList.Draw(label, position, listVisibility, tooltip, includeChildren);
                    return(!includeChildren && property.isExpanded);
                }

                // Remember state
                Vector2 oldIconSize = EditorGUIUtility.GetIconSize();
                bool    wasEnabled  = GUI.enabled;
                int     origIndent  = EditorGUI.indentLevel;

                int relIndent = origIndent - property.depth;

                SerializedProperty prop = property.Copy();

                position.height = EditorGUI.GetSinglePropertyHeight(prop, label);

                // First property with custom label
                EditorGUI.indentLevel = prop.depth + relIndent;
                bool childrenAreExpanded = EditorGUI.DefaultPropertyField(position, prop, label) && EditorGUI.HasVisibleChildFields(prop);
                position.y += position.height + EditorGUI.kControlVerticalSpacing;

                // Loop through all child properties
                if (childrenAreExpanded)
                {
                    SerializedProperty endProperty = prop.GetEndProperty();
                    while (prop.NextVisible(childrenAreExpanded) && !SerializedProperty.EqualContents(prop, endProperty))
                    {
                        var handler = ScriptAttributeUtility.GetHandler(prop);
                        EditorGUI.indentLevel = prop.depth + relIndent;
                        position.height       = handler.GetHeight(prop, null, UseReorderabelListControl(prop) && includeChildren);

                        if (position.Overlaps(visibleArea))
                        {
                            EditorGUI.BeginChangeCheck();
                            childrenAreExpanded = handler.OnGUI(position, prop, null, UseReorderabelListControl(prop)) && EditorGUI.HasVisibleChildFields(prop);
                            // Changing child properties (like array size) may invalidate the iterator,
                            // so stop now, or we may get errors.
                            if (EditorGUI.EndChangeCheck())
                            {
                                break;
                            }
                        }

                        position.y += position.height + EditorGUI.kControlVerticalSpacing;
                    }
                }

                // Restore state
                GUI.enabled = wasEnabled;
                EditorGUIUtility.SetIconSize(oldIconSize);
                EditorGUI.indentLevel = origIndent;

                return(false);
            }
        }
Example #12
0
 public static Rect ScreenToGUIRect(Rect screenRect)
 {
     return(GUIUtility.ScreenToGUIRect(screenRect));
 }
        public void Show(Action <int> onItemSelected)
        {
            if (forceToUnShow)
            {
                forceToUnShow        = false;
                isClickedComboButton = false;
            }

            var done      = false;
            var controlID = GUIUtility.GetControlID(FocusType.Passive);

            Vector2 currentMousePosition = Vector2.zero;

            if (Event.current.GetTypeForControl(controlID) == EventType.mouseUp)
            {
                if (isClickedComboButton)
                {
                    done = true;
                    currentMousePosition = Event.current.mousePosition;
                }
            }

            if (GUI.Button(Rect, ButtonContent, buttonStyle))
            {
                if (useControlID == -1)
                {
                    useControlID         = controlID;
                    isClickedComboButton = false;
                }

                if (useControlID != controlID)
                {
                    forceToUnShow = true;
                    useControlID  = controlID;
                }
                isClickedComboButton = true;
            }

            if (isClickedComboButton)
            {
                GUI.enabled = false;
                GUI.color   = new Color(1, 1, 1, 2);

                var location = GUIUtility.GUIToScreenPoint(new Vector2(Rect.x, Rect.y + listStyle.CalcHeight(listContent[0], 1.0f)));
                var size     = new Vector2(Rect.width, listStyle.CalcHeight(listContent[0], 1.0f) * listContent.Length);

                var innerRect = new Rect(0, 0, size.x, size.y);

                var outerRectScreen = new Rect(location.x, location.y, size.x, size.y);
                if (outerRectScreen.yMax > _windowYmax)
                {
                    outerRectScreen.height = _windowYmax - outerRectScreen.y;
                    outerRectScreen.width += 20;
                }

                if (currentMousePosition != Vector2.zero && outerRectScreen.Contains(GUIUtility.GUIToScreenPoint(currentMousePosition)))
                {
                    done = false;
                }

                CurrentDropdownDrawer = () =>
                {
                    GUI.enabled = true;

                    var outerRectLocal = GUIUtility.ScreenToGUIRect(outerRectScreen);

                    GUI.Box(outerRectLocal, GUIContent.none, GUI.skin.box);

                    _scrollPosition = GUI.BeginScrollView(outerRectLocal, _scrollPosition, innerRect, false, false);
                    {
                        const int initialSelectedItem  = -1;
                        var       newSelectedItemIndex = GUI.SelectionGrid(innerRect, initialSelectedItem, listContent, 1, listStyle);
                        if (newSelectedItemIndex != initialSelectedItem)
                        {
                            onItemSelected(newSelectedItemIndex);
                            isClickedComboButton = false;
                        }
                    }
                    GUI.EndScrollView(true);
                };
            }

            if (done)
            {
                isClickedComboButton = false;
            }
        }
Example #14
0
    public static void RenderGameUsingDrawTexture(VGDLGame game, RenderTexture renderTarget, bool OnGUI = false)
    {
        var drawOrder = game.getSpriteOrder();

        RenderTexture prevRT = null;

        if (renderTarget != null)
        {
            prevRT = RenderTexture.active;
            Graphics.SetRenderTarget(renderTarget);
        }

        GL.PushMatrix();                                                //Saves both projection and modelview matrices to the matrix stack.
        GL.LoadPixelMatrix(0, game.screenSize.x, game.screenSize.y, 0); //Setup a matrix for pixel-correct rendering.

        //Clear the background before we render a new round of sprites.
        GL.Clear(true, true, Color.black);

        foreach (var stype in drawOrder)
        {
            foreach (var vgdlSprite in game.getSprites(stype))
            {
                //NOTE: hidden should just be handled when making observations.
                if (vgdlSprite.invisible.CompareAndIgnoreCase("True"))
                {
                    continue;
                }
                //|| vgdlSprite.hidden.CompareAndIgnoreCase("True")) continue;

                var show  = false;
                var invis = vgdlSprite.invisible.Split(',');

                //NOTE: this is similar to the boolean.parseBoolean() logic in JAVA.
                bool invis0 = bool.TryParse(invis[0], out invis0) && invis0;

                if (game.no_players == 2)
                {
                    bool invis1 = invis.Length > 1 ? bool.TryParse(invis[1], out invis1) && invis1 : invis0;

                    //NOTE: Actually it seems game.humanPlayers is always false for all elements, in GVGAI
                    //and humanID is never used, so the code has been refactored.

                    /*
                     *      boolean displayP1 = game.humanPlayer[0] && !invis0;
                     *      boolean displayP2 = game.humanPlayer[1] && !invis1;
                     *
                     *      if (game.humanPlayer[0] && game.humanPlayer[1] || !game.humanPlayer[0] && !game.humanPlayer[1]) {
                     *              if (invis0 == invis1) show = !invis0;
                     *              else if (color == Types.DARKGRAY) show = false;
                     *              else show = !invis0 || !invis1;
                     *      } else
                     *              show = displayP1 || displayP2;
                     */

                    if (invis0 == invis1)
                    {
                        show = !invis0;
                    }
                    else
                    {
                        //NOTE: this seems odd, an implicit invisibility feature.
                        show = vgdlSprite.color != VGDLColors.DarkGray;
                    }
                }
                else
                {
                    show = !invis0;
                }

                if (!show || vgdlSprite.is_disabled())
                {
                    continue;
                }

                //var screenRect = ConvertToScreenRect(game, vgdlSprite.rect);
                var screenRect = new Rect(vgdlSprite.rect);

                if (vgdlSprite.shrinkfactor != 1f && vgdlSprite.shrinkfactor > 0f)
                {
                    screenRect.width  *= vgdlSprite.shrinkfactor;
                    screenRect.height *= vgdlSprite.shrinkfactor;
                    screenRect.x      += (vgdlSprite.rect.width - screenRect.width) / 2;
                    screenRect.y      += (vgdlSprite.rect.height - screenRect.height) / 2;
                }

                if (vgdlSprite.is_avatar && vgdlSprite.is_oriented)
                {
                    //TODO: Draw arrow, look at _drawOriented()

                    GL.PushMatrix();
                    GL.LoadPixelMatrix(0, game.screenSize.x, game.screenSize.y, 0);                     //Setup a matrix for pixel-correct rendering.

                    //backup GUI matrix, before modifying.
                    var matrixBackup = GUI.matrix;

                    if (OnGUI)
                    {
                        //Convert it to a Screen rect, then convert it to a GUI rect.
                        screenRect = ConvertToScreenRect(game, screenRect);
                        screenRect = GUIUtility.ScreenToGUIRect(screenRect);

                        //GUIUtility.ScaleAroundPivot(Vector2.one, screenRect.center);
                        GUIUtility.RotateAroundPivot(vgdlSprite.rotation * Mathf.Rad2Deg, screenRect.center);

                        //NOTE: Don't think this is needed, but maybe adjust this if the sprite shows up behind other things.
                        //GUI.depth=149;
                    }
                    else
                    {
                        GL.MultMatrix(Matrix4x4.TRS(screenRect.center, Quaternion.AngleAxis(vgdlSprite.rotation * Mathf.Rad2Deg, Vector3.forward), screenRect.size));
                    }


                    if (!OnGUI)
                    {
                        //NOTE: Translation already applied by MatrixMult, but we need an offset of half the width/height.
                        screenRect.x      = -0.5f;
                        screenRect.y      = -0.5f;
                        screenRect.width  = 1;
                        screenRect.height = 1;
                    }


                    if (vgdlSprite.image != null)
                    {
                        //TODO: rescale location based on renderTarget?
                        Graphics.DrawTexture(screenRect, vgdlSprite.image.texture);
                    }
                    else
                    {
                        Graphics.DrawTexture(screenRect, Texture2D.whiteTexture,
                                             Rect.MinMaxRect(0, 0, 1, 1), 0, 0,
                                             0, 0, vgdlSprite.color);
                    }

                    if (OnGUI)
                    {
                        GUI.matrix = matrixBackup;
                    }

                    GL.PopMatrix();

                    //TODO: Draw Arrow if vgdlSprite.draw_arrow
                }
                else
                {
                    if (vgdlSprite.image != null)
                    {
                        //TODO: rescale location based on renderTarget?
                        Graphics.DrawTexture(screenRect, vgdlSprite.image.texture);
                    }
                    else
                    {
                        Graphics.DrawTexture(screenRect, Texture2D.whiteTexture, Rect.MinMaxRect(0, 0, 1, 1), 0, 0, 0, 0, vgdlSprite.color);
                    }
                }


                //TODO:Draw Health and Resources

                /*
                 * if(resources.size() > 0)
                 * {
                 * _drawResources(gphx, game, r);
                 * }
                 *
                 * if(healthPoints > 0)
                 * {
                 * _drawHealthBar(gphx, game, r);
                 * }
                 */
            }
        }

        GL.PopMatrix();         //Restores both projection and modelview matrices off the top of the matrix stack.

        if (prevRT != null)
        {
            RenderTexture.active = prevRT;
        }
    }
Example #15
0
        private static void OnSceneGUIDelegate(SceneView sceneView)
        {
            if (!Prefs.SceneViewHighlighter)
            {
                return;
            }

            var evt = Event.current;

            if (evt.type == EventType.Repaint)
            {
                var go = s_HoveredGameObject;
                if (go == null)
                {
                    go = s_HoveredGameObjectSV;
                }
                if (go == null || !s_DrawIndicator)
                {
                    return;
                }

                Color hc = Handles.color;
                if (go.transform is RectTransform && Prefs.svRectTransform)
                {
                    var rect = go.transform as RectTransform;
                    var v    = new Vector3[4];
                    rect.GetWorldCorners(v);
                    var outline = Prefs.svRectTransformOverlayColor;
                    outline.a = 1;
                    Handles.DrawSolidRectangleWithOutline(v, Prefs.svRectTransformOverlayColor, outline);
                }
                else if (Prefs.svIndicator)
                {
                    var        s = HandleUtility.GetHandleSize(go.transform.position) / 2.5f;
                    Quaternion q = Quaternion.Euler(45, -45, 0);
                    Handles.color = Prefs.svIndicatorColor;
                    Handles.ConeHandleCap(0, go.transform.position + new Vector3(s / 2, s / 2, -s / 2), q, s, EventType.Repaint);
                }
                if (go == s_HoveredGameObjectSV)
                {
                    if (GUIUtility.ScreenToGUIRect(sceneView.position).Contains(evt.mousePosition))
                    {
                        var style = (GUIStyle)"sv_label_1";
                        var rect  = new Rect();
                        rect.size   = style.CalcSize(Utils.TempContent(go.name));
                        rect.center = evt.mousePosition;
                        if (Prefs.svOutlineSceneViewName)
                        {
                            rect.y += 30;
                        }

                        var pos = HandleUtility.GUIPointToWorldRay(rect.center).GetPoint(1);
                        if (Prefs.svOutlineSceneViewLine)
                        {
                            Handles.DrawDottedLine(go.transform.position, pos, 5);
                        }

                        Handles.BeginGUI();
                        if (Prefs.svOutlineSceneViewName)
                        {
                            GUI.Label(rect, go.name, style);
                        }
                        Handles.EndGUI();
                    }
                }
                Handles.color = hc;
            }

            if (evt.type == EventType.ExecuteCommand && evt.commandName == "ModifierKeyChanged")
            {
                evt.Use();
                if (s_LastModifierKey != Utils.CheckModifierKey((ModifierKey)Prefs.svOutlineSceneViewModifier))
                {
                    s_LastModifierKey = Utils.CheckModifierKey((ModifierKey)Prefs.svOutlineSceneViewModifier);
                    if (s_LastModifierKey)
                    {
                        CheckSceneViewHover();
                    }
                    else
                    {
                        RemoveHighlightObjectSV();
                    }
                }
            }

            if (evt.type == EventType.MouseMove)
            {
                s_LastMousePosition = evt.mousePosition;
                if (s_LastModifierKey)
                {
                    CheckSceneViewHover();
                }
            }

            if (s_LastModifierKey && s_HoveredGameObjectSV != null)
            {
                if (evt.type == EventType.ScrollWheel)
                {
                    evt.Use();
                    int delta = 0;
                    if (evt.delta.y > 1)
                    {
                        delta = 1;
                    }
                    if (evt.delta.y < 1)
                    {
                        delta = -1;
                    }
                    if (delta != 0)
                    {
                        SwitchSceneViewHover(delta);
                    }
                }

                int cid = GUIUtility.GetControlID("HoveredGameObjectSV".GetHashCode(), FocusType.Passive);
                switch (Event.current.GetTypeForControl(cid))
                {
                case EventType.MouseDown:
                    GUIUtility.hotControl = cid;
                    Event.current.Use();
                    break;

                case EventType.MouseUp:
                    if (GUIUtility.hotControl == cid)
                    {
                        GUIUtility.hotControl = 0;
                        Event.current.Use();
                        Selection.activeGameObject = s_HoveredGameObjectSV;
                    }
                    break;
                }
            }
        }