コード例 #1
0
        /// <summary>
        /// Creates GUI elements for fields common to all joints.
        /// </summary>
        protected virtual void BuildGUI(Joint joint, bool showOffsets)
        {
            this.showOffsets = showOffsets;

            targetField = new GUIGameObjectField(typeof(Rigidbody), new LocEdString("Target"));
            anchorField = new GUIGameObjectField(typeof(Rigidbody), new LocEdString("Anchor"));

            if (showOffsets)
            {
                targetOffsetField = new GUIVector3Field(new LocEdString("Target offset"));
                anchorOffsetField = new GUIVector3Field(new LocEdString("Anchor offset"));
            }

            breakForceField  = new GUIFloatField(new LocEdString("Break force"));
            breakTorqueField = new GUIFloatField(new LocEdString("Break torque"));
            collisionField   = new GUIToggleField(new LocEdString("Enable collision"));

            targetField.OnChanged += x => { joint.SetRigidbody(JointBody.Target, (Rigidbody)x); MarkAsModified(); ConfirmModify(); };
            anchorField.OnChanged += x => { joint.SetRigidbody(JointBody.Anchor, (Rigidbody)x); MarkAsModified(); ConfirmModify(); };

            if (showOffsets)
            {
                targetOffsetField.OnChanged   += x => { joint.SetPosition(JointBody.Target, x); MarkAsModified(); };
                targetOffsetField.OnFocusLost += ConfirmModify;
                targetOffsetField.OnConfirmed += ConfirmModify;

                anchorOffsetField.OnChanged   += x => { joint.SetPosition(JointBody.Anchor, x); MarkAsModified(); };
                anchorOffsetField.OnFocusLost += ConfirmModify;
                anchorOffsetField.OnConfirmed += ConfirmModify;
            }

            breakForceField.OnChanged   += x => { joint.BreakForce = x; MarkAsModified(); };
            breakForceField.OnFocusLost += ConfirmModify;
            breakForceField.OnConfirmed += ConfirmModify;

            breakTorqueField.OnChanged   += x => { joint.BreakTorque = x; MarkAsModified(); };
            breakTorqueField.OnFocusLost += ConfirmModify;
            breakTorqueField.OnConfirmed += ConfirmModify;

            collisionField.OnChanged += x => { joint.EnableCollision = x; MarkAsModified(); ConfirmModify(); };

            Layout.AddElement(targetField);
            if (showOffsets)
            {
                Layout.AddElement(targetOffsetField);
            }
            Layout.AddElement(anchorField);
            if (showOffsets)
            {
                Layout.AddElement(anchorOffsetField);
            }
            Layout.AddElement(breakForceField);
            Layout.AddElement(breakTorqueField);
            Layout.AddElement(collisionField);
        }
コード例 #2
0
        /// <inheritoc/>
        protected internal override void Initialize(int layoutIndex)
        {
            if (property.Type == SerializableProperty.FieldType.Vector3)
            {
                guiField              = new GUIVector3Field(new GUIContent(title));
                guiField.OnChanged   += OnFieldValueChanged;
                guiField.OnConfirmed += OnFieldValueConfirm;
                guiField.OnFocusLost += OnFieldValueConfirm;

                layout.AddElement(layoutIndex, guiField);
            }
        }
コード例 #3
0
        /// <summary>
        /// Creates a new material parameter GUI.
        /// </summary>
        /// <param name="shaderParam">Shader parameter to create the GUI for. Must be of 3D vector type.</param>
        /// <param name="material">Material the parameter is a part of.</param>
        /// <param name="layout">Layout to append the GUI elements to.</param>
        internal MaterialParamVec3GUI(ShaderParameter shaderParam, Material material, GUILayout layout)
            : base(shaderParam)
        {
            LocString title = new LocEdString(shaderParam.name);

            guiElem            = new GUIVector3Field(title);
            guiElem.OnChanged += (x) =>
            {
                material.SetVector3(shaderParam.name, x);
                EditorApplication.SetDirty(material);
            };

            layout.AddElement(guiElem);
        }
コード例 #4
0
        /// <summary>
        /// Destroys all inspector GUI elements.
        /// </summary>
        internal void Clear()
        {
            for (int i = 0; i < inspectorComponents.Count; i++)
            {
                inspectorComponents[i].foldout.Destroy();
                inspectorComponents[i].removeBtn.Destroy();
                inspectorComponents[i].inspector.Destroy();
            }

            inspectorComponents.Clear();

            if (inspectorResource != null)
            {
                inspectorResource.inspector.Destroy();
                inspectorResource = null;
            }

            if (inspectorScrollArea != null)
            {
                inspectorScrollArea.Destroy();
                inspectorScrollArea = null;
            }

            if (scrollAreaHighlight != null)
            {
                scrollAreaHighlight.Destroy();
                scrollAreaHighlight = null;
            }

            if (highlightPanel != null)
            {
                highlightPanel.Destroy();
                highlightPanel = null;
            }

            activeSO       = null;
            soNameInput    = null;
            soActiveToggle = null;
            soMobility     = null;
            soPrefabLayout = null;
            soHasPrefab    = false;
            soPos          = null;
            soRot          = null;
            soScale        = null;
            dropAreas      = new Rect2I[0];

            activeResourcePath = null;
            currentType        = InspectorType.None;
        }
コード例 #5
0
        /// <inheritoc/>
        protected internal override void Initialize(int layoutIndex)
        {
            GUILayoutX boundsLayout = new GUILayoutX();

            centerField = new GUIVector3Field(new LocEdString("Center"), 50);
            sizeField   = new GUIVector3Field(new LocEdString("Size"), 50);

            layout.AddElement(layoutIndex, boundsLayout);

            boundsLayout.AddElement(new GUILabel(new LocEdString(title), GUIOption.FixedWidth(100)));

            GUILayoutY boundsContent = boundsLayout.AddLayoutY();

            boundsContent.AddElement(centerField);
            boundsContent.AddElement(sizeField);

            centerField.OnChanged += x =>
            {
                AABox   bounds = property.GetValue <AABox>();
                Vector3 min    = x - bounds.Size * 0.5f;
                Vector3 max    = x + bounds.Size * 0.5f;

                property.SetValue(new AABox(min, max));
                state |= InspectableState.ModifyInProgress;
            };
            centerField.OnConfirmed += OnFieldValueConfirm;
            centerField.OnFocusLost += OnFieldValueConfirm;

            sizeField.OnChanged += x =>
            {
                AABox   bounds = property.GetValue <AABox>();
                Vector3 min    = bounds.Center - x * 0.5f;
                Vector3 max    = bounds.Center + x * 0.5f;

                property.SetValue(new AABox(min, max));
                state |= InspectableState.ModifyInProgress;
            };
            sizeField.OnConfirmed += OnFieldValueConfirm;
            sizeField.OnFocusLost += OnFieldValueConfirm;
        }
コード例 #6
0
 private static extern void Internal_CreateInstance(GUIVector3Field instance, ref GUIContent title, int titleWidth,
                                                    string style, GUIOption[] options, bool withTitle);
コード例 #7
0
        /// <summary>
        /// Creates GUI elements required for displaying <see cref="SceneObject"/> fields like name, prefab data and
        /// transform (position, rotation, scale). Assumes that necessary inspector scroll area layout has already been
        /// created.
        /// </summary>
        private void CreateSceneObjectFields()
        {
            GUIPanel sceneObjectPanel = inspectorLayout.AddPanel();

            sceneObjectPanel.SetHeight(GetTitleBounds().height);

            GUILayoutY sceneObjectLayout = sceneObjectPanel.AddLayoutY();

            sceneObjectLayout.SetPosition(PADDING, PADDING);

            GUIPanel sceneObjectBgPanel = sceneObjectPanel.AddPanel(1);

            GUILayoutX nameLayout = sceneObjectLayout.AddLayoutX();

            soActiveToggle            = new GUIToggle("");
            soActiveToggle.OnToggled += OnSceneObjectActiveStateToggled;
            GUILabel nameLbl = new GUILabel(new LocEdString("Name"), GUIOption.FixedWidth(50));

            soNameInput              = new GUITextBox(false, GUIOption.FlexibleWidth(180));
            soNameInput.Text         = activeSO.Name;
            soNameInput.OnChanged   += OnSceneObjectRename;
            soNameInput.OnConfirmed += OnModifyConfirm;
            soNameInput.OnFocusLost += OnModifyConfirm;

            nameLayout.AddElement(soActiveToggle);
            nameLayout.AddSpace(3);
            nameLayout.AddElement(nameLbl);
            nameLayout.AddElement(soNameInput);
            nameLayout.AddFlexibleSpace();

            GUILayoutX mobilityLayout = sceneObjectLayout.AddLayoutX();
            GUILabel   mobilityLbl    = new GUILabel(new LocEdString("Mobility"), GUIOption.FixedWidth(50));

            soMobility       = new GUIEnumField(typeof(ObjectMobility), "", 0, GUIOption.FixedWidth(85));
            soMobility.Value = (ulong)activeSO.Mobility;
            soMobility.OnSelectionChanged += value => activeSO.Mobility = (ObjectMobility)value;
            mobilityLayout.AddElement(mobilityLbl);
            mobilityLayout.AddElement(soMobility);

            soPrefabLayout = sceneObjectLayout.AddLayoutX();

            soPos = new GUIVector3Field(new LocEdString("Position"), 50);
            sceneObjectLayout.AddElement(soPos);

            soPos.OnChanged   += OnPositionChanged;
            soPos.OnConfirmed += OnModifyConfirm;
            soPos.OnFocusLost += OnModifyConfirm;

            soRot = new GUIVector3Field(new LocEdString("Rotation"), 50);
            sceneObjectLayout.AddElement(soRot);

            soRot.OnChanged   += OnRotationChanged;
            soRot.OnConfirmed += OnModifyConfirm;
            soRot.OnFocusLost += OnModifyConfirm;

            soScale = new GUIVector3Field(new LocEdString("Scale"), 50);
            sceneObjectLayout.AddElement(soScale);

            soScale.OnChanged   += OnScaleChanged;
            soScale.OnConfirmed += OnModifyConfirm;
            soScale.OnFocusLost += OnModifyConfirm;

            sceneObjectLayout.AddFlexibleSpace();

            GUITexture titleBg = new GUITexture(null, EditorStylesInternal.InspectorTitleBg);

            sceneObjectBgPanel.AddElement(titleBg);
        }