Пример #1
0
        private object Instantiate(Type componentType, GameObjectAttribute gameObjectAttribute)
        {
            string gameObjectName;

            if (gameObjectAttribute.name == null)
            {
                gameObjectName = componentType.Name + (BoundName == null ? "" : "_" + BoundName);
                int c = 1;
                while (UnityEngine.GameObject.Find("/" + gameObjectName) != null)
                {
                    gameObjectName = componentType.Name + (BoundName == null ? "" : "_" + BoundName) + "(" + (c++) + ")";
                }
            }
            else
            {
                gameObjectName = gameObjectAttribute.name;
            }
            UnityEngine.GameObject instance = new UnityEngine.GameObject(gameObjectName);
            return(instance.AddComponent(componentType));
        }
Пример #2
0
        private object Instantiate(UnityEngine.Object unityObject, GameObjectAttribute gameObjectAttribute)
        {
            string gameObjectName;

            if (gameObjectAttribute.name == null)
            {
                gameObjectName = BoundType.Name + (BoundName == null ? "" : "_" + BoundName);
                int c = 1;
                while (UnityEngine.GameObject.Find("/" + gameObjectName) != null)
                {
                    gameObjectName = BoundType.Name + (BoundName == null ? "" : "_" + BoundName) + "(" + (c++) + ")";
                }
            }
            else
            {
                gameObjectName = gameObjectAttribute.name;
            }
            //UnityEngine.GameObject instanceParent = new UnityEngine.GameObject(gameObjectName);
            GameObject instance = GameObject.Instantiate(unityObject as GameObject /*, instanceParent.transform*/) as GameObject;

            instance.name = gameObjectName;

            foreach (MonoBehaviour monoBehaviour in instance.GetComponentsInChildren <MonoBehaviour>())
            {
                if (monoBehaviour != null)
                {
                    wire.Inject(monoBehaviour);
                }
            }

            /* if (type.IsAssignableFrom(typeof(Component)))
             * {
             *  return instance.GetComponent(type);
             * } else*/
            if (BoundType.IsAssignableFrom(typeof(GameObject)))
            {
                return(instance);
            }
            return(instance.GetComponent(BoundType));
            //throw new Exception("Unexpected binding type " + type);
        }