コード例 #1
0
        // TODO -- account for scale and rotation
        public static void CenterPivot(this PolydrawObject poly)
        {
            if (!poly.isValid)
            {
                return;
            }

            Vector3[] v = poly.transform.ToWorldSpace(poly.points.ToVector3(poly.drawSettings.zPosition));

            Vector3 avg = Vector3.zero;

            for (int i = 0; i < v.Length; i++)
            {
                avg += v[i];
            }

            avg /= (float)v.Length;

            for (int i = 0; i < v.Length; i++)
            {
                v[i] -= avg;
            }

            poly.points = v.ToVector2();

            poly.Refresh();

            // go.GetComponent<MeshFilter>().sharedMesh.vertices = v;
            poly.transform.position = avg;
        }
コード例 #2
0
ファイル: DrawEditor.cs プロジェクト: wtrebella/Grappler
	private void OnEnable()
	{
		HANDLE_ICON_NORMAL = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/Polydraw/Icons/HandleIcon-Normal.png", typeof(Texture2D));
		HANDLE_ICON_ACTIVE = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/Polydraw/Icons/HandleIcon-Active.png", typeof(Texture2D));
		HANDLE_ICON_ACTIVEBORDERIGNORED = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/Polydraw/Icons/HandleIcon-ActiveBorderIgnored.png", typeof(Texture2D));
		HANDLE_ICON_BORDERIGNORED = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/Polydraw/Icons/HandleIcon-BorderIgnored.png", typeof(Texture2D));
		INSERT_ICON_ACTIVE = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/Polydraw/Icons/InsertPoint-Active.png", typeof(Texture2D));
		INSERT_ICON_NORMAL = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/Polydraw/Icons/InsertPoint-Normal.png", typeof(Texture2D));
		DELETE_ICON_ACTIVE = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/Polydraw/Icons/DeletePoint-Active.png", typeof(Texture2D));
		DELETE_ICON_NORMAL = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/Polydraw/Icons/DeletePoint-Normal.png", typeof(Texture2D));
		TOGGLEBORDERIGNORE_ICON = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/Polydraw/Icons/ToggleBorderIgnore.png", typeof(Texture2D));

		insertIconStyle = new GUIStyle();
		insertIconStyle.normal.background = INSERT_ICON_NORMAL;
		insertIconStyle.active.background = INSERT_ICON_ACTIVE;
		deletePointStyle = new GUIStyle();
		deletePointStyle.normal.background = DELETE_ICON_NORMAL;
		deletePointStyle.active.background = DELETE_ICON_ACTIVE;
		borderIgnoreStyle = new GUIStyle();
		borderIgnoreStyle.normal.background = TOGGLEBORDERIGNORE_ICON;
		borderIgnoreStyle.active.background = TOGGLEBORDERIGNORE_ICON;

		#if UNITY_4_3
			if(Undo.undoRedoPerformed != this.UndoRedoPerformed)
				Undo.undoRedoPerformed += this.UndoRedoPerformed;
		#endif

		poly = (PolydrawObject)target;

		snapEnabled = EditorPrefs.HasKey("polydraw_snapEnabled") ? EditorPrefs.GetBool("polydraw_snapEnabled") : false;
		snapValue= EditorPrefs.HasKey("polydraw_snapValue") ? EditorPrefs.GetFloat("polydraw_snapValue") : .25f;
	}
コード例 #3
0
	private void Awake() {
		poly = GetComponentInParent<PolydrawObject>();
		if (poly == null) Debug.LogError("no PolydrawObject parent!");
	}