示例#1
0
 public S_SnapToObject()
 {
     if (m_prefabs != null && m_prefabs.Length == 1)
     {
         m_prefabs[0] = new S_SnapToObjectPrefab();
     }
 }
示例#2
0
 private void CreatePrefabPreview(S_SnapToObjectPrefab p_prefab)
 {
     if (p_prefab.m_currentInstance != null)
     {
         Debug.LogWarning("S_SnapToObject: CreatePrefabPreview: there was already an instance of this prefab '" + p_prefab.m_currentInstance.name + "'! Old instance will be destroyed...");
         Destroy(p_prefab.m_currentInstance);
     }
     if (p_prefab.PrefabResourcePath != null)
     {
         Object resource = Resources.Load(p_prefab.PrefabResourcePath);
         if (resource != null)
         {
             p_prefab.m_currentInstance = (GameObject)Instantiate(resource);
             p_prefab.m_currentInstance.transform.parent        = PreviewRoot;
             p_prefab.m_currentInstance.transform.localPosition = Vector3.zero;
             p_prefab.m_currentInstance.transform.localScale    = Vector3.one;
             // disable colliders if allowed, they could block mouse events otherwise
             if (p_prefab.IsCollidersDisabledInPreview)
             {
                 Collider[] colliders = p_prefab.m_currentInstance.GetComponentsInChildren <Collider>();
                 for (int i = 0; i < colliders.Length; i++)
                 {
                     colliders[i].enabled = false;
                 }
             }
             // scale down prefab for zoom out animation
             p_prefab.m_currentInstance.transform.localScale = MIN_SCALE;
             // add preview handling script
             p_prefab.m_currentInstancePreviewScript = p_prefab.m_currentInstance.AddComponent <S_SnapToObjectPreview>();
             p_prefab.m_currentInstancePreviewScript.Init(m_isDrawUI, PREVIEW_RELATIVE_SCREEN_CLICK_AREA, () =>
             {
                 PlacePrefabInternal(p_prefab);
             }, m_uiMaterialLine, m_uiMaterialFill);
             // notify listeners
             if (OnGlobalPreviewObjectInstantiated != null)
             {
                 OnGlobalPreviewObjectInstantiated(this, new S_SnapToObjectEventArgs(this, p_prefab.m_currentInstance));
             }
             if (OnPreviewObjectInstantiated != null)
             {
                 OnPreviewObjectInstantiated(this, new S_SnapToObjectEventArgs(this, p_prefab.m_currentInstance));
             }
         }
         else
         {
             Debug.LogError("S_SnapToObject: CreatePrefabPreview: could not find prefab in resources at '" + p_prefab.PrefabResourcePath + "'!");
         }
     }
     else
     {
         Debug.LogError("S_SnapToObject: CreatePrefabPreview: no prefab assigned!");
     }
 }
示例#3
0
        public void PlacePrefab(S_SnapToObjectPrefab p_prefab)
        {
            // instantly close selection
            if (m_isSelectionOpen)
            {
                DestroyAllPreviews();
                if (s_openSelection == this)
                {
                    s_openSelection = null;
                }
                m_isSelectionOpen   = false;
                m_animState         = EAnimationState.IDLE;
                m_zoomAnimationTime = -1f;
            }
            // create game object
            Object resource = Resources.Load(p_prefab.PrefabResourcePath);

            if (resource != null)
            {
                GameObject go = (GameObject)Instantiate(resource);
                if (m_isSetNameToResourcePath)
                {
                    go.name = p_prefab.PrefabResourcePath;
                }
                go.transform.localRotation = transform.rotation;
                go.transform.Rotate(p_prefab.LocalEulerRotation);
                go.transform.localScale = Vector3.Scale(p_prefab.LocalScale, transform.lossyScale);
                go.transform.position   = transform.position + go.transform.TransformPoint(p_prefab.LocalPosition);
                IncSnapCounter();
                // notify event listeners
                if (OnGlobalAfterObjectSnapped != null)
                {
                    OnGlobalAfterObjectSnapped(this, new S_SnapToObjectEventArgs(this, go));
                }
                if (OnAfterObjectSnapped != null)
                {
                    OnAfterObjectSnapped(this, new S_SnapToObjectEventArgs(this, go));
                }
            }
            else
            {
                Debug.LogError("S_SnapToObject: PlacePrefabInternal: could not find prefab in resources at '" + p_prefab.PrefabResourcePath + "'!");
            }
        }
示例#4
0
        private void PlacePrefabInternal(S_SnapToObjectPrefab p_prefab)
        {
            S_SnapToObjectBeforePlacementEventArgs beforePlacementArgs = new S_SnapToObjectBeforePlacementEventArgs(this, p_prefab);

            if (OnGlobalBeforeObjectSnapped != null)
            {
                OnGlobalBeforeObjectSnapped(this, beforePlacementArgs);
            }
            if (OnBeforeObjectSnapped != null)
            {
                OnBeforeObjectSnapped(this, beforePlacementArgs);
            }

            // if prefab placement is delayed, then the entity, which has changed beforePlacementArgs.IsDelayedPlacePrefab to true
            // is responsible for calling PlacePrefab later. This might be needed if further popups or UI is shown before placement.
            if (!beforePlacementArgs.IsDelayedPlacePrefab)
            {
                PlacePrefab(p_prefab);
            }
        }
 public S_SnapToObjectBeforePlacementEventArgs(S_SnapToObject p_source, S_SnapToObjectPrefab p_snapPrefab)
 {
     m_source     = p_source;
     m_snapPrefab = p_snapPrefab;
 }