Пример #1
0
 void OnDeleteObjectEvent(DeleteObjectEvent evt)
 {
     if (evt.toDelete == this.gameObject.name)
     {
         Destroy(this.gameObject);
     }
 }
Пример #2
0
        /// <summary>
        /// Creates the on complete function from an oncomplete string.
        /// </summary>
        /// <returns>The on complete function in the form of an Action.</returns>
        /// <param name="oc">OnComplete function in string form.</param>
        public static Action <InteractionEvent> CreateOnCompleteFunction(string oc)
        {
            // Just return a no-op if the user didn't provide an OnComplete string
            if (string.IsNullOrEmpty(oc))
            {
                return((InteractionEvent evt) => { });
            }
            ParsingResult pR = ParseString(oc);

            Action <InteractionEvent> ac = (InteractionEvent evt) => {
                IGameEvent outEvt;
                switch (pR.interactionKind)
                {
                case InteractionKind.Become:
                    if (pR.obj1 == "TargetItem")
                    {
                        outEvt = new ReplaceObjectEvent(evt.targetObject, pR.obj2);
                    }
                    else
                    {
                        outEvt = new ReplaceObjectEvent(pR.obj1, pR.obj2);
                    }
                    break;

                case InteractionKind.Show:
                    Debug.Log("Show InteractionKind");
                    Debug.Log(string.Format("{0}, {1}", pR.obj1, pR.obj2));
                    outEvt = new ShowObjectEvent(pR.obj1);
                    break;

                case InteractionKind.Hide:
                    outEvt = new HideObjectEvent(pR.obj1);
                    break;

                case InteractionKind.Delete:
                    Debug.Log("Delete InteractionKind");
                    Debug.Log(string.Format("{0} {1}", pR.obj1, pR.obj2));
                    outEvt = new DeleteObjectEvent(pR.obj1);
                    break;

                case InteractionKind.Play:
                    switch (pR.uiEventKind)
                    {
                    case UIActionKind.Dialog:
                        outEvt = new ShowTextEvent(pR.obj1);
                        break;

                    case UIActionKind.Sound:
                        outEvt = new PlaySoundEvent(pR.obj1);
                        break;

                    default:
                        throw new ArgumentException("Play must be followed by Dialog or Sound");
                    }
                    break;

                case InteractionKind.Get:
                    outEvt = new PlayerRecieveObjectEvent(pR.obj1);
                    break;

                default:
                    throw new ArgumentException(string.Format("Invalid interaction kind in OnComplete: {0} (OnComplete string: {1})", pR.interactionKind, oc));
                }
                EventManager.FireEvent(outEvt);
            };

            return(ac);
        }