Beispiel #1
0
    public T GetTypeInElement <T>(SpawnerOutput t, params string[] cN)
    {
        UIWrapperBase target = t.script as UIWrapperBase;

        if (target != null)
        {
            return(InternalRecursiveGetType <T>(target, 0, cN));
        }

        return((T)(object)t.script);
    }
Beispiel #2
0
    public static void ChangeUISize(SpawnerOutput t, Vector2 size)
    {
        (t.script.transform as RectTransform).sizeDelta = size;

        UIWrapperBase target = t.script as UIWrapperBase;

        if (target != null)
        {
            for (int i = 0; i < target.scriptsData.Length; i++)
            {
                (target.scriptsData[i].script.transform as RectTransform).sizeDelta = size;
            }
        }
    }
Beispiel #3
0
    /*public static T GetTypeInElement<T>(SpawnerOutput t) {
     *
     *  if(t.script is T)
     *      return (T)(object)t.script;
     *
     *  UIWrapperBase target = t.script as UIWrapperBase;
     *
     *  // Deals with UIWrapperBase objects.
     *  if(target != null) {
     *      if(target.mainScript is T)
     *          return (T)(object)target.mainScript;
     *
     *      if(target.mainScript is Button || target.mainScript is InputField) {
     *          MonoBehaviour inst = target.additionalScripts[butInpIds[typeof(T)]].script;
     *
     *          if(inst is UIWrapperBase)
     *              return (T)(object)(inst as UIWrapperBase).mainScript;
     *
     *          return (T)(object)target.additionalScripts[butInpIds[typeof(T)]].script;
     *      }
     *  }
     *
     *  return (T)(object)null;
     * }*/

    // Used to iterate internally.
    T InternalRecursiveGetType <T>(UIWrapperBase target, int currLoop = 0, params string[] cN)
    {
        if (cN.Length == 0 || cN[currLoop] == "")
        {
            return((T)(object)target.scriptsData[0].script);
        }

        if (!uiWrapperDir.ContainsKey(target.GetType()))
        {
            Dictionary <string, int> wrapperDir = new Dictionary <string, int>();

            target.PopulateScriptDirectory(wrapperDir);
            uiWrapperDir.Add(target.GetType(), wrapperDir);
        }

        if (currLoop + 1 >= cN.Length)
        {
            return((T)(object)target.scriptsData[uiWrapperDir[target.GetType()][cN[currLoop]]].script);
        }
        else
        {
            UIWrapperBase nextTarget = target.scriptsData[uiWrapperDir[target.GetType()][cN[currLoop]]].script as UIWrapperBase;

            if (nextTarget != null)
            {
                return(InternalRecursiveGetType <T>(nextTarget, currLoop++, cN));
            }
            else
            {
                Debug.LogError("Wrong component name given to nested loop. It does not contain a nest component.");
            }
        }


        return(default(T));
    }