Пример #1
0
        void Start()
        {
            // Note: we use start and not Awake so the BulletManager has some time to initialiez BulletML properly.

            // Find the manager
            bulletManager = FindObjectOfType <BulletManagerScript>();
            if (bulletManager == null)
            {
                throw new System.Exception("Cannot find a BulletManagerScript in the scene!");
            }

            // Parse pattern
            if (xmlFile == null)
            {
                throw new System.Exception("No pattern (Xml File) assigned to the emitter.");
            }

            // Cache the pattern to avoid reparsing everytime
            if (patternCache.TryGetValue(xmlFile, out pattern) == false)
            {
                System.Xml.XmlTextReader reader = new System.Xml.XmlTextReader(new System.IO.StringReader(xmlFile.text));
                reader.Normalization = false;
                reader.XmlResolver   = null;

                pattern = new BulletMLLib.BulletPattern();
                pattern.ParseXML(xmlFile.name, reader);

                patternCache.Add(xmlFile, pattern);
            }

            Initialize();
        }
Пример #2
0
        public void Fire()
        {
            if (!_fire)
            {
                _fire = true;
                // Find the manager
                bulletManager = FindObjectOfType<BulletManagerScript>();
                if (bulletManager == null)
                {
                    throw new System.Exception("Cannot find a BulletManagerScript in the scene!");
                }

                // Parse pattern
                if (xmlFile == null)
                {
                    throw new System.Exception("No pattern (Xml File) assigned to the emitter.");
                }

                // Cache the pattern to avoid reparsing everytime
                if (patternCache.TryGetValue(xmlFile, out pattern) == false)
                {
                    System.Xml.XmlTextReader reader = new System.Xml.XmlTextReader(new System.IO.StringReader(xmlFile.text));
                    reader.Normalization = false;
                    reader.XmlResolver = null;

                    pattern = new BulletMLLib.BulletPattern();
                    pattern.ParseXML(xmlFile.name, reader);

                    patternCache.Add(xmlFile, pattern);
                }

                Initialize();
            }
            else
            {
                Reset();
            }
        }