Example #1
0
    IEnumerator MakeRemote(string path, OutResult <GameObject> result)
    {
#if !UNITY_EDITOR
        if (Service.bundle.IsRemoteResource(path) == false)
        {
            logger.LogError("It is not a remote resource:" + path);
            yield break;
        }
#endif

        yield return(StartCoroutine(Service.bundle.Instantiate(path, result)));

        if (result.value == null)
        {
            yield break;
        }

        GameObject itemObj = result.value;
        GoItem     item    = itemObj.GetComponent <GoItem>();
        if (item == null)
        {
            logger.LogError("Doesn't have GoItem:" + path);
            yield break;
        }
        item.resourcePath = path;
    }
Example #2
0
    public void Return(GoItem item)
    {
        string path = item.resourcePath;

        if (path == null || path.Length == 0)
        {
            Destroy(item.gameObject);
            return;
        }

        if (item.gameObject.activeSelf == false)
        {
            return;
        }

        Stack stack = GetStack(path);

        stack.Push(new WeakReference(item.gameObject));
        item.OnGoingIntoPool();
        MatchParent(item);
        item.transform.localPosition = Vector3.up * 9999;
        item.gameObject.SetActive(false);
        Rigidbody rb = item.GetComponent <Rigidbody>();

        if (rb != null)
        {
            rb.velocity        = Vector3.zero;
            rb.angularVelocity = Vector3.zero;
        }
    }
Example #3
0
    IEnumerator PrepareRemote(string path, int count)
    {
        OutResult <List <GameObject> > result = new OutResult <List <GameObject> >();

        yield return(StartCoroutine(Service.bundle.Instantiate(path, count, result)));

        for (int i = 0; i < result.value.Count; i++)
        {
            GameObject itemObj = result.value[i];
            if (itemObj == null)
            {
                continue;
            }

            GoItem item = itemObj.GetComponent <GoItem>();
            if (item == null)
            {
                logger.LogError("Doesn't have GoItem:" + path);
            }

            MatchParent(item);
            item.transform.localPosition = Vector3.up * 9999;
            itemObj.SetActive(true);
            item.resourcePath = path;
            item.Prepare();
            Return(item, prepareTime);
        }
    }
Example #4
0
 void MatchParent(GoItem item)
 {
     if (IsNGUIWidget(item))
     {
         item.transform.parent = uiRoot.transform;
     }
     else
     {
         item.transform.parent = transform;
     }
 }
Example #5
0
    void SetReady(GameObject itemObj, GameObject parent)
    {
        if (parent != null)
        {
            itemObj.transform.parent = parent.transform;
        }

        itemObj.transform.localPosition = Vector3.up * 9999;
        itemObj.SetActive(true);

        GoItem item = itemObj.GetComponent <GoItem>();

        if (item != null)
        {
            item.OnGettingOutPool();
        }
    }
Example #6
0
    GameObject MakeLocal(string path)
    {
        GameObject itemObj = null;

        GameObject obj;

        if (!storedPrefabs.TryGetValue(path, out obj) || obj == null)
        {
            obj = Resources.Load <GameObject>(path);
            storedPrefabs[path] = obj;
        }

        if (obj == null)
        {
            logger.LogError("Can not load resource:" + path);
            return(null);
        }

        itemObj = Instantiate(obj) as GameObject;
        if (itemObj == null)
        {
            logger.LogError("Can not load GameObject:" + path);
            return(null);
        }

        GoItem item = itemObj.GetComponent <GoItem>();

        if (item == null)
        {
            logger.LogError("Doesn't have GoItem:" + path);
        }

        item.resourcePath = path;
        MatchParent(item);
        item.transform.localScale = Vector3.one;
        return(itemObj);
    }
Example #7
0
    void PrepareLocal(string path, int count)
    {
        for (int i = 0; i < count; i++)
        {
            GameObject itemObj = MakeLocal(path);
            if (itemObj == null)
            {
                continue;
            }

            GoItem item = itemObj.GetComponent <GoItem>();
            if (item == null)
            {
                logger.LogError("Doesn't have GoItem:" + path);
            }

            MatchParent(item);
            item.transform.localPosition = Vector3.zero;
            itemObj.SetActive(true);
            item.resourcePath = path;
            item.Prepare();
            Return(item, prepareTime);
        }
    }
Example #8
0
 void MatchParent(GoItem item)
 {
     item.transform.parent = transform;
 }
Example #9
0
 bool IsNGUIWidget(GoItem item)
 {
     return(item.GetComponentInChildren <UIWidget>() != null);
 }
Example #10
0
    IEnumerator ReturnWithDelay(GoItem item, float delay)
    {
        yield return(new WaitForSeconds(delay));

        Return(item);
    }
Example #11
0
 public void Return(GoItem item, float delay)
 {
     StartCoroutine(ReturnWithDelay(item, delay));
 }