bool HasSelectedTransparentAsset() { if (serializedObject.isEditingMultipleObjects) { UnityEngine.Object[] renderers = (UnityEngine.Object[])targets; for (int i = 0; i < renderers.Length; i++) { renderer = renderers [i] as SVGRenderer; if (renderer.vectorGraphics != null && renderer.vectorGraphics.format != SVGAssetFormat.Opaque) { return(true); } } } else { SVGRenderer renderer = target as SVGRenderer; if (renderer.vectorGraphics != null && renderer.vectorGraphics.format != SVGAssetFormat.Opaque) { return(true); } } return(false); }
protected static void RemoveSVGRenderer() { if (_renderer != null) { _renderer.vectorGraphics = null; GameObject.Destroy(_renderer.gameObject); _renderer = null; } }
// Code that runs on entering the state. public override void OnEnter() { var go = Fsm.GetOwnerDefaultTarget(gameObject); sprite = go.GetComponent <SVGImporter.SVGRenderer> (); sprite.color = color.Value; Finish(); }
void OnDisable() { if (svgRenderer == null) { svgRenderer = GetComponent <SVGRenderer>(); } svgRenderer.onVectorGraphicsChanged -= OnVectorGraphicsChanged; }
void RemoveSVGRenderer() { if (_editorRenderer != null) { _editorRenderer.vectorGraphics = null; DestroyImmediate(_editorRenderer.gameObject); _editorRenderer = null; //Debug.Log("Remove SVG Renderer"); } }
void OnEnable() { if (svgRenderer == null) { svgRenderer = GetComponent <SVGRenderer>(); } svgRenderer.onVectorGraphicsChanged += OnVectorGraphicsChanged; UpdateCollider(); }
void OnEnable() { vectorGraphics = serializedObject.FindProperty("_vectorGraphics"); color = serializedObject.FindProperty("_color"); transparentMaterial = serializedObject.FindProperty("_transparentMaterial"); opaqueMaterial = serializedObject.FindProperty("_opaqueMaterial"); type = serializedObject.FindProperty("_type"); sortingLayerID = serializedObject.FindProperty("_sortingLayerID"); // sortingLayerName = serializedObject.FindProperty("_sortingLayerName"); sortingOrder = serializedObject.FindProperty("_sortingOrder"); overrideSorter = serializedObject.FindProperty("_overrideSorter"); overrideSorterChildren = serializedObject.FindProperty("_overrideSorterChildren"); if (serializedObject.isEditingMultipleObjects) { SVGRenderer renderer = (SVGRenderer)target; Renderer meshRenderer = renderer.GetComponent <Renderer>(); if (meshRenderer != null) { //UnityEditor.EditorUtility.SetSelectedWireframeHidden(meshRenderer, true); EditorUtility.SetSelectedRenderState(meshRenderer, EditorSelectedRenderState.Wireframe); } } else { UnityEngine.Object[] renderers = (UnityEngine.Object[])targets; SVGRenderer renderer; if (renderers != null && renderers.Length > 0) { for (int i = 0; i < renderers.Length; i++) { renderer = renderers [i] as SVGRenderer; if (renderer == null) { continue; } MeshRenderer meshRenderer = renderer.GetComponent <MeshRenderer>(); if (meshRenderer != null) { EditorUtility.SetSelectedRenderState(meshRenderer, EditorSelectedRenderState.Wireframe); //EditorUtility.SetSelectedWireframeHidden(meshRenderer, true); } } } } }
public static GameObject DropSVGAssetToSceneToCreateGO(SVGAsset asset, Vector3 position) { GameObject go = new GameObject(asset.name); Undo.RegisterCreatedObjectUndo(go, "Create SVG Renderer"); //Vector3 destination = Camera.current.ScreenToWorldPoint(new Vector3(mousePosition.x, scenePosition.height - mousePosition.y, 0f)); //destination.z = 0f; go.transform.position = position; SVGRenderer renderer = go.AddComponent <SVGRenderer>(); renderer.vectorGraphics = asset; if (asset.generateCollider) { go.AddComponent <SVGCollider2D>(); } Selection.activeGameObject = go; return(go); }
public void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.tag == "Player") { GameLoop myGL = other.gameObject.transform.parent.gameObject.transform.parent.gameObject.GetComponent <GameLoop> (); if (myGL.pv.isMine == true) { // Make building transparent thisSvg = this.gameObject.GetComponent <SVGImporter.SVGRenderer> (); thisSvg.color = transparent; } // If not me if (myGL.pv.isMine == false) { } } }
void CreateSVGRenderer() { _editorRenderer = editorRenderer; }
protected virtual void Awake() { svgRenderer = GetComponent <SVGRenderer>(); }
public override void OnInspectorGUI() { serializedObject.Update(); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(vectorGraphics, new GUIContent("Vector Graphics")); EditorGUILayout.PropertyField(color, new GUIContent("Color")); if (!transparentMaterial.hasMultipleDifferentValues && !opaqueMaterial.hasMultipleDifferentValues) { if (transparentMaterial.objectReferenceValue != opaqueMaterial.objectReferenceValue) { EditorGUI.showMixedValue = true; Material material = EditorGUILayout.ObjectField("material", null, typeof(Material), false) as Material; if (material != null) { transparentMaterial.objectReferenceValue = material; opaqueMaterial.objectReferenceValue = material; } EditorGUI.showMixedValue = false; } else { Material oldMaterial = transparentMaterial.objectReferenceValue as Material; Material material = EditorGUILayout.ObjectField("material", oldMaterial, typeof(Material), false) as Material; if (oldMaterial != material) { transparentMaterial.objectReferenceValue = material; opaqueMaterial.objectReferenceValue = material; } } } EditorGUILayout.PropertyField(type, new GUIContent("Image Type")); if (type.hasMultipleDifferentValues || (SVGRenderer.Type)type.enumValueIndex == SVGRenderer.Type.Sliced) { RectTransform rectTransform = ((SVGRenderer)target).GetComponent <RectTransform>(); if (rectTransform == null) { EditorGUILayout.HelpBox("To use the sliced image type, you need to add RectTransform component first.", MessageType.Warning); } } materialsFoldout = EditorGUILayout.Foldout(materialsFoldout, "Advanced Materials"); if (materialsFoldout) { EditorGUI.indentLevel++; EditorGUILayout.PropertyField(transparentMaterial, new GUIContent("Transparent")); EditorGUILayout.PropertyField(opaqueMaterial, new GUIContent("Opaque")); if (HasSelectedTransparentAsset()) { OpaqueMaterialHelpBox(); } EditorGUI.indentLevel--; } sortingLayerFoldout = EditorGUILayout.Foldout(sortingLayerFoldout, "Sorting"); if (sortingLayerFoldout) { EditorGUI.indentLevel++; EditorGUILayout.LabelField("Unity Sorter", EditorStyles.boldLabel); MethodInfo sortingLayerField = typeof(EditorGUILayout).GetMethod("SortingLayerField", BindingFlags.Static | BindingFlags.NonPublic, System.Type.DefaultBinder, new System.Type[] { typeof(GUIContent), typeof(SerializedProperty), typeof(GUIStyle), typeof(GUIStyle) }, null ); if (sortingLayerField != null) { sortingLayerField.Invoke(null, new System.Object[] { new GUIContent("Sorting Layer"), sortingLayerID, EditorStyles.popup, EditorStyles.label }); } EditorGUILayout.PropertyField(sortingOrder); if (!HasSelectedTransparentAsset()) { SortingMaterialHelpBox(); } EditorGUILayout.Space(); EditorGUILayout.LabelField("SVG Sorter", EditorStyles.boldLabel); EditorGUILayout.PropertyField(overrideSorter); if (overrideSorter.hasMultipleDifferentValues || overrideSorter.boolValue) { EditorGUILayout.PropertyField(overrideSorterChildren, new GUIContent("Override Children", "Override sorting order in all children.")); } EditorGUI.indentLevel--; } if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); for (int i = 0; i < serializedObject.targetObjects.Length; i++) { SVGRenderer svgRenderer = serializedObject.targetObjects[i] as SVGRenderer; if (svgRenderer != null) { svgRenderer.UpdateRenderer(); } } } }
public override void Reset() { gameObject = null; color = null; sprite = null; }
protected virtual void UpdateCollider() { if (svgRenderer == null) { svgRenderer = GetComponent <SVGRenderer>(); } if (polygonCollider2D == null) { polygonCollider2D = GetComponent <PolygonCollider2D>(); } if (svgRenderer.vectorGraphics == null || svgRenderer.vectorGraphics.colliderShape == null || svgRenderer.vectorGraphics.colliderShape.Length == 0) { polygonCollider2D.pathCount = 0; polygonCollider2D.points = null; } else { SVGPath[] colliderShape = svgRenderer.vectorGraphics.colliderShape; polygonCollider2D.pathCount = 0; if (_quality < 1f) { Bounds bounds = svgRenderer.vectorGraphics.bounds; float finQuality = _quality; if (finQuality < 0.001f) { finQuality = 0.001f; } precision = Mathf.Max(bounds.size.x, bounds.size.y) / finQuality; if (precision < 0.001f) { precision = 0.001f; } precision *= 0.05f; } List <Vector2[]> optimisedPaths = new List <Vector2[]>(); Vector2[] points; for (int i = 0; i < colliderShape.Length; i++) { if (_quality < 1f) { points = SVGBezier.Optimise(colliderShape[i].points, precision); } else { points = (Vector2[])colliderShape[i].points.Clone(); } //bool clockwiseWinding = SVGGeomUtils.IsWindingClockWise(points); if (_offset != 0f) { points = SVGGeomUtils.OffsetVerts(points, _offset); } if (points != null && points.Length > 2) { optimisedPaths.Add(points); } } if (optimisedPaths.Count > 0) { polygonCollider2D.pathCount = optimisedPaths.Count; for (int i = 0; i < optimisedPaths.Count; i++) { polygonCollider2D.SetPath(i, optimisedPaths[i]); } } } }