void OnEnable()
    {
        myScript = (Util_PoolLoading)target;

        if (myScript._keys == null)
        {
            myScript._keys = new System.Collections.Generic.List <string>();
        }

        if (string.IsNullOrEmpty(myScript._keys[0]))
        {
            myScript._keys[0] = "kEverytime";
        }
    }
    public static void CreatePooling()
    {
        GameObject root = new GameObject("<Pooling>");

        Undo.RegisterCreatedObjectUndo(root, "ubik.pooling.create");

        Util_PoolLoading pooling = root.AddComponent <Util_PoolLoading>();

        pooling._keys = new System.Collections.Generic.List <string>();
        pooling._keys.Add("kEverytime");
        pooling._database = new System.Collections.Generic.List <Util_PoolManagerDatabase>();

        GameObject containers = new GameObject("Containers");

        containers.transform.parent = root.transform;

        SerializedObject   tagManager = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/TagManager.asset")[0]);
        SerializedProperty tagsProp   = tagManager.FindProperty("tags");
        bool found = false;

        for (int i = 0; i < tagsProp.arraySize; i++)
        {
            SerializedProperty t = tagsProp.GetArrayElementAtIndex(i);
            if (t.stringValue.Equals("PoolingContainer"))
            {
                found = true; break;
            }
        }
        // if not found, add it
        if (!found)
        {
            tagsProp.InsertArrayElementAtIndex(0);
            SerializedProperty n = tagsProp.GetArrayElementAtIndex(0);
            n.stringValue = "PoolingContainer";
            tagManager.ApplyModifiedProperties();
        }

        containers.tag = "PoolingContainer";

        pooling._containeres = containers;


        Selection.activeObject = root;
    }
示例#3
0
    void Awake()
    {
        // the system search Containers object. Don't create Util_PoolLooading alone. Use Tools/Pooling/Create
        _containeres = transform.FindChild("Containers").gameObject;

        if (_instance != null)
        {
            DestroyObject(gameObject);
            return;
        }

        if (_dontDestroy)
        {
            DontDestroyOnLoad(gameObject);             // preserviamo il pooling
        }

        _instance = this;

                #if UNITY_EDITOR
        if (!Application.isPlaying)
        {
            return;
        }
                #endif
        if (_autoplay)
        {
            // load pool with kEverytime key.
            // if you want create another key and load at another time another object list,

            // 1) create key

            // 2) create a manager and set you key

            // 3) when you load your scene, use on you OnEnable Util_PoolLoading.Instance.LoadByKeys(new List<string>(new string[]{<you key>}));

            // 4) on your OnDelete run Util_PoolLoading.Instance.UnLoad(<you KeyCode>)

            Util_PoolLoading.Instance.LoadByKeys(new List <string>(new string[] { "kEverytime" }));
        }
    }