/// <summary> /// Draws the node contents /// </summary> public virtual void DrawContent() { if (_Content == null) { GUILayout.FlexibleSpace(); GUILayout.Label("No content", NodeEditorStyle.NodeText); GUILayout.FlexibleSpace(); } else { GUILayout.FlexibleSpace(); string lTitle = ""; NodeContent lContent = _Content as NodeContent; if (lContent != null) { lTitle = lContent.Name; } if (lTitle.Length == 0) { lTitle = BaseNameAttribute.GetName(_Content.GetType()); } GUILayout.Label(lTitle, NodeEditorStyle.NodeText); GUILayout.FlexibleSpace(); } }
/// <summary> /// Draws in the title area of the window /// </summary> public override void DrawTitle() { if (Editor.Canvas.SelectedNode != null && Editor.Canvas.SelectedNode.Content != null) { string lTitle = ""; SpellAction lAction = Editor.Canvas.SelectedNode.Content as SpellAction; if (lAction != null) { lTitle = lAction.Name; } if (lTitle.Length == 0) { lTitle = BaseNameAttribute.GetName(Editor.Canvas.SelectedNode.Content.GetType()); } GUI.Label(new Rect(12f, 8f, Position.width - 12f, 20f), lTitle, PanelTitleStyle); if (GUI.Button(new Rect(Position.width - 31f, 10f, 16f, 16f), new GUIContent(" ", "Remove Spell Action"), NodeEditorStyle.ButtonX)) { Editor.Canvas.SelectedNode.DestroyContent(); } } else { GUI.Label(new Rect(12f, 8f, Position.width - 12f, 20f), Title, PanelTitleStyle); } }
/// <summary> /// Renders the currently selected step /// </summary> /// <param name="rStep"></param> private bool DrawStateDetailItem(ActorCoreState rItem) { bool lIsDirty = false; if (rItem == null) { EditorGUILayout.LabelField("NULL"); return(false); } if (rItem.Name.Length > 0) { EditorHelper.DrawSmallTitle(rItem.Name.Length > 0 ? rItem.Name : "Actor Core State"); } else { string lName = BaseNameAttribute.GetName(rItem.GetType()); EditorHelper.DrawSmallTitle(lName.Length > 0 ? lName : "Actor Core State"); } // Render out the State specific inspectors bool lIsStateDirty = rItem.OnInspectorGUI(mTarget); if (lIsStateDirty) { lIsDirty = true; } if (lIsDirty) { mTarget.InstantiateStates(); } return(lIsDirty); }
/// <summary> /// Renders the currently selected step /// </summary> /// <param name="rStep"></param> private bool DrawEffectDetailItem(ActorCoreEffect rItem) { bool lIsDirty = false; if (rItem == null) { EditorGUILayout.LabelField("NULL"); return(false); } if (rItem.Name.Length > 0) { EditorHelper.DrawSmallTitle(rItem.Name.Length > 0 ? rItem.Name : "Actor Core Effect"); } else { string lName = BaseNameAttribute.GetName(rItem.GetType()); EditorHelper.DrawSmallTitle(lName.Length > 0 ? lName : "Actor Core Effect"); } // Render out the Effect specific inspectors bool lIsEffectDirty = rItem.OnInspectorGUI(mTarget); if (lIsEffectDirty) { lIsDirty = true; } if (lIsDirty) { mTarget._EffectDefinitions[mEffectList.index] = rItem.Serialize(); } return(lIsDirty); }
/// <summary> /// Called when the object is selected in the editor /// </summary> private void OnEnable() { // Grab the serialized objects mTarget = (ActorCore)target; mTargetSO = new SerializedObject(target); // Update the effects so they can update with the definitions. if (!UnityEngine.Application.isPlaying) { mTarget.InstantiateStates(); mTarget.InstantiateReactors(); mTarget.InstantiateEffects(); } // Create the list of items to display InstantiateStateList(); // Generate the list to display Assembly lReactorAssembly = Assembly.GetAssembly(typeof(ReactorAction)); Type[] lReactorTypes = lReactorAssembly.GetTypes().OrderBy(x => x.Name).ToArray <Type>(); for (int i = 0; i < lReactorTypes.Length; i++) { Type lType = lReactorTypes[i]; if (lType.IsAbstract) { continue; } if (typeof(ReactorAction).IsAssignableFrom(lType)) { mReactorTypes.Add(lType); mReactorNames.Add(BaseNameAttribute.GetName(lType)); } } // Create the list of items to display InstantiateReactorList(); // Generate the list to display Assembly lEffectAssembly = Assembly.GetAssembly(typeof(ActorCoreEffect)); Type[] lEffectTypes = lEffectAssembly.GetTypes().OrderBy(x => x.Name).ToArray <Type>(); for (int i = 0; i < lEffectTypes.Length; i++) { Type lType = lEffectTypes[i]; if (lType.IsAbstract) { continue; } if (typeof(ActorCoreEffect).IsAssignableFrom(lType)) { mEffectTypes.Add(lType); mEffectNames.Add(BaseNameAttribute.GetName(lType)); } } // Create the list of items to display InstantiateEffectList(); }
/// <summary> /// Allows us to draw each item in the list /// </summary> /// <param name="rRect"></param> /// <param name="rIndex"></param> /// <param name="rIsActive"></param> /// <param name="rIsFocused"></param> private void DrawReactorListItem(Rect rRect, int rIndex, bool rIsActive, bool rIsFocused) { if (rIndex < mTarget._Reactors.Count) { ReactorAction lItem = mTarget._Reactors[rIndex]; if (lItem == null) { EditorGUI.LabelField(rRect, "NULL"); return; } rRect.y += 2; bool lIsDirty = false; float lHSpace = 5f; float lFlexVSpace = rRect.width - lHSpace - lHSpace - 40f - lHSpace - 16f; string lType = BaseNameAttribute.GetName(lItem.GetType()); EditorGUILayout.BeginHorizontal(); Rect lTypeRect = new Rect(rRect.x, rRect.y, lFlexVSpace / 2f, EditorGUIUtility.singleLineHeight); EditorGUI.LabelField(lTypeRect, lType); Rect lNameRect = new Rect(lTypeRect.x + lTypeRect.width + lHSpace, lTypeRect.y, lFlexVSpace / 2f, EditorGUIUtility.singleLineHeight); string lNewName = EditorGUI.TextField(lNameRect, lItem.Name); if (lNewName != lItem.Name) { lIsDirty = true; lItem.Name = lNewName; } Rect lPriorityRect = new Rect(lNameRect.x + lNameRect.width + lHSpace, lNameRect.y, 40f, EditorGUIUtility.singleLineHeight); float lNewPriority = EditorGUI.FloatField(lPriorityRect, lItem.Priority); if (lNewPriority != lItem.Priority) { lIsDirty = true; lItem.Priority = lNewPriority; } Rect lIsEnabledRect = new Rect(lPriorityRect.x + lPriorityRect.width + lHSpace, lPriorityRect.y, 16f, 16f); bool lNewIsEnabled = EditorGUI.Toggle(lIsEnabledRect, lItem.IsEnabled); if (lNewIsEnabled != lItem.IsEnabled) { lIsDirty = true; lItem.IsEnabled = lNewIsEnabled; } EditorGUILayout.EndHorizontal(); // Update the item if there's a change if (lIsDirty) { mIsDirty = true; mTarget._ReactorDefinitions[rIndex] = lItem.Serialize(); } } }
/// <summary> /// Grab the types from the assembly /// </summary> public void RefreshList() { mTypes.Clear(); mNames.Clear(); mDescriptions.Clear(); mSelectedItemIndex = -1; if (mBaseType == null) { return; } // Generate the list of motions to display Assembly lAssembly = Assembly.GetAssembly(mBaseType); Type[] lMotionTypes = lAssembly.GetTypes().OrderBy(x => x.Name).ToArray <Type>(); for (int i = 0; i < lMotionTypes.Length; i++) { Type lType = lMotionTypes[i]; if (lType.IsAbstract) { continue; } if (!mBaseType.IsAssignableFrom(lType)) { continue; } string lFriendlyName = BaseNameAttribute.GetName(lType); if (mSearchString.Length > 0) { if (lFriendlyName.IndexOf(mSearchString) < 0) { if (lType.Name.IndexOf(mSearchString) < 0) { continue; } } } string lDescription = BaseDescriptionAttribute.GetDescription(lType); mTypes.Add(lType); mNames.Add(lFriendlyName); mDescriptions.Add(lDescription); } }
/// <summary> /// Renders the currently selected step /// </summary> /// <param name="rStep"></param> private bool DrawReactorDetailItem(ReactorAction rItem) { bool lIsDirty = false; if (rItem == null) { EditorGUILayout.LabelField("NULL"); return(false); } if (rItem.Name.Length > 0) { EditorHelper.DrawSmallTitle(rItem.Name.Length > 0 ? rItem.Name : "Actor Core Reactor"); } else { string lName = BaseNameAttribute.GetName(rItem.GetType()); EditorHelper.DrawSmallTitle(lName.Length > 0 ? lName : "Actor Core Reactor"); } string lDescription = BaseDescriptionAttribute.GetDescription(rItem.GetType()); if (lDescription.Length > 0) { EditorHelper.DrawInspectorDescription(lDescription, MessageType.None); } if (EditorHelper.TextField("Name", "Friendly name of the reactor", rItem.Name, mTarget)) { lIsDirty = true; rItem.Name = EditorHelper.FieldStringValue; } // Render out the Reactor specific inspectors bool lIsReactorDirty = rItem.OnInspectorGUI(mTargetSO, mTarget); if (lIsReactorDirty) { lIsDirty = true; } if (lIsDirty) { mTarget._ReactorDefinitions[mReactorList.index] = rItem.Serialize(); } return(lIsDirty); }
/// <summary> /// Create the reorderable list /// </summary> private void InstantiateActionList() { // Dropdown values mActionTypes.Clear(); mActionNames.Clear(); // Generate the list of motions to display Assembly lAssembly = Assembly.GetAssembly(typeof(NodeLinkAction)); Type[] lMotionTypes = lAssembly.GetTypes().OrderBy(x => x.Name).ToArray <Type>(); for (int i = 0; i < lMotionTypes.Length; i++) { Type lType = lMotionTypes[i]; if (lType.IsAbstract) { continue; } if (typeof(NodeLinkAction).IsAssignableFrom(lType)) { mActionTypes.Add(lType); mActionNames.Add(BaseNameAttribute.GetName(lType)); } } mActionList = new ReorderableList(mTarget.Actions, typeof(NodeLinkAction), true, true, true, true); mActionList.drawHeaderCallback = DrawActionListHeader; mActionList.drawFooterCallback = DrawActionListFooter; mActionList.drawElementCallback = DrawActionListItem; mActionList.onAddCallback = OnActionListItemAdd; mActionList.onRemoveCallback = OnActionListItemRemove; mActionList.onSelectCallback = OnActionListItemSelect; mActionList.onReorderCallback = OnActionListReorder; mActionList.footerHeight = 17f; if (mEditorActionIndex >= 0 && mEditorActionIndex < mActionList.count) { mActionList.index = mEditorActionIndex; } }
/// <summary> /// Allows us to draw each item in the list /// </summary> /// <param name="rRect"></param> /// <param name="rIndex"></param> /// <param name="rIsActive"></param> /// <param name="rIsFocused"></param> private void DrawEffectListItem(Rect rRect, int rIndex, bool rIsActive, bool rIsFocused) { if (rIndex < mTarget._Effects.Count) { ActorCoreEffect lItem = mTarget._Effects[rIndex]; if (lItem == null) { EditorGUI.LabelField(rRect, "NULL"); return; } rRect.y += 2; string lName = lItem.Name; if (lName.Length == 0) { lName = BaseNameAttribute.GetName(lItem.GetType()); } Rect lNameRect = new Rect(rRect.x, rRect.y, rRect.width, EditorGUIUtility.singleLineHeight); EditorGUI.LabelField(lNameRect, lName); } }
/// <summary> /// Called when the object is selected in the editor /// </summary> private void OnEnable() { // Grab the serialized objects mTarget = (ActorCore)target; mTargetSO = new SerializedObject(target); // Update the effects so they can update with the definitions. if (!UnityEngine.Application.isPlaying) { mTarget.InstantiateStates(); mTarget.InstantiateReactors(); mTarget.InstantiateEffects(); } // Create the list of items to display InstantiateStateList(); // CDL 06 / 28 / 2018 - this only scans the assembly containing ReactorAction //// Generate the list to display //Assembly lReactorAssembly = Assembly.GetAssembly(typeof(ReactorAction)); //Type[] lReactorTypes = lReactorAssembly.GetTypes().OrderBy(x => x.Name).ToArray<Type>(); //for (int i = 0; i < lReactorTypes.Length; i++) //{ // Type lType = lReactorTypes[i]; // if (lType.IsAbstract) { continue; } // if (typeof(ReactorAction).IsAssignableFrom(lType)) // { // mReactorTypes.Add(lType); // mReactorNames.Add(BaseNameAttribute.GetName(lType)); // } //} // CDL 06 / 28 / 2018 - scan all assemblies for Reactors and Actor Core Effects List <Type> lFoundTypes = AssemblyHelper.FoundTypes; for (int i = 0; i < lFoundTypes.Count; i++) { Type lType = lFoundTypes[i]; if (lType.IsAbstract) { continue; } if (typeof(ReactorAction).IsAssignableFrom(lType)) { mReactorTypes.Add(lType); mReactorNames.Add(BaseNameAttribute.GetName(lType)); } else if (typeof(ActorCoreEffect).IsAssignableFrom(lType)) { mEffectTypes.Add(lType); mEffectNames.Add(BaseNameAttribute.GetName(lType)); } } // Create the list of items to display InstantiateReactorList(); // CDL 06 / 28 / 2018 - this only scans the assembly containing ActorCoreEffect //// Generate the list to display //Assembly lEffectAssembly = Assembly.GetAssembly(typeof(ActorCoreEffect)); //Type[] lEffectTypes = lEffectAssembly.GetTypes().OrderBy(x => x.Name).ToArray<Type>(); //for (int i = 0; i < lEffectTypes.Length; i++) //{ // Type lType = lEffectTypes[i]; // if (lType.IsAbstract) { continue; } // if (typeof(ActorCoreEffect).IsAssignableFrom(lType)) // { // mEffectTypes.Add(lType); // mEffectNames.Add(BaseNameAttribute.GetName(lType)); // } //} // Create the list of items to display InstantiateEffectList(); }
/// <summary> /// Gathers the master list of items and categories /// </summary> /// <param name="rItems">MotionSelectItems that represent the motion types</param> /// <param name="rTags">Tag strings</param> /// <returns></returns> public static int GetMasterMotionTypes(List <MotionSelectType> rTypes) { Type lBaseType = typeof(MotionControllerMotion); rTypes.Clear(); //rTypeTags.Clear(); // CDL 06/28/2018 - this only scans the "ootii" assembly //// Generate the list of motions to display //Assembly lAssembly = Assembly.GetAssembly(lBaseType); //Type[] lMotionTypes = lAssembly.GetTypes().OrderBy(x => x.Name).ToArray<Type>(); //for (int i = 0; i < lMotionTypes.Length; i++) //{ // Type lType = lMotionTypes[i]; // if (lType.IsAbstract) { continue; } // if (!lBaseType.IsAssignableFrom(lType)) { continue; } // string lName = MotionNameAttribute.GetName(lType); // if (lName == null || lName.Length == 0) { lName = BaseNameAttribute.GetName(lType); } // string lDescription = MotionDescriptionAttribute.GetDescription(lType); // if (lDescription == null || lDescription.Length == 0) { lDescription = BaseDescriptionAttribute.GetDescription(lType); } // string lTypeTags = MotionTypeTagsAttribute.GetTypeTags(lType); // MotionSelectType lItem = new MotionSelectType(); // lItem.Type = lType; // lItem.Path = lType.Name + ".cs"; // //string[] lFolders = System.IO.Directory.GetFiles(Application.dataPath, lItem.Path, System.IO.SearchOption.AllDirectories); // //if (lFolders.Length > 0) { lItem.Path = lFolders[0]; } // lItem.Name = lName; // lItem.Description = lDescription; // lItem.TypeTags = lTypeTags; // lItem.TypeTagArray = lTypeTags.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); // rTypes.Add(lItem); // //// Create the type tags // //if (lItem.TypeTagArray != null) // //{ // // for (int j = 0; j < lItem.TypeTagArray.Length; j++) // // { // // bool lIsFound = false; // // for (int k = 0; k < rTypeTags.Count; k++) // // { // // if (string.Compare(rTypeTags[k].Tag, lItem.TypeTagArray[j], true) == 0) // // { // // lIsFound = true; // // break; // // } // // } // // if (!lIsFound) // // { // // MotionSelectTypeTag lTypeTag = new MotionSelectTypeTag(); // // lTypeTag.Tag = lItem.TypeTagArray[j]; // // rTypeTags.Add(lTypeTag); // // } // // } // //} //} // CDL 06 / 28 / 2018 - scan all assemblies for Motions List <Type> lFoundTypes = AssemblyHelper.FoundTypes; // Generate the list of Motions to display for (int i = 0; i < lFoundTypes.Count; i++) { Type lType = lFoundTypes[i]; if (lType.IsAbstract) { continue; } if (!lBaseType.IsAssignableFrom(lType)) { continue; } string lName = MotionNameAttribute.GetName(lType); if (lName == null || lName.Length == 0) { lName = BaseNameAttribute.GetName(lType); } string lDescription = MotionDescriptionAttribute.GetDescription(lType); if (lDescription == null || lDescription.Length == 0) { lDescription = BaseDescriptionAttribute.GetDescription(lType); } string lTypeTags = MotionTypeTagsAttribute.GetTypeTags(lType); MotionSelectType lItem = new MotionSelectType(); lItem.Type = lType; lItem.Path = lType.Name + ".cs"; //string[] lFolders = System.IO.Directory.GetFiles(Application.dataPath, lItem.Path, System.IO.SearchOption.AllDirectories); //if (lFolders.Length > 0) { lItem.Path = lFolders[0]; } lItem.Name = lName; lItem.Description = lDescription; lItem.TypeTags = lTypeTags; lItem.TypeTagArray = lTypeTags.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); rTypes.Add(lItem); //// Create the type tags //if (lItem.TypeTagArray != null) //{ // for (int j = 0; j < lItem.TypeTagArray.Length; j++) // { // bool lIsFound = false; // for (int k = 0; k < rTypeTags.Count; k++) // { // if (string.Compare(rTypeTags[k].Tag, lItem.TypeTagArray[j], true) == 0) // { // lIsFound = true; // break; // } // } // if (!lIsFound) // { // MotionSelectTypeTag lTypeTag = new MotionSelectTypeTag(); // lTypeTag.Tag = lItem.TypeTagArray[j]; // rTypeTags.Add(lTypeTag); // } // } //} } return(rTypes.Count); }
/// <summary> /// Grab the types from the assembly /// </summary> public void RefreshList() { mTypes.Clear(); mNames.Clear(); mDescriptions.Clear(); mSelectedItemIndex = -1; if (mBaseType == null) { return; } // CDL 07/04/2018 - this only looks in the assembly containing the base type //// Generate the list of motions to display //Assembly lAssembly = Assembly.GetAssembly(mBaseType); //Type[] lMotionTypes = lAssembly.GetTypes().OrderBy(x => x.Name).ToArray<Type>(); //for (int i = 0; i < lMotionTypes.Length; i++) //{ // Type lType = lMotionTypes[i]; // if (lType.IsAbstract) { continue; } // if (!mBaseType.IsAssignableFrom(lType)) { continue; } // string lFriendlyName = BaseNameAttribute.GetName(lType); // if (mSearchString.Length > 0) // { // if (lFriendlyName.IndexOf(mSearchString) < 0) // { // if (lType.Name.IndexOf(mSearchString) < 0) // { // continue; // } // } // } // string lDescription = BaseDescriptionAttribute.GetDescription(lType); // mTypes.Add(lType); // mNames.Add(lFriendlyName); // mDescriptions.Add(lDescription); //} // CDL 07/04/2018 - used the cached found types from all assemblies // Create the list to display List <Type> lFoundTypes = AssemblyHelper.FoundTypes; for (int i = 0; i < lFoundTypes.Count; i++) { Type lType = lFoundTypes[i]; if (lType.IsAbstract) { continue; } if (!mBaseType.IsAssignableFrom(lType)) { continue; } string lFriendlyName = BaseNameAttribute.GetName(lType); if (mSearchString.Length > 0) { if (lFriendlyName.IndexOf(mSearchString) < 0) { if (lType.Name.IndexOf(mSearchString) < 0) { continue; } } } string lDescription = BaseDescriptionAttribute.GetDescription(lType); mTypes.Add(lType); mNames.Add(lFriendlyName); mDescriptions.Add(lDescription); } }