private static void GenerateActionSetsHelpers(string actionSetsClassFileName) { CodeCompileUnit compileUnit = new CodeCompileUnit(); CodeTypeDeclaration inputClass = CreatePartialInputClass(compileUnit); CodeMemberMethod startPreInitActionSetsMethod = CreateStaticMethod(inputClass, startPreInitActionSetsMethodName, false); CodeArrayCreateExpression actionSetsArray = new CodeArrayCreateExpression(new CodeTypeReference(typeof(SteamVR_ActionSet))); for (int actionSetIndex = 0; actionSetIndex < SteamVR_Input.actionFile.action_sets.Count; actionSetIndex++) { SteamVR_Input_ActionFile_ActionSet actionSet = SteamVR_Input.actionFile.action_sets[actionSetIndex]; string shortName = GetValidIdentifier(actionSet.shortName); string codeFriendlyInstanceName = shortName; string setTypeName = GetSetClassName(actionSet); CodeMemberField actionSetField = CreateFieldAndPropertyWrapper(inputClass, shortName, setTypeName); AddAssignActionSetStatement(startPreInitActionSetsMethod, inputClass.Name, actionSetField.Name, actionSet.name, setTypeName); actionSetsArray.Initializers.Add(new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(inputClass.Name), codeFriendlyInstanceName)); } AddAssignStatement(startPreInitActionSetsMethod, SteamVR_Input_Generator_Names.actionSetsFieldName, actionSetsArray); // Build the output file name. string fullSourceFilePath = GetSourceFilePath(actionSetsClassFileName); CreateFile(fullSourceFilePath, compileUnit); }
public static CreateType CreateFromName <CreateType>(string newSetName) where CreateType : SteamVR_ActionSet, new() { CreateType actionSet = new CreateType(); actionSet.PreInitialize(SteamVR_Input_ActionFile_ActionSet.GetPathFromName(newSetName)); return(actionSet); }
public SteamVR_Input_ActionFile_ActionSet GetCopy() { SteamVR_Input_ActionFile_ActionSet newSet = new SteamVR_Input_ActionFile_ActionSet(); newSet.name = this.name; newSet.usage = this.usage; return(newSet); }
private static CodeTypeDeclaration CreateActionSetClass(SteamVR_Input_ActionFile_ActionSet set) { CodeCompileUnit compileUnit = new CodeCompileUnit(); CodeNamespace codeNamespace = new CodeNamespace(typeof(SteamVR_Input).Namespace); codeNamespace.Imports.Add(new CodeNamespaceImport("System")); codeNamespace.Imports.Add(new CodeNamespaceImport("UnityEngine")); compileUnit.Namespaces.Add(codeNamespace); CodeTypeDeclaration setClass = new CodeTypeDeclaration(GetSetClassName(set)); setClass.BaseTypes.Add(typeof(SteamVR_ActionSet)); setClass.Attributes = MemberAttributes.Public; codeNamespace.Types.Add(setClass); string actionSetShortName = set.shortName; actionSetShortName = actionSetShortName.Substring(0, 1).ToLower() + actionSetShortName.Substring(1); foreach (var inAction in set.actionsInList) { string inActionName = inAction.shortName; if (set.actionsOutList.Any(outAction => inAction.shortName == outAction.shortName)) { inActionName = inActionFieldPrefix + inActionName; } string actionClassPropertyName = string.Format("{0}_{1}", actionSetShortName, inActionName); CreateActionPropertyWrapper(setClass, SteamVR_Input_Generator_Names.actionsClassName, inActionName, actionClassPropertyName, inAction); } foreach (var outAction in set.actionsOutList) { string outActionName = outAction.shortName; if (set.actionsInList.Any(inAction => inAction.shortName == outAction.shortName)) { outActionName = outActionFieldPrefix + outActionName; } string actionClassPropertyName = string.Format("{0}_{1}", actionSetShortName, outActionName); CreateActionPropertyWrapper(setClass, SteamVR_Input_Generator_Names.actionsClassName, outActionName, actionClassPropertyName, outAction); } // Build the output file name. string folderPath = GetSubFolderPath(); string fullSourceFilePath = Path.Combine(folderPath, setClass.Name + ".cs"); CreateFile(fullSourceFilePath, compileUnit); return(setClass); }
private static List <CodeTypeDeclaration> GenerateActionSetClasses() { List <CodeTypeDeclaration> setClasses = new List <CodeTypeDeclaration>(); for (int actionSetIndex = 0; actionSetIndex < SteamVR_Input.actionFile.action_sets.Count; actionSetIndex++) { SteamVR_Input_ActionFile_ActionSet actionSet = SteamVR_Input.actionFile.action_sets[actionSetIndex]; CodeTypeDeclaration setClass = CreateActionSetClass(actionSet); setClasses.Add(setClass); } return(setClasses); }
public override bool Equals(object obj) { if (obj is SteamVR_Input_ActionFile_ActionSet) { SteamVR_Input_ActionFile_ActionSet set = (SteamVR_Input_ActionFile_ActionSet)obj; if (set == this) { return(true); } if (set.name == this.name) { return(true); } return(false); } return(base.Equals(obj)); }
private static string GetSetClassName(SteamVR_Input_ActionFile_ActionSet set) { return(actionSetClassNamePrefix + set.shortName); }
private static void GenerateActionHelpers(string actionsClassFileName) { CodeCompileUnit compileUnit = new CodeCompileUnit(); CodeTypeDeclaration inputClass = CreatePartialInputClass(compileUnit); CodeArrayCreateExpression actionsArray = new CodeArrayCreateExpression(new CodeTypeReference(typeof(SteamVR_Action))); CodeArrayCreateExpression actionsInArray = new CodeArrayCreateExpression(new CodeTypeReference(typeof(ISteamVR_Action_In))); CodeArrayCreateExpression actionsOutArray = new CodeArrayCreateExpression(new CodeTypeReference(typeof(ISteamVR_Action_Out))); CodeArrayCreateExpression actionsVibrationArray = new CodeArrayCreateExpression(new CodeTypeReference(typeof(SteamVR_Action_Vibration))); CodeArrayCreateExpression actionsPoseArray = new CodeArrayCreateExpression(new CodeTypeReference(typeof(SteamVR_Action_Pose))); CodeArrayCreateExpression actionsSkeletonArray = new CodeArrayCreateExpression(new CodeTypeReference(typeof(SteamVR_Action_Skeleton))); CodeArrayCreateExpression actionsBooleanArray = new CodeArrayCreateExpression(new CodeTypeReference(typeof(SteamVR_Action_Boolean))); CodeArrayCreateExpression actionsSingleArray = new CodeArrayCreateExpression(new CodeTypeReference(typeof(SteamVR_Action_Single))); CodeArrayCreateExpression actionsVector2Array = new CodeArrayCreateExpression(new CodeTypeReference(typeof(SteamVR_Action_Vector2))); CodeArrayCreateExpression actionsVector3Array = new CodeArrayCreateExpression(new CodeTypeReference(typeof(SteamVR_Action_Vector3))); CodeArrayCreateExpression actionsNonPoseNonSkeletonArray = new CodeArrayCreateExpression(new CodeTypeReference(typeof(ISteamVR_Action_In))); //add the getaction method to CodeMemberMethod actionsArraysInitMethod = CreateStaticMethod(inputClass, initializeActionsArraysMethodName, false); CodeMemberMethod actionsPreInitMethod = CreateStaticMethod(inputClass, preInitActionsMethodName, false); for (int actionSetIndex = 0; actionSetIndex < SteamVR_Input.actionFile.action_sets.Count; actionSetIndex++) { SteamVR_Input_ActionFile_ActionSet actionSet = SteamVR_Input.actionFile.action_sets[actionSetIndex]; string actionSetShortName = actionSet.shortName; actionSetShortName = actionSetShortName.Substring(0, 1).ToLower() + actionSetShortName.Substring(1); for (int actionIndex = 0; actionIndex < actionSet.actionsList.Count; actionIndex++) { SteamVR_Input_ActionFile_Action action = actionSet.actionsList[actionIndex]; string actionShortName = action.shortName; string typeName = GetTypeStringForAction(action); string codeFriendlyInstanceName; if (actionSet.actionsList.Count(findAction => findAction.shortName == actionShortName) >= 2) { codeFriendlyInstanceName = string.Format("{0}_{1}_{2}", actionSetShortName, action.direction.ToString().ToLower(), actionShortName); } else { codeFriendlyInstanceName = string.Format("{0}_{1}", actionSetShortName, actionShortName); } CodeMemberField actionField = CreateFieldAndPropertyWrapper(inputClass, codeFriendlyInstanceName, typeName); AddAssignActionStatement(actionsPreInitMethod, inputClass.Name, actionField.Name, action.name, typeName); actionsArray.Initializers.Add(new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(inputClass.Name), codeFriendlyInstanceName)); if (action.direction == SteamVR_ActionDirections.In) { actionsInArray.Initializers.Add(new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(inputClass.Name), codeFriendlyInstanceName)); if (typeName == typeof(SteamVR_Action_Pose).Name) { actionsPoseArray.Initializers.Add(new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(inputClass.Name), codeFriendlyInstanceName)); } else if (typeName == typeof(SteamVR_Action_Skeleton).Name) { actionsSkeletonArray.Initializers.Add(new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(inputClass.Name), codeFriendlyInstanceName)); } else if (typeName == typeof(SteamVR_Action_Boolean).Name) { actionsBooleanArray.Initializers.Add(new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(inputClass.Name), codeFriendlyInstanceName)); } else if (typeName == typeof(SteamVR_Action_Single).Name) { actionsSingleArray.Initializers.Add(new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(inputClass.Name), codeFriendlyInstanceName)); } else if (typeName == typeof(SteamVR_Action_Vector2).Name) { actionsVector2Array.Initializers.Add(new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(inputClass.Name), codeFriendlyInstanceName)); } else if (typeName == typeof(SteamVR_Action_Vector3).Name) { actionsVector3Array.Initializers.Add(new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(inputClass.Name), codeFriendlyInstanceName)); } if ((typeName == typeof(SteamVR_Action_Skeleton).Name) == false && (typeName == typeof(SteamVR_Action_Pose).Name) == false) { actionsNonPoseNonSkeletonArray.Initializers.Add(new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(inputClass.Name), codeFriendlyInstanceName)); } } else { actionsVibrationArray.Initializers.Add(new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(inputClass.Name), codeFriendlyInstanceName)); actionsOutArray.Initializers.Add(new CodeFieldReferenceExpression(new CodeTypeReferenceExpression(inputClass.Name), codeFriendlyInstanceName)); } } } AddAssignStatement(actionsArraysInitMethod, SteamVR_Input_Generator_Names.actionsFieldName, actionsArray); AddAssignStatement(actionsArraysInitMethod, SteamVR_Input_Generator_Names.actionsInFieldName, actionsInArray); AddAssignStatement(actionsArraysInitMethod, SteamVR_Input_Generator_Names.actionsOutFieldName, actionsOutArray); AddAssignStatement(actionsArraysInitMethod, SteamVR_Input_Generator_Names.actionsVibrationFieldName, actionsVibrationArray); AddAssignStatement(actionsArraysInitMethod, SteamVR_Input_Generator_Names.actionsPoseFieldName, actionsPoseArray); AddAssignStatement(actionsArraysInitMethod, SteamVR_Input_Generator_Names.actionsBooleanFieldName, actionsBooleanArray); AddAssignStatement(actionsArraysInitMethod, SteamVR_Input_Generator_Names.actionsSingleFieldName, actionsSingleArray); AddAssignStatement(actionsArraysInitMethod, SteamVR_Input_Generator_Names.actionsVector2FieldName, actionsVector2Array); AddAssignStatement(actionsArraysInitMethod, SteamVR_Input_Generator_Names.actionsVector3FieldName, actionsVector3Array); AddAssignStatement(actionsArraysInitMethod, SteamVR_Input_Generator_Names.actionsSkeletonFieldName, actionsSkeletonArray); AddAssignStatement(actionsArraysInitMethod, SteamVR_Input_Generator_Names.actionsNonPoseNonSkeletonIn, actionsNonPoseNonSkeletonArray); // Build the output file name. string fullSourceFilePath = GetSourceFilePath(actionsClassFileName); CreateFile(fullSourceFilePath, compileUnit); }
private void DrawSets() { EditorGUILayout.LabelField("Action Sets", headerLabelStyle); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); for (int actionSetIndex = 0; actionSetIndex < SteamVR_Input.actionFile.action_sets.Count; actionSetIndex++) { if (selectedActionSet == actionSetIndex) { EditorGUILayout.BeginVertical(); string newName = GUILayout.TextField(SteamVR_Input.actionFile.action_sets[actionSetIndex].shortName); if (newName != SteamVR_Input.actionFile.action_sets[actionSetIndex].shortName) { string oldName = SteamVR_Input.actionFile.action_sets[actionSetIndex].name; foreach (var action in SteamVR_Input.actionFile.actions) { if (action.actionSet == oldName) { action.SetNewActionSet(newName); } } SteamVR_Input.actionFile.action_sets[actionSetIndex].SetNewShortName(newName); } EditorGUILayout.BeginHorizontal(); int selectedUsage = -1; for (int valueIndex = 0; valueIndex < SteamVR_Input_ActionFile_ActionSet_Usages.listValues.Length; valueIndex++) { if (SteamVR_Input_ActionFile_ActionSet_Usages.listValues[valueIndex] == SteamVR_Input.actionFile.action_sets[actionSetIndex].usage) { selectedUsage = valueIndex; break; } } int wasUsage = selectedUsage; if (selectedUsage == -1) { selectedUsage = 1; } selectedUsage = EditorGUILayout.Popup(selectedUsage, SteamVR_Input_ActionFile_ActionSet_Usages.listDescriptions); if (wasUsage != selectedUsage) { SteamVR_Input.actionFile.action_sets[actionSetIndex].usage = SteamVR_Input_ActionFile_ActionSet_Usages.listValues[selectedUsage]; } EditorGUILayout.Space(); bool removeSet = GUILayout.Button("-"); if (removeSet) { bool confirm = EditorUtility.DisplayDialog("Confirmation", "Are you sure you want to delete this action set and all of its actions?.", "Delete", "Cancel"); if (confirm) { //todo: this doesn't work SteamVR_Input.actionFile.action_sets.RemoveAt(selectedActionSet); selectedActionSet = -1; selectedAction = null; InitializeLists(); break; } } EditorGUILayout.Space(); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); } else { bool pressedSet = GUILayout.Button(SteamVR_Input.actionFile.action_sets[actionSetIndex].shortName); if (pressedSet) { selectedActionSet = actionSetIndex; selectedActionIndex = -1; selectedAction = null; InitializeLists(); } } if (actionSetIndex < SteamVR_Input.actionFile.action_sets.Count - 1) { GUILayout.FlexibleSpace(); } } EditorGUILayout.Space(); bool addSet = GUILayout.Button("+"); if (addSet) { SteamVR_Input_ActionFile_ActionSet newActionSet = new SteamVR_Input_ActionFile_ActionSet(); newActionSet.name = SteamVR_Input_ActionFile_ActionSet.CreateNewName(); SteamVR_Input.actionFile.action_sets.Add(newActionSet); selectedActionSet = SteamVR_Input.actionFile.action_sets.Count - 1; selectedActionIndex = -1; selectedAction = null; InitializeLists(); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); }