Beispiel #1
0
        private void AddComponentInternal(Component c)
        {
            cs.Add(c);
            //			com->SetHideFlags(GetHideFlags());
            c.SetGameObjectInternal(this);

            if (IsActive())
            {
                c.AwakeFromLoad(AwakeFromLoadMode.kActivateAwakeFromLoad);
            }
            else
            {
                c.AwakeFromLoad(AwakeFromLoadMode.kDefaultAwakeFromLoad);
            }
            c.SetDirty();
            SetDirty();
        }
Beispiel #2
0
        private Component Internal_AddComponentWithType(Type componentType, System.Object o = null)
        {
            bool isTransform     = typeof(Transform).IsAssignableFrom(componentType);
            bool isMonoBehaviour = typeof(MonoBehaviour).IsAssignableFrom(componentType);

            if (!typeof(Component).IsAssignableFrom(componentType))
            {
                return(null);
            }
            if (isTransform && transform != null)
            {
                Debug.LogError("Transform can't be add twice.");
                return(null);
            }
            BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
            Component    co    = null;

            // HACK! MonoBehaviour can have default ctor only!
            if (o != null && !isMonoBehaviour)
            {
                co = (Component)Activator.CreateInstance(componentType, flags, null, new object[] { o }, null);
            }
            else
            {
                co = (Component)Activator.CreateInstance(componentType, flags, null, new object[] {}, null);
            }


            if (co == null)
            {
                Debug.LogError("Internal_AddComponentWithType can't create object.");
                return(null);
            }
            co.__Reset();
            AddComponentInternal(co);

            co.AwakeFromLoad(AwakeFromLoadMode.kInstantiateOrCreateFromCodeAwakeFromLoad);
            co.SetDirty();

            return(co);
        }