using UnityEngine;
using System.Collections;
public class CurvedLinePoint : MonoBehaviour
{
[HideInInspector] public bool showGizmo = true;
[HideInInspector] public float gizmoSize = 0.1f;
[HideInInspector] public Color gizmoColor = new Color(1, 0, 0, 0.5f);
void OnDrawGizmos()
{
if (ResetLineRendererPositions.hasReseted == false)
{
if (showGizmo == true)
{
Gizmos.color = gizmoColor;
Gizmos.DrawSphere(this.transform.position, gizmoSize);
}
}
}
//update parent line when this point moved
void OnDrawGizmosSelected()
{
if (ResetLineRendererPositions.hasReseted == false)
{
CurvedLineRenderer curvedLine = this.transform.parent.GetComponent<CurvedLineRenderer>();
if (curvedLine != null)
{
curvedLine.Update();
}
}
}
}
Then I created two scripts one is editor type with two buttons. One to reset the linerenderer positions and one to generate the positions :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ResetLineRendererPositions : MonoBehaviour
{
public LineRenderer lineRenderer;
public static bool hasReseted = false;
public void ResetLinerendererPositions()
{
lineRenderer.positionCount = 0;
hasReseted = true;
}
public void GenerateLineRendererPositions()
{
hasReseted = false;
}
}
And
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(ResetLineRendererPositions))]
public class ResetLineRendererPositionsButton : Editor
{
public override void OnInspectorGUI()
{
ResetLineRendererPositions myScript = (ResetLineRendererPositions)target;
if (GUILayout.Button("Reset Linerenderer Positions"))
{
myScript.ResetLinerendererPositions();
}
GUILayout.Space(30);
if (GUILayout.Button("Generate Linerenderer Positions"))
{
myScript.GenerateLineRendererPositions();
}
}
}
The buttons are working the problem is when I click on the button "Generate Linerenderer Positions" then I have to select the linerenderer object in the hierarchy to make it take affect and draw the gizmos.
I want that when I click the "Generate Linerenderer Positions" button it will automatic run the code in the OnDrawGizmos and OnDrawGizmosSelected functions.