예제 #1
0
    protected virtual void DisplayInspectorGUI()
    {
        JellySprite targetObject = this.target as JellySprite;

        if (targetObject.GetComponent <Renderer>() != null)
        {
            string sortingLayerName = SortingLayerNamePopup("Sorting Layer", targetObject.GetComponent <Renderer>().sortingLayerName);

            if (sortingLayerName != targetObject.GetComponent <Renderer>().sortingLayerName)
            {
                targetObject.GetComponent <Renderer>().sortingLayerName = sortingLayerName;
            }

            int sortingOrder = EditorGUILayout.IntField("Order In Layer", targetObject.GetComponent <Renderer>().sortingOrder);

            if (sortingOrder != targetObject.GetComponent <Renderer>().sortingOrder)
            {
                targetObject.GetComponent <Renderer>().sortingOrder = sortingOrder;
            }
        }

        EditorGUILayout.PropertyField(m_FlipX, new GUIContent("Flip Horizontal"));
        EditorGUILayout.PropertyField(m_FlipY, new GUIContent("Flip Vertical"));

        if (Application.isPlaying)
        {
            GUI.enabled = false;
        }

        EditorGUILayout.PropertyField(m_SpriteScale, new GUIContent("Sprite Scale"));

        GUI.enabled = true;

        if (Application.isPlaying)
        {
            GUI.enabled = false;
        }

        GUILayout.Space(15);

        EditorGUILayout.PropertyField(m_PhysicsMode, new GUIContent("Use 2D Physics"));

        JellySprite.PhysicsStyle selectedStyle = (JellySprite.PhysicsStyle)m_PhysicsStyle.enumValueIndex;

        if (selectedStyle != JellySprite.PhysicsStyle.Grid)
        {
            EditorGUILayout.PropertyField(m_AttachNeighbors, new GUIContent("Attach Neighbors"));
        }

        int initialStyle = m_PhysicsStyle.enumValueIndex;

        EditorGUILayout.PropertyField(m_PhysicsStyle, new GUIContent("Body Configuration"));

        if (m_PhysicsStyle.enumValueIndex != initialStyle && (JellySprite.PhysicsStyle)m_PhysicsStyle.enumValueIndex == JellySprite.PhysicsStyle.Free)
        {
            m_PhysicsStyle.enumValueIndex = initialStyle;
            Debug.LogError("Please use the 'Copy Configuration to Free Mode' button to switch Jelly Sprites to Free Mode");
        }

        switch (selectedStyle)
        {
        case JellySprite.PhysicsStyle.Circle:
            EditorGUILayout.IntSlider(m_CircleRadiusPoints, 4, 128, new GUIContent("Num Colliders"));
            break;

        case JellySprite.PhysicsStyle.Grid:
            m_GridRows.intValue    = EditorGUILayout.IntField("Grid Rows", m_GridRows.intValue);
            m_GridColumns.intValue = EditorGUILayout.IntField("Grid Columns", m_GridColumns.intValue);
            break;

        case JellySprite.PhysicsStyle.Rectangle:
            break;

        case JellySprite.PhysicsStyle.Triangle:
            break;

        case JellySprite.PhysicsStyle.Free:
            for (int i = 0; i < targetObject.m_FreeModeBodyPositions.Count; i++)
            {
                EditorGUILayout.BeginHorizontal();
                Vector2 point     = targetObject.m_FreeModeBodyPositions[i];
                float   radius    = targetObject.m_FreeModeBodyRadii[i];
                bool    kinematic = targetObject.m_FreeModeBodyKinematic[i];

                Vector3 result          = EditorGUILayout.Vector3Field(i == 0? "Centre" : "Body " + i.ToString(), new Vector3(point.x, point.y, radius), GUILayout.MaxWidth(1500f));
                Vector2 positionResult  = new Vector2(result.x, result.y);
                bool    kinematicResult = false;

                if (point != positionResult)
                {
                    Undo.RecordObject(targetObject, "Adjusted Jelly Sprite Body Position");
                    targetObject.m_FreeModeBodyPositions[i] = positionResult;
                    SceneView.RepaintAll();
                }

                if (result.z != radius)
                {
                    Undo.RecordObject(targetObject, "Adjusted Jelly Sprite Body Radius");
                    targetObject.m_FreeModeBodyRadii[i] = result.z;
                    SceneView.RepaintAll();
                }

                using (new FixedWidthLabel("Kinematic"))
                {
                    kinematicResult = EditorGUILayout.Toggle(kinematic);
                }

                if (kinematicResult != kinematic)
                {
                    Undo.RecordObject(targetObject, "Adjusted Jelly Sprite Body Kinematic Flag");
                    targetObject.m_FreeModeBodyKinematic[i] = kinematicResult;
                    SceneView.RepaintAll();
                }

                if (GUILayout.Button(new GUIContent("Delete", "delete this point"), EditorStyles.miniButtonRight, GUILayout.MaxWidth(100f)))
                {
                    if (i == 0)
                    {
                        Debug.LogWarning("Cannot remove central Jelly Sprite control point!");
                    }
                    else
                    {
                        Undo.RecordObject(targetObject, "Deleted Jelly Sprite Body");
                        targetObject.m_FreeModeBodyPositions.RemoveAt(i);
                        targetObject.m_FreeModeBodyRadii.RemoveAt(i);
                        SceneView.RepaintAll();
                        i--;
                    }
                }

                EditorGUILayout.EndHorizontal();
            }

            GUILayout.Space(5);

            if (GUILayout.Button(new GUIContent("Add New Body", "Add new body"), EditorStyles.miniButtonLeft))
            {
                Undo.RecordObject(targetObject, "Added New Jelly Sprite Body");
                targetObject.m_FreeModeBodyPositions.Add(new Vector2(0.0f, -1.0f));
                targetObject.m_FreeModeBodyRadii.Add(1.0f);
                targetObject.m_FreeModeBodyKinematic.Add(false);
                SceneView.RepaintAll();
            }

            break;
        }

        if (selectedStyle != JellySprite.PhysicsStyle.Free)
        {
            EditorGUILayout.Slider(m_ColliderRadius, 0.001f, 0.25f, new GUIContent("Collider Radius"));
            EditorGUILayout.PropertyField(m_SoftBodyScale, new GUIContent("Collider Scale"));
            EditorGUILayout.PropertyField(m_SoftBodyRotation, new GUIContent("Collider Rotation"));
            EditorGUILayout.PropertyField(m_SoftBodyOffset, new GUIContent("Collider Offset"));
            EditorGUILayout.PropertyField(m_CentralBodyOffset, new GUIContent("Central Body Offset"));

            GUILayout.Space(5);

            if (GUILayout.Button(new GUIContent("Copy Configuration To Free Mode", "Copy this configuration to the free mode layout"), EditorStyles.miniButtonRight))
            {
                Undo.RecordObject(target, "Converted Jelly Sprite to Free Mode");
                targetObject.OnCopyToFreeModeSelected();
                SceneView.RepaintAll();
            }
        }

        GUI.enabled = true;

        EditorGUILayout.PropertyField(m_LockRotation, new GUIContent("Lock Rotation"));

        if (selectedStyle != JellySprite.PhysicsStyle.Free)
        {
            EditorGUILayout.PropertyField(m_CentralBodyKinematic, new GUIContent("Kinematic Central Body"));
        }

        GUILayout.Space(15);

        if (m_PhysicsMode.boolValue)
        {
            EditorGUILayout.PropertyField(m_PhysicsMaterial2D, new GUIContent("Physics Material"));
            m_GravityScale.floatValue = EditorGUILayout.FloatField("Gravity Scale", m_GravityScale.floatValue);
            EditorGUILayout.PropertyField(m_InterpolationMode2D, new GUIContent("Interpolate"));
        }
        else
        {
            EditorGUILayout.PropertyField(m_PhysicsMaterial, new GUIContent("Physics Material"));
            EditorGUILayout.PropertyField(m_InterpolationMode, new GUIContent("Interpolate"));
        }

        m_Drag.floatValue        = EditorGUILayout.FloatField("Drag", m_Drag.floatValue);
        m_AngularDrag.floatValue = EditorGUILayout.FloatField("Angular Drag", m_AngularDrag.floatValue);
        EditorGUILayout.PropertyField(m_CollideConnected, new GUIContent("Collide Connected"));
        EditorGUILayout.PropertyField(m_ManualPositioning, new GUIContent("Manual Positioning"));

        m_Stiffness.floatValue    = EditorGUILayout.FloatField("Spring Stiffness", m_Stiffness.floatValue);
        m_DampingRatio.floatValue = EditorGUILayout.FloatField("Spring Damping", m_DampingRatio.floatValue);
        EditorGUILayout.PropertyField(m_MassStyle, new GUIContent("Mass Type"));
        m_Mass.floatValue = EditorGUILayout.FloatField("Mass", m_Mass.floatValue);

        GUILayout.Space(15);

        if (Application.isPlaying)
        {
            GUI.enabled = false;
        }

        EditorGUILayout.Slider(m_DistanceExponent, 1.0f, 4.0f, new GUIContent("Ctrl Point Influence"));

        GUI.enabled = true;

        EditorGUILayout.IntSlider(m_VertexDensity, 2, 100, new GUIContent("Vertex Density"));

        GUILayout.Space(15);

        m_NumAttachPoints.intValue = EditorGUILayout.IntField("Num Attach Points", m_NumAttachPoints.intValue);

        for (int loop = 0; loop < targetObject.m_AttachPoints.Length; loop++)
        {
            targetObject.m_AttachPoints[loop] = (Transform)EditorGUILayout.ObjectField("Attach Point", targetObject.m_AttachPoints[loop], typeof(Transform), true, null);
        }

        m_Color.colorValue = EditorGUILayout.ColorField("Tint Color", m_Color.colorValue);
    }
예제 #2
0
    protected virtual void CheckForObjectChanges()
    {
        serializedObject.ApplyModifiedProperties();

        // Update the visible mesh if the sprite or vertex density was changed
        if (m_InitialVertexDensity != m_VertexDensity.intValue ||
            m_InitialSpriteScale != m_SpriteScale.vector2Value)
        {
            foreach (UnityEngine.Object targetObject in targets)
            {
                JellySprite targetObjectSprite = targetObject as JellySprite;
                targetObjectSprite.RefreshMesh();
            }
        }

        // Update the springs if we altered any of their settings
        if (m_InitialStiffness != m_Stiffness.floatValue || m_InitialDamping != m_DampingRatio.floatValue)
        {
            foreach (UnityEngine.Object targetObject in targets)
            {
                JellySprite targetObjectSprite = targetObject as JellySprite;
                targetObjectSprite.UpdateJoints();
                targetObjectSprite.WakeUp();
            }
        }

        // Recalculate weighting values if the exponent changes
        if (m_InitialDistanceExponent != m_DistanceExponent.floatValue)
        {
            foreach (UnityEngine.Object targetObject in targets)
            {
                JellySprite targetObjectSprite = targetObject as JellySprite;
                targetObjectSprite.CalculateWeightingValues();
            }
        }

        // Update the mass of each body if the value changed
        if (m_InitialMassStyle != m_MassStyle.enumValueIndex ||
            m_InitialMass != m_Mass.floatValue ||
            m_InitialGravityScale != m_GravityScale.floatValue ||
            m_InitialAngularDrag != m_AngularDrag.floatValue ||
            m_InitialInterpolation != m_InterpolationMode.enumValueIndex ||
            m_InitialInterpolation2D != m_InterpolationMode2D.enumValueIndex ||
            m_InitialDrag != m_Drag.floatValue)
        {
            foreach (UnityEngine.Object targetObject in targets)
            {
                JellySprite targetObjectSprite = targetObject as JellySprite;
                targetObjectSprite.InitMass();
                targetObjectSprite.WakeUp();
            }
        }

        if (m_InitialNumAttachPoints != m_NumAttachPoints.intValue)
        {
            foreach (UnityEngine.Object targetObject in targets)
            {
                JellySprite targetObjectSprite = targetObject as JellySprite;
                targetObjectSprite.ResizeAttachPoints();
            }
        }

        if (m_InitialFlipX != m_FlipX.boolValue ||
            m_InitialFlipY != m_FlipY.boolValue)
        {
            foreach (UnityEngine.Object targetObject in targets)
            {
                JellySprite targetObjectSprite = targetObject as JellySprite;
                targetObjectSprite.UpdateTextureCoords();
            }
        }

        if (m_InitialLockRotation != m_LockRotation.boolValue ||
            m_InitialCentralBodyKinematic != m_CentralBodyKinematic.boolValue)
        {
            foreach (UnityEngine.Object targetObject in targets)
            {
                JellySprite targetObjectSprite = targetObject as JellySprite;
                targetObjectSprite.UpdateRotationLock();
            }
        }

        if (m_InitialColor != m_Color.colorValue)
        {
            foreach (UnityEngine.Object targetObject in targets)
            {
                JellySprite targetObjectSprite = targetObject as JellySprite;
                targetObjectSprite.GetComponent <Renderer>().sharedMaterial.color = m_Color.colorValue;
            }
        }
    }