/*
  *  called when the attached event player plays an
  *  event with the pack name this ocmponent uses
  *  and chooses an appropriate asset object
  *
  *  endUseCallbacks should be called whenever the animation is done
  */
 protected abstract void UseAssetObject(AssetObject ao, bool asInterrupter, MiniTransform transforms, HashSet <System.Action> endUse);
Exemple #2
0
            bool PlayEvent(
                MiniTransform transforms,
                EventPlayer myPlayer,
                Dictionary <int, PlayerMessage> pack2playEvents,
                Dictionary <string, CustomParameter> paramDict,
                Event e, bool isMainEvent, bool asInterrupter, bool endAfterDuration)
            {
                int packID = e.mainPackID;

                if (skipPlays.Contains(packID))
                {
                    return(false);
                }


                EventResponse eventResponse = new EventResponse();//skipPlays);

                e.GetParamFilteredObjects(paramDict, eventResponse);

                eventResponse.LogErrors();
                eventResponse.LogWarnings();

                // bool mainFound = !eventResponse.noMainFound;

                // foreach (var k in eventResponse.objectsPerPack.Keys) {

                // bool isMainPack = k == e.mainPackID;


                // List<AssetObject> list = eventResponse.objectsPerPack[k];
                List <AssetObject> list = eventResponse.chosenObjects;


                if (list.Count > 0)
                {
                    AssetObject o = list.RandomChoice();

                    if (!endAfterDuration)
                    {
                        // if (isMainPack && isMainEvent) {
                        if (isMainEvent)
                        {
                            SetDuration(o["Duration"].GetValue <float>());


                            // current_duration = o["Duration"].GetValue<float>();
                        }
                    }

                    HashSet <Action> endUseSuccessCBs = new HashSet <Action>();

                    if (!endAfterDuration)
                    {
                        //give control to object when it's the main event
                        //and when the duration is < 0 and not overriden

                        // if (isMainEvent && isMainPack) {
                        if (isMainEvent)
                        {
                            endUseSuccessCBs.Add(() => { EndPlayAttempt(true, "controlled"); });
                        }
                    }

                    string logErrors = "";
                    CustomScripting.ExecuteMessageBlock(myLayer, myPlayer, o.messageBlock, Vector3.zero, ref logErrors);

                    if (!logErrors.IsEmpty())
                    {
                        logErrors = "Broadcast message from asset object: " + o.objRef.name + "\n" + logErrors;
                        Debug.LogError(logErrors);
                    }

                    int k = packID;

                    if (!pack2playEvents.ContainsKey(k))
                    {
                        Debug.LogError("skipping " + PacksManager.ID2Name(k) + " not connected to player");
                        return(false);
                    }

                    pack2playEvents[k](o, asInterrupter, transforms, endUseSuccessCBs);
                }


                return(list.Count > 0);// mainFound;
            }