Example #1
0
        public void RegisterFactory <T>(string category = "") where T : Object
        {
            var type = typeof(T);

            _factoryTypes[StringHash.Calculate(type.Name)] = type;

            // Find a wrapper base type.
            var baseType = type.BaseType;

            while (baseType != null && baseType.Assembly != typeof(Context).Assembly)
            {
                baseType = baseType.BaseType;
            }

            if (baseType == null)
            {
                throw new InvalidOperationException("This type can not be registered as factory.");
            }

            Urho3D_Context_RegisterFactory(__ToPInvoke(this), type.Name, StringHash.Calculate("Wrappers::" + baseType.Name), category);
        }
Example #2
0
        public void RegisterFactory(Type type, string category = "")
        {
            if (!type.IsSubclassOf(typeof(Object)))
            {
                throw new ArgumentException("Type must be sublass of Object.");
            }

            _factoryTypes[StringHash.Calculate(type.Name)] = type;

            // Find a wrapper base type.
            var baseType = type.BaseType;

            while (baseType != null && baseType.Assembly != typeof(Context).Assembly)
            {
                baseType = baseType.BaseType;
            }

            if (baseType == null)
            {
                throw new InvalidOperationException("This type can not be registered as factory.");
            }

            Urho3D_Context_RegisterFactory(GetNativeInstance(this), type.Name, StringHash.Calculate("Wrappers::" + baseType.Name), category);
        }
Example #3
0
        public T GetComponent <T>(bool recursive = false) where T : Component
        {
            var componentInstance = Urho3D__Node__GetComponent_Urho3D__StringHash_bool__const(NativeInstance, StringHash.Calculate(typeof(T).Name), recursive);

            if (componentInstance == IntPtr.Zero)
            {
                return(default(T));
            }
            return(InstanceCache.GetOrAdd(componentInstance, ptr => (T)Activator.CreateInstance(typeof(T),
                                                                                                BindingFlags.NonPublic | BindingFlags.Instance, null, new object[] { ptr, false }, null)));
        }
Example #4
0
        public T CreateComponent <T>(CreateMode mode = CreateMode.REPLICATED, uint id = 0) where T : Component
        {
            var componentInstance = Urho3D__Node__CreateComponent_Urho3D__StringHash_Urho3D__CreateMode_unsigned_int_(NativeInstance, StringHash.Calculate(typeof(T).Name), mode, id);

            if (componentInstance == IntPtr.Zero)
            {
                return(default(T));
            }
            return(InstanceCache.GetOrAdd(componentInstance, ptr => (T)Activator.CreateInstance(typeof(T),
                                                                                                BindingFlags.NonPublic | BindingFlags.Instance,
                                                                                                null, new object[] { ptr, false }, null)));
        }
Example #5
0
 public T GetComponent <T>() where T : Component
 {
     return(GetManagedInstance <T>(
                Urho3D__Component__GetComponent_Urho3D__StringHash__const(
                    NativeInstance, StringHash.Calculate(typeof(T).Name)), false));
 }
Example #6
0
 public T GetOrCreateComponent <T>(Urho3D.CreateMode mode = Urho3D.CreateMode.Replicated, uint id = 0) where T : Component
 {
     return(GetManagedInstance <T>(
                Urho3D__Node__GetOrCreateComponent_Urho3D__StringHash_Urho3D__CreateMode_unsigned_int_(
                    NativeInstance, StringHash.Calculate(typeof(T).Name), mode, id), false));
 }
Example #7
0
 public T GetComponent <T>(bool recursive = false) where T : Component
 {
     return(GetManagedInstance <T>(
                Urho3D__Node__GetComponent_Urho3D__StringHash_bool__const(
                    NativeInstance, StringHash.Calculate(typeof(T).Name), recursive), false));
 }
 public T GetResource <T>(string name, bool sendEventOnFailure = true) where T : Resource
 {
     return(GetManagedInstance <T>(
                Urho3D__ResourceCache__GetResource_Urho3D__StringHash_Urho3D__String_const__bool_(
                    NativeInstance, StringHash.Calculate(typeof(T).Name), name, sendEventOnFailure), true));
 }