コード例 #1
0
        protected override void Awake()
        {
            ObjectBender bender = (ObjectBender)target;

            if (!Application.isPlaying)
            {
                bender.UpdateReferences();
            }
            base.Awake();
        }
コード例 #2
0
        protected override void BodyGUI()
        {
            base.BodyGUI();
            ObjectBender bender     = (ObjectBender)target;
            int          childCount = 0;

            GetChildCount(bender.transform, ref childCount);
            if (bender.bendProperties.Length - 1 != childCount && !Application.isPlaying)
            {
                bender.UpdateReferences();
            }
            bender.axis   = (ObjectBender.Axis)EditorGUILayout.EnumPopup("Axis", bender.axis);
            bender.upMode = (ObjectBender.NormalMode)EditorGUILayout.EnumPopup("Up Vector", bender.upMode);
            if (bender.upMode == ObjectBender.NormalMode.Custom)
            {
                bender.customNormal = EditorGUILayout.Vector3Field("Custom Up", bender.customNormal);
            }
            bender.forwardMode = (ObjectBender.ForwardMode)EditorGUILayout.EnumPopup("Forward Vector", bender.forwardMode);
            if (bender.forwardMode == ObjectBender.ForwardMode.Custom)
            {
                bender.customForward = EditorGUILayout.Vector3Field("Custom Forward", bender.customForward);
            }
            if (!bender.bend)
            {
                float scrollHeight = Mathf.Min(bender.bendProperties.Length, 15) * 22;
                scroll = EditorGUILayout.BeginScrollView(scroll, GUILayout.Height(scrollHeight + 5));

                for (int i = 0; i < bender.bendProperties.Length; i++)
                {
                    bool isSelected = selected.Contains(i);
                    if (!bender.bendProperties[i].enabled)
                    {
                        GUI.color = Color.gray;
                        if (isSelected)
                        {
                            GUI.color = Color.Lerp(Color.gray, SplinePrefs.highlightColor, 0.5f);
                        }
                    }
                    else
                    {
                        if (isSelected)
                        {
                            GUI.color = SplinePrefs.highlightColor;
                        }
                        else
                        {
                            GUI.color = Color.white;
                        }
                    }
                    GUILayout.Box(bender.bendProperties[i].transform.transform.name, GUILayout.Height(18), GUILayout.Width(EditorGUIUtility.currentViewWidth - 60));
                    if (GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition) && Event.current.type == EventType.MouseDown)
                    {
                        if (Event.current.control)
                        {
                            if (!selected.Contains(i))
                            {
                                selected.Add(i);
                            }
                        }
                        else if (Event.current.shift && selected.Count > 0)
                        {
                            int from = selected[0];
                            selected.Clear();
                            if (from < i)
                            {
                                for (int n = from; n <= i; n++)
                                {
                                    selected.Add(n);
                                }
                            }
                            else
                            {
                                for (int n = from; n >= i; n--)
                                {
                                    selected.Add(n);
                                }
                            }
                        }
                        else
                        {
                            selected.Clear();
                            selected.Add(i);
                        }
                        Repaint();
                        SceneView.RepaintAll();
                    }
                    GUI.color = Color.white;
                }
                EditorGUILayout.EndScrollView();

                if (selected.Count > 0)
                {
                    PropertyEditor(bender.bendProperties);
                }

                if (selected.Count > 0)
                {
                    if (Event.current.type == EventType.KeyDown)
                    {
                        if (Event.current.keyCode == KeyCode.DownArrow)
                        {
                            if (selected.Count > 1)
                            {
                                int temp = selected[selected.Count - 1];
                                selected.Clear();
                                selected.Add(temp);
                            }
                            selected[0]++;
                            if (selected[0] >= bender.bendProperties.Length)
                            {
                                selected[0] = 0;
                            }
                        }
                        if (Event.current.keyCode == KeyCode.UpArrow)
                        {
                            if (selected.Count > 1)
                            {
                                int temp = selected[0];
                                selected.Clear();
                                selected.Add(temp);
                            }
                            selected[0]--;
                            if (selected[0] < 0)
                            {
                                selected[0] = bender.bendProperties.Length - 1;
                            }
                        }

                        Repaint();
                        SceneView.RepaintAll();
                        Event.current.Use();
                    }
                }
            }
            string editModeText = "Enter Edit Mode";

            if (!bender.bend)
            {
                editModeText = "Bend";
            }
            if (GUILayout.Button(editModeText))
            {
                if (bender.bend)
                {
                    bender.bend = false;
                }
                else
                {
                    bender.bend = true;
                }
            }
            if (bender.bend && !generatedUvs)
            {
                if (GUILayout.Button("Generate Lightmap UVS"))
                {
                    bender.EditorGenerateLightmapUVs();
                    generatedUvs = true;
                }
            }
        }
コード例 #3
0
        public override void BaseGUI()
        {
            EditorGUILayout.LabelField("ObjectBender is in BETA. Contact [email protected] for support");
            ObjectBender bender = (ObjectBender)target;

            showAveraging = false;
            base.BaseGUI();

            if (bender.bendProperties.Length - 1 != bender.transform.childCount && !Application.isPlaying)
            {
                bender.UpdateReferences();
            }
            bender.axis        = (ObjectBender.Axis)EditorGUILayout.EnumPopup("Axis", bender.axis);
            bender.autoNormals = EditorGUILayout.Toggle("Auto Normals", bender.autoNormals);
            if (bender.autoNormals)
            {
                bender.upVector = EditorGUILayout.Vector3Field("Up Vector3", bender.upVector);
            }
            showProperties = EditorGUILayout.Foldout(showProperties, "Object Properties");
            if (showProperties)
            {
                BendPropertiesGUI(bender.bendProperties);
                if (selectedProperty >= 0)
                {
                    if (Event.current.type == EventType.KeyDown)
                    {
                        if (Event.current.keyCode == KeyCode.DownArrow)
                        {
                            selectedProperty++;
                        }
                        if (Event.current.keyCode == KeyCode.UpArrow)
                        {
                            selectedProperty--;
                        }
                        if (selectedProperty < 0)
                        {
                            selectedProperty = 0;
                        }
                        if (selectedProperty >= bender.bendProperties.Length)
                        {
                            selectedProperty = bender.bendProperties.Length - 1;
                        }
                        drawTransform = bender.bendProperties[selectedProperty].transform.transform;
                        Repaint();
                        SceneView.RepaintAll();
                        Event.current.Use();
                    }
                }
            }
            else
            {
                drawTransform = null;
            }
            string editModeText = "Enter Edit Mode";

            if (!bender.bend)
            {
                editModeText = "Bend";
            }
            if (GUILayout.Button(editModeText))
            {
                if (bender.bend)
                {
                    bender.bend = false;
                }
                else
                {
                    bender.bend = true;
                }
            }
        }