private void OnScene(SceneView scene)
        {
            if (!enabled)
            {
                return;
            }
            if (goPainter == null)
            {
                goPainter = GetComponent <GOPainter>();
            }
            if (goPainter.active == false || !goPainter.showInfoBar)
            {
                return;
            }

            float offset = 0;

            if (TryGetComponent(out GORandomizer rand) && rand.enabled)
            {
                offset = 100;
            }
            if (!goPainter.alignWithStroke && !goPainter.alignWithSurface)
            {
                offset -= 140;
            }
            Handles.BeginGUI();

            GUI.Box(new Rect(offset + 140, scene.position.height - 77, 100, 30), "");
            GUI.skin.label.fontSize  = 13;
            GUI.skin.label.fontStyle = FontStyle.Normal;

            GUI.Label(new Rect(offset + 143, scene.position.height - 70, 100, 30), "Snap2Ground");

            Handles.EndGUI();
        }
        public void DeRegister()
        {
            if (goPainter == null)
            {
                goPainter = GetComponent <GOPainter>();
            }

            goPainter.OnObjectPainted     -= PopObject;
            goPainter.OnObjectMassPainted -= PopObjects;
        }
        void CastObjectDownInternal(GameObject go)
        {
            if (!enabled)
            {
                return;
            }
            if (this != null && goPainter == null)
            {
                goPainter = GetComponent <GOPainter>();
            }

            if (this != null && !enabled || goPainter.snapToGrid)
            {
                return;
            }
            //print("yo, snap down!");

            int layerMask = (1 << LayerMask.NameToLayer(goPainter.canvasLayer));

            if (goPainter.paintOnlyOnGround == false)
            {
                layerMask = ~(1 << LayerMask.NameToLayer(goPainter.editLayer));
            }

            RaycastHit[] hits      = null;
            Vector3      direction = goPainter.GetCanvasAxis();

            if (goPainter.GetSceneCamAxisPolarity() > 0)
            {
                direction *= -1;
            }
            if (goPainter.GetCanvasAxis() == Vector3.forward)
            {
                direction *= -1;
            }

            hits = Physics.RaycastAll(go.transform.position + direction * maxHeightToCastDownFrom, -direction, maxHeightToCastDownFrom * 10, layerMask);
            RaycastHit nearestHit      = new RaycastHit();
            float      nearestDistance = 99999;

            foreach (RaycastHit hit in hits)
            {
                if (hit.distance < nearestDistance && hit.collider.gameObject != go &&
                    !(goPainter.hideCanvas && hit.collider.gameObject == goPainter.paintCanvas))
                {
                    nearestDistance = hit.distance;
                    nearestHit      = hit;
                }
            }

            if (nearestHit.collider != null && nearestHit.collider.gameObject != go)
            {
                goPainter.SetObjectPosition(go, nearestHit.point, nearestHit.normal, true);
            }
        }
        public void DeRegister()
        {
#if UNITY_EDITOR
            if (goPainter == null)
            {
                goPainter = GetComponent <GOPainter>();
            }

            goPainter.OnObjectPainted     -= RandomizeTransform;
            goPainter.OnObjectMassPainted -= RandomizeMass;
            SceneView.duringSceneGui      -= OnScene;
#endif
        }
        void CastObjectsDown(GameObject[] gos, Vector3 axis, bool snapToGrid)
        {
            if (!enabled)
            {
                return;
            }
            if (this != null && goPainter == null)
            {
                goPainter = GetComponent <GOPainter>();
            }
            if (this != null && !enabled || snapToGrid)
            {
                return;
            }
            int layerMask = ~(1 << LayerMask.NameToLayer(goPainter.editLayer));

            foreach (GameObject go in gos)
            {
                RaycastHit[] hits      = null;
                Vector3      direction = axis;

                if (goPainter.GetSceneCamAxisPolarity() > 0)
                {
                    direction *= -1;
                }
                if (axis == Vector3.forward)
                {
                    direction *= -1;
                }

                hits = Physics.RaycastAll(go.transform.position + direction * maxHeightToCastDownFrom, -direction, maxHeightToCastDownFrom * 10, layerMask);
                RaycastHit nearestHit      = new RaycastHit();
                float      nearestDistance = 99999;

                foreach (RaycastHit hit in hits)
                {
                    if (hit.distance < nearestDistance && hit.collider.gameObject != go &&
                        !(goPainter.hideCanvas && hit.collider.gameObject == goPainter.paintCanvas))
                    {
                        nearestDistance = hit.distance;
                        nearestHit      = hit;
                    }
                }

                if (nearestHit.collider != null && nearestHit.collider.gameObject != go)
                {
                    goPainter.SetObjectPosition(go, nearestHit.point, nearestHit.normal, true);
                }
            }
        }
        public void DeRegister()
        {
            if (goPainter == null)
            {
                goPainter = GetComponent <GOPainter>();
            }

            goPainter.OnObjectPainted -= SwitchPrefab;

            if (factory == null)
            {
                factory = GetComponent <ObjectFactory>();
            }

            factory.OnObjectProduced -= SwitchProduced;

            SceneView.duringSceneGui -= OnScene;
        }
        public void DeRegister()
        {
            if (goPainter == null)
            {
                goPainter = GetComponent <GOPainter>();
            }

            goPainter.OnObjectMassPaintedLate -= CastObjectsDown;
            goPainter.OnObjectPainted         -= CastObjectDownGOP;

            if (factory == null)
            {
                factory = GetComponent <ObjectFactory>();
            }

            factory.OnObjectProducedLate -= CastObjectDown;
            factory.OnObjectUpdatedLate  -= CastObjectDown;

            SceneView.duringSceneGui -= OnScene;
        }
        private void Awake()
        {
#if UNITY_EDITOR
            if (goPainter == null)
            {
                goPainter = GetComponent <GOPainter>();
            }
#endif
            propBlock = new MaterialPropertyBlock();

            Marker[] markers = GameObject.FindObjectsOfType <Marker>();
            if (markers == null)
            {
                return;
            }
            foreach (Marker marker in markers)
            {
                DoColorVariateCheck(marker.gameObject);
            }
        }
        protected GameObject CreateFromTemplate(GameObject template, Vector3 position)
        {
            if (gop == null)
            {
                gop = GetComponent <GOPainter>();
            }

            GameObject product = null;

            if (template.IsPrefab() && !Application.isPlaying)
            {
                product = PrefabUtility.InstantiatePrefab(template.GetPrefabAsset()) as GameObject;
            }
            else
            {
                product = Instantiate(template, CalcPos(position), template.transform.rotation);
            }

            product.transform.position = CalcPos(position);
            product.transform.rotation = template.transform.rotation;
            origLayer     = product.layer;
            product.layer = LayerMask.NameToLayer(gop.editLayer);

            if (objectEuler != Vector3.zero)
            {
                Transform center = product.transform.Find("Center");
                if (center != null)
                {
                    center.eulerAngles = objectEuler;
                }
                else
                {
                    product.transform.eulerAngles = objectEuler;
                }
            }
            product.transform.localScale = objectScale;

            // Fix naming
            if (product.name.StartsWith(gop.PickedPrefix))
            {
                product.name = product.name.Substring(gop.PickedPrefix.Length);
            }
            if (product.name.EndsWith("(Clone)"))
            {
                product.name = product.name.Substring(0, product.name.Length - "(Clone)".Length);
            }

            string appendix = "";

            if (appendChargeNumber)
            {
                appendix += "_" + charge;
            }
            if (appendIndexNumber)
            {
                appendix += "_" + products.Count;
            }

            product.name += appendix;

            if (createUnderGroup)
            {
                if (group == null)
                {
                    product.transform.SetParent(this.transform, true);
                }
                else
                {
                    product.transform.SetParent(group, true);
                }
            }

            return(product);
        }
 private void Awake()
 {
     gop = GetComponent <GOPainter>();
 }