Ejemplo n.º 1
0
 protected void Awake()
 {
     Debug.Log("Container awake", this);
     BloxGlobal.Create(this.bloxGlobalPrefab);
     this.customEvents = new Dictionary <string, List <BloxEvent> >();
     this.bloxVarCache = new Dictionary <string, BloxVariables>();
     Debug.Log("生成事件和变量缓存");
     for (int i = 0; i < this.bloxVars.Count; i++)
     {
         Debug.Log("添加变量缓存" + this.bloxVars[i].bloxIdent + " 值 " + this.bloxVars[i]);
         this.bloxVarCache.Add(this.bloxVars[i].bloxIdent, this.bloxVars[i]);
         this.CheckVariables(this.bloxVars[i], BloxGlobal.Instance.FindBloxDef(this.bloxIdents[i]));
         this.bloxVars[i].BuildCache();
     }
     for (int j = 0; j < this.bloxIdents.Count; j++)
     {
         Blox blox = BloxGlobal.Instance.FindBloxDef(this.bloxIdents[j]);
         if (!((UnityEngine.Object)blox == (UnityEngine.Object)null))
         {
             if (!this.bloxVarCache.ContainsKey(this.bloxIdents[j]))
             {
                 BloxVariables bloxVariables = new BloxVariables();
                 bloxVariables.bloxIdent = this.bloxIdents[j];
                 this.bloxVars.Add(bloxVariables);
                 this.bloxVarCache.Add(bloxVariables.bloxIdent, bloxVariables);
                 this.CheckVariables(bloxVariables, blox);
                 bloxVariables.BuildCache();
             }
             this.AttachComponents(blox);
         }
     }
 }
Ejemplo n.º 2
0
 public void CopyTo(Blox def)
 {
     def.scriptDirty = true;
     def.variables   = this.variables.Copy();
     def.events      = new BloxEvent[this.events.Length];
     for (int i = 0; i < this.events.Length; i++)
     {
         def.events[i] = this.events[i].Copy();
     }
 }
Ejemplo n.º 3
0
        public Blox FindBloxDef(string ident)
        {
            Blox result = null;

            if (BloxGlobal.bloxDefCache.TryGetValue(ident, out result))
            {
                return(result);
            }
            return(null);
        }
Ejemplo n.º 4
0
        public string FindBloxIdentByName(string bloxName)
        {
            Blox blox = this.FindBloxDefByName(bloxName);

            if ((object)blox == null)
            {
                return(null);
            }
            return(blox.ident);
        }
Ejemplo n.º 5
0
 private void AttachComponents(Blox b)
 {
     if (b.scriptDirty || b.scriptType == null)
     {
         this.AttachEventHandlers(b);
     }
     else
     {
         base.gameObject.AddComponent(b.scriptType);
     }
 }
Ejemplo n.º 6
0
 private void CheckVariables(BloxVariables v, Blox b)
 {
     Debug.Log("CheckVariables " + " BloxVariables: " + v + "Blox: " + b);
     if (v != null && !((UnityEngine.Object)b == (UnityEngine.Object)null))
     {
         if (v.varDefs.Count > 0)
         {
             for (int num = v.varDefs.Count - 1; num >= 0; num--)
             {
                 plyVar plyVar = v.varDefs[num];
                 bool   flag   = false;
                 for (int i = 0; i < b.variables.varDefs.Count; i++)
                 {
                     plyVar plyVar2 = b.variables.varDefs[i];
                     if (plyVar.ident == plyVar2.ident)
                     {
                         plyVar.name = plyVar2.name;
                         if (plyVar.variableType != plyVar2.variableType)
                         {
                             plyVar2.CopyTo(plyVar);
                         }
                         flag = true;
                         break;
                     }
                 }
                 if (!flag)
                 {
                     v.varDefs.RemoveAt(num);
                 }
             }
         }
         for (int j = 0; j < b.variables.varDefs.Count; j++)
         {
             plyVar plyVar3 = b.variables.varDefs[j];
             bool   flag2   = false;
             int    num2    = 0;
             while (num2 < v.varDefs.Count)
             {
                 if (plyVar3.ident != v.varDefs[num2].ident)
                 {
                     num2++;
                     continue;
                 }
                 flag2 = true;
                 break;
             }
             if (!flag2)
             {
                 v.varDefs.Add(plyVar3.Copy());
             }
         }
     }
 }
Ejemplo n.º 7
0
        public BloxVariables GetBloxVariables(string bloxIdent, Blox b = null)
        {
            BloxVariables bloxVariables = null;

            if ((UnityEngine.Object)b == (UnityEngine.Object)null)
            {
                if (this.bloxVarCache == null)
                {
                    this.BuildVarCache();
                }
                if (this.bloxVarCache.TryGetValue(bloxIdent, out bloxVariables))
                {
                    return(bloxVariables);
                }
                Debug.LogError("This Blox Container does not contain variables for a Blox with ident: " + bloxIdent, base.gameObject);
            }
            else
            {
                if (this.bloxVars.Count > 0)
                {
                    for (int num = this.bloxVars.Count - 1; num >= 0; num--)
                    {
                        if (!this.bloxIdents.Contains(this.bloxVars[num].bloxIdent))
                        {
                            this.bloxVars.RemoveAt(num);
                        }
                    }
                }
                if (this.bloxVarCache == null)
                {
                    this.bloxVarCache = new Dictionary <string, BloxVariables>();
                    for (int i = 0; i < this.bloxVars.Count; i++)
                    {
                        this.bloxVarCache.Add(this.bloxVars[i].bloxIdent, this.bloxVars[i]);
                    }
                }
                this.bloxVarCache.TryGetValue(bloxIdent, out bloxVariables);
                if (bloxVariables == null)
                {
                    bloxVariables           = new BloxVariables();
                    bloxVariables.bloxIdent = bloxIdent;
                    this.bloxVars.Add(bloxVariables);
                    this.bloxVarCache.Add(bloxIdent, bloxVariables);
                }
                else if (!Application.isPlaying)
                {
                    bloxVariables.Deserialize(false);
                }
                this._CheckVariables(bloxVariables, b);
            }
            return(bloxVariables);
        }
Ejemplo n.º 8
0
        private void AttachEventHandlers(Blox b)
        {
            if (!b.bloxLoaded)
            {
                b.Deserialize();
            }
            Common_BloxEventHandler common_BloxEventHandler = null;

            for (int i = 0; i < b.events.Length; i++)
            {
                if (b.events[i].active)
                {
                    b.events[i].Init(this);
                    if (b.events[i].ident.Equals("Custom"))
                    {
                        if (!this.customEvents.ContainsKey(b.events[i].screenName))
                        {
                            this.customEvents.Add(b.events[i].screenName, new List <BloxEvent>());
                        }
                        this.customEvents[b.events[i].screenName].Add(b.events[i]);
                    }
                    else
                    {
                        Type type = BloxGlobal.FindEventHandlerType(b.events[i].ident);
                        if (type == null)
                        {
                            Debug.LogWarning("Could not find a handler for: " + b.events[i].ident, base.gameObject);
                        }
                        else
                        {
                            BloxEventHandler bloxEventHandler = (BloxEventHandler)base.gameObject.GetComponent(type);
                            if ((UnityEngine.Object)bloxEventHandler == (UnityEngine.Object)null)
                            {
                                bloxEventHandler           = (BloxEventHandler)base.gameObject.AddComponent(type);
                                bloxEventHandler.container = this;
                                if (bloxEventHandler.GetType() == typeof(Common_BloxEventHandler))
                                {
                                    common_BloxEventHandler = (Common_BloxEventHandler)bloxEventHandler;
                                }
                            }
                            bloxEventHandler.AddEvent(b.events[i]);
                        }
                    }
                }
            }
            if ((UnityEngine.Object)common_BloxEventHandler != (UnityEngine.Object)null)
            {
                common_BloxEventHandler.Awake();
                common_BloxEventHandler.OnEnable();
            }
        }
Ejemplo n.º 9
0
        public BloxEvent Init(BloxContainer container, Blox blox)
        {
            Debug.Log("Init", "BloxEvent", Color.yellow);
            if (!this.active)
            {
                return(null);
            }
            BloxEvent bloxEvent = new BloxEvent();

            bloxEvent.ident           = this.ident;
            bloxEvent.screenName      = this.screenName;
            bloxEvent.active          = this.active;
            bloxEvent.yieldAllowed    = this.yieldAllowed;
            bloxEvent.container       = container;
            bloxEvent.data            = this.data;
            bloxEvent.storedBlocksIdx = this.storedBlocksIdx;
            bloxEvent.Deserialize(blox);
            bloxEvent.data            = null;
            bloxEvent.storedBlocksIdx = null;
            for (BloxBlock next = bloxEvent.firstBlock; next != null; next = next.next)
            {
                next.owningEvent = bloxEvent;
                if (next.next != null)
                {
                    next.next.prevBlock = next;
                }
                next.Init();
                if (next.selfOrChildCanYield)
                {
                    if (bloxEvent.yieldAllowed)
                    {
                        bloxEvent.canYield = true;
                    }
                    else
                    {
                        Debug.LogWarningFormat("You should not use Flow Blocks related to Waiting in this Event [{0}]. The Wait Block will be ignored.", this.ident);
                    }
                }
            }
            return(bloxEvent);
        }
Ejemplo n.º 10
0
 protected void Awake()
 {
     BloxGlobal.Create(this.bloxGlobalPrefab);
     this.customEvents = new Dictionary <string, List <BloxEvent> >();
     this.BuildVarCache();
     for (int i = 0; i < this.bloxIdents.Count; i++)
     {
         Blox blox = BloxGlobal.Instance.FindBloxDef(this.bloxIdents[i]);
         if (!((UnityEngine.Object)blox == (UnityEngine.Object)null))
         {
             if (!this.bloxVarCache.ContainsKey(this.bloxIdents[i]))
             {
                 BloxVariables bloxVariables = new BloxVariables();
                 bloxVariables.bloxIdent = this.bloxIdents[i];
                 this.bloxVars.Add(bloxVariables);
                 this.bloxVarCache.Add(bloxVariables.bloxIdent, bloxVariables);
                 this._CheckVariables(bloxVariables, blox);
                 bloxVariables.BuildCache();
             }
             this.AttachComponents(blox);
         }
     }
 }
Ejemplo n.º 11
0
 public void Deserialize(Blox owningBlox)
 {
     this.owningBlox = owningBlox;
     if (this._isDirty)
     {
         this.Serialize();
     }
     if (this.data != null)
     {
         this.firstBlock = null;
         this.unlinkedBlocks.Clear();
         List <BloxBlock> list = new List <BloxBlock>();
         for (int i = 0; i < this.data.blocks.Count; i++)
         {
             BloxBlock item = this.data.blocks[i].CreateBlock();
             list.Add(item);
         }
         for (int j = 0; j < this.data.blocks.Count; j++)
         {
             if (this.data.blocks[j].next >= 0)
             {
                 list[j].next = list[this.data.blocks[j].next];
             }
             if (this.data.blocks[j].firstChild >= 0)
             {
                 list[j].firstChild = list[this.data.blocks[j].firstChild];
             }
             if (this.data.blocks[j].contextBlock >= 0)
             {
                 list[j].contextBlock = list[this.data.blocks[j].contextBlock];
             }
             if (this.data.blocks[j].paramBlocks.Length != 0)
             {
                 list[j].paramBlocks = new BloxBlock[this.data.blocks[j].paramBlocks.Length];
                 for (int k = 0; k < this.data.blocks[j].paramBlocks.Length; k++)
                 {
                     if (this.data.blocks[j].paramBlocks[k] >= 0)
                     {
                         list[j].paramBlocks[k] = list[this.data.blocks[j].paramBlocks[k]];
                     }
                 }
             }
         }
         if (this.storedBlocksIdx != null)
         {
             if (this.storedBlocksIdx.Count > 0 && this.storedBlocksIdx[0] >= 0)
             {
                 this.firstBlock = list[this.storedBlocksIdx[0]];
             }
             if (this.storedBlocksIdx.Count > 1)
             {
                 for (int l = 1; l < this.storedBlocksIdx.Count; l++)
                 {
                     if (this.storedBlocksIdx[l] >= 0 && this.storedBlocksIdx[l] < list.Count)
                     {
                         BloxBlock bloxBlock = list[this.storedBlocksIdx[l]];
                         if (bloxBlock != null)
                         {
                             this.unlinkedBlocks.Add(bloxBlock);
                         }
                     }
                 }
             }
         }
         if (Application.isPlaying && !Application.isEditor)
         {
             this.data            = null;
             this.storedBlocksIdx = null;
         }
     }
 }