Example #1
0
        private void Awake()
        {
            _text              = GetComponentInChildren <Text>();
            _camera            = Camera.main;
            _canvasGroup       = GetComponent <CanvasGroup>();
            _canvasGroup.alpha = 1;
            OnPointerExit(null);

            //DieSides component is required, but Die component is optional
            if (_dieSides != null)
            {
                _die = _dieSides.GetComponent <Die>();
                if (_die != null)
                {
                    _die.OnRollBegin += onDieRollBegin;
                    _die.OnRollEnd   += onDieRollEnd;
                }
            }
            else
            {
                Debug.Log("Please connect this script to an instance of DieSides.");
            }
        }
Example #2
0
        /**
         * Show the UI that allows you to trigger the side finding algorithm.
         */
        private void showCalculateSidesUI()
        {
            EditorGUILayout.HelpBox(
                "There is no side info available for this object, "+
                "press the 'Calculate sides' to fix this.", 
                MessageType.Info
            );

            _areaCutOffMultiplier = EditorGUILayout.Slider(
                new GUIContent(
                    "Cut off value:",
                    "All areas with a size that falls below " + (_areaCutOffMultiplier * 100) + "% of the maximum area size will be ignored."
                ),
                _areaCutOffMultiplier,
                0,
                1
            );

            if (GUILayout.Button("Calculate sides"))
            {
                //find all die sides through our findDieSides algorithm
                DieSides dieSides = target as DieSides;
                Mesh mesh = null;

                //if we have a collider, use the collider for the normals, otherwise our regular mesh
                MeshCollider meshCollider = dieSides.GetComponent<MeshCollider>();
                if (meshCollider != null)
                {
                    mesh = meshCollider.sharedMesh;
                } else
                {
                    MeshFilter meshFilter = dieSides.GetComponent<MeshFilter>();
                    mesh = meshFilter.sharedMesh;
                }

                List<DieAreaFinder.DieArea> foundSides = DieAreaFinder.FindDieAreas(mesh, _areaCutOffMultiplier);
				//show any debug data that was generated during this process
                _generationDebugData = DieAreaFinder.LogContents();
				_showGenerationDebugData = true;

				if (foundSides.Count == 0) return;

				_matchType.enumValueIndex = (foundSides.Count == 4) ? 1 : 0;

				//initialize our serialized properties with values based on the found die sides
				_dieSides.arraySize = foundSides.Count;

                for (int i = 0; i < foundSides.Count; i++)
                {
                    DieAreaFinder.DieArea foundSide = foundSides[i];
                    SerializedProperty dieSide = _dieSides.GetArrayElementAtIndex(i);
                    dieSide.FindPropertyRelative("_normal").vector3Value = foundSide.normal;
                    dieSide.FindPropertyRelative("_centerPoint").vector3Value = foundSide.centerPoint;
                }
                
				//make sure all data values are initialized for each dieside
                ensureDataValueCountPerSide();

				//save properties then align
				serializedObject.ApplyModifiedProperties();
				dieSides.transform.rotation = dieSides.GetWorldRotationFor(0);
            }
        }