static void DemoPhysics()
    {
        ManagerPackage package = AssetDatabase.LoadAssetAtPath(Resource.MainFolderPath + "/DemoPhysics/PhysicsDemo_ManagerPackage.asset", typeof(ManagerPackage)) as ManagerPackage;

        if (package != null)
        {
            if (!ACInstaller.IsInstalled())
            {
                ACInstaller.DoInstall();
            }

            package.AssignManagers();
            AdventureCreator.RefreshActions();

            if (UnityVersionHandler.GetCurrentSceneName() != "Office")
            {
                                #if UNITY_5_3 || UNITY_5_4 || UNITY_5_3_OR_NEWER
                bool canProceed = EditorUtility.DisplayDialog("Open demo scene", "Would you like to open the Physics Demo scene, Office, now?", "Yes", "No");
                if (canProceed)
                {
                    if (UnityVersionHandler.SaveSceneIfUserWants())
                    {
                        UnityEditor.SceneManagement.EditorSceneManager.OpenScene(Resource.MainFolderPath + "/DemoPhysics/Scenes/Office.unity");
                    }
                }
                                #else
                ACDebug.Log("Physics Demo managers loaded - you can now run the Physics Demo scene in '" + Resource.mainFolderPath + "/DemoPhysics/Scenes/Office.unity'");
                                #endif
            }

            AdventureCreator.Init();
        }
    }
Exemplo n.º 2
0
    static void Demo3D()
    {
        ManagerPackage package = AssetDatabase.LoadAssetAtPath("Assets/AdventureCreator/Demo/ManagerPackage.asset", typeof(ManagerPackage)) as ManagerPackage;

        package.AssignManagers();
        AdventureCreator.RefreshActions();
    }
        public ManagerPackage AddPackage(ManagerAddPackage cmd, IManagerCommandLogger logger)
        {
            //Make sure the package doesn't already exist
            if (packages.ContainsKey(cmd.name))
            {
                logger.FinishFail("The package requested already exists.");
                return(null);
            }

            //Make sure all requested dependencies exist
            foreach (var d in cmd.dependencies)
            {
                if (!packages.ContainsKey(d))
                {
                    logger.FinishFail($"The requested dependency \"{d}\" does not exist.");
                    return(null);
                }
            }

            //Create package
            ManagerPackage package = new ManagerPackage
            {
                name                = cmd.name,
                project_path        = cmd.project_path,
                git_repo            = cmd.git_repo,
                exec                = cmd.exec,
                required_user_ports = cmd.required_user_ports,
                dependencies        = cmd.dependencies
            };

            //Clone GIT directory
            logger.Log("AddPackage", "Cloning source project files...");
            int status = new GitTool(package.GetGitPath(this), logger).Clone(cmd.git_repo, "AddPackage", "Cloning...");

            if (status != 0)
            {
                logger.FinishFail($"Failed to clone source project files. (Code {status}) Aborting!");
                return(null);
            }

            //Add
            packages.Add(cmd.name, package);
            Save();

            //Finish
            logger.FinishSuccess($"Successfully added package {package.name}.");

            return(package);
        }
Exemplo n.º 4
0
        private void OnCmdAddInstance(RouterMessage msg)
        {
            //Decode arguments and create logger
            ManagerAddInstance  args   = msg.DeserializeAs <ManagerAddInstance>();
            MasterCommandLogger logger = new MasterCommandLogger(msg);

            //Find package
            if (!session.packages.ContainsKey(args.package_name))
            {
                logger.FinishFail("Could not find that package on the server.");
                return;
            }
            ManagerPackage package = session.packages[args.package_name];

            //Run
            try
            {
                session.CreateNewInstance(package, logger, args.count, true);
            }
            catch (Exception ex)
            {
                logger.FinishFail($"Unexpected error: {ex.Message}{ex.StackTrace}");
            }
        }
        public ManagerInstance[] CreateNewInstance(ManagerPackage package, IManagerCommandLogger logger, int count = 1, bool spawn = true)
        {
            //Make sure this has a version
            if (package.latest_version == null)
            {
                logger?.FinishFail("Package has no version. Please compile a new version before continuing.");
                return(null);
            }

            //Loop through creation
            ManagerInstance[] newInstances = new ManagerInstance[count];
            for (int i = 0; i < count; i++)
            {
                //Generate a new ID
                long id;
                while (true)
                {
                    //Create
                    byte[] idBytes = new byte[8];
                    rand.NextBytes(idBytes);
                    id = Math.Abs(BitConverter.ToInt64(idBytes));

                    //Validate
                    bool exists = false;
                    foreach (var s in instances)
                    {
                        exists = exists || s.id == id;
                    }
                    if (!exists)
                    {
                        break;
                    }
                }

                //Allocate ports
                int[] ports = new int[package.required_user_ports];
                for (int p = 0; p < ports.Length; p++)
                {
                    ports[p] = ClaimNewUserPort();
                }

                //Create
                ManagerInstance instance = new ManagerInstance
                {
                    id           = id,
                    package_name = package.name,
                    ports        = ports,
                    version_id   = package.latest_version
                };
                instances.Add(instance);
                newInstances[i] = instance;

                //Spawn
                if (spawn)
                {
                    instance.StartInstance(this);
                }

                //Log
                logger?.Log("CreateNewInstance", $"Created instance {id} with version {package.latest_version}.");
            }

            //Save
            Save();

            //Log
            logger?.FinishSuccess("Created " + newInstances.Length + " instances.");
            return(newInstances);
        }