コード例 #1
0
    /// <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);
    }
コード例 #2
0
    /// <summary>
    /// This is called when this component is woken up.
    /// </summary>
    public virtual void Awake()
    {
        //make sure to restore the targets if needed
        VisManager.RestoreVisManagerTarget(this);

        //check if there is already a vis manager assigned to this data group
        if (m_oVisManager == null)
        {
            //try to grab a vis manager that belongs to this game object.
            m_oVisManager = GetComponent <VisManager>();

            //check if a vis manager was found
            if (m_oVisManager == null)
            {
                //find all game objects with vis managers
                Object[] visManagers = GameObject.FindObjectsOfType(typeof(VisManager));
                for (int i = 0; i < visManagers.Length; i++)
                {
                    //get this manager and check if it is enabled
                    VisManager manager = visManagers[i] as VisManager;
                    if (manager.enabled)
                    {
                        //assign this vis manager
                        m_oVisManager = manager;
                        break;
                    }
                }
            }
        }

        //validate manager
        ValidateManager(true);

        //make sure this data group is registered with it vis manager
        EnsureRegistered();

        //log an error if no vis manager is assigned
        if (m_oVisManager == null)
        {
            Debug.LogError("This Controller does not have a VisManager assigned to it, nor could it find an active VisManager. In order to function, this Controller needs a VisManager!");
        }
    }
コード例 #3
0
 /// <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);
 }
コード例 #4
0
    /// <summary>
    /// This displays the drop down for selecting a manager from the inspector.
    /// </summary>
    /// <param name="managerTarget">The manager target to set the manager for.</param>
    /// <returns>Whether or not a manager is currently set.</returns>
    public bool DisplayIVisManagerTargetGUI(IVisManagerTarget managerTarget)
    {
        if (managerTarget != null)
        {
            if (managerTarget is MonoBehaviour)
            {
                GameObject gameObject = (managerTarget as MonoBehaviour).gameObject;
                if (managerTarget.Manager == null ||
                    managerTarget.Manager.gameObject != gameObject)
                {
                    VisManager manager = gameObject.GetComponent <VisManager>();
                    if (manager != null)
                    {
                        managerTarget.Manager = manager;
                        return(true);
                    }
                }
                else if (managerTarget.Manager != null &&
                         managerTarget.Manager.gameObject == gameObject)
                {
                    return(true);
                }
            }

            bool result = false;

            EditorGUILayout.BeginHorizontal();

            //make sure and try to restore it first
            VisManager.RestoreVisManagerTarget(managerTarget);

            Object[] visManagers = GameObject.FindObjectsOfType(typeof(VisManager));

            if (visManagers.Length > 0)
            {
                //create list of vis manager names and a dictionary to map IDs, and sort it
                List <string>            sortedNames    = new List <string>(visManagers.Length);
                Dictionary <string, int> nameToIndexMap = new Dictionary <string, int>(visManagers.Length);
                for (int i = 0; i < visManagers.Length; i++)
                {
                    string name = (visManagers[i] as VisManager).name;
                    if (nameToIndexMap.ContainsKey(name) &&
                        ((visManagers[nameToIndexMap[name]] as VisManager).Controllers.Count < (visManagers[i] as VisManager).Controllers.Count ||
                         (visManagers[nameToIndexMap[name]] as VisManager).DataGroups.Count < (visManagers[i] as VisManager).DataGroups.Count))
                    {//override index
                        nameToIndexMap[name] = i;
                    }
                    else
                    {//add new
                        sortedNames.Add((visManagers[i] as VisManager).name);
                        nameToIndexMap.Add((visManagers[i] as VisManager).name, i);
                    }
                }
                sortedNames.Sort();

                //create array of names and set current index
                int      currentIndex   = 0;
                string[] displayedNames = new string[visManagers.Length + 1];
                displayedNames[0] = "None";
                for (int i = 0; i < sortedNames.Count; i++)
                {
                    displayedNames[i + 1] = sortedNames[i];
                    if (managerTarget.Manager == visManagers[nameToIndexMap[sortedNames[i]]])
                    {
                        currentIndex = i + 1;
                    }
                }

                //display popup
                int newIndex = EditorGUILayout.Popup("   Manager", currentIndex, displayedNames);

                //set new vis manager if the index has changed
                if (newIndex != currentIndex)
                {
                    if (newIndex == 0)
                    {
                        managerTarget.Manager = null;
                    }
                    else
                    {
                        string newName       = sortedNames[newIndex - 1];
                        int    remappedIndex = nameToIndexMap[newName];
                        managerTarget.Manager = visManagers[remappedIndex] as VisManager;
                    }
                    EditorUtility.SetDirty(target);
                }
                result = managerTarget.Manager != null;
            }
            else
            {
                if (managerTarget.LastManagerName != null && managerTarget.LastManagerName.Length > 0)
                {
                    EditorGUILayout.LabelField("   Manager", managerTarget.LastManagerName + " (not found, try selecting the Object with this Manager)");
                }
                else
                {
                    EditorGUILayout.LabelField("   Manager", "NO MANAGERS FOUND!");
                }
                result = false;
            }

            managerTarget.Manager = (VisManager)EditorGUILayout.ObjectField(managerTarget.Manager, typeof(VisManager), true, GUILayout.Width(Screen.width * 0.2f));

            EditorGUILayout.EndHorizontal();

            return(result);
        }
        return(false);
    }