Пример #1
0
    void selectTarget()
    {
        if (Input.GetMouseButtonDown(0))
        {
            RaycastHit hitInfo = new RaycastHit();
            bool       hit     = Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hitInfo);
            if (hit)
            {
                if (hitInfo.transform.gameObject.tag == "Column")
                {
                    Column from  = columns[getColumnOfChecker(checkerselected)].GetComponent <Column>();
                    Column to    = hitInfo.transform.GetComponent <Column>();
                    Column onHit = columns[PlayerB.turn ? 25 : 24].GetComponent <Column>();
                    bool   moved = move(from, to, onHit);

                    if (moved)
                    {
                        movesTaken++;
                        checkerselected = null;
                    }
                    //check if with the current move taken the player won
                    if (PlayerB.turn && PlayerB.won)
                    {
                        gameStatusText.text = winMsg;
                        Invoke("GoToScene", 5);
                    }
                    else if (PlayerA.turn && PlayerA.won)
                    {
                        gameStatusText.text = loseMsg;
                        Invoke("GoToScene", 5);
                    }

                    if (movesTaken == Moves)
                    {
                        setUnavailableToMove();
                        state = GameState.Finalizing;
                    }
                    else
                    {
                        setUnavailableToMove();
                        SetAvailableToMove();
                        state = GameState.SelectingChecker;
                    }
                }
            }

            MaterialUtilities.DisableColumnColliders(ref collidersSet, ref columns);
            MaterialUtilities.DisableMeshRenderers(ref columns);
        }
    }
Пример #2
0
    IEnumerator selectTargetAfterSeconds(float x)
    {
        yield return(new WaitForSeconds(x));

        if (checkerselected != null)
        {
            Column from  = columns[getColumnOfChecker(checkerselected)].GetComponent <Column>();
            Column to    = AI.getTargetColumn(ref columns);
            Column onHit = columns[PlayerB.turn ? 25 : 24].GetComponent <Column>();
            bool   moved = move(from, to, onHit);

            if (moved)
            {
                checkerselected = null;
                movesTaken++;
            }
            if (PlayerA.won)
            {
                gameStatusText.text = loseMsg;
                Invoke("GoToScene", 5);
            }
            if (movesTaken == Moves)
            {
                setUnavailableToMove();
                state = GameState.Finalizing;
            }
            else
            {
                setUnavailableToMove();
                SetAvailableToMove();
                state = GameState.SelectingChecker;
            }
            MaterialUtilities.DisableColumnColliders(ref collidersSet, ref columns);
            MaterialUtilities.DisableMeshRenderers(ref columns);
        }
    }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="commandData"></param>
        /// <param name="message"></param>
        /// <param name="elements"></param>
        /// <returns></returns>
        Result IExternalCommand.Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            if (!TryGetActiveDocument(commandData, out Autodesk.Revit.DB.Document docToExport))
            {
                return(Result.Failed);
            }
            if (!TryGetDefaultView(docToExport, out View viewToExport))
            {
                return(Result.Failed);
            }


            // Grab doc name
            string docName = Path.GetFileNameWithoutExtension(docToExport.Title);

            // Prep FBX export
            var vs = new ViewSet();

            vs.Insert(viewToExport);

            // Grab configuration
            var configuration = ConfigurationManager.ActiveConfiguration;

            // Create a new folder for the export
            configuration.ExportFilePathRoot = $"C:/Cityzenith/{docName}";
            if (!Directory.Exists(configuration.ExportFilePathRoot))
            {
                Directory.CreateDirectory(configuration.ExportFilePathRoot);
            }

            // Export FBX file
            docToExport.Export(
                configuration.ExportFilePathRoot,
                docName,
                vs,
                new FBXExportOptions()
            {
                LevelsOfDetailValue  = 15,
                UseLevelsOfDetail    = true,
                WithoutBoundaryEdges = true
            }
                );



            // Check that file was created successfully
            var fbxFileName = configuration.ExportFilePathRoot + "/" + docName + ".fbx";

            if (!System.IO.File.Exists(fbxFileName))
            {
                return(Result.Failed);
            }
            var fbxModel = AssimpUtilities.LoadFbx(fbxFileName);

            // Get conversions between local ids
            var localToUniqueIdMap = docToExport.ExportableElements()
                                     .ToDictionary(e => e.Id.ToString(), e => e.UniqueId.ToString());

            // Replace auto-generated element names in Fbx with unqiue ids from revit doc
            AssimpUtilities.ReplaceNamesWithUniqueIds(fbxModel, localToUniqueIdMap);

            // Create textures subfolder
            string textureDirPath = configuration.ExportFilePathRoot + '/' + "Textures";

            if (!Directory.Exists(textureDirPath))
            {
                Directory.CreateDirectory(textureDirPath);
            }

            var bundles = MaterialUtilities.GetTextureBundles(docToExport, out var paths);

            foreach (var b in bundles)
            {
                // Create material
                var assimpMaterial = AssimpUtilities.ConvertToAssimpMaterial(b, docToExport);

                // Add material to model and assign
                AssimpUtilities.AddAndAssignMaterial(
                    fbxModel,
                    assimpMaterial,
                    docToExport.ExportableElements().Where(e =>
                {
                    var id = e.GetMaterialIds(false).FirstOrDefault();
                    if (id != null && id == b.Material.Id)
                    {
                        return(true);
                    }
                    return(false);
                })
                    .Select(e => e.UniqueId.ToString())
                    .ToHashSet()
                    , out bool utilized);

                if (!utilized)
                {
                    continue;
                }

                // Copy textures into textures folder
                foreach (var path in b.TexturePaths.Values)
                {
                    string destination = $"{textureDirPath}/{path.SafeFileName}";
                    try
                    {
                        File.Copy(path.FileLocation, destination, true);
                    }
                    catch (Exception e)
                    {
                        // This is likely due to duplicate materials copied in.
                        // This could also be an access issue, but less commonly.
                        //Logger.LogException("Error in copying textures: ", e);
                    }
                }
            }

            // Grab all element data
            var paramData = docToExport.SiphonElementParamValues(out var legend);
            var combined  = paramData.Values.Combine();

            JsonConvert.SerializeObject(combined).WriteToFile($"{configuration.ExportFilePathRoot}/Params.json");
            JsonConvert.SerializeObject(legend).WriteToFile($"{configuration.ExportFilePathRoot}/Legend.json");

            // Write out gltf
            AssimpUtilities.SaveToGltf(fbxModel, $"{configuration.ExportFilePathRoot}", docName);

            // Delete .FBX
            File.Delete(fbxFileName);

            // Let em know!
            TaskDialog dlg = new TaskDialog("Export Successful");

            dlg.MainInstruction = $"Gltf file exported successfully: \n\n {configuration.ExportFilePathRoot}";
            dlg.Show();

            Process.Start(configuration.ExportFilePathRoot);

            return(Result.Succeeded);
        }
Пример #4
0
    // Update is called once per frame
    void Update()
    {
        if (state == GameState.Rolling)
        {
            if (firstTimePlay)
            {
                decideWhoGoesFirst();
            }

            if (!rollButton.interactable)
            {
                rollButton.interactable = true;
            }
            else if (AIEnabled)
            {
                rollButton.onClick.Invoke();
            }
        }
        else if (state == GameState.SelectingChecker)
        {
            if (!undoButton.interactable && movesTaken != 0)
            {
                undoButton.interactable = true;
            }

            if (AIEnabled)
            {
                StartCoroutine(selectCheckerAfterSeconds(1f));
            }
            else
            {
                selectChecker();
            }
        }
        else if (state == GameState.SelectingColumn)
        {
            // enable the colliders
            MaterialUtilities.EnableColumnColliders(ref collidersSet, ref columns);
            MaterialUtilities.EnableMeshRenderers(PlayerA, PlayerB, checkerselected, diceToPlay, ref columns);

            if (collidersSet)
            {
                if (AIEnabled)
                {
                    StartCoroutine(selectTargetAfterSeconds(1f));
                }
                else
                {
                    selectTarget();
                }
            }
            else
            {
                state = GameState.Finalizing;
            }
        }
        else if (state == GameState.Finalizing)
        {
            if (!endButton.interactable)
            {
                endButton.interactable = true;
            }
        }
    }