Ejemplo n.º 1
0
 ///<summary>
 ///Package a ValidationResult inside this validation result
 ///</summary>
 public void Capture(ValidationResult v)
 {
     Result = v.Result && Result;
     errorMessages.AddRange(v.errorMessages);
 }
        /// <summary>
        /// Compiles our generated code for the user
        /// </summary>
        public void Compile()
        {
            if (ActiveButton == null)
            {
                Debug.LogError("WHAT?! LOL");
                return;
            }

            if (string.IsNullOrEmpty(ActiveButton.ButtonName))
            {
                Debug.LogError("Can't have an empty class name");
                return;
            }

            EditorApplication.LockReloadAssemblies();

            try
            {
                int identity = 1;
                for (int i = 0; i < _editorButtons.Count; ++i)
                {
                    ForgeEditorButton btn      = _editorButtons[i];
                    ValidationResult  validate = btn.ValidateSetup();
                    if (!validate.Result)
                    {
                        foreach (string error in validate.errorMessages)
                        {
                            Debug.LogError(error);
                        }
                        Debug.LogError(String.Format("Compilation of {0} failed. Please resolve any outputted errors and try again.", btn.ButtonName));
                        break;
                    }

                    if (_editorButtons[i].IsCreated)
                    {
                        //Brand new class being added!
                        string networkObjectData   = SourceCodeNetworkObject(null, _editorButtons[i], identity);
                        string networkBehaviorData = SourceCodeNetworkBehavior(null, _editorButtons[i]);
                        if (!string.IsNullOrEmpty(networkObjectData))
                        {
                            using (StreamWriter sw = File.CreateText(Path.Combine(_userStoringPath, string.Format("{0}{1}.cs", _editorButtons[i].StrippedSearchName, "NetworkObject").Checkout())))
                            {
                                sw.Write(networkObjectData);
                            }

                            using (StreamWriter sw = File.CreateText(Path.Combine(_userStoringPath, string.Format("{0}{1}.cs", _editorButtons[i].StrippedSearchName, "Behavior").Checkout())))
                            {
                                sw.Write(networkBehaviorData);
                            }
                            identity++;

                            string strippedName = _editorButtons[i].StrippedSearchName;
                            _editorButtons[i].ButtonName = strippedName + "NetworkObject";
                        }
                    }
                    else
                    {
                        if (_editorButtons[i].TiedObject != null)
                        {
                            if (_editorButtons[i].TiedObject.IsNetworkBehavior)
                            {
                                string networkBehaviorData = SourceCodeNetworkBehavior(null, _editorButtons[i]);

                                using (StreamWriter sw = File.CreateText(Path.Combine(_userStoringPath, _editorButtons[i].TiedObject.Filename).Checkout()))
                                {
                                    sw.Write(networkBehaviorData);
                                }
                            }
                            else if (_editorButtons[i].TiedObject.IsNetworkObject)
                            {
                                string networkObjectData = SourceCodeNetworkObject(null, _editorButtons[i], identity);
                                using (StreamWriter sw = File.CreateText(Path.Combine(_userStoringPath, _editorButtons[i].TiedObject.Filename).Checkout()))
                                {
                                    sw.Write(networkObjectData);
                                }
                                identity++;
                            }
                        }
                    }
                }

                string factoryData = SourceCodeFactory();
                using (StreamWriter sw = File.CreateText(Path.Combine(_storingPath, "NetworkObjectFactory.cs").Checkout()))
                {
                    sw.Write(factoryData);
                }

                string networkManagerData = SourceCodeNetworkManager();
                using (StreamWriter sw = File.CreateText(Path.Combine(_storingPath, "NetworkManager.cs").Checkout()))
                {
                    sw.Write(networkManagerData);
                }

                //IFormatter previousSavedState = new BinaryFormatter();
                //using (Stream s = new FileStream(Path.Combine(Application.persistentDataPath, FN_WIZARD_DATA), FileMode.OpenOrCreate, FileAccess.Write, FileShare.None))
                //{
                //    previousSavedState.Serialize(s, _editorButtons);
                //}
            }
            finally
            {
                EditorApplication.UnlockReloadAssemblies();
            }

            AssetDatabase.Refresh();

            //_editorButtons.Remove(ActiveButton);
            ActiveButton = null;
            CloseFinal();
        }