internal override void load() { size = new Vector2(1024, 768); DLabelNode.defaultLoadFont = GameFonts.openSansLight; label = new DLabelNode("", 144); label.position.X = size.X / 2; label.position.Y = size.Y / 2; label.alpha = 0.0f; label.run(DAction.fadeIn(2.0f)); addChild(label); pulse = DAction.group(new[] { DAction.sequence(new[] { DAction.scaleBy(0.6f, 0.3f), DAction.scaleTo(1.0f, 0.3f) }), DAction.sequence(new[] { DAction.fadeOut(0.3f), DAction.fadeIn(0.3f) }) }); }
private void ChangeState(states s) { DAction da = new DAction(); da.OnUpdate += (d) => { state = s; d.state = ActionState.Done; }; queue.Enqueue(da); }
//============= test methods ============ public DAction SimpleAction(Action <DAction> act) { DAction da = new DAction(); da.OnUpdate += act; return(da); }
public void RegisterSpawnPool(string name, GameObject prefab, DAction <GameObject> onSpawn, DAction <GameObject> onDeSpawn) { if (!mObjectPools.ContainsKey(name)) { mObjectPools.Add(name, new ObjectPool(prefab, onSpawn, onDeSpawn)); } }
public bool IsActionFull(EAction type) { DAction actDB = ReadCfgAction.GetDataById(type); DItem db = ReadCfgItem.GetDataById(actDB.ItemID); int count = GTDataManager.Instance.GetActionCountByType(type); return(count >= db.Data1); }
IEnumerator PrintAction(DAction action) { yield return(YieldInstrucioner.GetWaitUntil(() => { return true; })); if (action != null) { action(); } }
private void ExecuteCreateEntity(Type type, string entityName = "", DAction <float> loadingAction = null, DAction <Entity> loadDoneAction = null) { EntityInfoAttribute att = (EntityInfoAttribute)type.GetCustomAttributes(false) [0]; if (att == null) { this.e("damon", "资源信息未添加"); return; } //取回一个实体对象并且进行初始化 Entity entity = (Entity)Main.referencePoolManager.OnSpawn(type); GameObject go = null; entity.Reset(); string typeName = type.GetType().FullName; if (mEntities.ContainsKey(type)) { if (att.isUseObject) { if (mObjectPool.Count > 0) { go = mObjectPool[type].Dequeue(); } else { } } else { if (mDefineEntity.ContainsKey(typeName) && (mDefineEntity.ContainsKey(typeName) != null)) { GameObject prefab = mDefineEntity[typeName]; go = Instantiate(prefab); go.SetParent(mEntityGroup[type]); entity.gameObject = go; } else { //需要将游戏对象加载到容器中 } } go.SetParent(mEntityGroup[type]); entity.gameObject = go; mEntities[type].Add(entity); entity.name = (entityName == "" ? type.Name : entityName); entity.OnAwake(); entity.active = true; entity.OnStart(); } else //这里字典中包含该类型 { this.e("damon", "不是指定的类型"); } }
public void ClearEvent(Type t) { DAction <Object, BaseEvent> action = null; if (mEvents.TryGetValue(t, out action)) { mEvents[t] = null; mEvents.Remove(t); } }
public void Register(Type type, DAction <Object, BaseEvent> action) { if (!mEvents.ContainsKey(type)) { mEvents.Add(type, action); } else { mEvents[type] += action; } this.d("Register", type.ToString()); }
private DSpriteNode spinnyNode() { DSpriteNode spriteNode = new DSpriteNode("spinnyNode"); spriteNode.run(DAction.repeatForever(DAction.rotateBy((float)Math.PI, 1.0f))); spriteNode.run(DAction.sequence(new[] { DAction.waitForDuration(0.5f), DAction.fadeOut(0.5f), DAction.removeFromParent() })); return(spriteNode); }
private void Give(Man target) { DAction da = new DAction(); da.OnUpdate += (d) => { var inv = GetComponent <Inventory>(); var targetinv = target.GetComponent <Inventory>(); foreach (var i in inv.GetInventory()) { targetinv.AddToInventory(i.Key, i.Value); inv.AddToInventory(i.Key, -i.Value); } d.state = ActionState.Done; state = states.idle; }; queue.Enqueue(da); }
public int GetAllRemainSeconds(EAction actionType) { int index = 0; for (int i = 0; i < mActionKeyList.Count; i++) { int key = mActionKeyList[i]; EAction type = GetActionType(key); if (type == actionType) { index = i; break; } } int count = GTDataManager.Instance.GetActionCountByType(actionType); DAction actDB = ReadCfgAction.GetDataById(actionType); DItem db = ReadCfgItem.GetDataById(actDB.ItemID); return((int)((db.Data1 - count - 1) * db.Data2 + mActionNextTimes[index] - CurServerTime)); }
public void Run() { if (IsNative) { DAction runnable = (DAction)Entity; if (runnable == null) { runnable = (MetaAction.DAction)Delegate.CreateDelegate(typeof(MetaAction.DAction), Father.Entity, Name); } //Console.WriteLine("[MetaAction.Run] RUNNING {0}.{1}", this.Father.Name, this.Name); runnable(); //chamada da função via delegate. } else { ((IConnectorImpl)father.Entity).perform_action(Name); //TODO Solucao para manter no mesmo ConfigurationManager suspensa. //WaitHandle.WaitAll(new ManualResetEvent[] {protocol.doneEvent}); } }
public void MoveTo(Vector3 WorldLocation) { destination = WorldLocation; var da = new DAction(); da.OnBegin += (d) => { directionUnit = (destination - transform.position).normalized; currentSpeed = 0f; distance = MathUtil.CrowFliesDistance(destination - transform.position); // Debug.Log ("walk>?"); GetComponentInChildren <Animation>().Play("walk"); }; da.OnUpdate += (d) => { directionUnit = (destination - transform.position).normalized; lastDistance = distance; distance = MathUtil.CrowFliesDistance(destination - transform.position); currentSpeed = speed * Time.deltaTime; if (distance < 0.5f) { //Debug.Log("last: " + lastDistance + " dist: " + distance); d.state = ActionState.Done; GetComponentInChildren <Animation>().Play("idle"); return; } ; controller.SimpleMove(directionUnit * currentSpeed); pos = transform.position; currentFacing = Vector3.Slerp(pos + transform.forward, destination, rotateSpeed * Time.deltaTime); transform.LookAt(new Vector3(currentFacing.x, pos.y, currentFacing.z)); }; //da.OnEnd += (d) => {Debug.Log("Ended Moveto");}; queue.Enqueue(da); }
public void MoveTo(WorldObject target) { var da = new DAction(); da.OnBegin += (d) => { targetObject = target; destination = target.transform.position; directionUnit = (destination - transform.position).normalized; currentSpeed = 0f; distance = MathUtil.CrowFliesDistance(destination - transform.position); }; da.OnUpdate += (d) => { destination = target.transform.position; directionUnit = (destination - transform.position).normalized; lastDistance = distance; distance = MathUtil.CrowFliesDistance(destination - transform.position); currentSpeed = speed * Time.deltaTime; if (distance < 2.5f) { // Debug.Log("last: " + lastDistance + " dist: " + distance); d.state = ActionState.Done; return; } ; controller.SimpleMove(directionUnit * currentSpeed); pos = transform.position; currentFacing = Vector3.Slerp(pos + transform.forward, destination, rotateSpeed * Time.deltaTime); transform.LookAt(new Vector3(currentFacing.x, pos.y, currentFacing.z)); }; //da.OnEnd += (d) => {Debug.Log("Ended MoveTo");}; queue.Enqueue(da); }
private void FindClosestAct <T>(float maxDistance = Mathf.Infinity) where T : WorldObject { DAction da = new DAction(); da.OnUpdate += (d) => { float rays = 50f; float inc = 2.0f * Mathf.PI / rays; float start = Random.Range(0f, inc); state = states.searching; float i = start; RaycastHit info; T closest = null; float shortestdistance = maxDistance; while (i < 2.0f) { if (Physics.Raycast(transform.position, new Vector3(Mathf.Cos(i * Mathf.PI), 0f, Mathf.Sin(i * Mathf.PI)), out info, shortestdistance) && info.collider.GetComponent <T>() != null && info.distance < shortestdistance) { Debug.Log(shortestdistance + " > " + info.distance); closest = info.collider.GetComponent <T>(); shortestdistance = info.distance; ChangeState(states.idle); } i += inc; } targetObject = closest; d.state = ActionState.Done; }; queue.Enqueue(da); }
public ObjectPool(GameObject prefab, DAction <GameObject> onSpawn = null, DAction <GameObject> deSpawn = null) { this.mPrefab = prefab; this.mOnSpawn = onSpawn; this.mDeSpawn = deSpawn; }
public unsafe NIDAction (BlockLiteral *block) { blockPtr = _Block_copy ((IntPtr) block); invoker = block->GetDelegateForBlock<DAction> (); }
public void Register <T> (DAction <Object, BaseEvent> action) where T : BaseEvent { Type t = typeof(T); Register(t, action); }
public void CreateEntity(Type type, string entityName, DAction <float> loadingAction = null, DAction <Entity> loadDoneAction = null) { Entity temp = null; if (mEntities.ContainsKey(type))//字典中包含该类 { List <Entity> list = mEntities[type]; if (list.Count > 0) { temp = list[list.Count - 1]; temp.Reset(); } else { Entity entity = Activator.CreateInstance <Entity> (); mEntities[type].Add(entity); } } else//字典中不包含此类 { List <Entity> list = new List <Entity> (); Entity entity = Activator.CreateInstance <Entity> (); list.Add(entity); mEntities[type] = list; temp = entity; } if (loadDoneAction != null) { loadDoneAction(temp); } }
/// <summary> /// Note: Until javascript in Mono is complete and stable, this will interpret the script code. /// For simplicity's sake, the only supported format is: /// variable = FullQualifiedObject(param0, param1, ...); /// The variable is expected to be in field scope, and is optional. Parameters can only be of /// type string, and are always passed by value. /// </summary> /// <param name="i_dfActive"></param> /// <param name="i_iOptionIndex"></param> /// <returns></returns> // public static bool ScriptExecute(ILegacyLogger i_Logger, string i_sVmcId, DField i_dfField, DAction i_daAction) public static bool ScriptExecute(ILegacyLogger i_Logger, string i_sVmcId, ISubdocContext i_SubdocContext, DAction i_daAction) { bool bRet = true, bRes = true; int ii = 0, iIndexStart = 0; System.Int32 iTmp = 0; // I know, same as 'int', but... DScript dsCode; string sStatement, sVarName, sVarNameShort, sRes = ""; DVariable dvTmp = null; try { // FIX - The parsing code is currently a hack to get a demo working. // FIX - The variables we look for in the javascript may be VoiceXML variables. // Right now we only handle two types of statements: variable declarations (with or // without assignment) and function calls (w/ or w/out assignment.) All parameters and // return values from function calls are of type string. Any text results to be TTSed // need to be done through the reserved statement 'document.writeln(svar);'. // dsCode = (DScript)i_daAction.m_oValue; for (ii = 0; ii < dsCode.Code.Count; ii++) { dvTmp = null; sStatement = dsCode.Code[ii]; // Check if there is a variable declared if (sStatement.IndexOf("var ") >= 0) { sVarName = ScriptExtractVariableName(sStatement.Substring(4)); iTmp = sVarName.IndexOf('.'); if (iTmp < 0) { sVarNameShort = sVarName; } else { sVarNameShort = sVarName.Substring(iTmp + 1); } dvTmp = DialogEngine.DialogEngine.FindVariableByName(i_SubdocContext, sVarName); // Reuse variable if it exists, even though script has (erroneously) declared a new one. if (dvTmp == null) { // Allocate variable and put it in proper scope. dvTmp = new DVariable(); dvTmp.Name = sVarNameShort; iIndexStart = sStatement.IndexOf("var ") + 4; if (i_SubdocContext.GetType() == typeof(DField)) { DField dfField = (DField)i_SubdocContext; if (sVarName.IndexOf("session.") >= 0) { dfField.m_dfParentForm.m_ddParentDocument.m_dsParentSession.m_DVariables.Add(dvTmp); } else if (sVarName.IndexOf("application.") >= 0) { // FIX - Keep it in session since we don't currently have an "application" in USCs? dfField.m_dfParentForm.m_ddParentDocument.m_dsParentSession.m_DVariables.Add(dvTmp); } else if (sVarName.IndexOf("document.") >= 0) { dfField.m_dfParentForm.m_ddParentDocument.m_DVariables.Add(dvTmp); } else if (sVarName.IndexOf("dialog.") >= 0) { dfField.m_dfParentForm.Variables.Add(dvTmp); } else { i_SubdocContext.Variables.Add(dvTmp); } } else if (i_SubdocContext.GetType() == typeof(DForm)) { DForm dfForm = (DForm)i_SubdocContext; if (sVarName.IndexOf("session.") >= 0) { dfForm.m_ddParentDocument.m_dsParentSession.m_DVariables.Add(dvTmp); } else if (sVarName.IndexOf("application.") >= 0) { // FIX - Keep it in session since we don't currently have an "application" in USCs? dfForm.m_ddParentDocument.m_dsParentSession.m_DVariables.Add(dvTmp); } else if (sVarName.IndexOf("document.") >= 0) { dfForm.m_ddParentDocument.m_DVariables.Add(dvTmp); } else if (sVarName.IndexOf("dialog.") >= 0) { dfForm.Variables.Add(dvTmp); } else { i_SubdocContext.Variables.Add(dvTmp); } } else { i_Logger.Log(Level.Exception, string.Format("[{0}]DialogEngine.ScriptExecute - invalid type '{1}'.", i_sVmcId, i_SubdocContext.GetType().ToString())); } } } else if (sStatement.IndexOf(m_csBoolEqual) >= 0) { i_Logger.Log(Level.Warning, "[" + i_sVmcId + "]" + "DialogEngine.ScriptExecute - Boolean conditions not yet supported."); } else if (sStatement.IndexOf('=') >= 0) { sVarName = sStatement.Substring(0, sStatement.IndexOfAny(DialogEngine.VoiceXmlParser.s_acBreakNonVar)); dvTmp = DialogEngine.DialogEngine.FindVariableByName(i_SubdocContext, sVarName); if (dvTmp == null) { i_Logger.Log(Level.Exception, "[" + i_sVmcId + "]" + "DialogEngine.ScriptExecute - Variable named '" + sVarName + "' was not found, line " + ii + " '" + sStatement + "'."); // Create a new temporary variable so we can keep going // FIX - probably ought to return a failure if we get here... dvTmp = new DVariable(); dvTmp.Name = sVarName; } } else { // No variable assigned to the return value, so create a temporary variable dvTmp = new DVariable("TEMPORARY", ""); } // if 'var' // Check if there is an assignment iIndexStart = sStatement.IndexOf('='); if (iIndexStart >= 0) { iIndexStart++; bRes = ScriptAssignVariable(i_Logger, i_sVmcId, i_SubdocContext, dvTmp, sStatement.Substring(iIndexStart).Trim()); } else { // Check for a function call that doesn't assign a return value to a variable if (sStatement.IndexOf('(') >= 0) { sRes = ScriptCallFunction(i_Logger, i_sVmcId, i_SubdocContext, sStatement.TrimEnd(DialogEngine.VoiceXmlParser.s_acTerminator)); } else { i_Logger.Log(Level.Info, "[" + i_sVmcId + "]" + "DialogEngine.ExecuteScript - Seem to have found a no-op on line " + ii + ": '" + sStatement + "'."); } } } // for } catch (Exception e) { bRet = false; i_Logger.Log(Level.Exception, "[" + i_sVmcId + "]" + "DialogEngine.ScriptExecute: " + e.ToString()); } return(bRet); }
public unsafe NIDAction(BlockLiteral *block) : base(block) { invoker = block->GetDelegateForBlock <DAction> (); }
public unsafe NIDAction(BlockLiteral *block) { blockPtr = _Block_copy((IntPtr)block); invoker = block->GetDelegateForBlock <DAction> (); }
//============= test methods ============ public DAction SimpleAction(Action<DAction> act) { DAction da = new DAction(); da.OnUpdate += act; return da; }