public static vp_ComponentPreset LoadFromTextAsset(Component component, TextAsset file) { vp_ComponentPreset vp_ComponentPreset = new vp_ComponentPreset(); vp_ComponentPreset.LoadFromTextAsset(file); vp_ComponentPreset.Apply(component, vp_ComponentPreset); return(vp_ComponentPreset); }
/// <summary> /// static overload: creates and loads a preset and sets all /// the values on 'component', then returns the preset /// </summary> public static vp_ComponentPreset LoadFromTextAsset(vp_Component component, TextAsset file) { vp_ComponentPreset preset = new vp_ComponentPreset(); preset.LoadFromTextAsset(file); Apply(component, preset); return(preset); }
public static Type GetFileTypeFromAsset(TextAsset asset) { bool logErrors = vp_ComponentPreset.LogErrors; vp_ComponentPreset.LogErrors = false; vp_ComponentPreset vp_ComponentPreset = new vp_ComponentPreset(); vp_ComponentPreset.LoadFromTextAsset(asset); vp_ComponentPreset.LogErrors = logErrors; if (vp_ComponentPreset != null && vp_ComponentPreset.m_ComponentType != null) { return(vp_ComponentPreset.m_ComponentType); } return(null); }
/// <summary> /// loads the preset at 'fullPath' and returns the component /// type described in it /// </summary> public static Type GetFileTypeFromAsset(TextAsset asset) { // attempt to load target preset into memory, ignoring // load errors in the process bool logErrorState = LogErrors; LogErrors = false; vp_ComponentPreset preset = new vp_ComponentPreset(); preset.LoadFromTextAsset(asset); LogErrors = logErrorState; // try to get hold of a preset and a component type from the file if (preset != null) { if (preset.m_ComponentType != null) { return(preset.m_ComponentType); } } // the file was not found return(null); }
/// <summary> /// /// </summary> public static void GenerateStatesAndPresetsFromDerivedComponent(Component derivedComponent, Component baseComponent, string path) { //System.Type derivedType = derivedComponent.GetType(); // TEST (see below) System.Type baseType = baseComponent.GetType(); // TEST: disabled to allow converting from vp_FPController to // vp_CapsuleController. evaluate this down the line //if (!vp_EditorUtility.IsSameOrSubclass(baseType, derivedType)) // return; vp_Component vpDerived = derivedComponent as vp_Component; vp_Component vpBase = baseComponent as vp_Component; if (vpDerived == null) { return; } if (vpBase == null) { return; } for (int v = 0; v < vpDerived.States.Count; v++) { // abort if old state has no text asset vp_State oldState = vpDerived.States[v]; if (oldState.TextAsset == null) { continue; } // abort if we fail to load old text asset into a preset vp_ComponentPreset preset = new vp_ComponentPreset(); if (!preset.LoadFromTextAsset(oldState.TextAsset)) { continue; } // try to make the preset compatible with the base component. this // will fail if it has no compatible fields, in which case we abort if (preset.TryMakeCompatibleWithComponent(vpBase) < 1) { continue; } // we have a new preset that is compatible with the base component. // save it at a temporary, auto-generated path string typeName = oldState.TypeName.Replace("vp_FP", ""); typeName = typeName.Replace("vp_", ""); string filePath = path + "/" + typeName + "_" + vpBase.gameObject.name + "_" + oldState.Name + ".txt"; vp_ComponentPreset.Save(preset, filePath); AssetDatabase.Refresh(); // add a corresponding state, into which we load the new preset vp_State newState = new vp_State(baseType.Name, vpDerived.States[v].Name, null, null); vpBase.States.Add(newState); // System.Threading.Thread.Sleep(100); // might come in handy on slow disk (?) newState.TextAsset = AssetDatabase.LoadAssetAtPath(filePath, typeof(TextAsset)) as TextAsset; } }
/// <summary> /// loads the preset at 'fullPath' and returns the component /// type described in it /// </summary> public static Type GetFileTypeFromAsset(TextAsset asset) { // attempt to load target preset into memory, ignoring // load errors in the process bool logErrorState = LogErrors; LogErrors = false; vp_ComponentPreset preset = new vp_ComponentPreset(); preset.LoadFromTextAsset(asset); LogErrors = logErrorState; // try to get hold of a preset and a component type from the file if (preset != null) { if (preset.m_ComponentType != null) return preset.m_ComponentType; } // the file was not found return null; }
/// <summary> /// static overload: creates and loads a preset and sets all /// the values on 'component', then returns the preset /// </summary> public static vp_ComponentPreset LoadFromTextAsset(vp_Component component, TextAsset file) { vp_ComponentPreset preset = new vp_ComponentPreset(); preset.LoadFromTextAsset(file); Apply(component, preset); return preset; }
/// <summary> /// /// </summary> public static void GenerateStatesAndPresetsFromDerivedComponent(Component derivedComponent, Component baseComponent, string path) { //System.Type derivedType = derivedComponent.GetType(); // TEST (see below) System.Type baseType = baseComponent.GetType(); // TEST: disabled to allow converting from vp_FPController to // vp_CapsuleController. evaluate this down the line //if (!vp_EditorUtility.IsSameOrSubclass(baseType, derivedType)) // return; vp_Component vpDerived = derivedComponent as vp_Component; vp_Component vpBase = baseComponent as vp_Component; if (vpDerived == null) return; if (vpBase == null) return; for (int v = 0; v < vpDerived.States.Count; v++) { // abort if old state has no text asset vp_State oldState = vpDerived.States[v]; if (oldState.TextAsset == null) continue; // abort if we fail to load old text asset into a preset vp_ComponentPreset preset = new vp_ComponentPreset(); if (!preset.LoadFromTextAsset(oldState.TextAsset)) continue; // try to make the preset compatible with the base component. this // will fail if it has no compatible fields, in which case we abort if (preset.TryMakeCompatibleWithComponent(vpBase) < 1) continue; // we have a new preset that is compatible with the base component. // save it at a temporary, auto-generated path string typeName = oldState.TypeName.Replace("vp_FP", ""); typeName = typeName.Replace("vp_", ""); string filePath = path + "/" + typeName + "_" + vpBase.gameObject.name + "_" + oldState.Name + ".txt"; vp_ComponentPreset.Save(preset, filePath); AssetDatabase.Refresh(); // add a corresponding state, into which we load the new preset vp_State newState = new vp_State(baseType.Name, vpDerived.States[v].Name, null, null); vpBase.States.Add(newState); // System.Threading.Thread.Sleep(100); // might come in handy on slow disk (?) newState.TextAsset = AssetDatabase.LoadAssetAtPath(filePath, typeof(TextAsset)) as TextAsset; } }