コード例 #1
0
    /// <summary>
    /// This attempts to restore the last set controller on the target.
    /// </summary>
    /// <param name="target">The target to restore.</param>
    /// <returns>Whether or not the target was restored.</returns>
    public static bool RestoreVisBaseControllerTarget(IVisBaseControllerTarget target)
    {
        //make sure the controller is set, and if not, check if there
        //is a name set and try and find that object as the controller
        if (target.Controller == null && target.LastControllerName != null && target.LastControllerName.Length > 0)
        {
            //try to get the manager for this target
            VisManager manager = null;
            if (target is IVisManagerTarget)
            {
                manager = (target as IVisManagerTarget).Manager;
            }

            //make sure a manager was found
            if (manager != null)
            {
                //loop through all controllers and make sure it was found
                for (int i = 0; i < manager.Controllers.Count; i++)
                {
                    if (manager.Controllers[i].controllerName == target.LastControllerName)
                    {
                        target.Controller = manager.Controllers[i];
                        return(true);
                    }
                }
            }
        }

        return(false);
    }
コード例 #2
0
    /// <summary>
    /// This attempts to restore the last set controller on the target.
    /// </summary>
    /// <param name="target">The target to restore.</param>
    /// <returns>Whether or not the target was restored.</returns>
    public static bool RestoreVisBaseControllerTarget(IVisBaseControllerTarget target)
    {
        //make sure the controller is set, and if not, check if there 
        //is a name set and try and find that object as the controller
        if (target.Controller == null && target.LastControllerName != null && target.LastControllerName.Length > 0)
        {
            //try to get the manager for this target
            VisManager manager = null;
            if (target is IVisManagerTarget)
                manager = (target as IVisManagerTarget).Manager;

            //make sure a manager was found
            if (manager != null)
            {
                //loop through all controllers and make sure it was found
                for (int i = 0; i < manager.Controllers.Count; i++)
                {
                    if (manager.Controllers[i].controllerName == target.LastControllerName)
                    {
                        target.Controller = manager.Controllers[i];
                        return true;
                    }
                }
            }
        }

        return false;
    }
コード例 #3
0
    /// <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;
	}
コード例 #4
0
    /// <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);
    }