/// <summary> /// This adds a controller to this VisManager. /// </summary> /// <param name="controller"> /// This is the controller to add. /// </param> public void AddController(VisBaseController controller) { //Make sure the controller is not null, and it is not already in this VisManager. if (controller != null && m_oControllers.Contains(controller) == false && (controller.Manager != this || GetControllerByName(controller.controllerName) == null)) { //make sure there is not a controller already in here with the game object name and controller name the same for (int i = 0; i < m_oControllers.Count; i++) { if (m_oControllers[i].name == controller.name && m_oControllers[i].controllerName == controller.controllerName) { Debug.Log("Ignore 1"); //this object may already be in there, ignore it! return; } } //force unique name controller.controllerName = EnsureUniqueControllerName(controller.controllerName); //add the controller m_oControllers.Add(controller); } }
/// <summary> /// This removes a controller to this VisManager. /// </summary> /// <param name="controller"> /// This is the controller to remove. /// </param> public void RemoveController(VisBaseController controller) { //Make sure the controller is not null, and it is already in this VisManager. if (controller != null && m_oControllers.Contains(controller)) { //remove the controller m_oControllers.Remove(controller); } }
/// <summary> /// This function is called when this trigger is started. /// Should be override by sub classes to initialize. /// </summary> public virtual void Start() { //make sure to restore the targets if needed VisManager.RestoreVisManagerTarget(this); VisBaseController.RestoreVisBaseControllerTarget(this); //validate trigger variables. triggerThreshold = VisHelper.Validate(triggerThreshold, 0.0001f, 10000.0f, Defaults.triggerThreshold, this, "triggerThreshold", false); triggerReactivateDelay = VisHelper.Validate(triggerReactivateDelay, 0.0f, 10000.0f, Defaults.triggerReactivateDelay, this, "triggerReactivateDelay", false); }
/// <summary> /// This is the function that is called by the base editor in order to display the custom inspector gui for required target objects. /// </summary> /// <returns>Whether or not the custom inspector gui found valid targets.</returns> protected override bool TargetInspectorGUI() { bool result = DisplayIVisManagerTargetGUI(target as IVisManagerTarget); VisBaseController controller = target as VisBaseController; if (controller != null && !controller.ValidateManager(false)) { GUIStyle style = new GUIStyle(EditorStyles.boldLabel); style.normal.textColor = Color.white; style.wordWrap = true; style.alignment = TextAnchor.MiddleCenter; Color oldColor = GUI.color; GUI.color = new Color(1.0f, 0.0f, 0.0f); GUILayout.Label("To prevent issues, please make sure this Controller is attached to the same Game Object as it's Manager.", style); GUI.color = oldColor; } return(result); }
/// <summary> /// This function is called by the base editor to display normal custom inspector gui. /// </summary> protected override void CustomInspectorGUI() { base.CustomInspectorGUI(); VisBaseController controller = target as VisBaseController; if (controller == null) { return; } controller.controllerName = EditorGUILayout.TextField(" Controller Name", controller.controllerName); controller.limitIncreaseRate = EditorGUILayout.Toggle(" Limit Increase Rate", controller.limitIncreaseRate); if (controller.limitIncreaseRate) { controller.increaseRate = EditorGUILayout.FloatField(" Increase Rate", controller.increaseRate); } controller.limitDecreaseRate = EditorGUILayout.Toggle(" Limit Decrease Rate", controller.limitDecreaseRate); if (controller.limitDecreaseRate) { controller.decreaseRate = EditorGUILayout.FloatField(" Decrease Rate", controller.decreaseRate); } }
/// <summary> /// This function is called when this modifier is started. /// Should be override by sub classes to initialize. /// </summary> public virtual void Start() { //make sure to restore the targets if needed VisManager.RestoreVisManagerTarget(this); VisBaseController.RestoreVisBaseControllerTarget(this); }
/// <summary> /// This displays the drop down for selecting a controller from the inspector. /// </summary> /// <param name="baseControllerTarget">The base controller target to set the controller for.</param> /// <returns>Whether or not a controller is currently set.</returns> public bool DisplayIVisBaseControllerTargetGUI(IVisBaseControllerTarget baseControllerTarget) { EnsureAllControllersRegistered(); if (baseControllerTarget != null && baseControllerTarget is IVisManagerTarget) { //make sure and try to restore it first VisBaseController.RestoreVisBaseControllerTarget(baseControllerTarget); VisManager manager = (baseControllerTarget as IVisManagerTarget).Manager; if (manager != null) { ReadOnlyCollection <VisBaseController> controllers = manager.Controllers; if (controllers.Count > 0) { //create list of vis controller names and a dictionary to map IDs, and sort it List <string> sortedNames = new List <string>(controllers.Count); Dictionary <string, int> nameToIndexMap = new Dictionary <string, int>(controllers.Count); for (int i = 0; i < controllers.Count; i++) { sortedNames.Add((controllers[i] as VisBaseController).controllerName); nameToIndexMap.Add((controllers[i] as VisBaseController).controllerName, i); } sortedNames.Sort(); //create array of names and set current index int currentIndex = 0; string[] displayedNames = new string[controllers.Count + 1]; displayedNames[0] = "None"; for (int i = 0; i < sortedNames.Count; i++) { displayedNames[i + 1] = sortedNames[i]; if (baseControllerTarget.Controller == controllers[nameToIndexMap[sortedNames[i]]]) { currentIndex = i + 1; } } //display popup int newIndex = EditorGUILayout.Popup(" Controller", currentIndex, displayedNames); //set new vis controller if the index has changed if (newIndex != currentIndex) { if (newIndex == 0) { baseControllerTarget.Controller = null; } else { string newName = sortedNames[newIndex - 1]; int remappedIndex = nameToIndexMap[newName]; baseControllerTarget.Controller = controllers[remappedIndex] as VisBaseController; } EditorUtility.SetDirty(target); } return(baseControllerTarget.Controller != null); } else { if (baseControllerTarget.LastControllerName != null && baseControllerTarget.LastControllerName.Length > 0) { EditorGUILayout.LabelField(" Controller", baseControllerTarget.LastControllerName + " (not found, try selecting the Object with this Controller)"); } else { EditorGUILayout.LabelField(" Controller", "NO CONTROLLERS FOUND!"); } return(false); } } } return(false); }