TryCreate() public static method

public static TryCreate ( Type type, CryScript &script ) : bool
type System.Type
script CryScript
return bool
Exemplo n.º 1
0
        public void AddScriptInstance(CryScriptInstance instance, ScriptType scriptType)
        {
#if !(RELEASE && RELEASE_DISABLE_CHECKS)
            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }
            if (!Enum.IsDefined(typeof(ScriptType), scriptType))
            {
                throw new ArgumentException(string.Format("scriptType: value {0} was not defined in the enum", scriptType));
            }
#endif

            var script = FindScript(scriptType, x => x.Type == instance.GetType());
            if (script == null)
            {
                if (CryScript.TryCreate(instance.GetType(), out script))
                {
                    Scripts.Add(script);
                }
                else
                {
                    return;
                }
            }

            AddScriptInstance(script, instance);
        }
Exemplo n.º 2
0
        public void ReplaceScriptInstance(CryScriptInstance newInstance, int scriptId, ScriptType scriptType)
        {
            RemoveInstance(scriptId, scriptType);

            var script = FindScript(scriptType, x => x.Type == newInstance.GetType());

            if (script == null)
            {
                if (CryScript.TryCreate(newInstance.GetType(), out script))
                {
                    Scripts.Add(script);
                }
                else
                {
                    return;
                }
            }

            AddScriptInstance(script, newInstance, scriptId);
        }
Exemplo n.º 3
0
        void RegisterInternalTypes()
        {
            CryScript script;

            if (CryScript.TryCreate(typeof(NativeActor), out script))
            {
                Scripts.Add(script);
            }

            if (CryScript.TryCreate(typeof(NativeEntity), out script))
            {
                var entityRegistrationParams = new EntityRegistrationParams();

                entityRegistrationParams.name  = script.ScriptName;
                entityRegistrationParams.flags = EntityClassFlags.Default | EntityClassFlags.Invisible;

#if !UNIT_TESTING
                NativeEntityMethods.RegisterEntityClass(entityRegistrationParams);
#endif

                Scripts.Add(script);
            }
        }
Exemplo n.º 4
0
        void ProcessWaitingScripts(bool initialLoad)
        {
            bool hasDefaultGameRules = false;

            foreach (var pluginPair in PluginTypes)
            {
                ICryMonoPlugin plugin = pluginPair.Key;

                foreach (Type type in pluginPair.Value)
                {
                    var script = FindScript(ScriptType.Any, x => x.Type == type);
                    if (script == null)
                    {
                        if (!CryScript.TryCreate(type, out script))
                        {
                            continue;
                        }
                    }

                    script.RegistrationParams = plugin.GetRegistrationParams(script.ScriptType, type);

                    if (!script.Registered)
                    {
                        if (script == null || script.RegistrationParams == null)
                        {
                            continue;
                        }

                        // Contain types that can only be registered at startup here.
                        if (initialLoad)
                        {
                            if (script.RegistrationParams is ActorRegistrationParams)
                            {
                                var registrationParams = (ActorRegistrationParams)script.RegistrationParams;

                                NativeActorMethods.RegisterActorClass(script.ScriptName, script.Type.Implements(typeof(NativeActor)), registrationParams.isAI);
                            }
                            else if (script.RegistrationParams is EntityRegistrationParams)
                            {
                                var registrationParams = (EntityRegistrationParams)script.RegistrationParams;

                                if (registrationParams.name == null)
                                {
                                    registrationParams.name = script.ScriptName;
                                }
                                if (registrationParams.category == null)
                                {
                                    registrationParams.category = "Default";
                                }

                                NativeEntityMethods.RegisterEntityClass(registrationParams);

                                script.RegistrationParams = registrationParams;
                            }
                        }

                        if (script.RegistrationParams is GameRulesRegistrationParams)
                        {
                            var registrationParams = (GameRulesRegistrationParams)script.RegistrationParams;

                            if (registrationParams.name == null)
                            {
                                registrationParams.name = script.ScriptName;
                            }

                            NativeGameRulesMethods.RegisterGameMode(registrationParams.name);

                            if (registrationParams.defaultGamemode || !hasDefaultGameRules)
                            {
                                NativeGameRulesMethods.SetDefaultGameMode(registrationParams.name);

                                hasDefaultGameRules = true;
                            }

                            script.RegistrationParams = registrationParams;
                        }
                        else if (script.RegistrationParams is FlowNodeRegistrationParams)
                        {
                            var registrationParams = (FlowNodeRegistrationParams)script.RegistrationParams;

                            if (registrationParams.name == null)
                            {
                                registrationParams.name = script.ScriptName;
                            }
                            if (registrationParams.category == null)
                            {
                                registrationParams.category = script.Type.Namespace;
                            }
                            if (registrationParams.filter == 0)
                            {
                                registrationParams.filter = FlowNodeFilter.Approved;
                            }

                            script.RegistrationParams = registrationParams;

                            script.ScriptName = registrationParams.category + ":" + registrationParams.name;
                        }
                        else if (script.RegistrationParams is EntityFlowNodeRegistrationParams)
                        {
                            var registrationParams = (EntityFlowNodeRegistrationParams)script.RegistrationParams;

                            script.ScriptName = "entity" + ":" + registrationParams.entityName;
                        }

                        script.Registered = true;
                        Scripts.Add(script);
                    }
                }
            }
        }