duck

Scriptable Object Class and Wizard

Jan 31st, 2014
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.33 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class RobotAttributes : ScriptableObject {
  5.  
  6.     public int seeDistance = 20;
  7.     public int fieldOfView = 180;
  8.     public float turnSpeed = 180;
  9.     public float moveSpeed = 2;
  10.     public float jumpForce = 3;
  11.    
  12. }
  13.  
  14. // ----------------------------------------- Separate file in an Editor folder
  15.  
  16.  
  17. using UnityEditor;
  18. using UnityEngine;
  19.  
  20. public class RobotAttributesWizard : ScriptableWizard {
  21.    
  22.     public string assetName = "NewRobotAttributes";
  23.     public int seeDistance = 20;
  24.     public int fieldOfView = 180;
  25.     public float turnSpeed = 180;
  26.     public float moveSpeed = 2;
  27.     public float jumpForce = 3;
  28.    
  29.     [MenuItem ("Assets/Create/RobotAttributes Wizard")]
  30.     static void CreateWizard () {
  31.         ScriptableWizard.DisplayWizard<RobotAttributesWizard>("Create Robot Attributes", "Create");
  32.     }
  33.     void OnWizardCreate () {
  34.         RobotAttributes asset =  ScriptableObject.CreateInstance<RobotAttributes>();
  35.        
  36.         asset.seeDistance = seeDistance;
  37.         asset.fieldOfView = fieldOfView;
  38.         asset.turnSpeed = turnSpeed;
  39.         asset.moveSpeed = moveSpeed;
  40.         asset.jumpForce = jumpForce;
  41.        
  42.         AssetDatabase.CreateAsset(asset, "Assets/"+assetName+".asset");
  43.         AssetDatabase.SaveAssets();
  44.         EditorUtility.FocusProjectWindow();
  45.         Selection.activeObject = asset;  
  46.     }  
  47.    
  48. }
Advertisement
Add Comment
Please, Sign In to add comment