本文整理汇总了C#中IScript.InitApi方法的典型用法代码示例。如果您正苦于以下问题:C# IScript.InitApi方法的具体用法?C# IScript.InitApi怎么用?C# IScript.InitApi使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IScript
的用法示例。
在下文中一共展示了IScript.InitApi方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Load
/// <summary>
/// Load the script from an assembly into an AppDomain.
/// </summary>
/// <param name='dom'></param>
/// <param name='assembly'></param>
/// <param name='dataPath'>
/// Path for all script associated data (state, etc.). In a multi-region set up
/// with all scripts loading into the same AppDomain this may not be the same place as the DLL itself.
/// </param>
/// <param name='stateSource'></param>
/// <returns>false if load failed, true if suceeded</returns>
public bool Load(
IScript script, EventWaitHandle coopSleepHandle, string assemblyPath,
string dataPath, StateSource stateSource, bool coopTermination)
{
m_Script = script;
m_coopSleepHandle = coopSleepHandle;
m_assemblyPath = assemblyPath;
m_dataPath = dataPath;
m_stateSource = stateSource;
m_coopTermination = coopTermination;
if (m_coopTermination)
CoopWaitHandle = coopSleepHandle;
else
CoopWaitHandle = null;
ApiManager am = new ApiManager();
foreach (string api in am.GetApis())
{
m_Apis[api] = am.CreateApi(api);
m_Apis[api].Initialize(Engine, Part, ScriptTask);
}
try
{
foreach (KeyValuePair<string,IScriptApi> kv in m_Apis)
{
m_Script.InitApi(kv.Key, kv.Value);
}
// // m_log.Debug("[Script] Script instance created");
Part.SetScriptEvents(ItemID, (int)m_Script.GetStateEventFlags(State));
}
catch (Exception e)
{
m_log.ErrorFormat(
"[SCRIPT INSTANCE]: Not starting script {0} (id {1}) in part {2} (id {3}) in object {4} in {5}. Error initializing script instance. Exception {6}{7}",
ScriptTask.Name, ScriptTask.ItemID, Part.Name, Part.UUID, Part.ParentGroup.Name, Engine.World.Name, e.Message, e.StackTrace);
return false;
}
// For attachments, XEngine saves the state into a .state file when XEngine.SetXMLState() is called.
string savedState = Path.Combine(m_dataPath, ItemID.ToString() + ".state");
if (File.Exists(savedState))
{
// m_log.DebugFormat(
// "[SCRIPT INSTANCE]: Found state for script {0} for {1} ({2}) at {3} in {4}",
// ItemID, savedState, Part.Name, Part.ParentGroup.Name, Part.ParentGroup.Scene.Name);
string xml = String.Empty;
try
{
FileInfo fi = new FileInfo(savedState);
int size = (int)fi.Length;
if (size < 512000)
{
using (FileStream fs = File.Open(savedState,
FileMode.Open, FileAccess.Read, FileShare.None))
{
Byte[] data = new Byte[size];
fs.Read(data, 0, size);
xml = Encoding.UTF8.GetString(data);
ScriptSerializer.Deserialize(xml, this);
AsyncCommandManager.CreateFromData(Engine,
LocalID, ItemID, ObjectID,
PluginData);
// m_log.DebugFormat("[Script] Successfully retrieved state for script {0}.{1}", PrimName, m_ScriptName);
Part.SetScriptEvents(ItemID,
(int)m_Script.GetStateEventFlags(State));
if (!Running)
m_startOnInit = false;
Running = false;
// we get new rez events on sim restart, too
// but if there is state, then we fire the change
// event
//.........这里部分代码省略.........
示例2: ScriptInstance
public ScriptInstance(IScriptEngine engine, SceneObjectPart part,
UUID itemID, UUID assetID, string assembly,
AppDomain dom, string primName, string scriptName,
int startParam, bool postOnRez, StateSource stateSource,
int maxScriptQueue)
{
m_Engine = engine;
m_LocalID = part.LocalId;
m_ObjectID = part.UUID;
m_ItemID = itemID;
m_AssetID = assetID;
m_PrimName = primName;
m_ScriptName = scriptName;
m_Assembly = assembly;
m_StartParam = startParam;
m_MaxScriptQueue = maxScriptQueue;
m_stateSource = stateSource;
m_postOnRez = postOnRez;
m_AttachedAvatar = part.AttachedAvatar;
m_RegionID = part.ParentGroup.Scene.RegionInfo.RegionID;
if (part != null)
{
lock (part.TaskInventory)
{
if (part.TaskInventory.ContainsKey(m_ItemID))
{
m_thisScriptTask = part.TaskInventory[m_ItemID];
}
}
}
ApiManager am = new ApiManager();
foreach (string api in am.GetApis())
{
m_Apis[api] = am.CreateApi(api);
m_Apis[api].Initialize(engine, part, m_LocalID, itemID);
}
try
{
m_Script = (IScript)dom.CreateInstanceAndUnwrap(
Path.GetFileNameWithoutExtension(assembly),
"SecondLife.Script");
// Add a sponsor to the script
// ISponsor scriptSponsor = new ScriptSponsor();
// ILease lease = (ILease)RemotingServices.GetLifetimeService(m_Script as MarshalByRefObject);
// lease.Register(scriptSponsor);
//m_ScriptSponsor = scriptSponsor;
}
catch (Exception)
{
// m_log.ErrorFormat("[Script] Error loading assembly {0}\n"+e.ToString(), assembly);
}
try
{
foreach (KeyValuePair<string,IScriptApi> kv in m_Apis)
{
m_Script.InitApi(kv.Key, kv.Value);
}
// // m_log.Debug("[Script] Script instance created");
part.SetScriptEvents(m_ItemID,
(int)m_Script.GetStateEventFlags(State));
}
catch (Exception)
{
// m_log.Error("[Script] Error loading script instance\n"+e.ToString());
return;
}
m_SaveState = true;
string savedState = Path.Combine(Path.GetDirectoryName(assembly),
m_ItemID.ToString() + ".state");
if (File.Exists(savedState))
{
string xml = String.Empty;
try
{
FileInfo fi = new FileInfo(savedState);
int size=(int)fi.Length;
if (size < 512000)
{
using (FileStream fs = File.Open(savedState,
FileMode.Open, FileAccess.Read, FileShare.None))
{
System.Text.ASCIIEncoding enc =
new System.Text.ASCIIEncoding();
Byte[] data = new Byte[size];
fs.Read(data, 0, size);
//.........这里部分代码省略.........