Exemplo n.º 1
0
        public static AssetObjectPack ID2Pack(int id, out int index, bool debug = true)
        {
            index = -1;
            // if (!Application.isPlaying) {
            PacksManager pm = instance;

            for (int i = 0; i < pm.packs.Length; i++)
            {
                if (pm.packs[i].id == id)
                {
                    index = i;
                    return(pm.packs[i]);
                }
            }
            // }
            // else {
            //     InitializeDictionaries();
            //     if (id2name.ContainsKey(id)) return id2name[id];
            // }
            if (debug)
            {
                Debug.LogError("pack manager does not contain pack id: " + id);
            }
            return(null);
        }
Exemplo n.º 2
0
 public static string ID2Name(int id, bool debug = true)
 {
     if (!Application.isPlaying)
     {
         PacksManager pm = instance;
         for (int i = 0; i < pm.packs.Length; i++)
         {
             if (pm.packs[i].id == id)
             {
                 return(pm.packs[i].name);
             }
         }
     }
     else
     {
         InitializeDictionaries();
         if (id2name.ContainsKey(id))
         {
             return(id2name[id]);
         }
     }
     if (debug)
     {
         Debug.LogError("pack manager does not contain pack id: " + id);
     }
     return(null);
 }
Exemplo n.º 3
0
 public static int Name2ID(string name, bool debug = true)
 {
     if (!Application.isPlaying)
     {
         PacksManager pm = instance;
         for (int i = 0; i < pm.packs.Length; i++)
         {
             if (pm.packs[i].name == name)
             {
                 return(pm.packs[i].id);
             }
         }
     }
     else
     {
         InitializeDictionaries();
         if (name2ID.ContainsKey(name))
         {
             return(name2ID[name]);
         }
     }
     if (debug)
     {
         Debug.LogError("pack manager does not contain pack: " + name);
     }
     return(-1);
 }
Exemplo n.º 4
0
        public static string GetPacksErrors(PacksManager packsManager = null, EditorProp packsProp = null)
        {
            if (packsManager == null)
            {
                packsManager = PacksManager.instance;
            }

            if (packsManager == null)
            {
                return("\nPacks Manager Object could not be found!" +
                       "\n\nIf it was deleted, create a new one." +
                       "\n\nIn the Unity project window:" +
                       "\n\tRight Click -> Create -> Asset Objects Packs -> Packs Manager\n");
            }

            int l = packsManager.packs.Length;

            if (l == 0)
            {
                return("\nPlease create an Asset Object Pack\n");
            }

            if (packsProp == null)
            {
                packsProp = new EditorProp(new SerializedObject(packsManager))[packsField];
            }

            //check for duplicate pack name
            string dupName;

            if (packsProp.ContainsDuplicateNames(out dupName))
            {
                return("\nThere are multiple packs named:\n\t<i>'" + dupName + "'</i>\n");
            }

            string packsString = "";

            for (int i = 0; i < l; i++)
            {
                if (PackHasErrors(packsManager.packs[i], packsProp[i]))
                {
                    packsString += packsManager.packs[i].name + ", ";
                }
            }

            if (!packsString.IsEmpty())
            {
                return(string.Format("\nPack(s):\n<b>{0}</b>\nHave errors, fix them in the Packs Manager asset.\n", packsString));
            }

            return(null);
        }
Exemplo n.º 5
0
 static void InitializeDictionaries()
 {
     if (id2name == null)
     {
         PacksManager inst = instance;
         int          l    = inst.packs.Length;
         id2name = new Dictionary <int, string>(l);
         name2ID = new Dictionary <string, int>(l);
         for (int i = 0; i < l; i++)
         {
             id2name.Add(inst.packs[i].id, inst.packs[i].name);
             name2ID.Add(inst.packs[i].name, inst.packs[i].id);
         }
     }
 }
        public static IEnumerable <int> GetAllUsedIDs(int packID)
        {
            List <int>          used      = new List <int>();
            IEnumerable <Event> allEvents = EditorUtils.GetAllAssetsOfType <Event>();

            foreach (var e in allEvents)
            {
                if (e.mainPackID == packID)
                {
                    for (int i = 0; i < e.allStates.Length; i++)
                    {
                        GetAOIDs(e.allStates[i], used);//, packID);
                    }
                }
            }
            if (used.Count == 0)
            {
                Debug.LogWarning("no IDs used for " + PacksManager.ID2Name(packID) + " pack!");
            }
            return(used);
        }
Exemplo n.º 7
0
        public void LinkAsPlayer(string packName, PlayerMessage onPlayEvent)
        {
            int packID = PacksManager.Name2ID(packName);

            pack2playEvents[packID] = onPlayEvent;
        }
Exemplo n.º 8
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;
            }
Exemplo n.º 9
0
 public void SkipPlay(string packName)
 {
     skipPlays.Add(PacksManager.Name2ID(packName));
 }
Exemplo n.º 10
0
 void OnEnable()
 {
     so           = new EditorProp(serializedObject);
     packsManager = target as PacksManager;
     errors       = GetPacksErrors(packsManager, packs);
 }