Exemplo n.º 1
0
        /// <summary>
        /// Saves current controller configuration as prefabs.
        /// </summary>
        private void SavePrefab()
        {
            //Get save path from save file panel.
            var path = EditorUtility.SaveFilePanel("Save As prefab", Application.dataPath, Preset.Name, "prefab");

            if (path == string.Empty)
            {
                return;
            }
            else if (path.Contains(Application.dataPath))
            {
                //Convert path to local path.
                path = path.Replace(Application.dataPath, "Assets");

                //Create First Person Preset Scriptable object.
                AssetDatabase.CreateAsset(Preset, path.Replace(".prefab", " Preset.asset"));

                //Create game object for controller.
                var gameObject = new GameObject(Preset.Name);

                //Create camera for controller.
                var camera = CreateCamera(Preset.Name + " Camera");
                camera.transform.SetParent(gameObject.transform);

                //Add first person controller. This should also add rigidbody and capsule collider.
                var controller = gameObject.AddComponent <FirstPersonController>();
                controller.Settings = Preset;

                //Add cursor controller if it's checked.
                if (m_addCursorController)
                {
                    gameObject.AddComponent <CursorController>();
                }

                //Add input manager.
                gameObject.AddComponent <FirstPersonInputManager>();

                //Create Prefab from newly created player controller.
                PrefabUtility.CreatePrefab(path, gameObject);

                //Destroy temporary game object and scriptable object.
                DestroyImmediate(gameObject);
                m_preset = null;

                //Load Prefab from path.
                //This is done to keep the link between the prefab and scene.
                PrefabUtility.InstantiatePrefab(AssetDatabase.LoadAssetAtPath <Object>(path));
            }
            else
            {
                //Saving outside Application.dataPath is not allowed by PrefabUtility.CreatePrefab() because it uses 'local' path starting at Assets/.
                Debug.LogError("Saving outside Asset folder is not supported.\nTry saving inside folder: " + Application.dataPath);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Draw Custom Inspector for Firts Person Preset.
 /// </summary>
 /// <param name="_preset">Target preset.</param>
 public static void DrawPresetInspector(ref FirstPersonPreset _preset)
 {
     EditorGUILayout.LabelField("Controller Settings", EditorStyles.boldLabel);
     _preset.Name = EditorGUILayout.TextField("Name", _preset.Name);
     _preset.Tag  = EditorGUILayout.TagField("Tag", _preset.Tag);
     EditorGUILayout.Space();
     EditorGUILayout.LabelField("Movement", EditorStyles.boldLabel);
     _preset.WalkSpeed        = EditorGUILayout.Slider("Walk Speed", _preset.WalkSpeed, 0.2f, 10f);
     _preset.RunMultiplier    = EditorGUILayout.Slider("Run Multiplier", _preset.RunMultiplier, 1f, 2.5f);
     _preset.CrouchMultiplier = EditorGUILayout.Slider("Crouch Multiplier", _preset.CrouchMultiplier, 0.1f, 1f);
     _preset.JumpForce        = EditorGUILayout.FloatField("Jump Force", _preset.JumpForce);
     EditorGUILayout.Space();
     EditorGUILayout.LabelField("Size", EditorStyles.boldLabel);
     _preset.Height = EditorGUILayout.Slider("Height", _preset.Height, 0.2f, 5f);
     _preset.Radius = EditorGUILayout.Slider("Radius", _preset.Radius, 0.1f, 2f);
     EditorGUILayout.Space();
     EditorGUILayout.LabelField("Other", EditorStyles.boldLabel);
     _preset.MaxSlopeAngle = EditorGUILayout.Slider("Max Slope Angle", _preset.MaxSlopeAngle, 0, 60f);
     _preset.MaxFriction   = EditorGUILayout.Slider("Slope Friction", _preset.MaxFriction, 0, 50f);
 }
Exemplo n.º 3
0
 private void OnEnable()
 {
     m_preset = Preset;
 }
 private void OnEnable()
 {
     m_preset = Target;
 }