UnityEditor.BodyMaskEditor.DoPicking C# (CSharp) Method

DoPicking() protected static method

protected static DoPicking ( Rect rect, UnityEditor.SerializedProperty bodyMask, int count ) : void
rect UnityEngine.Rect
bodyMask UnityEditor.SerializedProperty
count int
return void
        protected static void DoPicking(Rect rect, SerializedProperty bodyMask, int count)
        {
            if (styles.PickingTexture.image != null)
            {
                int controlID = GUIUtility.GetControlID(s_Hint, FocusType.Passive, rect);
                Event current = Event.current;
                if ((current.GetTypeForControl(controlID) == EventType.MouseDown) && rect.Contains(current.mousePosition))
                {
                    current.Use();
                    int x = ((int) current.mousePosition.x) - ((int) rect.x);
                    int y = styles.UnityDude.image.height - (((int) current.mousePosition.y) - ((int) rect.y));
                    Color pixel = (styles.PickingTexture.image as Texture2D).GetPixel(x, y);
                    bool flag = false;
                    for (int i = 0; i < count; i++)
                    {
                        if (m_MaskBodyPartPicker[i] == pixel)
                        {
                            GUI.changed = true;
                            bodyMask.GetArrayElementAtIndex(i).intValue = (bodyMask.GetArrayElementAtIndex(i).intValue != 1) ? 1 : 0;
                            flag = true;
                        }
                    }
                    if (!flag)
                    {
                        bool flag2 = false;
                        for (int j = 0; (j < count) && !flag2; j++)
                        {
                            flag2 = bodyMask.GetArrayElementAtIndex(j).intValue == 1;
                        }
                        for (int k = 0; k < count; k++)
                        {
                            bodyMask.GetArrayElementAtIndex(k).intValue = flag2 ? 0 : 1;
                        }
                        GUI.changed = true;
                    }
                }
            }
        }

Usage Example

示例#1
0
 public static void Show(SerializedProperty bodyMask, int count)
 {
     if (BodyMaskEditor.styles.UnityDude.image)
     {
         Rect rect = GUILayoutUtility.GetRect(BodyMaskEditor.styles.UnityDude, GUIStyle.none, new GUILayoutOption[]
         {
             GUILayout.MaxWidth((float)BodyMaskEditor.styles.UnityDude.image.width)
         });
         rect.x += (GUIView.current.position.width - rect.width) / 2f;
         Color color = GUI.color;
         GUI.color = ((bodyMask.GetArrayElementAtIndex(0).intValue != 1) ? Color.red : Color.green);
         if (BodyMaskEditor.styles.BodyPart[0].image)
         {
             GUI.DrawTexture(rect, BodyMaskEditor.styles.BodyPart[0].image);
         }
         GUI.color = new Color(0.2f, 0.2f, 0.2f, 1f);
         GUI.DrawTexture(rect, BodyMaskEditor.styles.UnityDude.image);
         for (int i = 1; i < count; i++)
         {
             GUI.color = ((bodyMask.GetArrayElementAtIndex(i).intValue != 1) ? Color.red : Color.green);
             if (BodyMaskEditor.styles.BodyPart[i].image)
             {
                 GUI.DrawTexture(rect, BodyMaskEditor.styles.BodyPart[i].image);
             }
         }
         GUI.color = color;
         BodyMaskEditor.DoPicking(rect, bodyMask, count);
     }
 }
All Usage Examples Of UnityEditor.BodyMaskEditor::DoPicking
BodyMaskEditor