Example #1
0
        // (What is "kindName" supposed to be?)
        // (Explain what this function is doing?)
        public UiItem GenerateItem(string sceneName, string objectPath, Vector3 position, string kindName,
                                   bool initialize)
        {
            if (!_sceneDict.ContainsKey(sceneName))
            {
                return(null);
            }
            GameObject newObject = Resources.Load <GameObject>(objectPath);

            if (newObject == null)
            {
                return(null);
            }

            // (Explain this chunk of code)
            Scene     theScene = _sceneDict[sceneName];
            BatchNode parentNode;

            if (theScene.DetectSceneBatch(kindName))
            {
                parentNode = theScene.GetSceneBatch(kindName);
            }
            else
            {
                parentNode = theScene.GetSceneBatch("Others");
            }

            newObject = Instantiate(newObject, parentNode.transform);
            newObject.transform.position = position;

            // Call parentNode.UpdatePosition here, if its leaves are likely to move from original position
            parentNode.AddLeaf(newObject.transform);

            UiItem returnValue = newObject.GetComponent <UiItem>();

            if (returnValue == null)
            {
                returnValue = newObject.AddComponent <UiItem>();
            }

            // (If what is initialized?)
            if (initialize)
            {
                returnValue.Initialize();
            }

            return(newObject.GetComponent <UiItem>());
        }
Example #2
0
        // This function generates (instantiates) an object
        public UiItem GenerateItem(string sceneName, string objectPath, Vector3 position, string kindName,
                                   bool initialize)
        {
            if (!_sceneDict.ContainsKey(sceneName))
            {
                return(null);
            }
            GameObject newObject = Resources.Load <GameObject>(objectPath);

            if (newObject == null)
            {
                return(null);
            }
            Scene     theScene = _sceneDict[sceneName];
            BatchNode parentNode;

            if (theScene.DetectSceneBatch(kindName))
            {
                parentNode = theScene.GetSceneBatch(kindName);
            }
            else
            {
                parentNode = theScene.GetSceneBatch("Others");
            }

            newObject = Instantiate(newObject, parentNode.transform);
            newObject.transform.position = position;
            parentNode.AddLeaf(newObject.transform);

            UiItem returnValue = newObject.GetComponent <UiItem>();

            if (returnValue == null)
            {
                returnValue = newObject.AddComponent <UiItem>();
            }

            if (initialize)
            {
                returnValue.Initialize();
            }

            return(newObject.GetComponent <UiItem>());
        }