/**
         * @brief Returns true if the given layers can collide.
         *
         * @param layerA Layer of the first object
         * @param layerB Layer of the second object
         **/
        public static bool CollisionEnabled(int layerA, int layerB)
        {
            FixedPointConfig tsConfig = SpaxManager.Config;

            if (tsConfig == null)
            {
                return(true);
            }

            return(!tsConfig.GetIgnoreLayerCollision(layerA, layerB));
        }
        void Awake()
        {
            instance = this;

            FixedPointConfig currentConfig = ActiveConfig;
            FP lockedTimeStep = currentConfig.lockedTimeStep;


            if (currentConfig.physics2DEnabled || currentConfig.physics3DEnabled)
            {
                PhysicsManager.New(currentConfig);
                PhysicsManager.instance.LockedTimeStep = lockedTimeStep;
                PhysicsManager.instance.Init();
            }
            physics = PhysicsManager.instance;
        }
        private static void CreateFixedPointConfigAsset()
        {
            FixedPointConfig asset = ScriptableObject.CreateInstance <FixedPointConfig>();

            string path = AssetDatabase.GetAssetPath(Selection.activeObject);

            if (path == "")
            {
                path = "Assets";
            }
            else if (Path.GetExtension(path) != "")
            {
                path = path.Replace(Path.GetFileName(AssetDatabase.GetAssetPath(Selection.activeObject)), "");
            }

            string assetPathAndName = AssetDatabase.GenerateUniqueAssetPath(path + "/FixedPointConfig.asset");

            AssetDatabase.CreateAsset(asset, assetPathAndName);

            AssetDatabase.SaveAssets();
            EditorUtility.FocusProjectWindow();
            Selection.activeObject = asset;
        }
Example #4
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            FixedPointConfig settings = (FixedPointConfig)target;

            Undo.RecordObject(settings, "Edit FixedPointConfig");

            EditorGUILayout.LabelField("General", EditorStyles.boldLabel);
            EditorGUI.indentLevel++;

            settings.syncWindow = EditorGUILayout.IntField("Sync Window", settings.syncWindow);
            if (settings.syncWindow < 0)
            {
                settings.syncWindow = 0;
            }

            settings.rollbackWindow = EditorGUILayout.IntField("Rollback Window", settings.rollbackWindow);
            if (settings.rollbackWindow < 0)
            {
                settings.rollbackWindow = 0;
            }

            settings.panicWindow = EditorGUILayout.IntField("Panic Window", settings.panicWindow);
            if (settings.panicWindow < 0)
            {
                settings.panicWindow = 0;
            }

            settings.lockedTimeStep = EditorGUILayout.FloatField("Locked Time Step", settings.lockedTimeStep.AsFloat());
            if (settings.lockedTimeStep < 0)
            {
                settings.lockedTimeStep = 0;
            }

            settings.showStats = EditorGUILayout.Toggle("Show Stats", settings.showStats);

            EditorGUI.indentLevel--;

            GUILayout.Space(10);

            settings.physics2DEnabled = EditorGUILayout.BeginToggleGroup("2D Physics", settings.physics2DEnabled);

            if (settings.physics2DEnabled)
            {
                settings.physics3DEnabled = false;

                EditorGUI.indentLevel++;

                Vector2 gField2D = EditorGUILayout.Vector2Field("Gravity", settings.gravity2D.ToVector());
                settings.gravity2D.x = gField2D.x;
                settings.gravity2D.y = gField2D.y;

                settings.speculativeContacts2D = EditorGUILayout.Toggle("Speculative Contacts", settings.speculativeContacts2D);

                physics2DCollisionFoldout = EditorGUILayout.Foldout(physics2DCollisionFoldout, "Layer Collision Matrix");
                if (physics2DCollisionFoldout)
                {
                    DrawLayerMatrix(settings.physics2DIgnoreMatrix);
                }

                EditorGUI.indentLevel--;
            }

            EditorGUILayout.EndToggleGroup();

            settings.physics3DEnabled = EditorGUILayout.BeginToggleGroup("3D Physics", settings.physics3DEnabled);

            if (settings.physics3DEnabled)
            {
                settings.physics2DEnabled = false;

                EditorGUI.indentLevel++;

                Vector3 gField3D = EditorGUILayout.Vector3Field("Gravity", settings.gravity3D.ToVector());
                settings.gravity3D.x = gField3D.x;
                settings.gravity3D.y = gField3D.y;
                settings.gravity3D.z = gField3D.z;

                settings.speculativeContacts3D = EditorGUILayout.Toggle("Speculative Contacts", settings.speculativeContacts3D);

                physics3DCollisionFoldout = EditorGUILayout.Foldout(physics3DCollisionFoldout, "Layer Collision Matrix");
                if (physics3DCollisionFoldout)
                {
                    DrawLayerMatrix(settings.physics3DIgnoreMatrix);
                }

                EditorGUI.indentLevel--;
            }

            EditorGUILayout.EndToggleGroup();

            serializedObject.ApplyModifiedProperties();

            GUILayout.Space(20);

            if (GUILayout.Button("Highlight Settings"))
            {
                EditorGUIUtility.PingObject(target);
            }

            if (GUI.changed)
            {
                EditorUtility.SetDirty(target);
            }
        }